mirror of
https://github.com/cmclark00/RetroMusicPlayer.git
synced 2025-05-17 15:45:21 +01:00
Merge pull request #1694 from tomaThomas/back-button
This commit is contained in:
commit
8548437633
3 changed files with 20 additions and 11 deletions
3
app/proguard-rules.pro
vendored
3
app/proguard-rules.pro
vendored
|
@ -31,6 +31,9 @@
|
|||
# RetroFit
|
||||
-dontwarn retrofit.**
|
||||
-keep class retrofit.** { *; }
|
||||
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
|
||||
-keep,allowobfuscation,allowshrinking class retrofit2.Response
|
||||
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
|
||||
|
||||
# Glide
|
||||
-keep public class * implements com.bumptech.glide.module.GlideModule
|
||||
|
|
|
@ -117,9 +117,6 @@ class MainActivity : AbsCastActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onSupportNavigateUp(): Boolean =
|
||||
findNavController(R.id.fragment_container).navigateUp()
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
val expand = intent?.extra<Boolean>(EXPAND_PANEL)?.value ?: false
|
||||
|
|
|
@ -33,6 +33,7 @@ import androidx.core.view.isGone
|
|||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.fragment.app.commit
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import code.name.monkey.appthemehelper.util.VersionUtils
|
||||
import code.name.monkey.retromusic.ADAPTIVE_COLOR_APP
|
||||
import code.name.monkey.retromusic.ALBUM_COVER_STYLE
|
||||
|
@ -132,6 +133,8 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(),
|
|||
|
||||
private val panelState: Int
|
||||
get() = bottomSheetBehavior.state
|
||||
private var panelStateBefore: Int? = null
|
||||
private var panelStateCurrent: Int? = null
|
||||
private lateinit var binding: SlidingMusicPanelLayoutBinding
|
||||
private var isInOneTabMode = false
|
||||
|
||||
|
@ -140,10 +143,13 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(),
|
|||
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
println("Handle back press ${bottomSheetBehavior.state}")
|
||||
if (!handleBackPress()) {
|
||||
remove()
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
if (handleBackPress()) {
|
||||
return
|
||||
}
|
||||
val navHostFragment =
|
||||
supportFragmentManager.findFragmentById(R.id.fragment_container) as NavHostFragment
|
||||
if (!navHostFragment.navController.navigateUp()) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -164,7 +170,10 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(),
|
|||
}
|
||||
|
||||
override fun onStateChanged(bottomSheet: View, newState: Int) {
|
||||
onBackPressedCallback.isEnabled = newState == STATE_EXPANDED
|
||||
if (panelStateCurrent != null) {
|
||||
panelStateBefore = panelStateCurrent
|
||||
}
|
||||
panelStateCurrent = newState
|
||||
when (newState) {
|
||||
STATE_EXPANDED -> {
|
||||
onPanelExpanded()
|
||||
|
@ -224,7 +233,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(),
|
|||
|
||||
navigationBarColor = surfaceColor()
|
||||
|
||||
onBackPressedDispatcher.addCallback(onBackPressedCallback)
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
}
|
||||
|
||||
private fun setupBottomSheet() {
|
||||
|
@ -408,7 +417,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(),
|
|||
}
|
||||
|
||||
private fun handleBackPress(): Boolean {
|
||||
if (panelState == STATE_EXPANDED) {
|
||||
if (panelState == STATE_EXPANDED || (panelState == STATE_SETTLING && panelStateBefore != STATE_EXPANDED)) {
|
||||
collapsePanel()
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue