Skip to content

Commit

Permalink
feat(Settings): use SettingsListItem consistently and overall improve…
Browse files Browse the repository at this point in the history
…ments (ReVanced#1427)
  • Loading branch information
Ushie committed Nov 1, 2023
1 parent 7fe4724 commit 25bd91d
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ fun GroupHeader(
text = title,
color = MaterialTheme.colorScheme.primary,
style = MaterialTheme.typography.labelLarge,
modifier = Modifier.padding(16.dp).semantics { heading() }.then(modifier)
modifier = Modifier.padding(24.dp).semantics { heading() }.then(modifier)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package app.revanced.manager.ui.component

import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ListItemColors
import androidx.compose.material3.ListItemDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.material3.ListItem

@Composable
fun SettingsListItem(
headlineContent: String,
modifier: Modifier = Modifier,
overlineContent: @Composable (() -> Unit)? = null,
supportingContent: String? = null,
leadingContent: @Composable (() -> Unit)? = null,
trailingContent: @Composable (() -> Unit)? = null,
colors: ListItemColors = ListItemDefaults.colors(),
tonalElevation: Dp = ListItemDefaults.Elevation,
shadowElevation: Dp = ListItemDefaults.Elevation,
) = ListItem(
headlineContent = {
Text(
text = headlineContent,
style = MaterialTheme.typography.titleLarge
)
},
modifier = modifier.then(Modifier.padding(horizontal = 8.dp)),
overlineContent = overlineContent,
supportingContent = {
if (supportingContent != null)
Text(
text = supportingContent,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.outline
) else null
},
leadingContent = leadingContent,
trailingContent = trailingContent,
colors = colors,
tonalElevation = tonalElevation,
shadowElevation = shadowElevation
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package app.revanced.manager.ui.component.settings

import androidx.annotation.StringRes
import androidx.compose.foundation.clickable
import androidx.compose.material3.ListItem
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
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 All @@ -37,10 +36,10 @@ fun BooleanItem(
onValueChange: (Boolean) -> Unit,
@StringRes headline: Int,
@StringRes description: Int
) = ListItem(
) = SettingsListItem(
modifier = Modifier.clickable { onValueChange(!value) },
headlineContent = { Text(stringResource(headline)) },
supportingContent = { Text(stringResource(description)) },
headlineContent = stringResource(headline),
supportingContent = stringResource(description),
trailingContent = {
Switch(
checked = value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ 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.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
Expand All @@ -21,7 +19,6 @@ import androidx.compose.material.icons.outlined.Update
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
Expand All @@ -32,18 +29,16 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import app.revanced.manager.R
import app.revanced.manager.data.room.apps.installed.InstallType
import app.revanced.manager.ui.component.AppIcon
import app.revanced.manager.ui.component.AppInfo
import app.revanced.manager.ui.component.AppLabel
import app.revanced.manager.ui.component.AppTopBar
import app.revanced.manager.ui.component.SettingsListItem
import app.revanced.manager.ui.component.SegmentedButton
import app.revanced.manager.ui.viewmodel.InstalledAppInfoViewModel
import app.revanced.manager.util.PatchesSelection
Expand Down Expand Up @@ -148,38 +143,35 @@ fun InstalledAppInfoScreen(
Column(
modifier = Modifier.padding(vertical = 16.dp)
) {
ListItem(
SettingsListItem(
modifier = Modifier.clickable { },
headlineContent = { Text(stringResource(R.string.applied_patches)) },
supportingContent = {
Text(
headlineContent = stringResource(R.string.applied_patches),
supportingContent =
(viewModel.appliedPatches?.values?.sumOf { it.size } ?: 0).let {
pluralStringResource(
id = R.plurals.applied_patches,
it,
it
)
}
)
},
},
trailingContent = { Icon(Icons.Filled.ArrowRight, contentDescription = stringResource(R.string.view_applied_patches)) }
)

ListItem(
headlineContent = { Text(stringResource(R.string.package_name)) },
supportingContent = { Text(viewModel.installedApp.currentPackageName) }
SettingsListItem(
headlineContent = stringResource(R.string.package_name),
supportingContent = viewModel.installedApp.currentPackageName
)

if (viewModel.installedApp.originalPackageName != viewModel.installedApp.currentPackageName) {
ListItem(
headlineContent = { Text(stringResource(R.string.original_package_name)) },
supportingContent = { Text(viewModel.installedApp.originalPackageName) }
SettingsListItem(
headlineContent = stringResource(R.string.original_package_name),
supportingContent = viewModel.installedApp.originalPackageName
)
}

ListItem(
headlineContent = { Text(stringResource(R.string.install_type)) },
supportingContent = { Text(stringResource(viewModel.installedApp.installType.stringResource)) }
SettingsListItem(
headlineContent = stringResource(R.string.install_type),
supportingContent = stringResource(viewModel.installedApp.installType.stringResource)
)
}

Expand Down
23 changes: 6 additions & 17 deletions app/src/main/java/app/revanced/manager/ui/screen/SettingsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ 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

@SuppressLint("BatteryLife")
@OptIn(ExperimentalMaterial3Api::class, ExperimentalAnimationApi::class)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SettingsScreen(
onBackClick: () -> Unit,
Expand Down Expand Up @@ -157,8 +158,7 @@ fun SettingsScreen(
modifier = Modifier
.padding(paddingValues)
.fillMaxSize()
.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(12.dp)
.verticalScroll(rememberScrollState())
) {
AnimatedVisibility(visible = showBatteryButton) {
Card(
Expand Down Expand Up @@ -197,21 +197,10 @@ fun SettingsScreen(
}
}
settingsSections.forEach { (titleDescIcon, destination) ->
ListItem(
SettingsListItem(
modifier = Modifier.clickable { navController.navigate(destination) },
headlineContent = {
Text(
stringResource(titleDescIcon.first),
style = MaterialTheme.typography.titleLarge
)
},
supportingContent = {
Text(
stringResource(titleDescIcon.second),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.outline
)
},
headlineContent = stringResource(titleDescIcon.first),
supportingContent = stringResource(titleDescIcon.second),
leadingContent = { Icon(titleDescIcon.third, null) }
)
}
Expand Down
Loading

0 comments on commit 25bd91d

Please sign in to comment.