Skip to content

Commit

Permalink
refactor(ui-components): deduplicate colors and move to settings folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Axelen123 committed Nov 1, 2023
1 parent 7741394 commit 8df7f29
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ fun NotificationCard(
icon: ImageVector,
actions: (@Composable () -> Unit)?
) {
val color =
if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer

NotificationCardInstance(isWarning = isWarning) {
Column(
modifier = Modifier.padding(if (title != null) 20.dp else 16.dp),
Expand All @@ -43,20 +46,20 @@ fun NotificationCard(
modifier = Modifier.size(36.dp),
imageVector = icon,
contentDescription = null,
tint = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer
tint = color,
)
Column(
verticalArrangement = Arrangement.spacedBy(6.dp)
) {
Text(
text = title,
style = MaterialTheme.typography.titleLarge,
color = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer
color = color,
)
Text(
text = text,
style = MaterialTheme.typography.bodyMedium,
color = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer
color = color,
)
}
} else {
Expand All @@ -65,12 +68,12 @@ fun NotificationCard(
modifier = Modifier.size(24.dp),
imageVector = icon,
contentDescription = null,
tint = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer
tint = color,
)
Text(
text = text,
style = MaterialTheme.typography.bodyMedium,
color = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer
color = color,
)
}
}
Expand All @@ -88,6 +91,9 @@ fun NotificationCard(
onDismiss: (() -> Unit)? = null,
primaryAction: (() -> Unit)? = null
) {
val color =
if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer

NotificationCardInstance(isWarning = isWarning, onClick = primaryAction) {
Row(
modifier = Modifier
Expand All @@ -100,7 +106,7 @@ fun NotificationCard(
modifier = Modifier.size(if (title != null) 36.dp else 24.dp),
imageVector = icon,
contentDescription = null,
tint = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer
tint = color,
)
if (title != null) {
Column(
Expand All @@ -110,28 +116,28 @@ fun NotificationCard(
Text(
text = title,
style = MaterialTheme.typography.titleLarge,
color = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer
color = color,
)
Text(
text = text,
style = MaterialTheme.typography.bodyMedium,
color = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer
color = color,
)
}
} else {
Text(
modifier = Modifier.weight(1f),
text = text,
style = MaterialTheme.typography.bodyMedium,
color = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer
color = color,
)
}
if (onDismiss != null) {
IconButton(onClick = onDismiss) {
Icon(
imageVector = Icons.Outlined.Close,
contentDescription = stringResource(R.string.close),
tint = if (isWarning) MaterialTheme.colorScheme.onError else MaterialTheme.colorScheme.onPrimaryContainer
tint = color,
)
}
}
Expand All @@ -144,28 +150,29 @@ fun NotificationCard(
private fun NotificationCardInstance(
isWarning: Boolean = false,
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) {
Card(
onClick = onClick,
colors = CardDefaults.cardColors(containerColor = (if (isWarning) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.primaryContainer)),
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.clip(RoundedCornerShape(24.dp))
colors = colors,
modifier = modifier
) {
content.invoke()
content()
}
} else {
Card(
colors = CardDefaults.cardColors(containerColor = (if (isWarning) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.primaryContainer)),
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.clip(RoundedCornerShape(24.dp))
colors = colors,
modifier = modifier,
) {
content.invoke()
content()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import app.revanced.manager.domain.manager.base.Preference
import app.revanced.manager.ui.component.SettingsListItem
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

Expand Down
Original file line number Diff line number Diff line change
@@ -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.material3.ListItemColors
Expand Down Expand Up @@ -37,7 +37,7 @@ fun SettingsListItem(
text = supportingContent,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.outline
) else null
)
},
leadingContent = leadingContent,
trailingContent = trailingContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import app.revanced.manager.R
import app.revanced.manager.data.room.apps.installed.InstallType
import app.revanced.manager.ui.component.AppInfo
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.viewmodel.InstalledAppInfoViewModel
import app.revanced.manager.util.PatchesSelection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ import android.os.PowerManager
import android.provider.Settings
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
Expand All @@ -28,7 +25,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import app.revanced.manager.R
import app.revanced.manager.ui.component.AppTopBar
import app.revanced.manager.ui.component.NotificationCard
Expand All @@ -40,7 +36,7 @@ import app.revanced.manager.ui.screen.settings.update.UpdatesSettingsScreen
import app.revanced.manager.ui.viewmodel.SettingsViewModel
import dev.olshevski.navigation.reimagined.*
import org.koin.androidx.compose.getViewModel
import app.revanced.manager.ui.component.SettingsListItem
import app.revanced.manager.ui.component.settings.SettingsListItem

@SuppressLint("BatteryLife")
@OptIn(ExperimentalMaterial3Api::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package app.revanced.manager.ui.screen.settings
import androidx.appcompat.content.res.AppCompatResources
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -39,7 +38,7 @@ import androidx.compose.ui.unit.dp
import app.revanced.manager.BuildConfig
import app.revanced.manager.R
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.openUrl
import com.google.accompanist.drawablepainter.rememberDrawablePainter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import androidx.lifecycle.viewModelScope
import app.revanced.manager.R
import app.revanced.manager.ui.component.AppTopBar
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.viewmodel.AdvancedSettingsViewModel
import org.koin.androidx.compose.getViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import app.revanced.manager.R
import app.revanced.manager.ui.component.AppTopBar
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.viewmodel.DownloadsViewModel
import org.koin.androidx.compose.getViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import app.revanced.manager.ui.component.settings.BooleanItem
import app.revanced.manager.ui.theme.Theme
import app.revanced.manager.ui.viewmodel.SettingsViewModel
import org.koin.compose.koinInject
import app.revanced.manager.ui.component.SettingsListItem
import app.revanced.manager.ui.component.settings.SettingsListItem

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import app.revanced.manager.ui.component.bundle.BundleSelector
import app.revanced.manager.util.toast
import kotlinx.coroutines.launch
import org.koin.androidx.compose.getViewModel
import app.revanced.manager.ui.component.SettingsListItem
import app.revanced.manager.ui.component.settings.SettingsListItem

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Update
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import app.revanced.manager.R
import app.revanced.manager.ui.component.AppTopBar
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)
@Composable
Expand Down

0 comments on commit 8df7f29

Please sign in to comment.