Compare commits

..

No commits in common. "dae7a00b41c73f89113e6ece001e9d613c9d7f70" and "ab0893b2d494f3b0722438778bd2a53e4d1cd0d2" have entirely different histories.

6 changed files with 15 additions and 9 deletions

View File

@ -184,10 +184,14 @@ private fun ColumnScope.SortPage(
MR.strings.action_sort_random to LibrarySort.Type.Random, MR.strings.action_sort_random to LibrarySort.Type.Random,
).plus(trackerSortOption).map { (titleRes, mode) -> ).plus(trackerSortOption).map { (titleRes, mode) ->
if (mode == LibrarySort.Type.Random) { if (mode == LibrarySort.Type.Random) {
val enabledIcon = if (sortingMode == LibrarySort.Type.Random) {
Icons.Default.Refresh
} else {
null
}
BaseSortItem( BaseSortItem(
label = stringResource(titleRes), label = stringResource(titleRes),
icon = Icons.Default.Refresh icon = enabledIcon,
.takeIf { sortingMode == LibrarySort.Type.Random },
onClick = { onClick = {
screenModel.setSort(category, mode, LibrarySort.Direction.Ascending) screenModel.setSort(category, mode, LibrarySort.Direction.Ascending)
}, },

View File

@ -302,15 +302,16 @@ class LibraryScreenModel(
item1Score.compareTo(item2Score) item1Score.compareTo(item2Score)
} }
LibrarySort.Type.Random -> { LibrarySort.Type.Random -> {
error("Why Are We Still Here? Just To Suffer?") error("A comparator should not be requested for the random sort style. Instead, intercept this " +
"case and call .shuffle()")
} }
} }
} }
return mapValues { (key, value) -> return mapValues { (key, value) ->
if (key.sort.type == LibrarySort.Type.Random) { if (key.sort.type == LibrarySort.Type.Random) {
return@mapValues value.shuffled(Random(libraryPreferences.randomSortSeed().get())) return@mapValues value.shuffled(Random(libraryPreferences.currentRandomSortSeed().get()))
} }
val comparator = key.sort.comparator() val comparator = key.sort.comparator()
.let { if (key.sort.isAscending) it else it.reversed() } .let { if (key.sort.isAscending) it else it.reversed() }

View File

@ -17,7 +17,7 @@ class SetSortModeForCategory(
val category = categoryId?.let { categoryRepository.get(it) } val category = categoryId?.let { categoryRepository.get(it) }
val flags = (category?.flags ?: 0) + type + direction val flags = (category?.flags ?: 0) + type + direction
if (type == LibrarySort.Type.Random) { if (type == LibrarySort.Type.Random) {
preferences.randomSortSeed().set(Random.nextInt()) preferences.currentRandomSortSeed().set(Random.nextInt())
} }
if (category != null && preferences.categorizedDisplaySettings().get()) { if (category != null && preferences.categorizedDisplaySettings().get()) {
categoryRepository.updatePartial( categoryRepository.updatePartial(

View File

@ -31,7 +31,7 @@ data class LibrarySort(
data object ChapterFetchDate : Type(0b00011000) data object ChapterFetchDate : Type(0b00011000)
data object DateAdded : Type(0b00011100) data object DateAdded : Type(0b00011100)
data object TrackerMean : Type(0b00100000) data object TrackerMean : Type(0b00100000)
data object Random : Type(0b00111100) data object Random : Type(0b00100100)
companion object { companion object {
fun valueOf(flag: Long): Type { fun valueOf(flag: Long): Type {

View File

@ -26,7 +26,7 @@ class LibraryPreferences(
LibrarySort.Serializer::deserialize, LibrarySort.Serializer::deserialize,
) )
fun randomSortSeed() = preferenceStore.getInt("library_random_sort_seed", 0) fun currentRandomSortSeed() = preferenceStore.getInt("library_random_sort_seed", 0)
fun portraitColumns() = preferenceStore.getInt("pref_library_columns_portrait_key", 0) fun portraitColumns() = preferenceStore.getInt("pref_library_columns_portrait_key", 0)

View File

@ -17,6 +17,7 @@ import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDownward import androidx.compose.material.icons.filled.ArrowDownward
import androidx.compose.material.icons.filled.ArrowUpward import androidx.compose.material.icons.filled.ArrowUpward
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.icons.rounded.CheckBox import androidx.compose.material.icons.rounded.CheckBox
import androidx.compose.material.icons.rounded.CheckBoxOutlineBlank import androidx.compose.material.icons.rounded.CheckBoxOutlineBlank
import androidx.compose.material.icons.rounded.DisabledByDefault import androidx.compose.material.icons.rounded.DisabledByDefault