Skip to content

Commit

Permalink
Starting to remove SystemUiController since it's deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
jakepurple13 committed Sep 22, 2023
1 parent aebd53f commit 91be1db
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 60 deletions.
2 changes: 2 additions & 0 deletions UIViews/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ dependencies {

implementation(libs.bundles.ktorLibs)

implementation(libs.androidx.activity.ktx)

//Multiplatform
implementation(projects.imageloader)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
15 changes: 0 additions & 15 deletions UIViews/src/main/java/com/programmersbox/uiviews/utils/MockData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
36 changes: 20 additions & 16 deletions UIViews/src/main/java/com/programmersbox/uiviews/utils/Screen.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
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
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
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" }
Expand Down Expand Up @@ -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" }
Expand Down Expand Up @@ -281,7 +282,7 @@ compose = [
"composeConstraintLayout", "permissions",
"drawablePainter", "uiUtil",
"materialYou", "materialWindow",
"navCompose", "navMaterial", "systemUiController"
"navCompose", "navMaterial"
]
composeTv = [
"composeUi", "composeUiTooling",
Expand All @@ -293,7 +294,7 @@ composeTv = [
"coilCompose",
"composeConstraintLayout", "permissions",
"drawablePainter", "uiUtil",
"navCompose", "navMaterial", "systemUiController"
"navCompose", "navMaterial"
]
media3 = [
"exoplayer",
Expand Down

0 comments on commit 91be1db

Please sign in to comment.