Migrate to edge to edge

This commit is contained in:
Sad Ellie 2024-01-23 17:57:56 +03:00
parent 21585983c6
commit f2db674432
5 changed files with 50 additions and 40 deletions

View File

@ -1,6 +1,6 @@
/* /*
* Unitto is a unit converter for Android * Unitto is a unit converter for Android
* Copyright (c) 2023 Elshan Agaev * Copyright (c) 2023-2024 Elshan Agaev
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -129,14 +129,14 @@ dependencies {
implementation(libs.androidx.profileinstaller.profileinstaller) implementation(libs.androidx.profileinstaller.profileinstaller)
coreLibraryDesugaring(libs.com.android.tools.desugar.jdk.libs) coreLibraryDesugaring(libs.com.android.tools.desugar.jdk.libs)
implementation(libs.androidx.activity.activity.compose)
implementation(libs.androidx.appcompat.appcompat)
implementation(libs.androidx.lifecycle.lifecycle.runtime.compose)
implementation(libs.androidx.compose.material3) implementation(libs.androidx.compose.material3)
implementation(libs.androidx.compose.material3.window.size) implementation(libs.androidx.compose.material3.window.size)
implementation(libs.androidx.compose.material.icons.extended) implementation(libs.androidx.compose.material.icons.extended)
implementation(libs.androidx.lifecycle.lifecycle.runtime.compose)
implementation(libs.com.github.sadellie.themmo) implementation(libs.com.github.sadellie.themmo)
implementation(libs.com.google.accompanist.accompanist.systemuicontroller)
implementation(libs.androidx.datastore.datastore.preferences) implementation(libs.androidx.datastore.datastore.preferences)
implementation(libs.androidx.appcompat.appcompat)
implementation(project(":feature:converter")) implementation(project(":feature:converter"))
implementation(project(":feature:calculator")) implementation(project(":feature:calculator"))

View File

@ -18,11 +18,14 @@
package com.sadellie.unitto package com.sadellie.unitto
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.compose.BackHandler import androidx.activity.compose.BackHandler
import androidx.activity.enableEdgeToEdge
import androidx.compose.animation.core.tween import androidx.compose.animation.core.tween
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
@ -34,7 +37,6 @@ import androidx.compose.ui.platform.LocalContext
import androidx.navigation.NavGraph.Companion.findStartDestination import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.sadellie.unitto.core.ui.common.NavigationDrawer import com.sadellie.unitto.core.ui.common.NavigationDrawer
import com.sadellie.unitto.core.ui.common.rememberDrawerState import com.sadellie.unitto.core.ui.common.rememberDrawerState
import com.sadellie.unitto.core.ui.model.DrawerItem import com.sadellie.unitto.core.ui.model.DrawerItem
@ -48,13 +50,10 @@ import io.github.sadellie.themmo.ThemmoController
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@Composable @Composable
internal fun App(prefs: AppPreferences?) { internal fun ComponentActivity.App(prefs: AppPreferences?) {
val mContext = LocalContext.current val mContext = LocalContext.current
val navController = rememberNavController() val navController = rememberNavController()
val sysUiController = rememberSystemUiController()
// Navigation drawer stuff
val drawerScope = rememberCoroutineScope() val drawerScope = rememberCoroutineScope()
val drawerState = rememberDrawerState() val drawerState = rememberDrawerState()
@ -87,7 +86,7 @@ internal fun App(prefs: AppPreferences?) {
animationSpec = tween(250) animationSpec = tween(250)
) { ) {
val backgroundColor = MaterialTheme.colorScheme.background val backgroundColor = MaterialTheme.colorScheme.background
val useDarkIcons = remember(backgroundColor) { backgroundColor.luminance() > 0.5f } val isDarkThemeEnabled = remember(backgroundColor) { backgroundColor.luminance() < 0.5f }
NavigationDrawer( NavigationDrawer(
modifier = Modifier, modifier = Modifier,
@ -119,9 +118,18 @@ internal fun App(prefs: AppPreferences?) {
} }
) )
LaunchedEffect(useDarkIcons) { DisposableEffect(isDarkThemeEnabled) {
sysUiController.setNavigationBarColor(Color.Transparent, useDarkIcons) enableEdgeToEdge(
sysUiController.setStatusBarColor(Color.Transparent, useDarkIcons) statusBarStyle = SystemBarStyle.auto(
android.graphics.Color.TRANSPARENT,
android.graphics.Color.TRANSPARENT,
) { isDarkThemeEnabled },
navigationBarStyle = SystemBarStyle.auto(
lightScrim,
darkScrim,
) { isDarkThemeEnabled },
)
onDispose {}
} }
} }
@ -134,4 +142,8 @@ private fun Long.toColor(): Color = try {
Color(this.toULong()) Color(this.toULong())
} catch (e: Exception) { } catch (e: Exception) {
Color.Unspecified Color.Unspecified
} }
// The default scrims, as defined by androidx and the platform
private val lightScrim = android.graphics.Color.argb(0xe6, 0xFF, 0xFF, 0xFF)
private val darkScrim = android.graphics.Color.argb(0x80, 0x1b, 0x1b, 0x1b)

View File

@ -18,19 +18,15 @@
package com.sadellie.unitto package com.sadellie.unitto
import android.app.Activity
import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.util.AttributeSet
import android.view.View
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalConfiguration
import androidx.core.os.ConfigurationCompat import androidx.core.os.ConfigurationCompat
import androidx.core.view.WindowCompat
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.sadellie.unitto.core.ui.LocalHapticPreference import com.sadellie.unitto.core.ui.LocalHapticPreference
import com.sadellie.unitto.core.ui.LocalLocale import com.sadellie.unitto.core.ui.LocalLocale
@ -53,6 +49,7 @@ internal class MainActivity : AppCompatActivity() {
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class) @OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent { setContent {
val configuration = LocalConfiguration.current val configuration = LocalConfiguration.current
@ -77,17 +74,4 @@ internal class MainActivity : AppCompatActivity() {
} }
} }
} }
override fun onCreateView(
parent: View?,
name: String,
context: Context,
attrs: AttributeSet
): View? {
val window = (parent?.context as? Activity)?.window
if (window != null) {
WindowCompat.setDecorFitsSystemWindows(window, false)
}
return super.onCreateView(parent, name, context, attrs)
}
} }

View File

@ -1,7 +1,21 @@
<!--
~ Unitto is a unit converter for Android
~ Copyright (c) 2024 Elshan Agaev
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<resources> <resources>
<style name="Theme.Unitto" parent="Theme.AppCompat.DayNight.NoActionBar"> <style name="Theme.Unitto" parent="Theme.AppCompat.DayNight.NoActionBar"/>
<item name="android:windowBackground">@color/window_background</item>
<item name="android:statusBarColor">@color/window_background</item>
<item name="android:navigationBarColor">@color/window_background</item>
</style>
</resources> </resources>

View File

@ -4,6 +4,7 @@ versionName = "Quick Silver"
androidxBrowserBrowser = "1.7.0" androidxBrowserBrowser = "1.7.0"
androidGradlePlugin = "8.2.1" androidGradlePlugin = "8.2.1"
androidxActivityActivityCompose = "1.8.2"
androidxAppCompatAppCompat = "1.6.1" androidxAppCompatAppCompat = "1.6.1"
androidxCompose = "1.6.0-rc01" androidxCompose = "1.6.0-rc01"
androidxComposeCompiler = "1.5.8" androidxComposeCompiler = "1.5.8"
@ -26,7 +27,6 @@ androidxWindowWindow = "1.2.0"
androidxWorkWorkRuntimeKtx = "2.9.0" androidxWorkWorkRuntimeKtx = "2.9.0"
comAndroidToolsDesugarJdkLibs = "2.0.4" comAndroidToolsDesugarJdkLibs = "2.0.4"
comGithubSadellieThemmo = "1.3.0" comGithubSadellieThemmo = "1.3.0"
comGoogleAccompanistAccompanistSystemuicontroller = "0.30.1"
comGoogleDagger = "2.48.1" comGoogleDagger = "2.48.1"
comSquareupMoshiMoshiKotlin = "1.15.0" comSquareupMoshiMoshiKotlin = "1.15.0"
comSquareupRetrofit2ConverterMoshi = "2.9.0" comSquareupRetrofit2ConverterMoshi = "2.9.0"
@ -39,6 +39,7 @@ orgJetbrainsKotlinxKotlinxCoroutinesTest = "1.7.3"
orgRobolectricRobolectric = "4.11.1" orgRobolectricRobolectric = "4.11.1"
[libraries] [libraries]
androidx-activity-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "androidxActivityActivityCompose" }
androidx-appcompat-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidxAppCompatAppCompat" } androidx-appcompat-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidxAppCompatAppCompat" }
androidx-benchmark-macro = { group = "androidx.benchmark", name = "benchmark-macro-junit4", version.ref = "androidxMacroBenchmark" } androidx-benchmark-macro = { group = "androidx.benchmark", name = "benchmark-macro-junit4", version.ref = "androidxMacroBenchmark" }
androidx-browser-browser = { group = "androidx.browser", name = "browser", version.ref = "androidxBrowserBrowser" } androidx-browser-browser = { group = "androidx.browser", name = "browser", version.ref = "androidxBrowserBrowser" }
@ -73,7 +74,6 @@ androidx-work-work-runtime-ktx = { group = "androidx.work", name = "work-runtime
com-android-tools-desugar-jdk-libs = { group = "com.android.tools", name = "desugar_jdk_libs", version.ref = "comAndroidToolsDesugarJdkLibs" } com-android-tools-desugar-jdk-libs = { group = "com.android.tools", name = "desugar_jdk_libs", version.ref = "comAndroidToolsDesugarJdkLibs" }
com-github-sadellie-themmo = { group = "com.github.sadellie.themmo", name = "themmo", version.ref = "comGithubSadellieThemmo" } com-github-sadellie-themmo = { group = "com.github.sadellie.themmo", name = "themmo", version.ref = "comGithubSadellieThemmo" }
com-github-sadellie-themmo-core = { group = "com.github.sadellie.themmo", name = "themmo-core", version.ref = "comGithubSadellieThemmo" } com-github-sadellie-themmo-core = { group = "com.github.sadellie.themmo", name = "themmo-core", version.ref = "comGithubSadellieThemmo" }
com-google-accompanist-accompanist-systemuicontroller = { group = "com.google.accompanist", name = "accompanist-systemuicontroller", version.ref = "comGoogleAccompanistAccompanistSystemuicontroller" }
com-google-dagger-android-hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "comGoogleDagger" } com-google-dagger-android-hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "comGoogleDagger" }
com-google-dagger-dagger-android-processor = { group = "com.google.dagger", name = "dagger-android-processor", version.ref = "comGoogleDagger" } com-google-dagger-dagger-android-processor = { group = "com.google.dagger", name = "dagger-android-processor", version.ref = "comGoogleDagger" }
com-google-dagger-hilt-compiler = { group = "com.google.dagger", name = "hilt-compiler", version.ref = "comGoogleDagger" } com-google-dagger-hilt-compiler = { group = "com.google.dagger", name = "hilt-compiler", version.ref = "comGoogleDagger" }