Skip to content

Commit

Permalink
Changes according to feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhamilton committed Oct 12, 2024
1 parent 0787583 commit ab0893b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down Expand Up @@ -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()")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit ab0893b

Please sign in to comment.