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

@@ -72,6 +72,7 @@ import tachiyomi.domain.track.model.Track
import tachiyomi.source.local.isLocal
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import kotlin.random.Random
/**
* Typealias for the library manga, using the category as keys, and list of manga as values.
@@ -300,10 +301,17 @@ class LibraryScreenModel(
val item2Score = trackerScores[i2.libraryManga.id] ?: defaultTrackerScoreSortValue
item1Score.compareTo(item2Score)
}
LibrarySort.Type.Random -> {
error("Why Are We Still Here? Just To Suffer?")
}
}
}
return mapValues { (key, value) ->
if (key.sort.type == LibrarySort.Type.Random) {
return@mapValues value.shuffled(Random(libraryPreferences.randomSortSeed().get()))
}
val comparator = key.sort.comparator()
.let { if (key.sort.isAscending) it else it.reversed() }
.thenComparator(sortAlphabetically)