mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-29 09:39:03 +03:00
rewrite next/previous episode functions
This commit is contained in:
parent
56b2c12a97
commit
6de403b404
7 changed files with 40 additions and 43 deletions
|
@ -68,7 +68,8 @@ abstract class SearchableNucleusController<VB : ViewBinding, P : BasePresenter<*
|
||||||
editable.getSpans(0, editable.length, CharacterStyle::class.java)
|
editable.getSpans(0, editable.length, CharacterStyle::class.java)
|
||||||
.forEach { editable.removeSpan(it) }
|
.forEach { editable.removeSpan(it) }
|
||||||
}
|
}
|
||||||
},)
|
},
|
||||||
|
)
|
||||||
|
|
||||||
searchView.queryTextEvents()
|
searchView.queryTextEvents()
|
||||||
.onEach {
|
.onEach {
|
||||||
|
|
|
@ -307,8 +307,8 @@ class PlayerActivity :
|
||||||
binding.playbackSeekbar.setOnSeekBarChangeListener(seekBarChangeListener)
|
binding.playbackSeekbar.setOnSeekBarChangeListener(seekBarChangeListener)
|
||||||
// player.playFile(currentVideoList!!.first().videoUrl!!.toString())
|
// player.playFile(currentVideoList!!.first().videoUrl!!.toString())
|
||||||
|
|
||||||
binding.nextBtn.setOnClickListener { goNextEpisode() }
|
binding.nextBtn.setOnClickListener { switchEpisode(false) }
|
||||||
binding.prevBtn.setOnClickListener { goPreviousEpisode() }
|
binding.prevBtn.setOnClickListener { switchEpisode(true) }
|
||||||
|
|
||||||
if (presenter?.needsInit() == true) {
|
if (presenter?.needsInit() == true) {
|
||||||
val anime = intent.extras!!.getLong("anime", -1)
|
val anime = intent.extras!!.getLong("anime", -1)
|
||||||
|
@ -323,39 +323,30 @@ class PlayerActivity :
|
||||||
playerIsDestroyed = false
|
playerIsDestroyed = false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun goNextEpisode() {
|
/**
|
||||||
|
* Switches to the previous episode if [previous] is true,
|
||||||
|
* to the next episode if [previous] is false
|
||||||
|
*/
|
||||||
|
private fun switchEpisode(previous: Boolean) {
|
||||||
|
val switchMethod = if (previous) presenter::previousEpisode else presenter::nextEpisode
|
||||||
|
val errorRes = if (previous) R.string.no_previous_episode else R.string.no_next_episode
|
||||||
|
|
||||||
|
presenter.saveEpisodeProgress(player.timePos, player.duration)
|
||||||
|
presenter.saveEpisodeHistory()
|
||||||
val wasPlayerPaused = player.paused
|
val wasPlayerPaused = player.paused
|
||||||
player.paused = true
|
player.paused = true
|
||||||
showLoadingIndicator(true)
|
showLoadingIndicator(true)
|
||||||
|
|
||||||
val nEpTxt = presenter.nextEpisode {
|
val epTxt = switchMethod {
|
||||||
if (wasPlayerPaused == false) {
|
if (wasPlayerPaused == false) {
|
||||||
player.paused = false
|
player.paused = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
when {
|
when {
|
||||||
nEpTxt == "Invalid" -> return
|
epTxt == "Invalid" -> return
|
||||||
nEpTxt == null -> { launchUI { toast(R.string.no_next_episode) }; showLoadingIndicator(false) }
|
epTxt == null -> { launchUI { toast(errorRes) }; showLoadingIndicator(false) }
|
||||||
isInPipMode -> launchUI { toast(nEpTxt) }
|
isInPipMode -> launchUI { toast(epTxt) }
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun goPreviousEpisode() {
|
|
||||||
val wasPlayerPaused = player.paused
|
|
||||||
player.paused = true
|
|
||||||
showLoadingIndicator(true)
|
|
||||||
|
|
||||||
val pEpTxt = presenter.previousEpisode {
|
|
||||||
if (wasPlayerPaused == false) {
|
|
||||||
player.paused = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
when {
|
|
||||||
pEpTxt == "Invalid" -> return
|
|
||||||
pEpTxt == null -> { launchUI { toast(R.string.no_previous_episode) }; showLoadingIndicator(false) }
|
|
||||||
isInPipMode -> launchUI { toast(pEpTxt) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -848,11 +839,11 @@ class PlayerActivity :
|
||||||
updatePictureInPictureActions(false)
|
updatePictureInPictureActions(false)
|
||||||
}
|
}
|
||||||
CONTROL_TYPE_PREVIOUS -> {
|
CONTROL_TYPE_PREVIOUS -> {
|
||||||
goPreviousEpisode()
|
switchEpisode(true)
|
||||||
player.paused?.let { updatePictureInPictureActions(!it) }
|
player.paused?.let { updatePictureInPictureActions(!it) }
|
||||||
}
|
}
|
||||||
CONTROL_TYPE_NEXT -> {
|
CONTROL_TYPE_NEXT -> {
|
||||||
goNextEpisode()
|
switchEpisode(false)
|
||||||
player.paused?.let { updatePictureInPictureActions(!it) }
|
player.paused?.let { updatePictureInPictureActions(!it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -882,7 +873,7 @@ class PlayerActivity :
|
||||||
iconResId: Int,
|
iconResId: Int,
|
||||||
titleResId: Int,
|
titleResId: Int,
|
||||||
requestCode: Int,
|
requestCode: Int,
|
||||||
controlType: Int
|
controlType: Int,
|
||||||
): RemoteAction {
|
): RemoteAction {
|
||||||
return RemoteAction(
|
return RemoteAction(
|
||||||
Icon.createWithResource(this, iconResId),
|
Icon.createWithResource(this, iconResId),
|
||||||
|
@ -893,14 +884,14 @@ class PlayerActivity :
|
||||||
requestCode,
|
requestCode,
|
||||||
Intent(ACTION_MEDIA_CONTROL)
|
Intent(ACTION_MEDIA_CONTROL)
|
||||||
.putExtra(EXTRA_CONTROL_TYPE, controlType),
|
.putExtra(EXTRA_CONTROL_TYPE, controlType),
|
||||||
PendingIntent.FLAG_IMMUTABLE
|
PendingIntent.FLAG_IMMUTABLE,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
fun updatePictureInPictureActions(
|
fun updatePictureInPictureActions(
|
||||||
playing: Boolean
|
playing: Boolean,
|
||||||
): PictureInPictureParams {
|
): PictureInPictureParams {
|
||||||
val mPictureInPictureParams = PictureInPictureParams.Builder()
|
val mPictureInPictureParams = PictureInPictureParams.Builder()
|
||||||
// Set action items for the picture-in-picture mode. These are the only custom controls
|
// Set action items for the picture-in-picture mode. These are the only custom controls
|
||||||
|
@ -912,7 +903,7 @@ class PlayerActivity :
|
||||||
R.drawable.ic_skip_previous_24dp,
|
R.drawable.ic_skip_previous_24dp,
|
||||||
R.string.action_previous_episode,
|
R.string.action_previous_episode,
|
||||||
CONTROL_TYPE_PREVIOUS,
|
CONTROL_TYPE_PREVIOUS,
|
||||||
REQUEST_PREVIOUS
|
REQUEST_PREVIOUS,
|
||||||
),
|
),
|
||||||
|
|
||||||
if (playing) {
|
if (playing) {
|
||||||
|
@ -920,24 +911,24 @@ class PlayerActivity :
|
||||||
R.drawable.ic_pause_24dp,
|
R.drawable.ic_pause_24dp,
|
||||||
R.string.action_pause,
|
R.string.action_pause,
|
||||||
CONTROL_TYPE_PAUSE,
|
CONTROL_TYPE_PAUSE,
|
||||||
REQUEST_PAUSE
|
REQUEST_PAUSE,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
createRemoteAction(
|
createRemoteAction(
|
||||||
R.drawable.ic_play_arrow_24dp,
|
R.drawable.ic_play_arrow_24dp,
|
||||||
R.string.action_play,
|
R.string.action_play,
|
||||||
CONTROL_TYPE_PLAY,
|
CONTROL_TYPE_PLAY,
|
||||||
REQUEST_PLAY
|
REQUEST_PLAY,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
createRemoteAction(
|
createRemoteAction(
|
||||||
R.drawable.ic_skip_next_24dp,
|
R.drawable.ic_skip_next_24dp,
|
||||||
R.string.action_next_episode,
|
R.string.action_next_episode,
|
||||||
CONTROL_TYPE_NEXT,
|
CONTROL_TYPE_NEXT,
|
||||||
REQUEST_NEXT
|
REQUEST_NEXT,
|
||||||
)
|
),
|
||||||
|
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
.setAspectRatio(player.videoAspect?.times(10000)?.let { Rational(it.toInt(), 10000) })
|
.setAspectRatio(player.videoAspect?.times(10000)?.let { Rational(it.toInt(), 10000) })
|
||||||
.build()
|
.build()
|
||||||
|
|
|
@ -363,7 +363,8 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||||
override fun onStopTrackingTouch(slider: Slider) {
|
override fun onStopTrackingTouch(slider: Slider) {
|
||||||
isScrollingThroughPages = false
|
isScrollingThroughPages = false
|
||||||
}
|
}
|
||||||
},)
|
},
|
||||||
|
)
|
||||||
binding.pageSlider.addOnChangeListener { slider, value, fromUser ->
|
binding.pageSlider.addOnChangeListener { slider, value, fromUser ->
|
||||||
if (viewer != null && fromUser) {
|
if (viewer != null && fromUser) {
|
||||||
isScrollingThroughPages = true
|
isScrollingThroughPages = true
|
||||||
|
|
|
@ -54,7 +54,8 @@ class ReaderSettingsSheet(
|
||||||
activity.setMenuVisibility(!isFilterTab)
|
activity.setMenuVisibility(!isFilterTab)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},)
|
},
|
||||||
|
)
|
||||||
|
|
||||||
if (showColorFilterSettings) {
|
if (showColorFilterSettings) {
|
||||||
binding.tabs.getTabAt(filterTabIndex)?.select()
|
binding.tabs.getTabAt(filterTabIndex)?.select()
|
||||||
|
|
|
@ -120,7 +120,8 @@ class TachiyomiBottomNavigationView @JvmOverloads constructor(
|
||||||
currentAnimator = null
|
currentAnimator = null
|
||||||
postInvalidate()
|
postInvalidate()
|
||||||
}
|
}
|
||||||
},)
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class SavedState : AbsSavedState {
|
internal class SavedState : AbsSavedState {
|
||||||
|
|
|
@ -42,7 +42,8 @@ class ThemesPreference @JvmOverloads constructor(context: Context, attrs: Attrib
|
||||||
super.onScrolled(recyclerView, dx, dy)
|
super.onScrolled(recyclerView, dx, dy)
|
||||||
lastScrollPosition = recyclerView.computeHorizontalScrollOffset()
|
lastScrollPosition = recyclerView.computeHorizontalScrollOffset()
|
||||||
}
|
}
|
||||||
},)
|
},
|
||||||
|
)
|
||||||
lastScrollPosition?.let { scrollToOffset(it) }
|
lastScrollPosition?.let { scrollToOffset(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ class BottomSheetViewPager @JvmOverloads constructor(
|
||||||
override fun onPageSelected(position: Int) {
|
override fun onPageSelected(position: Int) {
|
||||||
requestLayout()
|
requestLayout()
|
||||||
}
|
}
|
||||||
},)
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue