Changes according to feedback

This commit is contained in:
Jack Hamilton 2024-10-11 21:29:02 -05:00
parent 078758391e
commit ab0893b2d4
4 changed files with 18 additions and 25 deletions

View File

@ -29,9 +29,9 @@ import tachiyomi.domain.library.model.LibrarySort
import tachiyomi.domain.library.model.sort
import tachiyomi.domain.library.service.LibraryPreferences
import tachiyomi.i18n.MR
import tachiyomi.presentation.core.components.BaseSortItem
import tachiyomi.presentation.core.components.CheckboxItem
import tachiyomi.presentation.core.components.HeadingItem
import tachiyomi.presentation.core.components.NondirectionalSortItem
import tachiyomi.presentation.core.components.SettingsChipRow
import tachiyomi.presentation.core.components.SliderItem
import tachiyomi.presentation.core.components.SortItem
@ -184,10 +184,14 @@ private fun ColumnScope.SortPage(
MR.strings.action_sort_random to LibrarySort.Type.Random,
).plus(trackerSortOption).map { (titleRes, mode) ->
if (mode == LibrarySort.Type.Random) {
NondirectionalSortItem(
val enabledIcon = if (sortingMode == LibrarySort.Type.Random) {
Icons.Default.Refresh
} else {
null
}
BaseSortItem(
label = stringResource(titleRes),
enabled = sortingMode == LibrarySort.Type.Random,
enabledIcon = Icons.Default.Refresh,
icon = enabledIcon,
onClick = {
screenModel.setSort(category, mode, LibrarySort.Direction.Ascending)
},

View File

@ -268,7 +268,7 @@ class LibraryScreenModel(
fun LibrarySort.comparator(): Comparator<LibraryItem> = Comparator { i1, i2 ->
when (this.type) {
LibrarySort.Type.Alphabetical, LibrarySort.Type.Random -> {
LibrarySort.Type.Alphabetical -> {
sortAlphabetically(i1, i2)
}
LibrarySort.Type.LastRead -> {
@ -301,6 +301,10 @@ class LibraryScreenModel(
val item2Score = trackerScores[i2.libraryManga.id] ?: defaultTrackerScoreSortValue
item1Score.compareTo(item2Score)
}
LibrarySort.Type.Random -> {
error("A comparator should not be requested for the random sort style. Instead, intercept this " +
"case and call .shuffle()")
}
}
}

View File

@ -30,8 +30,8 @@ data class LibrarySort(
data object LatestChapter : Type(0b00010100)
data object ChapterFetchDate : Type(0b00011000)
data object DateAdded : Type(0b00011100)
data object TrackerMean : Type(0b000100000)
data object Random : Type(0b000100100)
data object TrackerMean : Type(0b00100000)
data object Random : Type(0b00100100)
companion object {
fun valueOf(flag: Long): Type {

View File

@ -99,30 +99,15 @@ fun SortItem(label: String, sortDescending: Boolean?, onClick: () -> Unit) {
null -> null
}
BaseSettingsItem(
BaseSortItem(
label = label,
widget = {
if (arrowIcon != null) {
Icon(
imageVector = arrowIcon,
contentDescription = null,
tint = MaterialTheme.colorScheme.primary,
)
} else {
Spacer(modifier = Modifier.size(24.dp))
}
},
icon = arrowIcon,
onClick = onClick,
)
}
@Composable
fun NondirectionalSortItem(label: String, enabled: Boolean, enabledIcon: ImageVector, onClick: () -> Unit) {
val icon = when(enabled) {
true -> enabledIcon
false -> null
}
fun BaseSortItem(label: String, icon: ImageVector?, onClick: () -> Unit) {
BaseSettingsItem(
label = label,
widget = {