Added random library sort (#1317)
Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> (cherry picked from commit a72db41bf1746db095fd27bbbce9765c06453581) # Conflicts: # app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt # domain/src/main/java/tachiyomi/domain/library/model/LibrarySortMode.kt
This commit is contained in:
@@ -7,6 +7,7 @@ import tachiyomi.domain.library.model.LibraryGroup
|
||||
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,
|
||||
@@ -22,6 +23,9 @@ class SetSortModeForCategory(
|
||||
// SY <--
|
||||
val category = categoryId?.let { categoryRepository.get(it) }
|
||||
val flags = (category?.flags ?: 0) + type + direction
|
||||
if (type == LibrarySort.Type.Random) {
|
||||
preferences.randomSortSeed().set(Random.nextInt())
|
||||
}
|
||||
if (category != null && preferences.categorizedDisplaySettings().get()) {
|
||||
categoryRepository.updatePartial(
|
||||
CategoryUpdate(
|
||||
|
||||
@@ -30,7 +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 TrackerMean : Type(0b00100000)
|
||||
data object Random : Type(0b00111100)
|
||||
|
||||
// SY -->
|
||||
data object TagList : Type(0b00100100)
|
||||
@@ -81,6 +82,7 @@ data class LibrarySort(
|
||||
Type.ChapterFetchDate,
|
||||
Type.DateAdded,
|
||||
Type.TrackerMean,
|
||||
Type.Random,
|
||||
/* SY -->*/ Type.TagList, /* SY <--*/
|
||||
)
|
||||
}
|
||||
@@ -109,6 +111,7 @@ data class LibrarySort(
|
||||
"CHAPTER_FETCH_DATE" -> Type.ChapterFetchDate
|
||||
"DATE_ADDED" -> Type.DateAdded
|
||||
"TRACKER_MEAN" -> Type.TrackerMean
|
||||
"RANDOM" -> Type.Random
|
||||
// SY -->
|
||||
"TAG_LIST" -> Type.TagList
|
||||
// SY <--
|
||||
@@ -133,6 +136,7 @@ data class LibrarySort(
|
||||
Type.ChapterFetchDate -> "CHAPTER_FETCH_DATE"
|
||||
Type.DateAdded -> "DATE_ADDED"
|
||||
Type.TrackerMean -> "TRACKER_MEAN"
|
||||
Type.Random -> "RANDOM"
|
||||
// SY -->
|
||||
Type.TagList -> "TAG_LIST"
|
||||
// SY <--
|
||||
|
||||
@@ -28,6 +28,8 @@ class LibraryPreferences(
|
||||
LibrarySort.Serializer::deserialize,
|
||||
)
|
||||
|
||||
fun randomSortSeed() = 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)
|
||||
|
||||
@@ -12,7 +12,7 @@ class LibraryFlagsTest {
|
||||
@Test
|
||||
fun `Check the amount of flags`() {
|
||||
LibraryDisplayMode.values.size shouldBe 4
|
||||
LibrarySort.types.size shouldBe 9
|
||||
LibrarySort.types.size shouldBe 10
|
||||
LibrarySort.directions.size shouldBe 2
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user