Skip to content

Commit

Permalink
Close UpNext sheet whenever player sheet is closed (#1731)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiSikora authored Jan 23, 2024
1 parent 0331528 commit c16b02b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,14 @@ class MainActivity :
return binding.playerBottomSheet.sheetBehavior?.state ?: BottomSheetBehavior.STATE_COLLAPSED
}

override fun addPlayerBottomSheetCallback(callback: BottomSheetBehavior.BottomSheetCallback) {
binding.playerBottomSheet.sheetBehavior?.addBottomSheetCallback(callback)
}

override fun removePlayerBottomSheetCallback(callback: BottomSheetBehavior.BottomSheetCallback) {
binding.playerBottomSheet.sheetBehavior?.removeBottomSheetCallback(callback)
}

override fun lockPlayerBottomSheet(locked: Boolean) {
binding.playerBottomSheet.isDragEnabled = !locked
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import au.com.shiftyjelly.pocketcasts.models.type.EpisodeViewSource
import au.com.shiftyjelly.pocketcasts.ui.helper.FragmentHostListener
import com.google.android.material.bottomsheet.BottomSheetBehavior
import dagger.hilt.android.AndroidEntryPoint
import au.com.shiftyjelly.pocketcasts.images.R as IR
import au.com.shiftyjelly.pocketcasts.profile.R as PR
Expand Down Expand Up @@ -117,6 +118,10 @@ class AutomotiveSettingsActivity : AppCompatActivity(), FragmentHostListener {
return 0
}

override fun addPlayerBottomSheetCallback(callback: BottomSheetBehavior.BottomSheetCallback) = Unit

override fun removePlayerBottomSheetCallback(callback: BottomSheetBehavior.BottomSheetCallback) = Unit

override fun openEpisodeDialog(
episodeUuid: String?,
source: EpisodeViewSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,24 @@ class PlayerContainerFragment : BaseFragment(), HasBackstack {
val overrideTheme: Theme.ThemeType
get() = if (settings.useDarkUpNextTheme.value) Theme.ThemeType.DARK else theme.activeTheme

private val closeUpNextCallback = object : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) {
if (newState in listOf(BottomSheetBehavior.STATE_COLLAPSED, BottomSheetBehavior.STATE_HIDDEN)) {
upNextBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
}
}

override fun onSlide(bottomSheet: View, slideOffset: Float) = Unit
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding = FragmentPlayerContainerBinding.inflate(inflater, container, false)
return binding?.root
}

override fun onDestroyView() {
super.onDestroyView()
(activity as? FragmentHostListener)?.removePlayerBottomSheetCallback(closeUpNextCallback)
binding = null
bookmarksViewModel.multiSelectHelper.context = null
}
Expand All @@ -92,6 +103,7 @@ class PlayerContainerFragment : BaseFragment(), HasBackstack {
// Having it gone from the beginning adds a small delay before it can be initially shown.
binding.upNextFrameBottomSheet.doOnLayout {
it.isGone = true
(activity as? FragmentHostListener)?.addPlayerBottomSheetCallback(closeUpNextCallback)
}
upNextBottomSheetBehavior = BottomSheetBehavior.from(binding.upNextFrameBottomSheet)
upNextBottomSheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package au.com.shiftyjelly.pocketcasts.ui.helper
import android.view.View
import androidx.fragment.app.Fragment
import au.com.shiftyjelly.pocketcasts.models.type.EpisodeViewSource
import com.google.android.material.bottomsheet.BottomSheetBehavior

interface FragmentHostListener {
fun addFragment(fragment: Fragment, onTop: Boolean = false)
Expand All @@ -22,6 +23,8 @@ interface FragmentHostListener {
fun showAccountUpgradeNow(autoSelectPlus: Boolean)
fun updateStatusBar()
fun getPlayerBottomSheetState(): Int
fun addPlayerBottomSheetCallback(callback: BottomSheetBehavior.BottomSheetCallback)
fun removePlayerBottomSheetCallback(callback: BottomSheetBehavior.BottomSheetCallback)
fun openEpisodeDialog(episodeUuid: String?, source: EpisodeViewSource, podcastUuid: String?, forceDark: Boolean)
fun lockPlayerBottomSheet(locked: Boolean)
fun updateSystemColors()
Expand Down

0 comments on commit c16b02b

Please sign in to comment.