Dynamic colors [2/2]
This commit is contained in:
@@ -19,27 +19,12 @@
|
||||
|
||||
package com.aurora.extensions
|
||||
|
||||
import android.graphics.Color
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
private fun AppCompatActivity.setSystemBarConfiguration(light: Boolean) {
|
||||
WindowInsetsControllerCompat(this.window, this.window.decorView.rootView).apply {
|
||||
// Status bar color
|
||||
if (isMAndAbove()) {
|
||||
isAppearanceLightStatusBars = light
|
||||
} else {
|
||||
// Add a semi-transparent black color to the status bar & navigation bar
|
||||
window.statusBarColor = ColorUtils.setAlphaComponent(Color.BLACK, 120)
|
||||
window.navigationBarColor = ColorUtils.setAlphaComponent(Color.BLACK, 120)
|
||||
}
|
||||
|
||||
// Navigation bar color
|
||||
if (isOMR1AndAbove()) {
|
||||
isAppearanceLightNavigationBars = light
|
||||
window.navigationBarColor = getStyledAttributeColor(android.R.attr.colorBackground)
|
||||
}
|
||||
fun setAppTheme(themeStyle: Int) {
|
||||
when (themeStyle) {
|
||||
1 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||
2 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||
else -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,12 +25,14 @@ import androidx.core.content.ContextCompat
|
||||
import androidx.hilt.work.HiltWorkerFactory
|
||||
import androidx.work.Configuration
|
||||
import com.aurora.extensions.isPAndAbove
|
||||
import com.aurora.extensions.setAppTheme
|
||||
import com.aurora.store.data.event.EventFlow
|
||||
import com.aurora.store.data.receiver.PackageManagerReceiver
|
||||
import com.aurora.store.util.CommonUtil
|
||||
import com.aurora.store.util.DownloadWorkerUtil
|
||||
import com.aurora.store.util.NotificationUtil
|
||||
import com.aurora.store.util.PackageUtil
|
||||
import com.aurora.store.util.Preferences
|
||||
import com.google.android.material.color.DynamicColors
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
import kotlinx.coroutines.MainScope
|
||||
@@ -64,9 +66,13 @@ class AuroraApp : Application(), Configuration.Provider {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
// Set the app theme
|
||||
val themeStyle = Preferences.getInteger(this, Preferences.PREFERENCE_THEME_STYLE)
|
||||
setAppTheme(themeStyle)
|
||||
|
||||
// Apply dynamic colors to activities0
|
||||
DynamicColors.applyToActivitiesIfAvailable(this);
|
||||
DynamicColors.applyToActivitiesIfAvailable(this)
|
||||
DynamicColors.wrapContextIfAvailable(this)
|
||||
|
||||
// Required for Shizuku installer
|
||||
if (isPAndAbove()) HiddenApiBypass.addHiddenApiExemptions("I", "L")
|
||||
|
||||
@@ -25,7 +25,6 @@ import android.view.View
|
||||
import androidx.activity.addCallback
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.updatePadding
|
||||
@@ -72,8 +71,6 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||
|
||||
B = ActivityMainBinding.inflate(layoutInflater)
|
||||
|
||||
ViewCompat.setOnApplyWindowInsetsListener(B.root) { view, windowInsets ->
|
||||
|
||||
@@ -5,20 +5,18 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import com.aurora.Constants
|
||||
import com.aurora.extensions.isSAndAbove
|
||||
import com.aurora.store.data.work.CacheWorker
|
||||
import com.aurora.store.util.CertUtil
|
||||
import com.aurora.store.util.Preferences
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_DISPENSER_URLS
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_INTRO
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_MIGRATION_VERSION
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_THEME_ACCENT
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_VENDING_VERSION
|
||||
import com.aurora.store.util.save
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
class MigrationReceiver: BroadcastReceiver() {
|
||||
class MigrationReceiver : BroadcastReceiver() {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "MigrationReceiver"
|
||||
@@ -47,7 +45,6 @@ class MigrationReceiver: BroadcastReceiver() {
|
||||
// 58 -> 59
|
||||
if (currentVersion == 0) {
|
||||
CacheWorker.scheduleAutomatedCacheCleanup(context) // !1089
|
||||
if (isSAndAbove()) context.save(PREFERENCE_THEME_ACCENT, 0)
|
||||
context.save(PREFERENCE_DISPENSER_URLS, setOf(Constants.URL_DISPENSER)) // !1117
|
||||
if (Preferences.getInteger(context, PREFERENCE_VENDING_VERSION) == -1) {
|
||||
context.save(PREFERENCE_VENDING_VERSION, 0) // !1049
|
||||
|
||||
@@ -31,8 +31,7 @@ object Preferences {
|
||||
|
||||
const val PREFERENCE_AUTH_DATA = "PREFERENCE_AUTH_DATA"
|
||||
const val PREFERENCE_INSTALLER_ID = "PREFERENCE_INSTALLER_ID"
|
||||
const val PREFERENCE_THEME_TYPE = "PREFERENCE_THEME_TYPE"
|
||||
const val PREFERENCE_THEME_ACCENT = "PREFERENCE_THEME_ACCENT"
|
||||
const val PREFERENCE_THEME_STYLE = "PREFERENCE_THEME_STYLE"
|
||||
const val PREFERENCE_FOR_YOU = "PREFERENCE_FOR_YOU"
|
||||
const val PREFERENCE_DEFAULT_SELECTED_TAB = "PREFERENCE_DEFAULT_SELECTED_TAB"
|
||||
const val PREFERENCE_SIMILAR = "PREFERENCE_SIMILAR"
|
||||
|
||||
@@ -11,23 +11,25 @@ import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.requiredSize
|
||||
import androidx.compose.foundation.layout.wrapContentWidth
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
@@ -52,9 +54,11 @@ import com.aurora.Constants
|
||||
import com.aurora.Constants.URL_TOS
|
||||
import com.aurora.extensions.browse
|
||||
import com.aurora.extensions.getStyledAttributeColor
|
||||
import com.aurora.extensions.setAppTheme
|
||||
import com.aurora.store.MR
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
import com.aurora.store.util.Preferences
|
||||
import com.aurora.store.view.theme.AuroraTheme
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
@@ -152,21 +156,30 @@ class MoreDialogFragment : DialogFragment() {
|
||||
|
||||
@Composable
|
||||
fun AppBar(backgroundColor: Color = Color.Transparent, onBackgroundColor: Color) {
|
||||
Box(contentAlignment = Alignment.CenterEnd) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(4.dp, 10.dp, 4.dp, 10.dp)
|
||||
) {
|
||||
ThreeStateIconButton(tint = onBackgroundColor)
|
||||
Text(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
modifier = Modifier.wrapContentWidth(),
|
||||
text = stringResource(id = R.string.app_name),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
color = onBackgroundColor,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
IconButton(onClick = { findNavController().navigateUp() }) {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.ic_cancel),
|
||||
contentDescription = stringResource(id = R.string.action_cancel),
|
||||
tint = onBackgroundColor
|
||||
)
|
||||
}
|
||||
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.ic_cancel),
|
||||
contentDescription = stringResource(id = R.string.action_cancel),
|
||||
modifier = Modifier.clickable {
|
||||
findNavController().navigateUp()
|
||||
},
|
||||
colorFilter = ColorFilter.tint(onBackgroundColor)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,6 +311,56 @@ class MoreDialogFragment : DialogFragment() {
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ThreeStateIconButton(
|
||||
tint: Color = Color.White
|
||||
) {
|
||||
var currentState by remember {
|
||||
mutableStateOf(
|
||||
Preferences.getInteger(
|
||||
requireContext(),
|
||||
Preferences.PREFERENCE_THEME_STYLE
|
||||
).let {
|
||||
State.entries.getOrNull(it)
|
||||
} ?: State.Auto
|
||||
)
|
||||
}
|
||||
|
||||
val iconRes = when (currentState) {
|
||||
State.Light -> R.drawable.ic_light
|
||||
State.Dark -> R.drawable.ic_dark
|
||||
else -> R.drawable.ic_auto
|
||||
}
|
||||
|
||||
Image(
|
||||
painter = painterResource(id = iconRes),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.clickable {
|
||||
currentState = when (currentState) {
|
||||
State.Light -> State.Dark
|
||||
State.Dark -> State.Auto
|
||||
State.Auto -> State.Light
|
||||
}
|
||||
|
||||
Preferences.putInteger(
|
||||
requireContext(),
|
||||
Preferences.PREFERENCE_THEME_STYLE,
|
||||
currentState.value
|
||||
)
|
||||
|
||||
setAppTheme(currentState.value)
|
||||
findNavController().navigateUp()
|
||||
},
|
||||
colorFilter = ColorFilter.tint(tint)
|
||||
)
|
||||
}
|
||||
|
||||
enum class State(val value: Int) {
|
||||
Auto(0),
|
||||
Light(1),
|
||||
Dark(2),
|
||||
}
|
||||
|
||||
private fun getOptions(): List<Option> {
|
||||
return listOf(
|
||||
Option(
|
||||
|
||||
@@ -29,7 +29,6 @@ import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
|
||||
import com.aurora.Constants
|
||||
import com.aurora.extensions.isIgnoringBatteryOptimizations
|
||||
import com.aurora.extensions.isSAndAbove
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.work.CacheWorker
|
||||
import com.aurora.store.data.work.UpdateWorker
|
||||
@@ -48,8 +47,7 @@ import com.aurora.store.util.Preferences.PREFERENCE_FOR_YOU
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_INSTALLER_ID
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_INTRO
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_SIMILAR
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_THEME_ACCENT
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_THEME_TYPE
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_THEME_STYLE
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_UPDATES_AUTO
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_UPDATES_CHECK_INTERVAL
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_UPDATES_EXTENDED
|
||||
@@ -161,8 +159,7 @@ class OnboardingFragment : BaseFragment<FragmentOnboardingBinding>() {
|
||||
save(PREFERENCE_VENDING_VERSION, 0)
|
||||
|
||||
/*Customization*/
|
||||
save(PREFERENCE_THEME_TYPE, 0)
|
||||
save(PREFERENCE_THEME_ACCENT, if (isSAndAbove()) 0 else 1)
|
||||
save(PREFERENCE_THEME_STYLE, 0)
|
||||
save(PREFERENCE_DEFAULT_SELECTED_TAB, 0)
|
||||
save(PREFERENCE_FOR_YOU, true)
|
||||
save(PREFERENCE_SIMILAR, true)
|
||||
|
||||
@@ -21,18 +21,14 @@ package com.aurora.store.view.ui.preferences
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.view.View
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.preference.ListPreference
|
||||
import androidx.preference.Preference
|
||||
import com.aurora.extensions.isTAndAbove
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.util.Preferences
|
||||
import com.aurora.store.util.save
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import java.util.Locale
|
||||
|
||||
@@ -64,28 +60,5 @@ class UIPreference : BasePreferenceFragment() {
|
||||
title = getString(R.string.pref_ui_title)
|
||||
setNavigationOnClickListener { findNavController().navigateUp() }
|
||||
}
|
||||
|
||||
val themePreference: ListPreference? = findPreference(Preferences.PREFERENCE_THEME_TYPE)
|
||||
themePreference?.let {
|
||||
it.setOnPreferenceChangeListener { _, newValue ->
|
||||
val themeId = Integer.parseInt(newValue.toString())
|
||||
|
||||
save(Preferences.PREFERENCE_THEME_TYPE, themeId)
|
||||
requireActivity().recreate()
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
val accentPreference: ListPreference? = findPreference(Preferences.PREFERENCE_THEME_ACCENT)
|
||||
accentPreference?.let {
|
||||
it.isVisible = Build.VERSION.SDK_INT < Build.VERSION_CODES.S
|
||||
it.setOnPreferenceChangeListener { _, newValue ->
|
||||
val accentId = Integer.parseInt(newValue.toString())
|
||||
|
||||
save(Preferences.PREFERENCE_THEME_ACCENT, accentId)
|
||||
requireActivity().recreate()
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user