Skip to content

Commit 0a70eb0

Browse files
authored
feat: edge-to-edge display (#229)
1 parent e7f1782 commit 0a70eb0

7 files changed

Lines changed: 27 additions & 33 deletions

File tree

.idea/ktfmt.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ android {
5353
kotlinOptions {
5454
jvmTarget = "17"
5555
freeCompilerArgs +=
56-
listOf(
57-
"-opt-in=kotlin.RequiresOptIn",
58-
"-opt-in=kotlin.time.ExperimentalTime",
59-
"-opt-in=io.ktor.utils.io.InternalAPI",
60-
)
56+
listOf(
57+
"-opt-in=kotlin.RequiresOptIn",
58+
"-opt-in=kotlin.time.ExperimentalTime",
59+
"-opt-in=io.ktor.utils.io.InternalAPI",
60+
)
6161
}
6262

6363
buildFeatures { compose = true }
@@ -121,12 +121,10 @@ dependencies {
121121

122122
implementation(libs.android.billingclient.ktx)
123123
implementation(libs.androidx.activity.compose)
124-
implementation(libs.androidx.appcompat)
125124
implementation(libs.androidx.core.ktx)
126125
implementation(libs.androidx.datastore)
127126
implementation(libs.androidx.hilt.navigation.compose)
128127
implementation(libs.androidx.navigation.compose)
129-
implementation(libs.bundles.accompanist)
130128
implementation(libs.bundles.compose)
131129
implementation(libs.bundles.kotlin)
132130
implementation(libs.bundles.ktor)
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
package com.tien.piholeconnect
22

33
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
45
import androidx.activity.compose.setContent
5-
import androidx.appcompat.app.AppCompatActivity
6+
import androidx.activity.enableEdgeToEdge
67
import com.tien.piholeconnect.service.InAppPurchase
78
import com.tien.piholeconnect.ui.App
89
import dagger.hilt.android.AndroidEntryPoint
910
import javax.inject.Inject
1011

1112
@AndroidEntryPoint
12-
class MainActivity : AppCompatActivity() {
13+
class MainActivity : ComponentActivity() {
1314
@Inject lateinit var inAppPurchase: InAppPurchase
1415

1516
override fun onCreate(savedInstanceState: Bundle?) {
1617
super.onCreate(savedInstanceState)
18+
1719
lifecycle.addObserver(inAppPurchase)
20+
21+
enableEdgeToEdge()
22+
1823
setContent { App() }
1924
}
2025
}

app/src/main/java/com/tien/piholeconnect/ui/App.kt

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.net.Uri
55
import androidx.compose.foundation.isSystemInDarkTheme
66
import androidx.compose.foundation.layout.Box
77
import androidx.compose.foundation.layout.Spacer
8+
import androidx.compose.foundation.layout.consumeWindowInsets
89
import androidx.compose.foundation.layout.fillMaxSize
910
import androidx.compose.foundation.layout.fillMaxWidth
1011
import androidx.compose.foundation.layout.padding
@@ -23,14 +24,11 @@ import androidx.compose.material3.Button
2324
import androidx.compose.material3.ButtonDefaults
2425
import androidx.compose.material3.Icon
2526
import androidx.compose.material3.MaterialTheme
26-
import androidx.compose.material3.NavigationBarDefaults
2727
import androidx.compose.material3.Scaffold
2828
import androidx.compose.material3.SnackbarHost
2929
import androidx.compose.material3.SnackbarHostState
3030
import androidx.compose.material3.Text
31-
import androidx.compose.material3.surfaceColorAtElevation
3231
import androidx.compose.runtime.Composable
33-
import androidx.compose.runtime.SideEffect
3432
import androidx.compose.runtime.getValue
3533
import androidx.compose.runtime.remember
3634
import androidx.compose.ui.Alignment
@@ -45,7 +43,6 @@ import androidx.navigation.compose.composable
4543
import androidx.navigation.compose.currentBackStackEntryAsState
4644
import androidx.navigation.compose.rememberNavController
4745
import androidx.navigation.navArgument
48-
import com.google.accompanist.systemuicontroller.rememberSystemUiController
4946
import com.tien.piholeconnect.R
5047
import com.tien.piholeconnect.model.BottomTabItem
5148
import com.tien.piholeconnect.model.Screen
@@ -76,7 +73,6 @@ fun App(viewModel: AppViewModel = hiltViewModel()) {
7673

7774
val snackbarHostState = remember { SnackbarHostState() }
7875
val navController = rememberNavController()
79-
val systemUiController = rememberSystemUiController()
8076

8177
val isDarkTheme =
8278
when (userPreferences?.theme) {
@@ -193,17 +189,6 @@ fun App(viewModel: AppViewModel = hiltViewModel()) {
193189
useDarkTheme = isDarkTheme,
194190
useDynamicColor = userPreferences?.useDynamicColor == true,
195191
) {
196-
val themeColors = MaterialTheme.colorScheme
197-
198-
SideEffect {
199-
systemUiController.apply {
200-
setStatusBarColor(themeColors.background)
201-
setNavigationBarColor(
202-
themeColors.surfaceColorAtElevation(NavigationBarDefaults.Elevation)
203-
)
204-
}
205-
}
206-
207192
Scaffold(
208193
snackbarHost = { SnackbarHost(snackbarHostState) },
209194
topBar = {
@@ -241,7 +226,7 @@ fun App(viewModel: AppViewModel = hiltViewModel()) {
241226
NavHost(
242227
navController = navController,
243228
startDestination = Screen.Home.route,
244-
modifier = Modifier.padding(padding),
229+
modifier = Modifier.padding(padding).consumeWindowInsets(padding),
245230
) {
246231
composable(Screen.Home.route) { ConnectionGuard { HomeScreen() } }
247232
composable(Screen.Statistics.route) {

app/src/main/java/com/tien/piholeconnect/ui/theme/Theme.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.tien.piholeconnect.ui.theme
22

3+
import android.app.Activity
34
import android.os.Build
45
import androidx.compose.foundation.isSystemInDarkTheme
56
import androidx.compose.material3.ColorScheme
@@ -10,9 +11,12 @@ import androidx.compose.material3.dynamicDarkColorScheme
1011
import androidx.compose.material3.dynamicLightColorScheme
1112
import androidx.compose.material3.lightColorScheme
1213
import androidx.compose.runtime.Composable
14+
import androidx.compose.runtime.LaunchedEffect
1315
import androidx.compose.runtime.ReadOnlyComposable
1416
import androidx.compose.ui.graphics.Color
1517
import androidx.compose.ui.platform.LocalContext
18+
import androidx.compose.ui.platform.LocalView
19+
import androidx.core.view.WindowCompat
1620

1721
private val LightColors =
1822
lightColorScheme(
@@ -153,5 +157,12 @@ fun PiHoleConnectTheme(
153157
else -> LightColors
154158
}
155159

160+
val view = LocalView.current
161+
LaunchedEffect(useDarkTheme) {
162+
val window = (view.context as Activity).window
163+
WindowCompat.getInsetsController(window, window.decorView).isAppearanceLightStatusBars =
164+
!useDarkTheme
165+
}
166+
156167
MaterialTheme(colorScheme = colorScheme, content = content)
157168
}

app/src/main/res/values/themes.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33

4-
<style name="Theme.PiHoleConnect" parent="Theme.Material3.DayNight.NoActionBar">
5-
<item name="android:navigationBarColor">@android:color/transparent</item>
6-
<item name="android:statusBarColor">@android:color/transparent</item>
7-
</style>
4+
<style name="Theme.PiHoleConnect" parent="android:Theme.Material.Light.NoActionBar" />
85
</resources>

gradle/libs.versions.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ protoBufJavaLite = "4.29.3"
1212
vico = "1.15.0"
1313

1414
[libraries]
15-
accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "accompanist" }
1615
android-billingclient-ktx = { module = "com.android.billingclient:billing-ktx", version = "7.1.1" }
1716
androidx-activity-compose = { module = "androidx.activity:activity-compose", version = "1.10.1" }
18-
androidx-appcompat = { module = "androidx.appcompat:appcompat", version = "1.7.0" }
1917
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "androidx-compose-bom" }
2018
androidx-compose-iconsExtended = { module = "androidx.compose.material:material-icons-extended" }
2119
androidx-compose-material3 = { module = "androidx.compose.material3:material3" }
@@ -46,7 +44,6 @@ vico-compose-material3 = { module = "com.patrykandpatrick.vico:compose-m3", vers
4644
vico-core = { module = "com.patrykandpatrick.vico:core", version.ref = "vico" }
4745

4846
[bundles]
49-
accompanist = ["accompanist-systemuicontroller"]
5047
androidTest = ["androidx-test-espresso-core", "androidx-test-ext-junit"]
5148
compose = ["androidx-compose-iconsExtended", "androidx-compose-material3", "androidx-compose-ui-tooling"]
5249
kotlin = ["kotlin-reflect", "kotlin-serialization"]

0 commit comments

Comments
 (0)