Skip to content

Commit

Permalink
refactor(m3): remove accompanist systemuicontroller.
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot committed Oct 12, 2023
1 parent b672b1c commit b614092
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.res.stringResource
import androidx.core.app.ShareCompat
import androidx.core.content.FileProvider
Expand Down Expand Up @@ -42,7 +46,7 @@ import java.util.Locale
@FlowPreview
@ExperimentalSettingsApi
@ExperimentalCoroutinesApi
class MainActivity : AppCompatActivity() {
class MainActivity : ComponentActivity() {
private lateinit var navController: NavHostController

override fun onNewIntent(intent: Intent?) {
Expand All @@ -52,6 +56,7 @@ class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
val baseUrl = BuildConfig.BASE_URL
val db = DatabaseWrapper(context = this).createDb()
val platform = Platform(AndroidContext(this.applicationContext))
Expand Down Expand Up @@ -94,6 +99,17 @@ class MainActivity : AppCompatActivity() {
)
val openFeedbackState = (application as MainApplication).openFeedbackConfig
setContent {
val inDarkTheme = isSystemInDarkTheme()
DisposableEffect(inDarkTheme) {
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.auto(
android.graphics.Color.TRANSPARENT,
android.graphics.Color.TRANSPARENT,
) { inDarkTheme },
navigationBarStyle = SystemBarStyle.auto(lightScrim, darkScrim) { inDarkTheme },
)
onDispose {}
}
navController = rememberNavController()
val exportSubject = stringResource(id = R.string.text_export_subject)
val reportSubject = stringResource(id = R.string.text_report_subject)
Expand Down Expand Up @@ -155,6 +171,18 @@ class MainActivity : AppCompatActivity() {
}

companion object {
/**
* The default light scrim, as defined by androidx and the platform:
* https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/EdgeToEdge.kt;l=35-38;drc=27e7d52e8604a080133e8b842db10c89b4482598
*/
private val lightScrim = android.graphics.Color.argb(0xe6, 0xFF, 0xFF, 0xFF)

/**
* The default dark scrim, as defined by androidx and the platform:
* https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/EdgeToEdge.kt;l=40-44;drc=27e7d52e8604a080133e8b842db10c89b4482598
*/
private val darkScrim = android.graphics.Color.argb(0x80, 0x1b, 0x1b, 0x1b)

fun create(context: Context) = Intent(context, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
Expand Down
8 changes: 1 addition & 7 deletions androidApp/src/main/res/values-night/styles.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<resources>

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/grey800</item>
<item name="colorPrimaryDark">@color/grey800</item>
<item name="android:windowBackground">@color/grey800</item>
<item name="android:navigationBarColor">@color/grey800</item>
<item name="isLightTheme">false</item>
</style>
<style name="AppTheme" parent="android:Theme.Material.NoActionBar" />

</resources>
4 changes: 0 additions & 4 deletions androidApp/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#191919</color>
<color name="grey800">#001F24</color>
<color name="grey50">#F6FEFF</color>
<color name="pink">#E6147C</color>
<color name="blue">#03B7D5</color>
</resources>
4 changes: 2 additions & 2 deletions androidApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Devfest Lille</string>
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="app_name" tools:ignore="MissingTranslation">Devfest Lille</string>
</resources>
9 changes: 1 addition & 8 deletions androidApp/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<resources>

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/grey50</item>
<item name="colorPrimaryDark">@color/grey50</item>
<item name="android:windowBackground">@color/grey50</item>
<item name="android:navigationBarColor">@color/grey50</item>
<item name="android:statusBarColor">@color/grey50</item>
<item name="isLightTheme">true</item>
</style>
<style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar" />

</resources>
3 changes: 1 addition & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ androidxCamera = "1.2.3"
androidxProfile = "1.3.1"
composeBom = "2023.09.00"
composeCompiler = "1.4.8"
composeActivity = "1.7.2"
composeActivity = "1.8.0"
composeNavigation = "2.7.2"
composeFont = "1.0.0"
composeRichText = "0.11.0"
Expand Down Expand Up @@ -94,7 +94,6 @@ compose-openfeedback-m3 = { group = "io.openfeedback", name = "feedback-android-

accompanist-placeholder = { group = "com.google.accompanist", name = "accompanist-placeholder-material", version.ref = "accompanist" }
accompanist-permissions = { group = "com.google.accompanist", name = "accompanist-permissions", version.ref = "accompanist" }
accompanist-systemuicontroller = { group = "com.google.accompanist", name = "accompanist-systemuicontroller", version.ref = "accompanist" }

coil-compose = { group = "io.coil-kt", name = "coil-compose", version.ref = "coil" }
coil-svg = { group = "io.coil-kt", name = "coil-svg", version.ref = "coil" }
Expand Down
2 changes: 0 additions & 2 deletions theme-m3/main/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,5 @@ dependencies {
implementation(libs.androidx.compose.runtime)
implementation(libs.androidx.compose.navigation)

implementation(libs.accompanist.systemuicontroller)

implementation(libs.kotlinx.collections)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.gdglille.devfest.android.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.collectAsState
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
Expand All @@ -12,22 +9,21 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import androidx.navigation.navDeepLink
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import io.openfeedback.android.OpenFeedbackConfig
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import org.gdglille.devfest.AlarmScheduler
import org.gdglille.devfest.android.theme.m3.infos.feature.TicketQrCodeScanner
import org.gdglille.devfest.android.theme.m3.networking.feature.VCardQrCodeScanner
import org.gdglille.devfest.android.theme.m3.schedules.feature.AgendaFiltersVM
import org.gdglille.devfest.android.theme.m3.events.feature.EventListVM
import org.gdglille.devfest.android.theme.m3.infos.feature.TicketQrCodeScanner
import org.gdglille.devfest.android.theme.m3.main.Home
import org.gdglille.devfest.android.theme.m3.partners.feature.PartnerDetailVM
import org.gdglille.devfest.android.theme.m3.main.HomeResultKey
import org.gdglille.devfest.android.theme.m3.networking.feature.ProfileInputVM
import org.gdglille.devfest.android.theme.m3.networking.feature.VCardQrCodeScanner
import org.gdglille.devfest.android.theme.m3.partners.feature.PartnerDetailVM
import org.gdglille.devfest.android.theme.m3.schedules.feature.AgendaFiltersVM
import org.gdglille.devfest.android.theme.m3.schedules.feature.ScheduleDetailVM
import org.gdglille.devfest.android.theme.m3.speakers.feature.SpeakerDetailVM
import org.gdglille.devfest.android.theme.m3.style.Conferences4HallTheme
import org.gdglille.devfest.android.theme.m3.main.HomeResultKey
import org.gdglille.devfest.models.ExportNetworkingUi
import org.gdglille.devfest.repositories.AgendaRepository
import org.gdglille.devfest.repositories.EventRepository
Expand Down Expand Up @@ -58,12 +54,6 @@ fun Main(
) {
val rootUri = "c4h://event"
Conferences4HallTheme {
val systemUiController = rememberSystemUiController()
val useDarkIcons = !isSystemInDarkTheme()
val statusBarColor = MaterialTheme.colorScheme.surface
SideEffect {
systemUiController.setSystemBarsColor(color = statusBarColor, darkIcons = useDarkIcons)
}
val uiState = viewModel.uiState.collectAsState()
when (uiState.value) {
is MainUiState.Success -> {
Expand Down

0 comments on commit b614092

Please sign in to comment.