diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 3e4375040..38a2065c6 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -127,10 +127,9 @@ dependencies { implementation("com.google.accompanist:accompanist-pager-indicators:$accompanistVersion") implementation("com.google.accompanist:accompanist-flowlayout:$accompanistVersion") implementation("com.google.accompanist:accompanist-navigation-animation:$accompanistVersion") - implementation("com.google.accompanist:accompanist-systemuicontroller:$accompanistVersion") // LiveData - implementation("androidx.compose.runtime:runtime-livedata:1.6.2") + implementation("androidx.compose.runtime:runtime-livedata:1.6.3") implementation("androidx.lifecycle:lifecycle-runtime-compose:2.7.0") implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.7.0") @@ -163,20 +162,20 @@ dependencies { implementation("io.arrow-kt:arrow-core:1.2.3") // Unfortunately, ui tooling, and the markdown thing, still brings in the other material2 dependencies - implementation("androidx.compose.material3:material3:1.2.0") - implementation("androidx.compose.material3:material3-window-size-class:1.2.0") + implementation("androidx.compose.material3:material3:1.2.1") + implementation("androidx.compose.material3:material3-window-size-class:1.2.1") implementation("org.ocpsoft.prettytime:prettytime:5.0.7.Final") implementation("androidx.navigation:navigation-compose:2.7.7") testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.0") testImplementation("androidx.arch.core:core-testing:2.2.0") - implementation("androidx.compose.ui:ui:1.6.2") - implementation("androidx.compose.ui:ui-tooling-preview:1.6.2") - androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.6.2") - debugImplementation("androidx.compose.ui:ui-tooling:1.6.2") - debugImplementation("androidx.compose.ui:ui-test-manifest:1.6.2") - implementation("androidx.compose.material:material-icons-extended:1.6.2") + implementation("androidx.compose.ui:ui:1.6.3") + implementation("androidx.compose.ui:ui-tooling-preview:1.6.3") + androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.6.3") + debugImplementation("androidx.compose.ui:ui-tooling:1.6.3") + debugImplementation("androidx.compose.ui:ui-test-manifest:1.6.3") + implementation("androidx.compose.material:material-icons-extended:1.6.3") implementation("androidx.activity:activity-compose:1.8.2") testImplementation("junit:junit:4.13.2") @@ -186,7 +185,7 @@ dependencies { testImplementation("org.mockito:mockito-core:5.11.0") testImplementation("org.mockito.kotlin:mockito-kotlin:5.2.1") - implementation("androidx.browser:browser:1.7.0") + implementation("androidx.browser:browser:1.8.0") implementation("androidx.profileinstaller:profileinstaller:1.3.1") baselineProfile(project(":benchmarks")) diff --git a/app/src/main/java/com/jerboa/MainActivity.kt b/app/src/main/java/com/jerboa/MainActivity.kt index 8e5ae556f..cf801d974 100644 --- a/app/src/main/java/com/jerboa/MainActivity.kt +++ b/app/src/main/java/com/jerboa/MainActivity.kt @@ -7,6 +7,7 @@ import android.os.Bundle import android.util.Patterns import android.widget.TextView import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import androidx.compose.animation.EnterTransition @@ -90,7 +91,7 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - + enableEdgeToEdge() setContent { val ctx = LocalContext.current @@ -119,7 +120,7 @@ class MainActivity : AppCompatActivity() { } DisposableEffect(appSettings.backConfirmationMode) { - when (BackConfirmationMode.entries[appSettings.backConfirmationMode]) { + when (appSettings.backConfirmationMode.toEnum()) { BackConfirmationMode.Toast -> { this@MainActivity.addConfirmationToast(appState.navController, ctx) } diff --git a/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt b/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt index 35c4429f5..cf0711b76 100644 --- a/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt @@ -1,9 +1,6 @@ package com.jerboa.ui.components.home -import androidx.compose.foundation.layout.ExperimentalLayoutApi -import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.foundation.layout.isImeVisible -import androidx.compose.foundation.layout.padding +import android.annotation.SuppressLint import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.AppRegistration import androidx.compose.material.icons.filled.Bookmarks @@ -39,7 +36,6 @@ import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.testTagsAsResourceId -import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable @@ -144,8 +140,8 @@ enum class NavTab( } } +@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter") @OptIn( - ExperimentalLayoutApi::class, ExperimentalComposeUiApi::class, ) @Composable @@ -242,18 +238,10 @@ fun BottomNavActivity( ) } }, - ) { padding -> - val bottomPadding = - if (selectedTab == NavTab.Search && WindowInsets.isImeVisible) { - 0.dp - } else { - padding.calculateBottomPadding() - } - + ) { _ -> NavHost( navController = bottomNavController, startDestination = NavTab.Home.name, - modifier = Modifier.padding(bottom = bottomPadding), ) { composable(route = NavTab.Home.name) { HomeActivity( diff --git a/app/src/main/java/com/jerboa/ui/components/imageviewer/ImageViewerActivity.kt b/app/src/main/java/com/jerboa/ui/components/imageviewer/ImageViewerActivity.kt index d301eaeca..20ac16590 100644 --- a/app/src/main/java/com/jerboa/ui/components/imageviewer/ImageViewerActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/imageviewer/ImageViewerActivity.kt @@ -1,8 +1,6 @@ package com.jerboa.ui.components.imageviewer import android.app.Activity -import android.os.Build.VERSION.SDK_INT -import android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS import android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.tween @@ -39,16 +37,17 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.alpha import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalView import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.core.view.WindowCompat +import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE import androidx.lifecycle.compose.collectAsStateWithLifecycle import coil.request.ImageRequest -import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.jerboa.JerboaAppState import com.jerboa.JerboaApplication import com.jerboa.PostType @@ -75,43 +74,29 @@ fun ImageViewer( var showTopBar by remember { mutableStateOf(true) } val imageGifLoader = (ctx.applicationContext as JerboaApplication).imageViewerLoader - val systemUiController = rememberSystemUiController() val window = (ctx as Activity).window val controller = WindowCompat.getInsetsController(window, LocalView.current) - val oldBarColor = Color(window.statusBarColor) + + val oldBarColor = window.statusBarColor val oldIcons = controller.isAppearanceLightStatusBars - DisposableEffect(systemUiController) { - WindowCompat.setDecorFitsSystemWindows(window, false) - window.clearFlags(FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) + DisposableEffect(Unit) { + controller.isAppearanceLightStatusBars = false + window.statusBarColor = Color.Transparent.toArgb() // Unable to get the bottom navbar transparent without this @Suppress("DEPRECATION") window.addFlags(FLAG_TRANSLUCENT_NAVIGATION) - systemUiController.setStatusBarColor( - color = Color.Transparent, - darkIcons = false, - ) - - onDispose { // Restore previous system bars - - // Does weird behaviour on android 10 and below - if (SDK_INT >= 30) { - WindowCompat.setDecorFitsSystemWindows(window, true) - } - - systemUiController.setStatusBarColor( - color = oldBarColor, - darkIcons = oldIcons, - ) - + onDispose { if (!showTopBar) { - systemUiController.isSystemBarsVisible = true + controller.show(WindowInsetsCompat.Type.systemBars()) } - window.addFlags(FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) + controller.isAppearanceLightStatusBars = oldIcons + window.statusBarColor = oldBarColor + @Suppress("DEPRECATION") window.clearFlags(FLAG_TRANSLUCENT_NAVIGATION) } @@ -123,17 +108,15 @@ fun ImageViewer( mutableStateOf(ImageState.LOADING) } - val image = - remember { - ImageRequest.Builder(ctx) - .placeholder(null) - .data(url) - .setParameter("retry_hash", retryHash, memoryCacheKey = null) - .listener( - onSuccess = { _, _ -> imageState = ImageState.SUCCESS }, - onError = { _, _ -> imageState = ImageState.FAILED }, - ).build() - } + val image = remember { + ImageRequest.Builder(ctx) + .placeholder(null) + .data(url) + .setParameter("retry_hash", retryHash, memoryCacheKey = null).listener( + onSuccess = { _, _ -> imageState = ImageState.SUCCESS }, + onError = { _, _ -> imageState = ImageState.FAILED }, + ).build() + } val zoomableState = rememberZoomableState(ZoomSpec(20F, preventOverOrUnderZoom = false)) val zoomableImageState = rememberZoomableImageState(zoomableState) @@ -144,8 +127,7 @@ fun ImageViewer( }, content = { Box( - Modifier - .background(backColor), + Modifier.background(backColor), ) { if (imageState == ImageState.FAILED) { Column( @@ -171,10 +153,9 @@ fun ImageViewer( if (currentProgress.value.progressAvailable) { LinearProgressIndicator( progress = { currentProgress.value.progress }, - modifier = - Modifier - .padding(it) - .fillMaxWidth(), + modifier = Modifier + .padding(it) + .fillMaxWidth(), ) } else { LoadingBar(it) @@ -189,13 +170,17 @@ fun ImageViewer( state = zoomableImageState, onClick = { showTopBar = !showTopBar - systemUiController.isSystemBarsVisible = showTopBar + if (showTopBar) { + controller.show(WindowInsetsCompat.Type.systemBars()) + } else { + controller.hide(WindowInsetsCompat.Type.systemBars()) + } // Default behavior is that if navigation bar is hidden, the system will "steal" touches // and show it again upon user's touch. We just want the user to be able to show the // navigation bar by swipe, touches are handled by custom code -> change system bar behavior. // Alternative to deprecated SYSTEM_UI_FLAG_IMMERSIVE. - systemUiController.systemBarsBehavior = BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + controller.systemBarsBehavior = BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE }, modifier = Modifier.fillMaxSize(), ) diff --git a/app/src/main/java/com/jerboa/ui/theme/Theme.kt b/app/src/main/java/com/jerboa/ui/theme/Theme.kt index ac3a2fb80..ba8c04218 100644 --- a/app/src/main/java/com/jerboa/ui/theme/Theme.kt +++ b/app/src/main/java/com/jerboa/ui/theme/Theme.kt @@ -12,7 +12,6 @@ import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.ReadOnlyComposable import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalView import androidx.core.graphics.ColorUtils @@ -20,6 +19,7 @@ import androidx.core.view.WindowCompat import com.jerboa.ThemeColor import com.jerboa.ThemeMode import com.jerboa.db.entity.AppSettings +import com.jerboa.toEnum // Defines a provider for custom color scheme use; initializes it to a default scheme that will // be overridden by JerboaTheme @@ -30,8 +30,8 @@ fun JerboaTheme( appSettings: AppSettings, content: @Composable () -> Unit, ) { - val themeMode = ThemeMode.entries[appSettings.theme] - val themeColor = ThemeColor.entries[appSettings.themeColor] + val themeMode = appSettings.theme.toEnum() + val themeColor = appSettings.themeColor.toEnum() val fontSize = appSettings.fontSize val ctx = LocalContext.current @@ -55,7 +55,7 @@ fun JerboaTheme( ), ) } else { - pink() + blue() } val colorPair = @@ -122,10 +122,7 @@ fun JerboaTheme( window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) } - window.statusBarColor = colors.material.background.toArgb() - // The navigation bar color is also set on BottomAppBarAll - window.navigationBarColor = colors.material.background.toArgb() - + // The navigation bar color is set on BottomAppBarAll insets.isAppearanceLightStatusBars = isLight insets.isAppearanceLightNavigationBars = isLight diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 8cfd7d3a0..6a4e3d19d 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -1,9 +1,7 @@ -