mirror of
https://github.com/mihonapp/mihon.git
synced 2025-02-08 00:05:02 +01:00
Keyed random seed
This commit is contained in:
parent
0ab795bfa3
commit
3d087f4428
@ -72,6 +72,8 @@ import tachiyomi.domain.track.model.Track
|
||||
import tachiyomi.source.local.isLocal
|
||||
import uy.kohesive.injekt.Injekt
|
||||
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.
|
||||
@ -305,7 +307,7 @@ class LibraryScreenModel(
|
||||
|
||||
return mapValues { (key, value) ->
|
||||
when (key.sort.type) {
|
||||
LibrarySort.Type.Random -> value.shuffled()
|
||||
LibrarySort.Type.Random -> value.shuffled(Random(libraryPreferences.currentRandomSortSeed().get()))
|
||||
else -> {
|
||||
val comparator = key.sort.comparator()
|
||||
.let { if (key.sort.isAscending) it else it.reversed() }
|
||||
|
@ -6,6 +6,7 @@ import tachiyomi.domain.category.repository.CategoryRepository
|
||||
import tachiyomi.domain.library.model.LibrarySort
|
||||
import tachiyomi.domain.library.model.plus
|
||||
import tachiyomi.domain.library.service.LibraryPreferences
|
||||
import kotlin.random.Random
|
||||
|
||||
class SetSortModeForCategory(
|
||||
private val preferences: LibraryPreferences,
|
||||
@ -15,6 +16,9 @@ class SetSortModeForCategory(
|
||||
suspend fun await(categoryId: Long?, type: LibrarySort.Type, direction: LibrarySort.Direction) {
|
||||
val category = categoryId?.let { categoryRepository.get(it) }
|
||||
val flags = (category?.flags ?: 0) + type + direction
|
||||
if (type == LibrarySort.Type.Random) {
|
||||
preferences.currentRandomSortSeed().set(Random.nextInt())
|
||||
}
|
||||
if (category != null && preferences.categorizedDisplaySettings().get()) {
|
||||
categoryRepository.updatePartial(
|
||||
CategoryUpdate(
|
||||
|
@ -26,6 +26,8 @@ class LibraryPreferences(
|
||||
LibrarySort.Serializer::deserialize,
|
||||
)
|
||||
|
||||
fun currentRandomSortSeed() = preferenceStore.getInt("library_random_sort_seed", 0)
|
||||
|
||||
fun portraitColumns() = preferenceStore.getInt("pref_library_columns_portrait_key", 0)
|
||||
|
||||
fun landscapeColumns() = preferenceStore.getInt("pref_library_columns_landscape_key", 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user