Fixed a rare crash because of notifyDataSetChanged in Now playing ViewPager

This commit is contained in:
Prathamesh More 2022-06-20 20:08:07 +05:30
parent 88b0299ef9
commit dba4edd8ef
3 changed files with 8 additions and 7 deletions

View file

@ -49,7 +49,6 @@ import code.name.monkey.retromusic.util.LyricUtil
import code.name.monkey.retromusic.util.CoverLyricsType import code.name.monkey.retromusic.util.CoverLyricsType
import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.color.MediaNotificationProcessor import code.name.monkey.retromusic.util.color.MediaNotificationProcessor
import code.name.monkey.retromusic.util.logD
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@ -250,8 +249,7 @@ class PlayerAlbumCoverFragment : AbsMusicServiceFragment(R.layout.fragment_playe
private fun updatePlayingQueue() { private fun updatePlayingQueue() {
binding.viewPager.apply { binding.viewPager.apply {
adapter = AlbumCoverPagerAdapter(childFragmentManager, MusicPlayerRemote.playingQueue) adapter = AlbumCoverPagerAdapter(parentFragmentManager, MusicPlayerRemote.playingQueue)
adapter?.notifyDataSetChanged()
setCurrentItem(MusicPlayerRemote.position, true) setCurrentItem(MusicPlayerRemote.position, true)
onPageSelected(MusicPlayerRemote.position) onPageSelected(MusicPlayerRemote.position)
} }
@ -260,7 +258,6 @@ class PlayerAlbumCoverFragment : AbsMusicServiceFragment(R.layout.fragment_playe
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {} override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
override fun onPageSelected(position: Int) { override fun onPageSelected(position: Int) {
logD("Page Selected $position")
currentPosition = position currentPosition = position
if (binding.viewPager.adapter != null) { if (binding.viewPager.adapter != null) {
(binding.viewPager.adapter as AlbumCoverPagerAdapter).receiveColor( (binding.viewPager.adapter as AlbumCoverPagerAdapter).receiveColor(

View file

@ -4,7 +4,9 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?colorSurface"> android:background="?colorSurface"
android:clickable="true"
android:focusable="true">
<include layout="@layout/shadow_statusbar_toolbar" /> <include layout="@layout/shadow_statusbar_toolbar" />

View file

@ -4,7 +4,9 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?colorSurface"> android:background="?colorSurface"
android:clickable="true"
android:focusable="true">
<include layout="@layout/shadow_statusbar_toolbar" /> <include layout="@layout/shadow_statusbar_toolbar" />
@ -27,7 +29,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0"
app:contentInsetLeft="0dp" app:contentInsetLeft="0dp"
app:contentInsetStart="0dp" app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp" app:contentInsetStartWithNavigation="0dp"
app:navigationIcon="@drawable/ic_keyboard_arrow_down_black" app:navigationIcon="@drawable/ic_keyboard_arrow_down_black"