diff --git a/UIViews/build.gradle.kts b/UIViews/build.gradle.kts index ab4d830b6..543953a23 100644 --- a/UIViews/build.gradle.kts +++ b/UIViews/build.gradle.kts @@ -111,6 +111,8 @@ dependencies { implementation(libs.bundles.ktorLibs) + implementation(libs.androidx.activity.ktx) + //Multiplatform implementation(projects.imageloader) diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/BaseMainActivity.kt b/UIViews/src/main/java/com/programmersbox/uiviews/BaseMainActivity.kt index 5bf3f3241..49673e629 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/BaseMainActivity.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/BaseMainActivity.kt @@ -8,6 +8,7 @@ import android.os.Build import android.os.Bundle import androidx.activity.compose.BackHandler import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate import androidx.compose.animation.AnimatedContentTransitionScope @@ -65,11 +66,13 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue +import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource import androidx.core.view.WindowCompat +import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsControllerCompat import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.lifecycleScope @@ -89,7 +92,6 @@ import com.google.accompanist.drawablepainter.rememberDrawablePainter import com.google.accompanist.navigation.material.ExperimentalMaterialNavigationApi import com.google.accompanist.permissions.ExperimentalPermissionsApi import com.google.accompanist.permissions.rememberPermissionState -import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.programmersbox.extensionloader.SourceRepository import com.programmersbox.favoritesdatabase.ItemDatabase import com.programmersbox.helpfulutils.notificationManager @@ -174,7 +176,20 @@ abstract class BaseMainActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setup() onCreate() - WindowCompat.setDecorFitsSystemWindows(window, false) + + enableEdgeToEdge() + + val insetsController = WindowCompat.getInsetsController(window, window.decorView) + insetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + snapshotFlow { showNavBar } + .onEach { + if (it) { + insetsController.show(WindowInsetsCompat.Type.systemBars()) + } else { + insetsController.hide(WindowInsetsCompat.Type.systemBars()) + } + } + .launchIn(lifecycleScope) setContent { val bottomSheetNavigator = rememberBottomSheetNavigator(skipHalfExpanded = true) @@ -188,17 +203,8 @@ abstract class BaseMainActivity : AppCompatActivity() { scope.launch { bottomSheetNavigator.sheetState.hide() } } - val systemUiController = rememberSystemUiController() val customPreferences = remember { ComposeSettingsDsl().apply(genericInfo.composeCustomPreferences(navController)) } - if (showNavBar) { - systemUiController.isSystemBarsVisible = true - systemUiController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE - } else { - systemUiController.isSystemBarsVisible = false - systemUiController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE - } - val windowSize = calculateWindowSizeClass(activity = this@BaseMainActivity) OtakuMaterialTheme(navController, genericInfo) { diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/utils/MockData.kt b/UIViews/src/main/java/com/programmersbox/uiviews/utils/MockData.kt index 32e57c030..b4cbc08a9 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/utils/MockData.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/utils/MockData.kt @@ -26,7 +26,6 @@ import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.runtime.SideEffect import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -38,7 +37,6 @@ import androidx.fragment.app.FragmentActivity import androidx.navigation.NavController import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController -import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.programmersbox.extensionloader.SourceRepository import com.programmersbox.favoritesdatabase.DbModel import com.programmersbox.favoritesdatabase.HistoryDatabase @@ -187,19 +185,6 @@ fun PreviewTheme( secondary = Color(0xff90CAF9) ), ) { - val systemUiController = rememberSystemUiController() - - SideEffect { - systemUiController.setNavigationBarColor( - color = Color.Transparent, - darkIcons = !darkTheme - ) - systemUiController.setStatusBarColor( - color = Color.Transparent, - darkIcons = !darkTheme - ) - } - CompositionLocalProvider( LocalNavController provides navController, LocalGenericInfo provides genericInfo, diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/utils/Screen.kt b/UIViews/src/main/java/com/programmersbox/uiviews/utils/Screen.kt index 55891d768..733b6bf10 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/utils/Screen.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/utils/Screen.kt @@ -1,6 +1,9 @@ package com.programmersbox.uiviews.utils import android.net.Uri +import androidx.activity.ComponentActivity +import androidx.activity.SystemBarStyle +import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatDelegate import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material.darkColors @@ -8,14 +11,13 @@ import androidx.compose.material.lightColors import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.runtime.SideEffect +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.remember import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.navigation.NavController import androidx.navigation.NavHostController -import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.programmersbox.extensionloader.SourceRepository import com.programmersbox.favoritesdatabase.HistoryDao import com.programmersbox.favoritesdatabase.HistoryDatabase @@ -79,11 +81,26 @@ fun NavController.navigateToDetails(model: ItemModel) = navigate( fun OtakuMaterialTheme( navController: NavHostController, genericInfo: GenericInfo, - content: @Composable () -> Unit + content: @Composable () -> Unit, ) { val context = LocalContext.current val darkTheme = AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES || (isSystemInDarkTheme() && AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) + + DisposableEffect(darkTheme) { + (context as? ComponentActivity)?.enableEdgeToEdge( + statusBarStyle = SystemBarStyle.auto( + android.graphics.Color.TRANSPARENT, + android.graphics.Color.TRANSPARENT, + ) { darkTheme }, + navigationBarStyle = SystemBarStyle.auto( + android.graphics.Color.TRANSPARENT, + android.graphics.Color.TRANSPARENT, + ) { darkTheme }, + ) + onDispose {} + } + MaterialTheme(currentColorScheme) { androidx.compose.material.MaterialTheme( colors = if (darkTheme) @@ -97,19 +114,6 @@ fun OtakuMaterialTheme( secondary = Color(0xff90CAF9) ), ) { - val systemUiController = rememberSystemUiController() - - SideEffect { - systemUiController.setNavigationBarColor( - color = Color.Transparent, - darkIcons = !darkTheme - ) - systemUiController.setStatusBarColor( - color = Color.Transparent, - darkIcons = !darkTheme - ) - } - CompositionLocalProvider( LocalActivity provides remember { context.findActivity() }, LocalNavController provides navController, diff --git a/animeworldtv/src/main/java/com/programmersbox/animeworldtv/compose/Utils.kt b/animeworldtv/src/main/java/com/programmersbox/animeworldtv/compose/Utils.kt index ca8cc6861..c66c2b8a3 100644 --- a/animeworldtv/src/main/java/com/programmersbox/animeworldtv/compose/Utils.kt +++ b/animeworldtv/src/main/java/com/programmersbox/animeworldtv/compose/Utils.kt @@ -13,7 +13,6 @@ import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.Immutable -import androidx.compose.runtime.SideEffect import androidx.compose.runtime.remember import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.Modifier @@ -31,7 +30,6 @@ import androidx.tv.material3.ExperimentalTvMaterial3Api import androidx.tv.material3.MaterialTheme import androidx.tv.material3.darkColorScheme import androidx.tv.material3.lightColorScheme -import com.google.accompanist.systemuicontroller.rememberSystemUiController @OptIn(ExperimentalTvMaterial3Api::class) @Composable @@ -43,19 +41,6 @@ fun OtakuMaterialTheme( val darkTheme = AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES || (isSystemInDarkTheme() && AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) MaterialTheme(currentColorScheme) { - val systemUiController = rememberSystemUiController() - - SideEffect { - systemUiController.setNavigationBarColor( - color = Color.Transparent, - darkIcons = !darkTheme - ) - systemUiController.setStatusBarColor( - color = Color.Transparent, - darkIcons = !darkTheme - ) - } - CompositionLocalProvider( LocalActivity provides remember { context.findActivity() }, LocalNavController provides navController, diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 45a03c44d..377886b77 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -27,6 +27,7 @@ ziplineVersion = "1.1.0" landscapist = "2.2.8" protobufVersion = "3.24.3" sketchVersion = "3.2.5" +activityKtx = "1.8.0-beta01" composeBomVersion = "2023.10.00-alpha02" ### MangaWorld @@ -52,6 +53,7 @@ kotlinStLib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "ko navigation-safe-args-gradle-plugin = { module = "androidx.navigation:navigation-safe-args-gradle-plugin", version.ref = "navVersion" } palette = "androidx.palette:palette-ktx:1.0.0" gson = "com.google.code.gson:gson:2.10.1" +androidx-activity-ktx = { module = "androidx.activity:activity-ktx", version.ref = "activityKtx" } #Compose composePlatform = { module = "dev.chrisbanes.compose:compose-bom", version.ref = "composeBomVersion" } @@ -83,7 +85,6 @@ navCompose = { module = "androidx.navigation:navigation-compose", version.ref = drawablePainter = { module = "com.google.accompanist:accompanist-drawablepainter", version.ref = "accompanist" } permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanist" } navMaterial = { module = "com.google.accompanist:accompanist-navigation-material", version.ref = "accompanist" } -systemUiController = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "accompanist" } adaptive = { module = "com.google.accompanist:accompanist-adaptive", version.ref = "accompanist" } okhttpLib = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttpVersion" } okhttpDns = { module = "com.squareup.okhttp3:okhttp-dnsoverhttps", version.ref = "okhttpVersion" } @@ -281,7 +282,7 @@ compose = [ "composeConstraintLayout", "permissions", "drawablePainter", "uiUtil", "materialYou", "materialWindow", - "navCompose", "navMaterial", "systemUiController" + "navCompose", "navMaterial" ] composeTv = [ "composeUi", "composeUiTooling", @@ -293,7 +294,7 @@ composeTv = [ "coilCompose", "composeConstraintLayout", "permissions", "drawablePainter", "uiUtil", - "navCompose", "navMaterial", "systemUiController" + "navCompose", "navMaterial" ] media3 = [ "exoplayer",