Skip to content

Commit ab4ca61

Browse files
ashiagrMiSikora
andauthored
Android15 upgrade layout fix (#3779)
Co-authored-by: Michał Sikora <[email protected]>
1 parent af064ee commit ab4ca61

File tree

7 files changed

+77
-127
lines changed

7 files changed

+77
-127
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
-----
33

44

5+
7.84.1
6+
-----
7+
* Bug Fixes
8+
* Fixed an issue where the Up Next queue obstructed the bottom navigation bar in some cases.
9+
([#3762](https://github.com/Automattic/pocket-casts-android/pull/3762))
10+
* Fixed an issue where the navigation bar was drawn over the player in some cases.
11+
([#3762](https://github.com/Automattic/pocket-casts-android/pull/3762))
12+
* Fixed an issue where the mini player could sometimes hide behind the navigation bar.
13+
([#3687](https://github.com/Automattic/pocket-casts-android/pull/3687))
14+
515
7.84
616
-----
717
* New Features

app/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
alias(libs.plugins.android.application)
33
alias(libs.plugins.kotlin.android)
4+
alias(libs.plugins.kotlin.parcelize)
45
alias(libs.plugins.ksp)
56
alias(libs.plugins.hilt)
67
alias(libs.plugins.sentry)

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

+17-55
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ import androidx.compose.runtime.getValue
2424
import androidx.compose.ui.platform.ComposeView
2525
import androidx.core.content.ContextCompat
2626
import androidx.core.view.WindowCompat
27-
import androidx.core.view.doOnLayout
2827
import androidx.core.view.isVisible
2928
import androidx.core.view.updateLayoutParams
3029
import androidx.core.view.updatePadding
3130
import androidx.fragment.app.Fragment
3231
import androidx.fragment.app.commitNow
3332
import androidx.lifecycle.Lifecycle
34-
import androidx.lifecycle.LiveData
3533
import androidx.lifecycle.Observer
3634
import androidx.lifecycle.lifecycleScope
3735
import androidx.lifecycle.repeatOnLifecycle
@@ -120,7 +118,6 @@ import au.com.shiftyjelly.pocketcasts.repositories.notification.NotificationHelp
120118
import au.com.shiftyjelly.pocketcasts.repositories.opml.OpmlImportTask
121119
import au.com.shiftyjelly.pocketcasts.repositories.playback.PlaybackManager
122120
import au.com.shiftyjelly.pocketcasts.repositories.playback.PlaybackState
123-
import au.com.shiftyjelly.pocketcasts.repositories.playback.UpNextQueue
124121
import au.com.shiftyjelly.pocketcasts.repositories.playback.UpNextSource
125122
import au.com.shiftyjelly.pocketcasts.repositories.podcast.EpisodeManager
126123
import au.com.shiftyjelly.pocketcasts.repositories.podcast.PlaylistManager
@@ -149,7 +146,6 @@ import au.com.shiftyjelly.pocketcasts.utils.featureflag.Feature
149146
import au.com.shiftyjelly.pocketcasts.utils.featureflag.FeatureFlag
150147
import au.com.shiftyjelly.pocketcasts.utils.log.LogBuffer
151148
import au.com.shiftyjelly.pocketcasts.utils.observeOnce
152-
import au.com.shiftyjelly.pocketcasts.view.BottomNavHideManager
153149
import au.com.shiftyjelly.pocketcasts.view.LockableBottomSheetBehavior
154150
import au.com.shiftyjelly.pocketcasts.views.activity.WebViewActivity
155151
import au.com.shiftyjelly.pocketcasts.views.extensions.setSystemWindowInsetToPadding
@@ -188,8 +184,7 @@ import android.provider.Settings as AndroidProviderSettings
188184
import au.com.shiftyjelly.pocketcasts.localization.R as LR
189185
import au.com.shiftyjelly.pocketcasts.views.R as VR
190186

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"
193188
private const val EXTRA_LONG_SNACKBAR_DURATION_MS: Int = 5000
194189

195190
@AndroidEntryPoint
@@ -247,9 +242,6 @@ class MainActivity :
247242

248243
@Inject lateinit var crashLogging: CrashLogging
249244

250-
private lateinit var bottomNavHideManager: BottomNavHideManager
251-
private lateinit var observeUpNext: LiveData<UpNextQueue.State>
252-
253245
private val viewModel: MainActivityViewModel by viewModels()
254246
private val disposables = CompositeDisposable()
255247
private var videoPlayerShown: Boolean = false
@@ -264,8 +256,9 @@ class MainActivity :
264256
private val childrenWithBackStack: List<HasBackstack>
265257
get() = supportFragmentManager.fragments.filterIsInstance<HasBackstack>()
266258

259+
@Suppress("UNCHECKED_CAST")
267260
private val frameBottomSheetBehavior: LockableBottomSheetBehavior<View>
268-
get() = getBottomSheetBehavior()
261+
get() = BottomSheetBehavior.from(binding.frameBottomSheet) as LockableBottomSheetBehavior<View>
269262

270263
private val miniPlayerHeight: Int
271264
get() = resources.getDimension(R.dimen.miniPlayerHeight).toInt()
@@ -360,6 +353,7 @@ class MainActivity :
360353
super.onCreate(savedInstanceState)
361354
theme.setupThemeForConfig(this, resources.configuration)
362355
enableEdgeToEdge(navigationBarStyle = theme.getNavigationBarStyle(this))
356+
bottomSheetTag = savedInstanceState?.getString(SAVEDSTATE_BOTTOM_SHEET_TAG)
363357

364358
playbackManager.setNotificationPermissionChecker(this)
365359

@@ -376,7 +370,7 @@ class MainActivity :
376370

377371
binding.root.setSystemWindowInsetToPadding(left = true, right = true)
378372

379-
binding.bottomNavigation.doOnLayout {
373+
binding.bottomNavigation.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
380374
val miniPlayerHeight = miniPlayerHeight
381375
val bottomNavigationHeight = binding.bottomNavigation.height
382376
val bottomSheetBehavior = BottomSheetBehavior.from(binding.playerBottomSheet)
@@ -448,23 +442,11 @@ class MainActivity :
448442
})
449443
.addTo(disposables)
450444

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) {
468450
trackTabOpened(selectedTab, isInitial = true)
469451
}
470452
navigator.infoStream()
@@ -562,8 +544,7 @@ class MainActivity :
562544

563545
override fun onSaveInstanceState(outState: Bundle) {
564546
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)
567548
}
568549

569550
override fun overrideNextRefreshTimer() {
@@ -791,8 +772,9 @@ class MainActivity :
791772
}
792773

793774
@Suppress("DEPRECATION")
794-
private fun setupPlayerViews(showMiniPlayerImmediately: Boolean) {
775+
private fun setupPlayerViews(animateMiniPlayer: Boolean) {
795776
binding.playerBottomSheet.listener = this
777+
binding.playerBottomSheet.initializeBottomSheetBehavior()
796778

797779
lifecycleScope.launch {
798780
repeatOnLifecycle(Lifecycle.State.STARTED) {
@@ -839,7 +821,7 @@ class MainActivity :
839821
binding.playerBottomSheet.setUpNext(
840822
upNext = upNextQueue,
841823
theme = theme,
842-
shouldAnimateOnAttach = !showMiniPlayerImmediately,
824+
shouldAnimateOnAttach = animateMiniPlayer,
843825
useEpisodeArtwork = artworkConfiguration.useEpisodeArtwork,
844826
)
845827
}
@@ -941,8 +923,6 @@ class MainActivity :
941923
}
942924
}
943925

944-
bottomNavHideManager =
945-
BottomNavHideManager(findViewById(R.id.root), binding.bottomNavigation)
946926
frameBottomSheetBehavior.setBottomSheetCallback(object :
947927
BottomSheetBehavior.BottomSheetCallback() {
948928
override fun onSlide(bottomSheet: View, slideOffset: Float) {}
@@ -1030,8 +1010,8 @@ class MainActivity :
10301010
}
10311011
}
10321012

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
10351015
}
10361016

10371017
override fun updateSystemColors() {
@@ -1072,27 +1052,14 @@ class MainActivity :
10721052
}
10731053

10741054
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-
10881055
supportFragmentManager.commitNow {
10891056
bottomSheetTag = fragment::class.java.name
10901057
replace(R.id.frameBottomSheet, fragment, bottomSheetTag)
10911058
}
10921059

10931060
frameBottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
1061+
frameBottomSheetBehavior.swipeEnabled = true
10941062
binding.frameBottomSheet.importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_YES
1095-
frameBottomSheetBehavior.swipeEnabled = swipeEnabled
10961063
}
10971064

10981065
override fun bottomSheetClosePressed(fragment: Fragment) {
@@ -1596,11 +1563,6 @@ class MainActivity :
15961563
}
15971564
}
15981565

1599-
@Suppress("UNCHECKED_CAST")
1600-
private fun getBottomSheetBehavior(): LockableBottomSheetBehavior<View> {
1601-
return (BottomSheetBehavior.from(binding.frameBottomSheet) as LockableBottomSheetBehavior<View>)
1602-
}
1603-
16041566
private fun trackTabOpened(tab: Int, isInitial: Boolean = false) {
16051567
val event: AnalyticsEvent? = when (tab) {
16061568
VR.id.navigation_podcasts -> AnalyticsEvent.PODCASTS_TAB_OPENED

app/src/main/java/au/com/shiftyjelly/pocketcasts/view/BottomNavHideManager.kt

-28
This file was deleted.

app/src/main/java/au/com/shiftyjelly/pocketcasts/view/LockableBottomSheetBehavior.kt

+21
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package au.com.shiftyjelly.pocketcasts.view
22

33
import android.content.Context
4+
import android.os.Parcelable
45
import android.util.AttributeSet
56
import android.view.MotionEvent
67
import android.view.View
78
import androidx.coordinatorlayout.widget.CoordinatorLayout
89
import com.google.android.material.bottomsheet.ViewPager2AwareBottomSheetBehavior
10+
import kotlinx.parcelize.Parcelize
911

1012
// StackOverflow: https://stackoverflow.com/questions/35794264/disabling-user-dragging-on-bottomsheet
1113

@@ -95,4 +97,23 @@ class LockableBottomSheetBehavior<V : View> : ViewPager2AwareBottomSheetBehavior
9597
false
9698
}
9799
}
100+
101+
override fun onSaveInstanceState(parent: CoordinatorLayout, child: V): Parcelable {
102+
return SavedState(
103+
isSwipeEnabled = swipeEnabled,
104+
parentState = super.onSaveInstanceState(parent, child),
105+
)
106+
}
107+
108+
override fun onRestoreInstanceState(parent: CoordinatorLayout, child: V, state: Parcelable) {
109+
val savedState = state as SavedState
110+
swipeEnabled = savedState.isSwipeEnabled
111+
super.onRestoreInstanceState(parent, child, savedState.parentState)
112+
}
113+
114+
@Parcelize
115+
private class SavedState(
116+
val isSwipeEnabled: Boolean,
117+
val parentState: Parcelable,
118+
) : Parcelable
98119
}

app/src/main/res/layout/activity_main.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
android:id="@+id/root">
88

99
<androidx.coordinatorlayout.widget.CoordinatorLayout
10+
android:id="@+id/parent_coordinator"
1011
android:layout_width="match_parent"
1112
android:layout_height="match_parent">
1213

@@ -78,4 +79,4 @@
7879
android:layout_width="match_parent"
7980
android:layout_height="match_parent"
8081
android:visibility="gone"/>
81-
</FrameLayout>
82+
</FrameLayout>

0 commit comments

Comments
 (0)