Skip to content

Commit

Permalink
17
Browse files Browse the repository at this point in the history
17
  • Loading branch information
umerov1999 committed Mar 23, 2023
1 parent 9a9cb3d commit 36286c5
Show file tree
Hide file tree
Showing 59 changed files with 350 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ class DeltaOwnerActivity : AppCompatActivity(), PlaceProvider, AppStyleable {
)

val viewPager: ViewPager2 = findViewById(R.id.delta_pager)
viewPager.offscreenPageLimit = 1
viewPager.setPageTransformer(
Utils.createPageTransform(
Settings.get().main().viewpager_page_transform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ class SendAttachmentsActivity : MainActivity() {
context.startActivity(intent)
}

fun startForSendAttachmentsIntent(
context: Context,
accountId: Long,
bundle: ModelsBundle?
): Intent {
val intent = Intent(context, SendAttachmentsActivity::class.java)
intent.action = ACTION_SEND_ATTACHMENTS
intent.putExtra(EXTRA_INPUT_ATTACHMENTS, bundle)
intent.putExtra(EXTRA_NO_REQUIRE_PIN, true)
intent.putExtra(Extra.PLACE, PlaceFactory.getDialogsPlace(accountId, accountId, null))
return intent
}

fun startForSendAttachmentsFor(
context: Context,
accountId: Long,
Expand All @@ -62,11 +75,17 @@ class SendAttachmentsActivity : MainActivity() {
context.startActivity(intent)
}


fun startForSendAttachments(context: Context, accountId: Long, model: AbsModel) {
startForSendAttachments(context, accountId, ModelsBundle(1).append(model))
}

fun startForSendAttachmentsIntent(
context: Context,
accountId: Long,
model: AbsModel
): Intent {
return startForSendAttachmentsIntent(context, accountId, ModelsBundle(1).append(model))
}

fun startForSendAttachmentsFor(
context: Context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class VideoPlayerActivity : AppCompatActivity(), SurfaceHolder.Callback,
VideoControllerView.MediaPlayerControl, IVideoPlayer.IVideoSizeChangeListener, AppStyleable {
private val mCompositeDisposable = CompositeDisposable()
private var mDecorView: View? = null
private var mSpeed: ImageView? = null
private var mPlaySpeed: ImageView? = null
private var mControllerView: VideoControllerView? = null
private var mSurfaceView: ExpandableSurfaceView? = null
private var mPlayer: IVideoPlayer? = null
Expand Down Expand Up @@ -251,17 +251,17 @@ class VideoPlayerActivity : AppCompatActivity(), SurfaceHolder.Callback,
if (seekSave > 0) {
mPlayer?.seekTo(seekSave)
}
mSpeed = findViewById(R.id.toolbar_play_speed)
mPlaySpeed = findViewById(R.id.toolbar_play_speed)
Utils.setTint(
mSpeed,
mPlaySpeed,
if (mPlayer?.isPlaybackSpeed == true) CurrentTheme.getColorPrimary(this) else Color.parseColor(
"#ffffff"
)
)
mSpeed?.setOnClickListener {
mPlaySpeed?.setOnClickListener {
mPlayer?.togglePlaybackSpeed()
Utils.setTint(
mSpeed,
mPlaySpeed,
if (mPlayer?.isPlaybackSpeed == true) CurrentTheme.getColorPrimary(this) else Color.parseColor(
"#ffffff"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class GifPagerActivity : AbsDocumentPreviewActivity<GifPagerPresenter, IGifPager
presenter?.fireAddDeleteButtonClick()
}
mViewPager = findViewById(R.id.view_pager)
mViewPager?.offscreenPageLimit = 1
mViewPager?.setPageTransformer(
Utils.createPageTransform(
Settings.get().main().viewpager_page_transform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ class PhotoPagerActivity : BaseMvpActivity<PhotoPagerPresenter, IPhotoPagerView>
mToolbar = findViewById(R.id.toolbar)
setSupportActionBar(mToolbar)
mViewPager = findViewById(R.id.view_pager)
mViewPager?.offscreenPageLimit = 1
mViewPager?.setPageTransformer(
Utils.createPageTransform(
Settings.get().main().viewpager_page_transform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface IShortVideoPagerView : IMvpView, IErrorView, IToastView {
fun setPreparingProgressVisible(position: Int, preparing: Boolean)
fun attachDisplayToPlayer(adapterPosition: Int, storyPlayer: IStoryPlayer?)
fun setToolbarTitle(@StringRes titleRes: Int, vararg params: Any?)
fun setToolbarSubtitle(shortVideo: Video, account_id: Long)
fun setToolbarSubtitle(shortVideo: Video, account_id: Long, isPlaySpeed: Boolean)
fun onShare(shortVideo: Video, account_id: Long)
fun configHolder(adapterPosition: Int, progress: Boolean, aspectRatioW: Int, aspectRatioH: Int)
fun onNext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import dev.ragnarok.fenrir.view.CircleCounterButton
import dev.ragnarok.fenrir.view.ExpandableSurfaceView
import dev.ragnarok.fenrir.view.natives.rlottie.RLottieImageView
import io.reactivex.rxjava3.core.Completable
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.disposables.Disposable
import java.lang.ref.WeakReference
import java.util.concurrent.TimeUnit
Expand All @@ -60,6 +61,7 @@ class ShortVideoPagerActivity : BaseMvpActivity<ShortVideoPagerPresenter, IShort
private var mViewPager: ViewPager2? = null
private var mToolbar: Toolbar? = null
private var mAvatar: ImageView? = null
private var mPlaySpeed: ImageView? = null
private var transformation: Transformation? = null
private var mDownload: CircleCounterButton? = null
private var mShare: CircleCounterButton? = null
Expand All @@ -72,7 +74,8 @@ class ShortVideoPagerActivity : BaseMvpActivity<ShortVideoPagerPresenter, IShort
private var mLoadingProgressBarDispose = Disposable.disposed()
private var mLoadingProgressBarLoaded = false
private var mLoadingProgressBar: RLottieImageView? = null
private var shortVideoLength: TextView? = null
private var shortVideoDuration: TextView? = null
private var playDispose = Disposable.disposed()

@LayoutRes
override fun getNoMainContentView(): Int {
Expand All @@ -88,10 +91,19 @@ class ShortVideoPagerActivity : BaseMvpActivity<ShortVideoPagerPresenter, IShort
setSupportActionBar(mToolbar)
mAvatar = findViewById(R.id.toolbar_avatar)
mViewPager = findViewById(R.id.view_pager)
mViewPager?.offscreenPageLimit = 1
likeButton = findViewById(R.id.like_button)
commentsButton = findViewById(R.id.comments_button)
shortVideoLength = findViewById(R.id.item_short_video_length)
shortVideoDuration = findViewById(R.id.item_short_video_duration)
mPlaySpeed = findViewById(R.id.toolbar_play_speed)
mPlaySpeed?.setOnClickListener {
val stateSpeed = presenter?.togglePlaybackSpeed() ?: false
Utils.setTint(
mPlaySpeed,
if (stateSpeed) CurrentTheme.getColorPrimary(this) else Color.parseColor(
"#ffffff"
)
)
}
commentsButton?.setOnClickListener {
presenter?.fireCommentsClick()
}
Expand Down Expand Up @@ -130,7 +142,11 @@ class ShortVideoPagerActivity : BaseMvpActivity<ShortVideoPagerPresenter, IShort
mViewPager?.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
presenter?.firePageSelected(position)
playDispose.dispose()
playDispose = Observable.just(Object())
.delay(400, TimeUnit.MILLISECONDS)
.toMainThread()
.subscribe { presenter?.firePageSelected(position) }
}
})
mDownload = findViewById(R.id.button_download)
Expand Down Expand Up @@ -412,7 +428,7 @@ class ShortVideoPagerActivity : BaseMvpActivity<ShortVideoPagerPresenter, IShort
supportActionBar?.title = getString(titleRes, *params)
}

override fun setToolbarSubtitle(shortVideo: Video, account_id: Long) {
override fun setToolbarSubtitle(shortVideo: Video, account_id: Long, isPlaySpeed: Boolean) {
supportActionBar?.subtitle = shortVideo.optionalOwner?.fullName
mAvatar?.setOnClickListener {
shortVideo.optionalOwner?.let { it1 ->
Expand All @@ -428,7 +444,13 @@ class ShortVideoPagerActivity : BaseMvpActivity<ShortVideoPagerPresenter, IShort
Constants.PICASSO_TAG
)
}
shortVideoLength?.text = AppTextUtils.getDurationString(shortVideo.duration)
Utils.setTint(
mPlaySpeed,
if (isPlaySpeed) CurrentTheme.getColorPrimary(this) else Color.parseColor(
"#ffffff"
)
)
shortVideoDuration?.text = AppTextUtils.getDurationString(shortVideo.duration)
displayLikes(shortVideo.likesCount, shortVideo.isUserLikes)
displayCommentCount(shortVideo.commentsCount)
}
Expand All @@ -453,6 +475,7 @@ class ShortVideoPagerActivity : BaseMvpActivity<ShortVideoPagerPresenter, IShort
super.onDestroy()
helpDisposable.dispose()
mLoadingProgressBarDispose.dispose()
playDispose.dispose()
}

override fun onNext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ShortVideoPagerPresenter(
private var nextFrom: String? = null
private var isEndContent: Boolean = false
private var loadingNow = false
private var isPlayBackSpeed = false

override fun onGuiCreated(viewHost: IShortVideoPagerView) {
super.onGuiCreated(viewHost)
Expand All @@ -48,6 +49,12 @@ class ShortVideoPagerPresenter(
resolveToolbarSubtitle()
}

fun togglePlaybackSpeed(): Boolean {
isPlayBackSpeed = !isPlayBackSpeed
mShortVideoPlayer?.setPlaybackSpeed(isPlayBackSpeed)
return isPlayBackSpeed
}

private fun receiveShortVideos() {
loadingNow = true
view?.displayListLoading(loadingNow)
Expand Down Expand Up @@ -123,11 +130,7 @@ class ShortVideoPagerPresenter(
}

private fun initStoryPlayer() {
if (mShortVideoPlayer != null) {
val old: IStoryPlayer? = mShortVideoPlayer
mShortVideoPlayer = null
old?.release()
}
val update: Boolean = mShortVideoPlayer != null
val shortVideo = mShortVideos[mCurrentIndex]
val url = firstNonEmptyString(
shortVideo.mp4link2160, shortVideo.mp4link1440,
Expand All @@ -138,9 +141,14 @@ class ShortVideoPagerPresenter(
view?.showError(R.string.unable_to_play_file)
return
}
mShortVideoPlayer = storyPlayerFactory.createStoryPlayer(url, false)
mShortVideoPlayer?.addStatusChangeListener(this)
mShortVideoPlayer?.addVideoSizeChangeListener(this)
if (!update) {
mShortVideoPlayer = storyPlayerFactory.createStoryPlayer(url, false)
mShortVideoPlayer?.setPlaybackSpeed(isPlayBackSpeed)
mShortVideoPlayer?.addStatusChangeListener(this)
mShortVideoPlayer?.addVideoSizeChangeListener(this)
} else {
mShortVideoPlayer?.updateSource(url)
}
try {
mShortVideoPlayer?.play()
} catch (e: Exception) {
Expand Down Expand Up @@ -191,7 +199,7 @@ class ShortVideoPagerPresenter(
}
view?.setToolbarSubtitle(
mShortVideos[mCurrentIndex],
accountId
accountId, isPlayBackSpeed
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface IStoryPagerView : IMvpView, IErrorView, IToastView {
fun setPreparingProgressVisible(position: Int, preparing: Boolean)
fun attachDisplayToPlayer(adapterPosition: Int, storyPlayer: IStoryPlayer?)
fun setToolbarTitle(@StringRes titleRes: Int, vararg params: Any?)
fun setToolbarSubtitle(story: Story, account_id: Long)
fun setToolbarSubtitle(story: Story, account_id: Long, isPlaySpeed: Boolean)
fun onShare(story: Story, account_id: Long)
fun configHolder(adapterPosition: Int, progress: Boolean, aspectRatioW: Int, aspectRatioH: Int)
fun onNext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import dev.ragnarok.fenrir.place.PlaceProvider
import dev.ragnarok.fenrir.settings.CurrentTheme
import dev.ragnarok.fenrir.settings.Settings
import dev.ragnarok.fenrir.util.AppPerms.requestPermissionsAbs
import dev.ragnarok.fenrir.util.AppTextUtils
import dev.ragnarok.fenrir.util.HelperSimple
import dev.ragnarok.fenrir.util.Utils
import dev.ragnarok.fenrir.util.ViewUtils
Expand All @@ -59,6 +60,7 @@ import dev.ragnarok.fenrir.view.TouchImageView
import dev.ragnarok.fenrir.view.natives.rlottie.RLottieImageView
import dev.ragnarok.fenrir.view.pager.WeakPicassoLoadCallback
import io.reactivex.rxjava3.core.Completable
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.disposables.Disposable
import java.lang.ref.WeakReference
import java.util.Calendar
Expand All @@ -70,14 +72,17 @@ class StoryPagerActivity : BaseMvpActivity<StoryPagerPresenter, IStoryPagerView>
private var mViewPager: ViewPager2? = null
private var mToolbar: Toolbar? = null
private var mAvatar: ImageView? = null
private var mExp: TextView? = null
private var mExpires: TextView? = null
private var mDuration: TextView? = null
private var transformation: Transformation? = null
private var mDownload: CircleCounterButton? = null
private var mShare: CircleCounterButton? = null
private var mLink: CircleCounterButton? = null
private var mFullscreen = false
private var hasExternalUrl = false
private var mPlaySpeed: ImageView? = null
private var helpDisposable = Disposable.disposed()
private var playDispose = Disposable.disposed()

@LayoutRes
override fun getNoMainContentView(): Int {
Expand All @@ -93,13 +98,23 @@ class StoryPagerActivity : BaseMvpActivity<StoryPagerPresenter, IStoryPagerView>
setSupportActionBar(mToolbar)
mAvatar = findViewById(R.id.toolbar_avatar)
mViewPager = findViewById(R.id.view_pager)
mViewPager?.offscreenPageLimit = 1
mViewPager?.setPageTransformer(
Utils.createPageTransform(
Settings.get().main().viewpager_page_transform
)
)
mExp = findViewById(R.id.item_story_expires)
mExpires = findViewById(R.id.item_story_expires)
mDuration = findViewById(R.id.item_story_duration)
mPlaySpeed = findViewById(R.id.toolbar_play_speed)
mPlaySpeed?.setOnClickListener {
val stateSpeed = presenter?.togglePlaybackSpeed() ?: false
Utils.setTint(
mPlaySpeed,
if (stateSpeed) CurrentTheme.getColorPrimary(this) else Color.parseColor(
"#ffffff"
)
)
}
val mHelper = findViewById<RLottieImageView?>(R.id.swipe_helper)
if (HelperSimple.needHelp(HelperSimple.STORY_HELPER, 2)) {
mHelper?.visibility = View.VISIBLE
Expand All @@ -122,7 +137,11 @@ class StoryPagerActivity : BaseMvpActivity<StoryPagerPresenter, IStoryPagerView>
mViewPager?.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
presenter?.firePageSelected(position)
playDispose.dispose()
playDispose = Observable.just(Object())
.delay(400, TimeUnit.MILLISECONDS)
.toMainThread()
.subscribe { presenter?.firePageSelected(position) }
}
})
mDownload = findViewById(R.id.button_download)
Expand Down Expand Up @@ -327,7 +346,7 @@ class StoryPagerActivity : BaseMvpActivity<StoryPagerPresenter, IStoryPagerView>
supportActionBar?.title = getString(titleRes, *params)
}

override fun setToolbarSubtitle(story: Story, account_id: Long) {
override fun setToolbarSubtitle(story: Story, account_id: Long, isPlaySpeed: Boolean) {
supportActionBar?.subtitle = story.owner?.fullName
mAvatar?.setOnClickListener {
story.owner?.let { it1 ->
Expand All @@ -343,10 +362,10 @@ class StoryPagerActivity : BaseMvpActivity<StoryPagerPresenter, IStoryPagerView>
Constants.PICASSO_TAG
)
}
if (story.expires <= 0) mExp?.visibility = View.GONE else {
mExp?.visibility = View.VISIBLE
if (story.expires <= 0) mExpires?.visibility = View.GONE else {
mExpires?.visibility = View.VISIBLE
val exp = (story.expires - Calendar.getInstance().time.time / 1000) / 3600
mExp?.text = getString(
mExpires?.text = getString(
R.string.expires,
exp.toString(),
getString(
Expand All @@ -357,6 +376,20 @@ class StoryPagerActivity : BaseMvpActivity<StoryPagerPresenter, IStoryPagerView>
)
)
}
if (story.isStoryIsVideo()) {
mDuration?.visibility = View.VISIBLE
mDuration?.text = story.video?.duration?.let { AppTextUtils.getDurationString(it) }
mPlaySpeed?.visibility = View.VISIBLE
} else {
mDuration?.visibility = View.GONE
mPlaySpeed?.visibility = View.GONE
}
Utils.setTint(
mPlaySpeed,
if (isPlaySpeed) CurrentTheme.getColorPrimary(this) else Color.parseColor(
"#ffffff"
)
)
if (story.target_url.isNullOrEmpty()) {
mLink?.visibility = View.GONE
hasExternalUrl = false
Expand Down Expand Up @@ -392,6 +425,7 @@ class StoryPagerActivity : BaseMvpActivity<StoryPagerPresenter, IStoryPagerView>
override fun onDestroy() {
super.onDestroy()
helpDisposable.dispose()
playDispose.dispose()
}

override fun onNext() {
Expand Down
Loading

0 comments on commit 36286c5

Please sign in to comment.