refactor(ui-components): deduplicate colors and move to settings folder

This commit is contained in:
Ax333l 2023-11-01 21:57:00 +01:00
parent 7741394c9c
commit 8df7f2992d
11 changed files with 40 additions and 42 deletions

View File

@ -33,6 +33,9 @@ fun NotificationCard(
icon: ImageVector, icon: ImageVector,
actions: (@Composable () -> Unit)? actions: (@Composable () -> Unit)?
) { ) {
val color =
if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer
NotificationCardInstance(isWarning = isWarning) { NotificationCardInstance(isWarning = isWarning) {
Column( Column(
modifier = Modifier.padding(if (title != null) 20.dp else 16.dp), modifier = Modifier.padding(if (title != null) 20.dp else 16.dp),
@ -43,7 +46,7 @@ fun NotificationCard(
modifier = Modifier.size(36.dp), modifier = Modifier.size(36.dp),
imageVector = icon, imageVector = icon,
contentDescription = null, contentDescription = null,
tint = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer tint = color,
) )
Column( Column(
verticalArrangement = Arrangement.spacedBy(6.dp) verticalArrangement = Arrangement.spacedBy(6.dp)
@ -51,12 +54,12 @@ fun NotificationCard(
Text( Text(
text = title, text = title,
style = MaterialTheme.typography.titleLarge, style = MaterialTheme.typography.titleLarge,
color = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer color = color,
) )
Text( Text(
text = text, text = text,
style = MaterialTheme.typography.bodyMedium, style = MaterialTheme.typography.bodyMedium,
color = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer color = color,
) )
} }
} else { } else {
@ -65,12 +68,12 @@ fun NotificationCard(
modifier = Modifier.size(24.dp), modifier = Modifier.size(24.dp),
imageVector = icon, imageVector = icon,
contentDescription = null, contentDescription = null,
tint = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer tint = color,
) )
Text( Text(
text = text, text = text,
style = MaterialTheme.typography.bodyMedium, style = MaterialTheme.typography.bodyMedium,
color = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer color = color,
) )
} }
} }
@ -88,6 +91,9 @@ fun NotificationCard(
onDismiss: (() -> Unit)? = null, onDismiss: (() -> Unit)? = null,
primaryAction: (() -> Unit)? = null primaryAction: (() -> Unit)? = null
) { ) {
val color =
if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer
NotificationCardInstance(isWarning = isWarning, onClick = primaryAction) { NotificationCardInstance(isWarning = isWarning, onClick = primaryAction) {
Row( Row(
modifier = Modifier modifier = Modifier
@ -100,7 +106,7 @@ fun NotificationCard(
modifier = Modifier.size(if (title != null) 36.dp else 24.dp), modifier = Modifier.size(if (title != null) 36.dp else 24.dp),
imageVector = icon, imageVector = icon,
contentDescription = null, contentDescription = null,
tint = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer tint = color,
) )
if (title != null) { if (title != null) {
Column( Column(
@ -110,12 +116,12 @@ fun NotificationCard(
Text( Text(
text = title, text = title,
style = MaterialTheme.typography.titleLarge, style = MaterialTheme.typography.titleLarge,
color = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer color = color,
) )
Text( Text(
text = text, text = text,
style = MaterialTheme.typography.bodyMedium, style = MaterialTheme.typography.bodyMedium,
color = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer color = color,
) )
} }
} else { } else {
@ -123,7 +129,7 @@ fun NotificationCard(
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
text = text, text = text,
style = MaterialTheme.typography.bodyMedium, style = MaterialTheme.typography.bodyMedium,
color = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer color = color,
) )
} }
if (onDismiss != null) { if (onDismiss != null) {
@ -131,7 +137,7 @@ fun NotificationCard(
Icon( Icon(
imageVector = Icons.Outlined.Close, imageVector = Icons.Outlined.Close,
contentDescription = stringResource(R.string.close), contentDescription = stringResource(R.string.close),
tint = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer tint = color,
) )
} }
} }
@ -144,28 +150,29 @@ fun NotificationCard(
private fun NotificationCardInstance( private fun NotificationCardInstance(
isWarning: Boolean = false, isWarning: Boolean = false,
onClick: (() -> Unit)? = null, onClick: (() -> Unit)? = null,
content: (@Composable () -> Unit), content: @Composable () -> Unit,
) { ) {
val colors =
CardDefaults.cardColors(containerColor = if (isWarning) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.primaryContainer)
val modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.clip(RoundedCornerShape(24.dp))
if (onClick != null) { if (onClick != null) {
Card( Card(
onClick = onClick, onClick = onClick,
colors = CardDefaults.cardColors(containerColor = (if (isWarning) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.primaryContainer)), colors = colors,
modifier = Modifier modifier = modifier
.fillMaxWidth()
.padding(16.dp)
.clip(RoundedCornerShape(24.dp))
) { ) {
content.invoke() content()
} }
} else { } else {
Card( Card(
colors = CardDefaults.cardColors(containerColor = (if (isWarning) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.primaryContainer)), colors = colors,
modifier = Modifier modifier = modifier,
.fillMaxWidth()
.padding(16.dp)
.clip(RoundedCornerShape(24.dp))
) { ) {
content.invoke() content()
} }
} }
} }

View File

@ -9,7 +9,6 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import app.revanced.manager.domain.manager.base.Preference import app.revanced.manager.domain.manager.base.Preference
import app.revanced.manager.ui.component.SettingsListItem
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch

View File

@ -1,4 +1,4 @@
package app.revanced.manager.ui.component package app.revanced.manager.ui.component.settings
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ListItemColors import androidx.compose.material3.ListItemColors
@ -37,7 +37,7 @@ fun SettingsListItem(
text = supportingContent, text = supportingContent,
style = MaterialTheme.typography.bodyMedium, style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.outline color = MaterialTheme.colorScheme.outline
) else null )
}, },
leadingContent = leadingContent, leadingContent = leadingContent,
trailingContent = trailingContent, trailingContent = trailingContent,

View File

@ -38,7 +38,7 @@ import app.revanced.manager.R
import app.revanced.manager.data.room.apps.installed.InstallType import app.revanced.manager.data.room.apps.installed.InstallType
import app.revanced.manager.ui.component.AppInfo import app.revanced.manager.ui.component.AppInfo
import app.revanced.manager.ui.component.AppTopBar import app.revanced.manager.ui.component.AppTopBar
import app.revanced.manager.ui.component.SettingsListItem import app.revanced.manager.ui.component.settings.SettingsListItem
import app.revanced.manager.ui.component.SegmentedButton import app.revanced.manager.ui.component.SegmentedButton
import app.revanced.manager.ui.viewmodel.InstalledAppInfoViewModel import app.revanced.manager.ui.viewmodel.InstalledAppInfoViewModel
import app.revanced.manager.util.PatchesSelection import app.revanced.manager.util.PatchesSelection

View File

@ -8,11 +8,8 @@ import android.os.PowerManager
import android.provider.Settings import android.provider.Settings
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
@ -28,7 +25,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import app.revanced.manager.R import app.revanced.manager.R
import app.revanced.manager.ui.component.AppTopBar import app.revanced.manager.ui.component.AppTopBar
import app.revanced.manager.ui.component.NotificationCard import app.revanced.manager.ui.component.NotificationCard
@ -40,7 +36,7 @@ import app.revanced.manager.ui.screen.settings.update.UpdatesSettingsScreen
import app.revanced.manager.ui.viewmodel.SettingsViewModel import app.revanced.manager.ui.viewmodel.SettingsViewModel
import dev.olshevski.navigation.reimagined.* import dev.olshevski.navigation.reimagined.*
import org.koin.androidx.compose.getViewModel import org.koin.androidx.compose.getViewModel
import app.revanced.manager.ui.component.SettingsListItem import app.revanced.manager.ui.component.settings.SettingsListItem
@SuppressLint("BatteryLife") @SuppressLint("BatteryLife")
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)

View File

@ -3,7 +3,6 @@ package app.revanced.manager.ui.screen.settings
import androidx.appcompat.content.res.AppCompatResources import androidx.appcompat.content.res.AppCompatResources
import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
@ -39,7 +38,7 @@ import androidx.compose.ui.unit.dp
import app.revanced.manager.BuildConfig import app.revanced.manager.BuildConfig
import app.revanced.manager.R import app.revanced.manager.R
import app.revanced.manager.ui.component.AppTopBar import app.revanced.manager.ui.component.AppTopBar
import app.revanced.manager.ui.component.SettingsListItem import app.revanced.manager.ui.component.settings.SettingsListItem
import app.revanced.manager.util.isDebuggable import app.revanced.manager.util.isDebuggable
import app.revanced.manager.util.openUrl import app.revanced.manager.util.openUrl
import com.google.accompanist.drawablepainter.rememberDrawablePainter import com.google.accompanist.drawablepainter.rememberDrawablePainter

View File

@ -35,7 +35,7 @@ import androidx.lifecycle.viewModelScope
import app.revanced.manager.R import app.revanced.manager.R
import app.revanced.manager.ui.component.AppTopBar import app.revanced.manager.ui.component.AppTopBar
import app.revanced.manager.ui.component.GroupHeader import app.revanced.manager.ui.component.GroupHeader
import app.revanced.manager.ui.component.SettingsListItem import app.revanced.manager.ui.component.settings.SettingsListItem
import app.revanced.manager.ui.component.settings.BooleanItem import app.revanced.manager.ui.component.settings.BooleanItem
import app.revanced.manager.ui.viewmodel.AdvancedSettingsViewModel import app.revanced.manager.ui.viewmodel.AdvancedSettingsViewModel
import org.koin.androidx.compose.getViewModel import org.koin.androidx.compose.getViewModel

View File

@ -22,7 +22,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import app.revanced.manager.R import app.revanced.manager.R
import app.revanced.manager.ui.component.AppTopBar import app.revanced.manager.ui.component.AppTopBar
import app.revanced.manager.ui.component.GroupHeader import app.revanced.manager.ui.component.GroupHeader
import app.revanced.manager.ui.component.SettingsListItem import app.revanced.manager.ui.component.settings.SettingsListItem
import app.revanced.manager.ui.component.settings.BooleanItem import app.revanced.manager.ui.component.settings.BooleanItem
import app.revanced.manager.ui.viewmodel.DownloadsViewModel import app.revanced.manager.ui.viewmodel.DownloadsViewModel
import org.koin.androidx.compose.getViewModel import org.koin.androidx.compose.getViewModel

View File

@ -23,7 +23,7 @@ import app.revanced.manager.ui.component.settings.BooleanItem
import app.revanced.manager.ui.theme.Theme import app.revanced.manager.ui.theme.Theme
import app.revanced.manager.ui.viewmodel.SettingsViewModel import app.revanced.manager.ui.viewmodel.SettingsViewModel
import org.koin.compose.koinInject import org.koin.compose.koinInject
import app.revanced.manager.ui.component.SettingsListItem import app.revanced.manager.ui.component.settings.SettingsListItem
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable

View File

@ -39,7 +39,7 @@ import app.revanced.manager.ui.component.bundle.BundleSelector
import app.revanced.manager.util.toast import app.revanced.manager.util.toast
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.koin.androidx.compose.getViewModel import org.koin.androidx.compose.getViewModel
import app.revanced.manager.ui.component.SettingsListItem import app.revanced.manager.ui.component.settings.SettingsListItem
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable

View File

@ -10,10 +10,7 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Update import androidx.compose.material.icons.filled.Update
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
@ -21,7 +18,7 @@ import androidx.compose.ui.unit.dp
import app.revanced.manager.R import app.revanced.manager.R
import app.revanced.manager.ui.component.AppTopBar import app.revanced.manager.ui.component.AppTopBar
import app.revanced.manager.ui.component.NotificationCard import app.revanced.manager.ui.component.NotificationCard
import app.revanced.manager.ui.component.SettingsListItem import app.revanced.manager.ui.component.settings.SettingsListItem
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable