Fix crashes due to SharedPreferences listener

This commit is contained in:
Prathamesh More 2022-05-20 16:44:56 +05:30
parent 01f7a4874d
commit 51f298be8f
3 changed files with 15 additions and 16 deletions

View file

@ -3,17 +3,15 @@ package code.name.monkey.retromusic
import android.content.Context
import android.content.ContextWrapper
import android.os.LocaleList
import code.name.monkey.appthemehelper.util.VersionUtils.hasNougatMR
import com.google.android.gms.common.annotation.KeepName
import code.name.monkey.appthemehelper.util.VersionUtils.hasNougat
import java.util.*
class LanguageContextWrapper(base: Context?) : ContextWrapper(base) {
companion object {
@KeepName
fun wrap(context: Context?, newLocale: Locale?): LanguageContextWrapper {
if (context == null) return LanguageContextWrapper(context)
val configuration = context.resources.configuration
if (hasNougatMR()) {
if (hasNougat()) {
configuration.setLocale(newLocale)
val localeList = LocaleList(newLocale)
LocaleList.setDefault(localeList)

View file

@ -206,7 +206,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(),
onServiceConnected()
}
SWIPE_ANYWHERE_NOW_PLAYING -> {
playerFragment.onResume()
playerFragment.addSwipeDetector()
}
ADAPTIVE_COLOR_APP -> {
if (PreferenceUtil.nowPlayingScreen in listOf(Normal, Material, Flat)) {
@ -310,15 +310,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(),
override fun onServiceConnected() {
super.onServiceConnected()
if (MusicPlayerRemote.playingQueue.isNotEmpty()) {
binding.slidingPanel.viewTreeObserver.addOnGlobalLayoutListener(object :
ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
binding.slidingPanel.viewTreeObserver.removeOnGlobalLayoutListener(this)
hideBottomSheet(false)
}
})
} // don't call hideBottomSheet(true) here as it causes a bug with the SlidingUpPanelLayout
hideBottomSheet(false)
}
override fun onQueueChanged() {
@ -514,7 +506,8 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(),
supportFragmentManager.commit {
replace(R.id.playerFragmentContainer, fragment)
}
playerFragment = fragment
supportFragmentManager.executePendingTransactions()
playerFragment = whichFragment(R.id.playerFragmentContainer)
miniPlayerFragment = whichFragment<MiniPlayerFragment>(R.id.miniPlayerFragment)
miniPlayerFragment?.view?.setOnClickListener { expandPanel() }
}

View file

@ -327,7 +327,15 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMusicServiceFragme
showLyricsIcon(this)
}
}
requireView().setOnTouchListener(
}
override fun onStart() {
super.onStart()
addSwipeDetector()
}
fun addSwipeDetector() {
view?.setOnTouchListener(
if (PreferenceUtil.swipeAnywhereToChangeSong) {
SwipeDetector(
requireContext(),