Added random library sort (#1317)

Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
Jack Hamilton
2024-10-13 02:51:34 -05:00
committed by GitHub
parent 6b2bba4e54
commit a72db41bf1
8 changed files with 47 additions and 4 deletions

View File

@@ -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.randomSortSeed().set(Random.nextInt())
}
if (category != null && preferences.categorizedDisplaySettings().get()) {
categoryRepository.updatePartial(
CategoryUpdate(

View File

@@ -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)
companion object {
fun valueOf(flag: Long): Type {
@@ -77,6 +78,7 @@ data class LibrarySort(
Type.ChapterFetchDate,
Type.DateAdded,
Type.TrackerMean,
Type.Random,
)
}
val directions by lazy { setOf(Direction.Ascending, Direction.Descending) }
@@ -104,6 +106,7 @@ data class LibrarySort(
"CHAPTER_FETCH_DATE" -> Type.ChapterFetchDate
"DATE_ADDED" -> Type.DateAdded
"TRACKER_MEAN" -> Type.TrackerMean
"RANDOM" -> Type.Random
else -> Type.Alphabetical
}
val ascending = if (values[1] == "ASCENDING") Direction.Ascending else Direction.Descending
@@ -125,6 +128,7 @@ data class LibrarySort(
Type.ChapterFetchDate -> "CHAPTER_FETCH_DATE"
Type.DateAdded -> "DATE_ADDED"
Type.TrackerMean -> "TRACKER_MEAN"
Type.Random -> "RANDOM"
}
val direction = if (direction == Direction.Ascending) "ASCENDING" else "DESCENDING"
return "$type,$direction"

View File

@@ -26,6 +26,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)

View File

@@ -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
}