From acb94118699cef5cc5e63e18939f002837eca42a Mon Sep 17 00:00:00 2001 From: FunkyMuse Date: Sun, 9 Jul 2023 23:44:05 +0200 Subject: [PATCH] fix blinking and match the navigation and sytem bar color --- .../calculator/activities/SettingsActivity.kt | 9 ++-- .../calculator/compose/theme/Theme.kt | 47 +++++-------------- 2 files changed, 17 insertions(+), 39 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt index 683746f7..b161ba22 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.calculator.activities import android.annotation.SuppressLint import android.content.Intent +import android.graphics.Color import android.os.Bundle import androidx.activity.compose.setContent import androidx.appcompat.app.AppCompatActivity @@ -15,9 +16,7 @@ import com.simplemobiletools.calculator.compose.theme.getAppIconIds import com.simplemobiletools.calculator.compose.theme.getAppLauncherName import com.simplemobiletools.calculator.extensions.* import com.simplemobiletools.commons.activities.CustomizationActivity -import com.simplemobiletools.commons.extensions.getCustomizeColorsString -import com.simplemobiletools.commons.extensions.isOrWasThankYouInstalled -import com.simplemobiletools.commons.extensions.launchPurchaseThankYouIntent +import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* import java.util.Locale import kotlin.system.exitProcess @@ -80,6 +79,10 @@ class SettingsActivity : AppCompatActivity() { } } + private fun updateStatusbarColor() { + window.statusBarColor = Color.TRANSPARENT + } + private fun handleCustomizeColorsClick() { Intent(applicationContext, CustomizationActivity::class.java).apply { putExtra(APP_ICON_IDS, getAppIconIds()) diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/compose/theme/Theme.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/compose/theme/Theme.kt index a80d44c2..a9ea3d54 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/compose/theme/Theme.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/compose/theme/Theme.kt @@ -6,7 +6,6 @@ import android.content.Context import android.content.res.Configuration import android.graphics.BitmapFactory import android.os.Build -import androidx.compose.foundation.LocalOverscrollConfiguration import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.* @@ -27,10 +26,8 @@ import com.simplemobiletools.calculator.compose.theme.Theme.Companion.systemDefa import com.simplemobiletools.calculator.extensions.config import com.simplemobiletools.calculator.helpers.Config import com.simplemobiletools.commons.R -import com.simplemobiletools.commons.extensions.adjustAlpha import com.simplemobiletools.commons.helpers.APP_ICON_IDS import com.simplemobiletools.commons.helpers.APP_LAUNCHER_NAME -import com.simplemobiletools.commons.helpers.HIGHER_ALPHA private val darkColorScheme = darkColorScheme( primary = color_primary, @@ -150,16 +147,15 @@ fun Color.isNotLitWell() = luminance() < LUMINANCE_THRESHOLD @Composable private fun Theme( - useTransparentNavigation: Boolean = true, theme: Theme = systemDefaultMaterialYou(), content: @Composable () -> Unit, ) { val view = LocalView.current val context = LocalContext.current val systemUiController = rememberSystemUiController() + val baseConfig = remember { context.config } - val colorScheme = if (!view.isInEditMode){ - val baseConfig = remember { context.config } + val colorScheme = if (!view.isInEditMode) { val colorScheme = when { theme is Theme.SystemDefaultMaterialYou && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { @@ -188,40 +184,19 @@ private fun Theme( else -> darkColorScheme } - LaunchedEffect(Unit) { - /* if (context.navigationBarHeight > 0 || context.isUsingGestureNavigation() && useTransparentNavigation) { - systemUiController.isNavigationBarVisible = false - } else { - systemUiController.isNavigationBarVisible = true - }*/ - - /* if (context.navigationBarHeight > 0 || context.isUsingGestureNavigation()) { - window.decorView.systemUiVisibility = window.decorView.systemUiVisibility.addBit(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) - *//* updateTopBottomInsets(statusBarHeight, navigationBarHeight) - // Don't touch this. Window Inset API often has a domino effect and things will most likely break. - onApplyWindowInsets { - val insets = it.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.ime()) - updateTopBottomInsets(insets.top, insets.bottom) - }*//* - } else { - window.decorView.systemUiVisibility = window.decorView.systemUiVisibility.removeBit(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) - //updateTopBottomInsets(0, 0) - }*/ - systemUiController.setStatusBarColor( - color = colorScheme.surface - ) - context.getActivity().setTaskDescription(ActivityManager.TaskDescription(null, null, colorScheme.surface.toArgb())) - systemUiController.setNavigationBarColor(Color(theme.backgroundColor.toArgb().adjustAlpha(HIGHER_ALPHA))) - } - - SideEffect { - updateRecentsAppIcon(baseConfig, context) - } - colorScheme } else darkColorScheme + SideEffect { + systemUiController.setNavigationBarColor(colorScheme.surface) + systemUiController.setSystemBarsColor(colorScheme.surface) + } + + SideEffect { + updateRecentsAppIcon(baseConfig, context) + } + MaterialTheme( colorScheme = colorScheme,