Skip to content

Commit c16b02b

Browse files
authored
Close UpNext sheet whenever player sheet is closed (#1731)
1 parent 0331528 commit c16b02b

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

app/src/main/java/au/com/shiftyjelly/pocketcasts/ui/MainActivity.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,14 @@ class MainActivity :
884884
return binding.playerBottomSheet.sheetBehavior?.state ?: BottomSheetBehavior.STATE_COLLAPSED
885885
}
886886

887+
override fun addPlayerBottomSheetCallback(callback: BottomSheetBehavior.BottomSheetCallback) {
888+
binding.playerBottomSheet.sheetBehavior?.addBottomSheetCallback(callback)
889+
}
890+
891+
override fun removePlayerBottomSheetCallback(callback: BottomSheetBehavior.BottomSheetCallback) {
892+
binding.playerBottomSheet.sheetBehavior?.removeBottomSheetCallback(callback)
893+
}
894+
887895
override fun lockPlayerBottomSheet(locked: Boolean) {
888896
binding.playerBottomSheet.isDragEnabled = !locked
889897
}

automotive/src/main/java/au/com/shiftyjelly/pocketcasts/AutomotiveSettingsActivity.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import androidx.appcompat.widget.Toolbar
88
import androidx.fragment.app.Fragment
99
import au.com.shiftyjelly.pocketcasts.models.type.EpisodeViewSource
1010
import au.com.shiftyjelly.pocketcasts.ui.helper.FragmentHostListener
11+
import com.google.android.material.bottomsheet.BottomSheetBehavior
1112
import dagger.hilt.android.AndroidEntryPoint
1213
import au.com.shiftyjelly.pocketcasts.images.R as IR
1314
import au.com.shiftyjelly.pocketcasts.profile.R as PR
@@ -117,6 +118,10 @@ class AutomotiveSettingsActivity : AppCompatActivity(), FragmentHostListener {
117118
return 0
118119
}
119120

121+
override fun addPlayerBottomSheetCallback(callback: BottomSheetBehavior.BottomSheetCallback) = Unit
122+
123+
override fun removePlayerBottomSheetCallback(callback: BottomSheetBehavior.BottomSheetCallback) = Unit
124+
120125
override fun openEpisodeDialog(
121126
episodeUuid: String?,
122127
source: EpisodeViewSource,

modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/view/PlayerContainerFragment.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,24 @@ class PlayerContainerFragment : BaseFragment(), HasBackstack {
6666
val overrideTheme: Theme.ThemeType
6767
get() = if (settings.useDarkUpNextTheme.value) Theme.ThemeType.DARK else theme.activeTheme
6868

69+
private val closeUpNextCallback = object : BottomSheetBehavior.BottomSheetCallback() {
70+
override fun onStateChanged(bottomSheet: View, newState: Int) {
71+
if (newState in listOf(BottomSheetBehavior.STATE_COLLAPSED, BottomSheetBehavior.STATE_HIDDEN)) {
72+
upNextBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
73+
}
74+
}
75+
76+
override fun onSlide(bottomSheet: View, slideOffset: Float) = Unit
77+
}
78+
6979
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
7080
binding = FragmentPlayerContainerBinding.inflate(inflater, container, false)
7181
return binding?.root
7282
}
7383

7484
override fun onDestroyView() {
7585
super.onDestroyView()
86+
(activity as? FragmentHostListener)?.removePlayerBottomSheetCallback(closeUpNextCallback)
7687
binding = null
7788
bookmarksViewModel.multiSelectHelper.context = null
7889
}
@@ -92,6 +103,7 @@ class PlayerContainerFragment : BaseFragment(), HasBackstack {
92103
// Having it gone from the beginning adds a small delay before it can be initially shown.
93104
binding.upNextFrameBottomSheet.doOnLayout {
94105
it.isGone = true
106+
(activity as? FragmentHostListener)?.addPlayerBottomSheetCallback(closeUpNextCallback)
95107
}
96108
upNextBottomSheetBehavior = BottomSheetBehavior.from(binding.upNextFrameBottomSheet)
97109
upNextBottomSheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {

modules/services/ui/src/main/java/au/com/shiftyjelly/pocketcasts/ui/helper/FragmentHostListener.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package au.com.shiftyjelly.pocketcasts.ui.helper
33
import android.view.View
44
import androidx.fragment.app.Fragment
55
import au.com.shiftyjelly.pocketcasts.models.type.EpisodeViewSource
6+
import com.google.android.material.bottomsheet.BottomSheetBehavior
67

78
interface FragmentHostListener {
89
fun addFragment(fragment: Fragment, onTop: Boolean = false)
@@ -22,6 +23,8 @@ interface FragmentHostListener {
2223
fun showAccountUpgradeNow(autoSelectPlus: Boolean)
2324
fun updateStatusBar()
2425
fun getPlayerBottomSheetState(): Int
26+
fun addPlayerBottomSheetCallback(callback: BottomSheetBehavior.BottomSheetCallback)
27+
fun removePlayerBottomSheetCallback(callback: BottomSheetBehavior.BottomSheetCallback)
2528
fun openEpisodeDialog(episodeUuid: String?, source: EpisodeViewSource, podcastUuid: String?, forceDark: Boolean)
2629
fun lockPlayerBottomSheet(locked: Boolean)
2730
fun updateSystemColors()

0 commit comments

Comments
 (0)