Add an icon to "Item Per Row" on library sheet (#9414)

Also cleanup `SettingsItems.kt`
This commit is contained in:
AntsyLich 2023-04-28 20:08:35 +06:00 committed by GitHub
parent 2cb08e6bb1
commit c21813a8b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 48 deletions

View file

@ -5,6 +5,8 @@ import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Apps
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@ -25,9 +27,9 @@ import tachiyomi.domain.library.model.display
import tachiyomi.domain.library.model.sort
import tachiyomi.domain.library.service.LibraryPreferences
import tachiyomi.domain.manga.model.TriStateFilter
import tachiyomi.presentation.core.components.BasicItem
import tachiyomi.presentation.core.components.CheckboxItem
import tachiyomi.presentation.core.components.HeadingItem
import tachiyomi.presentation.core.components.IconItem
import tachiyomi.presentation.core.components.RadioItem
import tachiyomi.presentation.core.components.SortItem
@ -206,8 +208,9 @@ private fun ColumnScope.DisplayPage(
}
if (category.display != LibraryDisplayMode.List) {
BasicItem(
IconItem(
label = stringResource(R.string.pref_library_columns),
icon = Icons.Outlined.Apps,
onClick = { showColumnsDialog = true },
)
}

View file

@ -4,6 +4,7 @@ import androidx.annotation.StringRes
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
@ -20,6 +21,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import tachiyomi.presentation.core.theme.header
@ -50,13 +52,20 @@ fun HeadingItem(
}
@Composable
fun BasicItem(
fun IconItem(
label: String,
icon: ImageVector,
onClick: () -> Unit,
) {
SortItem(
BaseSettingsItem(
label = label,
sortDescending = null,
widget = {
Icon(
imageVector = icon,
contentDescription = null,
tint = MaterialTheme.colorScheme.primary,
)
},
onClick = onClick,
)
}
@ -73,28 +82,21 @@ fun SortItem(
null -> null
}
Row(
modifier = Modifier
.clickable(onClick = onClick)
.fillMaxWidth()
.padding(horizontal = SettingsItemsPaddings.Horizontal, vertical = SettingsItemsPaddings.Vertical),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(24.dp),
) {
if (arrowIcon != null) {
Icon(
imageVector = arrowIcon,
contentDescription = null,
tint = MaterialTheme.colorScheme.primary,
)
} else {
Spacer(modifier = Modifier.size(24.dp))
}
Text(
text = label,
style = MaterialTheme.typography.bodyMedium,
)
}
BaseSettingsItem(
label = label,
widget = {
if (arrowIcon != null) {
Icon(
imageVector = arrowIcon,
contentDescription = null,
tint = MaterialTheme.colorScheme.primary,
)
} else {
Spacer(modifier = Modifier.size(24.dp))
}
},
onClick = onClick,
)
}
@Composable
@ -103,23 +105,16 @@ fun CheckboxItem(
checked: Boolean,
onClick: () -> Unit,
) {
Row(
modifier = Modifier
.clickable(onClick = onClick)
.fillMaxWidth()
.padding(horizontal = SettingsItemsPaddings.Horizontal, vertical = SettingsItemsPaddings.Vertical),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(24.dp),
) {
Checkbox(
checked = checked,
onCheckedChange = null,
)
Text(
text = label,
style = MaterialTheme.typography.bodyMedium,
)
}
BaseSettingsItem(
label = label,
widget = {
Checkbox(
checked = checked,
onCheckedChange = null,
)
},
onClick = onClick,
)
}
@Composable
@ -127,6 +122,24 @@ fun RadioItem(
label: String,
selected: Boolean,
onClick: () -> Unit,
) {
BaseSettingsItem(
label = label,
widget = {
RadioButton(
selected = selected,
onClick = null,
)
},
onClick = onClick,
)
}
@Composable
private fun BaseSettingsItem(
label: String,
widget: @Composable RowScope.() -> Unit,
onClick: () -> Unit,
) {
Row(
modifier = Modifier
@ -136,10 +149,7 @@ fun RadioItem(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(24.dp),
) {
RadioButton(
selected = selected,
onClick = null,
)
widget(this)
Text(
text = label,
style = MaterialTheme.typography.bodyMedium,