mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-05-05 18:11:04 +03:00
Fix calling PageChangeCallback.onPageSelected before mediaPlayerManager is ready
This commit is contained in:
parent
45c5a029b1
commit
ff8e6b194e
@ -39,6 +39,7 @@ import timber.log.Timber
|
|||||||
* Contains the mini-now playing information box displayed at the bottom of the screen
|
* Contains the mini-now playing information box displayed at the bottom of the screen
|
||||||
*/
|
*/
|
||||||
class NowPlayingFragment : Fragment() {
|
class NowPlayingFragment : Fragment() {
|
||||||
|
private var isInitialized = false
|
||||||
private lateinit var nowPlayingCollectionAdapter: NowPlayingCollectionAdapter
|
private lateinit var nowPlayingCollectionAdapter: NowPlayingCollectionAdapter
|
||||||
private lateinit var viewPager: ViewPager2
|
private lateinit var viewPager: ViewPager2
|
||||||
private var rxBusSubscription: Disposable? = null
|
private var rxBusSubscription: Disposable? = null
|
||||||
@ -68,6 +69,7 @@ class NowPlayingFragment : Fragment() {
|
|||||||
rxBusSubscription = RxBus.playerStateObservable.subscribe {
|
rxBusSubscription = RxBus.playerStateObservable.subscribe {
|
||||||
if (it.state == Player.STATE_READY) {
|
if (it.state == Player.STATE_READY) {
|
||||||
viewPager.setCurrentItem(it.index, true)
|
viewPager.setCurrentItem(it.index, true)
|
||||||
|
isInitialized = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,6 +84,7 @@ class NowPlayingFragment : Fragment() {
|
|||||||
|
|
||||||
private inner class PageChangeCallback : ViewPager2.OnPageChangeCallback() {
|
private inner class PageChangeCallback : ViewPager2.OnPageChangeCallback() {
|
||||||
override fun onPageSelected(position: Int) {
|
override fun onPageSelected(position: Int) {
|
||||||
|
if (!isInitialized) return
|
||||||
val newIndex = mediaPlayerManager.getUnshuffledIndexOf(position)
|
val newIndex = mediaPlayerManager.getUnshuffledIndexOf(position)
|
||||||
if (mediaPlayerManager.currentMediaItemIndex != newIndex) {
|
if (mediaPlayerManager.currentMediaItemIndex != newIndex) {
|
||||||
mediaPlayerManager.seekTo(newIndex, 0)
|
mediaPlayerManager.seekTo(newIndex, 0)
|
||||||
@ -153,7 +156,7 @@ class NowPlayingChildFragment(private val mediaItem: MediaItem?) : Fragment() {
|
|||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
rxBusSubscription!!.dispose()
|
rxBusSubscription?.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user