@@ -24,14 +24,12 @@ import androidx.compose.runtime.getValue
24
24
import androidx.compose.ui.platform.ComposeView
25
25
import androidx.core.content.ContextCompat
26
26
import androidx.core.view.WindowCompat
27
- import androidx.core.view.doOnLayout
28
27
import androidx.core.view.isVisible
29
28
import androidx.core.view.updateLayoutParams
30
29
import androidx.core.view.updatePadding
31
30
import androidx.fragment.app.Fragment
32
31
import androidx.fragment.app.commitNow
33
32
import androidx.lifecycle.Lifecycle
34
- import androidx.lifecycle.LiveData
35
33
import androidx.lifecycle.Observer
36
34
import androidx.lifecycle.lifecycleScope
37
35
import androidx.lifecycle.repeatOnLifecycle
@@ -120,7 +118,6 @@ import au.com.shiftyjelly.pocketcasts.repositories.notification.NotificationHelp
120
118
import au.com.shiftyjelly.pocketcasts.repositories.opml.OpmlImportTask
121
119
import au.com.shiftyjelly.pocketcasts.repositories.playback.PlaybackManager
122
120
import au.com.shiftyjelly.pocketcasts.repositories.playback.PlaybackState
123
- import au.com.shiftyjelly.pocketcasts.repositories.playback.UpNextQueue
124
121
import au.com.shiftyjelly.pocketcasts.repositories.playback.UpNextSource
125
122
import au.com.shiftyjelly.pocketcasts.repositories.podcast.EpisodeManager
126
123
import au.com.shiftyjelly.pocketcasts.repositories.podcast.PlaylistManager
@@ -149,7 +146,6 @@ import au.com.shiftyjelly.pocketcasts.utils.featureflag.Feature
149
146
import au.com.shiftyjelly.pocketcasts.utils.featureflag.FeatureFlag
150
147
import au.com.shiftyjelly.pocketcasts.utils.log.LogBuffer
151
148
import au.com.shiftyjelly.pocketcasts.utils.observeOnce
152
- import au.com.shiftyjelly.pocketcasts.view.BottomNavHideManager
153
149
import au.com.shiftyjelly.pocketcasts.view.LockableBottomSheetBehavior
154
150
import au.com.shiftyjelly.pocketcasts.views.activity.WebViewActivity
155
151
import au.com.shiftyjelly.pocketcasts.views.extensions.setSystemWindowInsetToPadding
@@ -188,8 +184,7 @@ import android.provider.Settings as AndroidProviderSettings
188
184
import au.com.shiftyjelly.pocketcasts.localization.R as LR
189
185
import au.com.shiftyjelly.pocketcasts.views.R as VR
190
186
191
- private const val SAVEDSTATE_PLAYER_OPEN = " player_open"
192
- private const val SAVEDSTATE_MINIPLAYER_SHOWN = " miniplayer_shown"
187
+ private const val SAVEDSTATE_BOTTOM_SHEET_TAG = " bottom_sheet_tag"
193
188
private const val EXTRA_LONG_SNACKBAR_DURATION_MS : Int = 5000
194
189
195
190
@AndroidEntryPoint
@@ -247,9 +242,6 @@ class MainActivity :
247
242
248
243
@Inject lateinit var crashLogging: CrashLogging
249
244
250
- private lateinit var bottomNavHideManager: BottomNavHideManager
251
- private lateinit var observeUpNext: LiveData <UpNextQueue .State >
252
-
253
245
private val viewModel: MainActivityViewModel by viewModels()
254
246
private val disposables = CompositeDisposable ()
255
247
private var videoPlayerShown: Boolean = false
@@ -264,8 +256,9 @@ class MainActivity :
264
256
private val childrenWithBackStack: List <HasBackstack >
265
257
get() = supportFragmentManager.fragments.filterIsInstance<HasBackstack >()
266
258
259
+ @Suppress(" UNCHECKED_CAST" )
267
260
private val frameBottomSheetBehavior: LockableBottomSheetBehavior <View >
268
- get() = getBottomSheetBehavior()
261
+ get() = BottomSheetBehavior .from(binding.frameBottomSheet) as LockableBottomSheetBehavior < View >
269
262
270
263
private val miniPlayerHeight: Int
271
264
get() = resources.getDimension(R .dimen.miniPlayerHeight).toInt()
@@ -360,6 +353,7 @@ class MainActivity :
360
353
super .onCreate(savedInstanceState)
361
354
theme.setupThemeForConfig(this , resources.configuration)
362
355
enableEdgeToEdge(navigationBarStyle = theme.getNavigationBarStyle(this ))
356
+ bottomSheetTag = savedInstanceState?.getString(SAVEDSTATE_BOTTOM_SHEET_TAG )
363
357
364
358
playbackManager.setNotificationPermissionChecker(this )
365
359
@@ -376,7 +370,7 @@ class MainActivity :
376
370
377
371
binding.root.setSystemWindowInsetToPadding(left = true , right = true )
378
372
379
- binding.bottomNavigation.doOnLayout {
373
+ binding.bottomNavigation.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
380
374
val miniPlayerHeight = miniPlayerHeight
381
375
val bottomNavigationHeight = binding.bottomNavigation.height
382
376
val bottomSheetBehavior = BottomSheetBehavior .from(binding.playerBottomSheet)
@@ -448,23 +442,11 @@ class MainActivity :
448
442
})
449
443
.addTo(disposables)
450
444
451
- val showMiniPlayerImmediately = savedInstanceState?.getBoolean(SAVEDSTATE_MINIPLAYER_SHOWN , false ) ? : false
452
- binding.playerBottomSheet.isVisible = showMiniPlayerImmediately
453
- settings.updateBottomInset(if (showMiniPlayerImmediately) miniPlayerHeight else 0 )
454
-
455
- setupPlayerViews(showMiniPlayerImmediately)
456
-
457
- if (savedInstanceState != null ) {
458
- val videoComingToPortrait =
459
- (playbackManager.isPlaying() && playbackManager.getCurrentEpisode()?.isVideo == true && resources.configuration.orientation == Configuration .ORIENTATION_PORTRAIT && viewModel.isPlayerOpen)
460
- if (savedInstanceState.getBoolean(
461
- SAVEDSTATE_PLAYER_OPEN ,
462
- false ,
463
- ) && ! playbackManager.upNextQueue.isEmpty || videoComingToPortrait
464
- ) {
465
- binding.playerBottomSheet.openPlayer()
466
- }
467
- } else {
445
+ setupPlayerViews(
446
+ animateMiniPlayer = savedInstanceState == null ,
447
+ )
448
+
449
+ if (savedInstanceState == null ) {
468
450
trackTabOpened(selectedTab, isInitial = true )
469
451
}
470
452
navigator.infoStream()
@@ -562,8 +544,7 @@ class MainActivity :
562
544
563
545
override fun onSaveInstanceState (outState : Bundle ) {
564
546
super .onSaveInstanceState(outState)
565
- outState.putBoolean(SAVEDSTATE_PLAYER_OPEN , binding.playerBottomSheet.isPlayerOpen)
566
- outState.putBoolean(SAVEDSTATE_MINIPLAYER_SHOWN , binding.playerBottomSheet.isShown)
547
+ outState.putString(SAVEDSTATE_BOTTOM_SHEET_TAG , bottomSheetTag)
567
548
}
568
549
569
550
override fun overrideNextRefreshTimer () {
@@ -791,8 +772,9 @@ class MainActivity :
791
772
}
792
773
793
774
@Suppress(" DEPRECATION" )
794
- private fun setupPlayerViews (showMiniPlayerImmediately : Boolean ) {
775
+ private fun setupPlayerViews (animateMiniPlayer : Boolean ) {
795
776
binding.playerBottomSheet.listener = this
777
+ binding.playerBottomSheet.initializeBottomSheetBehavior()
796
778
797
779
lifecycleScope.launch {
798
780
repeatOnLifecycle(Lifecycle .State .STARTED ) {
@@ -839,7 +821,7 @@ class MainActivity :
839
821
binding.playerBottomSheet.setUpNext(
840
822
upNext = upNextQueue,
841
823
theme = theme,
842
- shouldAnimateOnAttach = ! showMiniPlayerImmediately ,
824
+ shouldAnimateOnAttach = animateMiniPlayer ,
843
825
useEpisodeArtwork = artworkConfiguration.useEpisodeArtwork,
844
826
)
845
827
}
@@ -941,8 +923,6 @@ class MainActivity :
941
923
}
942
924
}
943
925
944
- bottomNavHideManager =
945
- BottomNavHideManager (findViewById(R .id.root), binding.bottomNavigation)
946
926
frameBottomSheetBehavior.setBottomSheetCallback(object :
947
927
BottomSheetBehavior .BottomSheetCallback () {
948
928
override fun onSlide (bottomSheet : View , slideOffset : Float ) {}
@@ -1030,8 +1010,8 @@ class MainActivity :
1030
1010
}
1031
1011
}
1032
1012
1033
- override fun onPlayerBottomSheetSlide (slideOffset : Float ) {
1034
- bottomNavHideManager.onSlide( slideOffset)
1013
+ override fun onPlayerBottomSheetSlide (bottomSheetView : View , slideOffset : Float ) {
1014
+ binding.bottomNavigation.translationY = bottomSheetView.height * slideOffset
1035
1015
}
1036
1016
1037
1017
override fun updateSystemColors () {
@@ -1072,27 +1052,14 @@ class MainActivity :
1072
1052
}
1073
1053
1074
1054
override fun showBottomSheet (fragment : Fragment ) {
1075
- showBottomSheet(fragment, showImmediate = true , swipeEnabled = true )
1076
- }
1077
-
1078
- private fun showBottomSheet (
1079
- fragment : Fragment ,
1080
- showImmediate : Boolean = true,
1081
- swipeEnabled : Boolean = true,
1082
- ) {
1083
- if (bottomSheetTag != null && ! showImmediate) {
1084
- bottomSheetQueue.add { showBottomSheet(fragment) }
1085
- return
1086
- }
1087
-
1088
1055
supportFragmentManager.commitNow {
1089
1056
bottomSheetTag = fragment::class .java.name
1090
1057
replace(R .id.frameBottomSheet, fragment, bottomSheetTag)
1091
1058
}
1092
1059
1093
1060
frameBottomSheetBehavior.state = BottomSheetBehavior .STATE_EXPANDED
1061
+ frameBottomSheetBehavior.swipeEnabled = true
1094
1062
binding.frameBottomSheet.importantForAccessibility = View .IMPORTANT_FOR_ACCESSIBILITY_YES
1095
- frameBottomSheetBehavior.swipeEnabled = swipeEnabled
1096
1063
}
1097
1064
1098
1065
override fun bottomSheetClosePressed (fragment : Fragment ) {
@@ -1596,11 +1563,6 @@ class MainActivity :
1596
1563
}
1597
1564
}
1598
1565
1599
- @Suppress(" UNCHECKED_CAST" )
1600
- private fun getBottomSheetBehavior (): LockableBottomSheetBehavior <View > {
1601
- return (BottomSheetBehavior .from(binding.frameBottomSheet) as LockableBottomSheetBehavior <View >)
1602
- }
1603
-
1604
1566
private fun trackTabOpened (tab : Int , isInitial : Boolean = false) {
1605
1567
val event: AnalyticsEvent ? = when (tab) {
1606
1568
VR .id.navigation_podcasts -> AnalyticsEvent .PODCASTS_TAB_OPENED
0 commit comments