Keyed random seed

This commit is contained in:
Jack Hamilton 2024-10-11 02:37:11 -05:00
parent 0ab795bfa3
commit 3d087f4428
3 changed files with 9 additions and 1 deletions

View File

@ -72,6 +72,8 @@ import tachiyomi.domain.track.model.Track
import tachiyomi.source.local.isLocal import tachiyomi.source.local.isLocal
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.util.Collections
import kotlin.random.Random
/** /**
* Typealias for the library manga, using the category as keys, and list of manga as values. * Typealias for the library manga, using the category as keys, and list of manga as values.
@ -305,7 +307,7 @@ class LibraryScreenModel(
return mapValues { (key, value) -> return mapValues { (key, value) ->
when (key.sort.type) { when (key.sort.type) {
LibrarySort.Type.Random -> value.shuffled() LibrarySort.Type.Random -> value.shuffled(Random(libraryPreferences.currentRandomSortSeed().get()))
else -> { else -> {
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

@ -6,6 +6,7 @@ import tachiyomi.domain.category.repository.CategoryRepository
import tachiyomi.domain.library.model.LibrarySort import tachiyomi.domain.library.model.LibrarySort
import tachiyomi.domain.library.model.plus import tachiyomi.domain.library.model.plus
import tachiyomi.domain.library.service.LibraryPreferences import tachiyomi.domain.library.service.LibraryPreferences
import kotlin.random.Random
class SetSortModeForCategory( class SetSortModeForCategory(
private val preferences: LibraryPreferences, private val preferences: LibraryPreferences,
@ -15,6 +16,9 @@ class SetSortModeForCategory(
suspend fun await(categoryId: Long?, type: LibrarySort.Type, direction: LibrarySort.Direction) { suspend fun await(categoryId: Long?, type: LibrarySort.Type, direction: LibrarySort.Direction) {
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) {
preferences.currentRandomSortSeed().set(Random.nextInt())
}
if (category != null && preferences.categorizedDisplaySettings().get()) { if (category != null && preferences.categorizedDisplaySettings().get()) {
categoryRepository.updatePartial( categoryRepository.updatePartial(
CategoryUpdate( CategoryUpdate(

View File

@ -26,6 +26,8 @@ class LibraryPreferences(
LibrarySort.Serializer::deserialize, LibrarySort.Serializer::deserialize,
) )
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)
fun landscapeColumns() = preferenceStore.getInt("pref_library_columns_landscape_key", 0) fun landscapeColumns() = preferenceStore.getInt("pref_library_columns_landscape_key", 0)