Skip to content

Commit

Permalink
Android 15 upgrade (#3392)
Browse files Browse the repository at this point in the history
  • Loading branch information
geekygecko authored Jan 28, 2025
1 parent 3f6468c commit 5c1e2e1
Show file tree
Hide file tree
Showing 153 changed files with 1,595 additions and 1,284 deletions.
50 changes: 29 additions & 21 deletions app/src/main/java/au/com/shiftyjelly/pocketcasts/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.activity.enableEdgeToEdge
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
Expand All @@ -22,6 +23,7 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.platform.ComposeView
import androidx.core.content.ContextCompat
import androidx.core.view.WindowCompat
import androidx.core.view.doOnLayout
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
Expand Down Expand Up @@ -138,7 +140,8 @@ import au.com.shiftyjelly.pocketcasts.settings.onboarding.OnboardingUpgradeSourc
import au.com.shiftyjelly.pocketcasts.settings.whatsnew.WhatsNewFragment
import au.com.shiftyjelly.pocketcasts.ui.MainActivityViewModel.NavigationState
import au.com.shiftyjelly.pocketcasts.ui.helper.FragmentHostListener
import au.com.shiftyjelly.pocketcasts.ui.helper.StatusBarColor
import au.com.shiftyjelly.pocketcasts.ui.helper.NavigationBarColor
import au.com.shiftyjelly.pocketcasts.ui.helper.StatusBarIconColor
import au.com.shiftyjelly.pocketcasts.ui.theme.Theme
import au.com.shiftyjelly.pocketcasts.ui.theme.ThemeColor
import au.com.shiftyjelly.pocketcasts.utils.Network
Expand All @@ -149,6 +152,7 @@ import au.com.shiftyjelly.pocketcasts.utils.observeOnce
import au.com.shiftyjelly.pocketcasts.view.BottomNavHideManager
import au.com.shiftyjelly.pocketcasts.view.LockableBottomSheetBehavior
import au.com.shiftyjelly.pocketcasts.views.activity.WebViewActivity
import au.com.shiftyjelly.pocketcasts.views.extensions.setSystemWindowInsetToPadding
import au.com.shiftyjelly.pocketcasts.views.extensions.showAllowingStateLoss
import au.com.shiftyjelly.pocketcasts.views.fragments.BaseFragment
import au.com.shiftyjelly.pocketcasts.views.helper.HasBackstack
Expand Down Expand Up @@ -323,7 +327,7 @@ class MainActivity :
shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS) -> {
if (settings.isNotificationsDisabledMessageShown()) return
Snackbar.make(
findViewById(R.id.root),
snackBarView(),
getString(LR.string.notifications_blocked_warning),
EXTRA_LONG_SNACKBAR_DURATION_MS,
).setAction(
Expand All @@ -350,8 +354,11 @@ class MainActivity :

override fun onCreate(savedInstanceState: Bundle?) {
Timber.d("Main Activity onCreate")
// Changing the theme draws the status and navigation bars as black, unless this is manually set
WindowCompat.setDecorFitsSystemWindows(window, false)
super.onCreate(savedInstanceState)
theme.setupThemeForConfig(this, resources.configuration)
enableEdgeToEdge(navigationBarStyle = theme.getNavigationBarStyle(this))

playbackManager.setNotificationPermissionChecker(this)

Expand All @@ -366,6 +373,8 @@ class MainActivity :
setContentView(view)
checkForNotificationPermission()

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

binding.bottomNavigation.doOnLayout {
val miniPlayerHeight = miniPlayerHeight
val bottomNavigationHeight = binding.bottomNavigation.height
Expand Down Expand Up @@ -453,7 +462,7 @@ class MainActivity :
}
navigator.infoStream()
.doOnNext {
updateStatusBar()
updateSystemColors()
if (it is NavigatorAction.TabSwitched) {
val currentTab = navigator.currentTab()
if (settings.selectedTab() != currentTab) {
Expand Down Expand Up @@ -674,33 +683,32 @@ class MainActivity :
}

override fun updateStatusBar() {
val topFragment = navigator.currentFragment()
val topFragment = supportFragmentManager.fragments.lastOrNull()
val color = if (binding.playerBottomSheet.isPlayerOpen) {
val playerBgColor = theme.playerBackgroundColor(viewModel.lastPlaybackState?.podcast)
StatusBarColor.Custom(playerBgColor, true)
StatusBarIconColor.Light
} else if (topFragment is BaseFragment) {
topFragment.statusBarColor
topFragment.statusBarIconColor
} else {
null
}

if (color != null) {
theme.updateWindowStatusBar(window = window, statusBarColor = color, context = this)
theme.updateWindowStatusBarIcons(window = window, statusBarIconColor = color)
}
}

private fun updateNavAndStatusColors(playerOpen: Boolean, playingPodcast: Podcast?) {
if (playerOpen) {
val playerBgColor = theme.playerBackgroundColor(playingPodcast)
theme.setNavigationBarColor(window, true, playerBgColor)
val navigationBarColor = if (playerOpen) {
NavigationBarColor.Player(playingPodcast)
} else {
theme.setNavigationBarColor(
window,
theme.isDarkTheme,
ThemeColor.primaryUi03(theme.activeTheme),
)
NavigationBarColor.Theme
}

theme.updateWindowNavigationBarColor(window = window, navigationBarColor = navigationBarColor)

// Color the side bars of the screen if there is inset for areas such as cameras
binding.root.setBackgroundColor(theme.getNavigationBarColor(navigationBarColor))

updateStatusBar()
}

Expand Down Expand Up @@ -799,7 +807,7 @@ class MainActivity :
}

if (viewModel.isPlayerOpen && isEpisodeChanged) {
updateNavAndStatusColors(true, state.podcast)
updateNavAndStatusColors(playerOpen = true, playingPodcast = state.podcast)
}

if (lastPlaybackState != null && (isEpisodeChanged || isPlaybackChanged) && settings.openPlayerAutomatically.value) {
Expand Down Expand Up @@ -942,8 +950,9 @@ class MainActivity :
}

binding.playerBottomSheet.isDragEnabled = true
frameBottomSheetBehavior.swipeEnabled = false

updateNavAndStatusColors(playerOpen = viewModel.isPlayerOpen, viewModel.lastPlaybackState?.podcast)
updateNavAndStatusColors(playerOpen = viewModel.isPlayerOpen, playingPodcast = viewModel.lastPlaybackState?.podcast)
} else {
binding.playerBottomSheet.isDragEnabled = false
}
Expand Down Expand Up @@ -999,7 +1008,6 @@ class MainActivity :

override fun onMiniPlayerVisible() {
updateSnackbarPosition(miniPlayerOpen = true)

settings.updateBottomInset(miniPlayerHeight)

// Handle up next shortcut
Expand All @@ -1026,7 +1034,7 @@ class MainActivity :
}
}

updateNavAndStatusColors(true, viewModel.lastPlaybackState?.podcast)
updateNavAndStatusColors(playerOpen = true, playingPodcast = viewModel.lastPlaybackState?.podcast)
UiUtil.hideKeyboard(binding.root)

viewModel.isPlayerOpen = true
Expand All @@ -1037,7 +1045,7 @@ class MainActivity :
}

override fun onPlayerClosed() {
updateNavAndStatusColors(false, null)
updateNavAndStatusColors(playerOpen = false, playingPodcast = null)

viewModel.isPlayerOpen = false
viewModel.closeMultiSelect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.google.android.material.bottomsheet.ViewPager2AwareBottomSheetBehavio
class LockableBottomSheetBehavior<V : View> : ViewPager2AwareBottomSheetBehavior<V> {
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)

var swipeEnabled = true
var swipeEnabled = false

override fun onInterceptTouchEvent(
parent: CoordinatorLayout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.fragment.app.Fragment
import androidx.fragment.compose.content
import au.com.shiftyjelly.pocketcasts.compose.AutomotiveTheme
import au.com.shiftyjelly.pocketcasts.compose.components.HorizontalDivider
import au.com.shiftyjelly.pocketcasts.compose.extensions.contentWithoutConsumedInsets
import au.com.shiftyjelly.pocketcasts.compose.theme
import au.com.shiftyjelly.pocketcasts.extensions.openUrl
import au.com.shiftyjelly.pocketcasts.localization.BuildConfig
Expand All @@ -49,7 +49,7 @@ class AutomotiveAboutFragment : Fragment() {
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
) = content {
) = contentWithoutConsumedInsets {
AutomotiveTheme {
AboutPage(
onOpenLicenses = { openLicenses() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.fragment.app.Fragment
import androidx.fragment.compose.content
import au.com.shiftyjelly.pocketcasts.compose.AutomotiveTheme
import au.com.shiftyjelly.pocketcasts.compose.extensions.contentWithoutConsumedInsets
import au.com.shiftyjelly.pocketcasts.compose.theme
import au.com.shiftyjelly.pocketcasts.extensions.openUrl
import com.mikepenz.aboutlibraries.Libs
Expand All @@ -27,7 +27,7 @@ class AutomotiveLicensesFragment : Fragment() {
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
) = content {
) = contentWithoutConsumedInsets {
AutomotiveTheme {
LicensesPage()
}
Expand Down
4 changes: 2 additions & 2 deletions dependencies.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ project.apply {
set("minSdkVersion", 24)
set("minSdkVersionWear", 26)
set("minSdkVersionAutomotive", 28)
set("targetSdkVersion", 34)
set("compileSdkVersion", 34)
set("targetSdkVersion", 35)
set("compileSdkVersion", 35)
set("testInstrumentationRunner", "androidx.test.runner.AndroidJUnitRunner")

// App Signing
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ guava = "com.google.guava:guava:33.3.1-android" # Required to fix conflict betwe
jsonassert = "org.skyscreamer:jsonassert:1.5.3"
junit = "junit:junit:4.13.2"
leakcanary = "com.squareup.leakcanary:leakcanary-android:2.14"
material = "com.google.android.material:material:1.9.0"
material = "com.google.android.material:material:1.12.0"
material-dialogs = "com.afollestad.material-dialogs:core:3.3.0"
material-progressbar = "me.zhanghai.android.materialprogressbar:library:1.6.1"
play-auth = "com.google.android.gms:play-services-auth:20.4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.fragment.app.activityViewModels
import androidx.fragment.compose.content
import au.com.shiftyjelly.pocketcasts.account.viewmodel.DoneViewModel
import au.com.shiftyjelly.pocketcasts.compose.AppThemeWithBackground
import au.com.shiftyjelly.pocketcasts.compose.extensions.contentWithoutConsumedInsets
import au.com.shiftyjelly.pocketcasts.views.fragments.BaseFragment
import dagger.hilt.android.AndroidEntryPoint

Expand All @@ -32,7 +32,7 @@ class ChangeDoneFragment : BaseFragment() {
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
) = content {
) = contentWithoutConsumedInsets {
AppThemeWithBackground(theme.activeTheme) {
ChangeDonePage(
viewModel = viewModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.fragment.app.activityViewModels
import androidx.fragment.compose.content
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import au.com.shiftyjelly.pocketcasts.account.AccountActivity.AccountUpdatedSource
import au.com.shiftyjelly.pocketcasts.account.viewmodel.ChangeEmailViewModel
import au.com.shiftyjelly.pocketcasts.account.viewmodel.DoneViewModel
import au.com.shiftyjelly.pocketcasts.compose.AppThemeWithBackground
import au.com.shiftyjelly.pocketcasts.compose.extensions.contentWithoutConsumedInsets
import au.com.shiftyjelly.pocketcasts.preferences.Settings
import au.com.shiftyjelly.pocketcasts.ui.extensions.setupKeyboardModePan
import au.com.shiftyjelly.pocketcasts.ui.extensions.setupKeyboardModeResize
Expand All @@ -41,7 +41,7 @@ class ChangeEmailFragment : BaseFragment() {
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
) = content {
) = contentWithoutConsumedInsets {
val email: String by viewModel.email.observeAsState("")
val password: String by viewModel.password.observeAsState("")
val bottomOffset by settings.bottomInset.collectAsStateWithLifecycle(initialValue = 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.fragment.compose.content
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import au.com.shiftyjelly.pocketcasts.account.viewmodel.ChangePwdViewModel
import au.com.shiftyjelly.pocketcasts.account.viewmodel.DoneViewModel
import au.com.shiftyjelly.pocketcasts.compose.AppThemeWithBackground
import au.com.shiftyjelly.pocketcasts.compose.extensions.contentWithoutConsumedInsets
import au.com.shiftyjelly.pocketcasts.preferences.Settings
import au.com.shiftyjelly.pocketcasts.ui.helper.FragmentHostListener
import au.com.shiftyjelly.pocketcasts.utils.extensions.pxToDp
Expand All @@ -40,7 +40,7 @@ class ChangePwdFragment : BaseFragment() {
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
) = content {
) = contentWithoutConsumedInsets {
val bottomOffset by settings.bottomInset.collectAsStateWithLifecycle(initialValue = 0)
AppThemeWithBackground(theme.activeTheme) {
ChangePasswordPage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal fun OnboardingCreateAccountPage(

LaunchedEffect(Unit) {
// Use secondaryUI01 so the status bar matches the ThemedTopAppBar
val statusBar = SystemBarStyle.custom(pocketCastsTheme.colors.secondaryUi01, theme.defaultLightIcons)
val statusBar = SystemBarStyle.custom(pocketCastsTheme.colors.secondaryUi01, theme.toolbarLightIcons)
val navigationBar = SystemBarStyle.transparent { theme.darkTheme }
onUpdateSystemBars(SystemBarsStyles(statusBar, navigationBar))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fun OnboardingForgotPasswordPage(
LaunchedEffect(Unit) {
emailFocusRequester.requestFocus()
// Use secondaryUI01 so the status bar matches the ThemedTopAppBar
val statusBar = SystemBarStyle.custom(pocketCastsTheme.colors.secondaryUi01, theme.defaultLightIcons)
val statusBar = SystemBarStyle.custom(pocketCastsTheme.colors.secondaryUi01, theme.toolbarLightIcons)
val navigationBar = SystemBarStyle.transparent { theme.darkTheme }
onUpdateSystemBars(SystemBarsStyles(statusBar, navigationBar))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal fun OnboardingLoginPage(

LaunchedEffect(Unit) {
// Use secondaryUI01 so the status bar matches the ThemedTopAppBar
val statusBar = SystemBarStyle.custom(pocketCastsTheme.colors.secondaryUi01, theme.defaultLightIcons)
val statusBar = SystemBarStyle.custom(pocketCastsTheme.colors.secondaryUi01, theme.toolbarLightIcons)
val navigationBar = SystemBarStyle.transparent { theme.darkTheme }
onUpdateSystemBars(SystemBarsStyles(statusBar, navigationBar))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import au.com.shiftyjelly.pocketcasts.discover.R.layout
import au.com.shiftyjelly.pocketcasts.localization.helper.tryToLocalise
import au.com.shiftyjelly.pocketcasts.views.extensions.setSystemWindowInsetToPadding
import au.com.shiftyjelly.pocketcasts.views.fragments.BaseDialogFragment
import com.google.android.material.bottomsheet.BottomSheetBehavior

Expand Down Expand Up @@ -36,6 +37,8 @@ class CategoriesBottomSheet(
}
recyclerView.adapter = adapter

recyclerView.setSystemWindowInsetToPadding(bottom = true)

val sortedCategories = categories.map {
it.copy(discoverCategory = it.discoverCategory.copy(name = it.discoverCategory.name.tryToLocalise(resources)))
}.sortedBy { it.discoverCategory.name }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ import au.com.shiftyjelly.pocketcasts.servers.model.ExpandedStyle
import au.com.shiftyjelly.pocketcasts.servers.model.ListType
import au.com.shiftyjelly.pocketcasts.servers.model.NetworkLoadableList
import au.com.shiftyjelly.pocketcasts.ui.helper.FragmentHostListener
import au.com.shiftyjelly.pocketcasts.ui.helper.StatusBarColor
import au.com.shiftyjelly.pocketcasts.views.fragments.BaseFragment
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import kotlinx.coroutines.launch

@AndroidEntryPoint
class DiscoverFragment : BaseFragment(), DiscoverAdapter.Listener, RegionSelectFragment.Listener {
override var statusBarColor: StatusBarColor = StatusBarColor.Light

@Inject lateinit var settings: Settings

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="14dp">
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
Expand All @@ -11,6 +10,7 @@
android:gravity="start"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingTop="24dp"
android:text="@string/discover_select_categories"
android:contentDescription="@string/discover_select_categories"
android:textAllCaps="true"
Expand All @@ -20,6 +20,7 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/categoriesRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:clipToPadding="false"/>

</LinearLayout>
</LinearLayout>
Loading

0 comments on commit 5c1e2e1

Please sign in to comment.