Fix crashes due to SharedPreferences listener
This commit is contained in:
parent
01f7a4874d
commit
51f298be8f
3 changed files with 15 additions and 16 deletions
|
@ -3,17 +3,15 @@ package code.name.monkey.retromusic
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.ContextWrapper
|
import android.content.ContextWrapper
|
||||||
import android.os.LocaleList
|
import android.os.LocaleList
|
||||||
import code.name.monkey.appthemehelper.util.VersionUtils.hasNougatMR
|
import code.name.monkey.appthemehelper.util.VersionUtils.hasNougat
|
||||||
import com.google.android.gms.common.annotation.KeepName
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class LanguageContextWrapper(base: Context?) : ContextWrapper(base) {
|
class LanguageContextWrapper(base: Context?) : ContextWrapper(base) {
|
||||||
companion object {
|
companion object {
|
||||||
@KeepName
|
|
||||||
fun wrap(context: Context?, newLocale: Locale?): LanguageContextWrapper {
|
fun wrap(context: Context?, newLocale: Locale?): LanguageContextWrapper {
|
||||||
if (context == null) return LanguageContextWrapper(context)
|
if (context == null) return LanguageContextWrapper(context)
|
||||||
val configuration = context.resources.configuration
|
val configuration = context.resources.configuration
|
||||||
if (hasNougatMR()) {
|
if (hasNougat()) {
|
||||||
configuration.setLocale(newLocale)
|
configuration.setLocale(newLocale)
|
||||||
val localeList = LocaleList(newLocale)
|
val localeList = LocaleList(newLocale)
|
||||||
LocaleList.setDefault(localeList)
|
LocaleList.setDefault(localeList)
|
||||||
|
|
|
@ -206,7 +206,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(),
|
||||||
onServiceConnected()
|
onServiceConnected()
|
||||||
}
|
}
|
||||||
SWIPE_ANYWHERE_NOW_PLAYING -> {
|
SWIPE_ANYWHERE_NOW_PLAYING -> {
|
||||||
playerFragment.onResume()
|
playerFragment.addSwipeDetector()
|
||||||
}
|
}
|
||||||
ADAPTIVE_COLOR_APP -> {
|
ADAPTIVE_COLOR_APP -> {
|
||||||
if (PreferenceUtil.nowPlayingScreen in listOf(Normal, Material, Flat)) {
|
if (PreferenceUtil.nowPlayingScreen in listOf(Normal, Material, Flat)) {
|
||||||
|
@ -310,15 +310,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(),
|
||||||
|
|
||||||
override fun onServiceConnected() {
|
override fun onServiceConnected() {
|
||||||
super.onServiceConnected()
|
super.onServiceConnected()
|
||||||
if (MusicPlayerRemote.playingQueue.isNotEmpty()) {
|
hideBottomSheet(false)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onQueueChanged() {
|
override fun onQueueChanged() {
|
||||||
|
@ -514,7 +506,8 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(),
|
||||||
supportFragmentManager.commit {
|
supportFragmentManager.commit {
|
||||||
replace(R.id.playerFragmentContainer, fragment)
|
replace(R.id.playerFragmentContainer, fragment)
|
||||||
}
|
}
|
||||||
playerFragment = fragment
|
supportFragmentManager.executePendingTransactions()
|
||||||
|
playerFragment = whichFragment(R.id.playerFragmentContainer)
|
||||||
miniPlayerFragment = whichFragment<MiniPlayerFragment>(R.id.miniPlayerFragment)
|
miniPlayerFragment = whichFragment<MiniPlayerFragment>(R.id.miniPlayerFragment)
|
||||||
miniPlayerFragment?.view?.setOnClickListener { expandPanel() }
|
miniPlayerFragment?.view?.setOnClickListener { expandPanel() }
|
||||||
}
|
}
|
||||||
|
|
|
@ -327,7 +327,15 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMusicServiceFragme
|
||||||
showLyricsIcon(this)
|
showLyricsIcon(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
requireView().setOnTouchListener(
|
}
|
||||||
|
|
||||||
|
override fun onStart() {
|
||||||
|
super.onStart()
|
||||||
|
addSwipeDetector()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addSwipeDetector() {
|
||||||
|
view?.setOnTouchListener(
|
||||||
if (PreferenceUtil.swipeAnywhereToChangeSong) {
|
if (PreferenceUtil.swipeAnywhereToChangeSong) {
|
||||||
SwipeDetector(
|
SwipeDetector(
|
||||||
requireContext(),
|
requireContext(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue