fix blinking and match the navigation and sytem bar color

This commit is contained in:
FunkyMuse 2023-07-09 23:44:05 +02:00
parent 221f1a2a88
commit acb9411869
2 changed files with 17 additions and 39 deletions

View File

@ -2,6 +2,7 @@ package com.simplemobiletools.calculator.activities
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Intent import android.content.Intent
import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity 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.compose.theme.getAppLauncherName
import com.simplemobiletools.calculator.extensions.* import com.simplemobiletools.calculator.extensions.*
import com.simplemobiletools.commons.activities.CustomizationActivity import com.simplemobiletools.commons.activities.CustomizationActivity
import com.simplemobiletools.commons.extensions.getCustomizeColorsString import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.extensions.isOrWasThankYouInstalled
import com.simplemobiletools.commons.extensions.launchPurchaseThankYouIntent
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.*
import java.util.Locale import java.util.Locale
import kotlin.system.exitProcess import kotlin.system.exitProcess
@ -80,6 +79,10 @@ class SettingsActivity : AppCompatActivity() {
} }
} }
private fun updateStatusbarColor() {
window.statusBarColor = Color.TRANSPARENT
}
private fun handleCustomizeColorsClick() { private fun handleCustomizeColorsClick() {
Intent(applicationContext, CustomizationActivity::class.java).apply { Intent(applicationContext, CustomizationActivity::class.java).apply {
putExtra(APP_ICON_IDS, getAppIconIds()) putExtra(APP_ICON_IDS, getAppIconIds())

View File

@ -6,7 +6,6 @@ import android.content.Context
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import android.os.Build import android.os.Build
import androidx.compose.foundation.LocalOverscrollConfiguration
import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.* 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.extensions.config
import com.simplemobiletools.calculator.helpers.Config import com.simplemobiletools.calculator.helpers.Config
import com.simplemobiletools.commons.R 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_ICON_IDS
import com.simplemobiletools.commons.helpers.APP_LAUNCHER_NAME import com.simplemobiletools.commons.helpers.APP_LAUNCHER_NAME
import com.simplemobiletools.commons.helpers.HIGHER_ALPHA
private val darkColorScheme = darkColorScheme( private val darkColorScheme = darkColorScheme(
primary = color_primary, primary = color_primary,
@ -150,16 +147,15 @@ fun Color.isNotLitWell() = luminance() < LUMINANCE_THRESHOLD
@Composable @Composable
private fun Theme( private fun Theme(
useTransparentNavigation: Boolean = true,
theme: Theme = systemDefaultMaterialYou(), theme: Theme = systemDefaultMaterialYou(),
content: @Composable () -> Unit, content: @Composable () -> Unit,
) { ) {
val view = LocalView.current val view = LocalView.current
val context = LocalContext.current val context = LocalContext.current
val systemUiController = rememberSystemUiController() val systemUiController = rememberSystemUiController()
val baseConfig = remember { context.config }
val colorScheme = if (!view.isInEditMode){ val colorScheme = if (!view.isInEditMode) {
val baseConfig = remember { context.config }
val colorScheme = when { val colorScheme = when {
theme is Theme.SystemDefaultMaterialYou && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { theme is Theme.SystemDefaultMaterialYou && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
@ -188,40 +184,19 @@ private fun Theme(
else -> darkColorScheme 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 colorScheme
} else darkColorScheme } else darkColorScheme
SideEffect {
systemUiController.setNavigationBarColor(colorScheme.surface)
systemUiController.setSystemBarsColor(colorScheme.surface)
}
SideEffect {
updateRecentsAppIcon(baseConfig, context)
}
MaterialTheme( MaterialTheme(
colorScheme = colorScheme, colorScheme = colorScheme,