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:
parent
457e5f963b
commit
2f102db19d
@ -6,6 +6,8 @@ import androidx.compose.foundation.layout.ColumnScope
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.Refresh
|
||||||
import androidx.compose.material3.FilterChip
|
import androidx.compose.material3.FilterChip
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@ -35,6 +37,7 @@ import tachiyomi.domain.library.model.sort
|
|||||||
import tachiyomi.domain.library.service.LibraryPreferences
|
import tachiyomi.domain.library.service.LibraryPreferences
|
||||||
import tachiyomi.i18n.MR
|
import tachiyomi.i18n.MR
|
||||||
import tachiyomi.i18n.sy.SYMR
|
import tachiyomi.i18n.sy.SYMR
|
||||||
|
import tachiyomi.presentation.core.components.BaseSortItem
|
||||||
import tachiyomi.presentation.core.components.CheckboxItem
|
import tachiyomi.presentation.core.components.CheckboxItem
|
||||||
import tachiyomi.presentation.core.components.HeadingItem
|
import tachiyomi.presentation.core.components.HeadingItem
|
||||||
import tachiyomi.presentation.core.components.IconItem
|
import tachiyomi.presentation.core.components.IconItem
|
||||||
@ -222,6 +225,7 @@ private fun ColumnScope.SortPage(
|
|||||||
MR.strings.action_sort_latest_chapter to LibrarySort.Type.LatestChapter,
|
MR.strings.action_sort_latest_chapter to LibrarySort.Type.LatestChapter,
|
||||||
MR.strings.action_sort_chapter_fetch_date to LibrarySort.Type.ChapterFetchDate,
|
MR.strings.action_sort_chapter_fetch_date to LibrarySort.Type.ChapterFetchDate,
|
||||||
MR.strings.action_sort_date_added to LibrarySort.Type.DateAdded,
|
MR.strings.action_sort_date_added to LibrarySort.Type.DateAdded,
|
||||||
|
MR.strings.action_sort_random to LibrarySort.Type.Random,
|
||||||
// SY -->
|
// SY -->
|
||||||
if (hasSortTags) {
|
if (hasSortTags) {
|
||||||
SYMR.strings.tag_sorting to LibrarySort.Type.TagList
|
SYMR.strings.tag_sorting to LibrarySort.Type.TagList
|
||||||
@ -230,6 +234,17 @@ private fun ColumnScope.SortPage(
|
|||||||
},
|
},
|
||||||
// SY <--
|
// SY <--
|
||||||
).plus(trackerSortOption).map { (titleRes, mode) ->
|
).plus(trackerSortOption).map { (titleRes, mode) ->
|
||||||
|
if (mode == LibrarySort.Type.Random) {
|
||||||
|
BaseSortItem(
|
||||||
|
label = stringResource(titleRes),
|
||||||
|
icon = Icons.Default.Refresh
|
||||||
|
.takeIf { sortingMode == LibrarySort.Type.Random },
|
||||||
|
onClick = {
|
||||||
|
screenModel.setSort(category, mode, LibrarySort.Direction.Ascending)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return@map
|
||||||
|
}
|
||||||
SortItem(
|
SortItem(
|
||||||
label = stringResource(titleRes),
|
label = stringResource(titleRes),
|
||||||
sortDescending = sortDescending.takeIf { sortingMode == mode },
|
sortDescending = sortDescending.takeIf { sortingMode == mode },
|
||||||
@ -241,7 +256,11 @@ private fun ColumnScope.SortPage(
|
|||||||
} else {
|
} else {
|
||||||
LibrarySort.Direction.Descending
|
LibrarySort.Direction.Descending
|
||||||
}
|
}
|
||||||
else -> if (sortDescending) LibrarySort.Direction.Descending else LibrarySort.Direction.Ascending
|
else -> if (sortDescending) {
|
||||||
|
LibrarySort.Direction.Descending
|
||||||
|
} else {
|
||||||
|
LibrarySort.Direction.Ascending
|
||||||
|
}
|
||||||
}
|
}
|
||||||
screenModel.setSort(category, mode, direction)
|
screenModel.setSort(category, mode, direction)
|
||||||
},
|
},
|
||||||
|
@ -117,6 +117,7 @@ import tachiyomi.source.local.LocalSource
|
|||||||
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 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.
|
||||||
@ -447,6 +448,9 @@ class LibraryScreenModel(
|
|||||||
val item2Score = trackerScores[i2.libraryManga.id] ?: defaultTrackerScoreSortValue
|
val item2Score = trackerScores[i2.libraryManga.id] ?: defaultTrackerScoreSortValue
|
||||||
item1Score.compareTo(item2Score)
|
item1Score.compareTo(item2Score)
|
||||||
}
|
}
|
||||||
|
LibrarySort.Type.Random -> {
|
||||||
|
error("Why Are We Still Here? Just To Suffer?")
|
||||||
|
}
|
||||||
// SY -->
|
// SY -->
|
||||||
LibrarySort.Type.TagList -> {
|
LibrarySort.Type.TagList -> {
|
||||||
val manga1IndexOfTag = listOfTags.indexOfFirst {
|
val manga1IndexOfTag = listOfTags.indexOfFirst {
|
||||||
@ -463,10 +467,13 @@ class LibraryScreenModel(
|
|||||||
|
|
||||||
return mapValues { (key, value) ->
|
return mapValues { (key, value) ->
|
||||||
// SY -->
|
// SY -->
|
||||||
val isAscending = groupSort?.isAscending ?: key.sort.isAscending
|
val sort = groupSort ?: key.sort
|
||||||
// SY <--
|
if (sort.type == LibrarySort.Type.Random) {
|
||||||
val comparator = key.sort.comparator()
|
return@mapValues value.shuffled(Random(libraryPreferences.randomSortSeed().get()))
|
||||||
.let { if (/* SY --> */ isAscending /* SY <-- */) it else it.reversed() }
|
}
|
||||||
|
val comparator = sort.comparator()
|
||||||
|
// SY <--
|
||||||
|
.let { if (/* SY --> */ sort.isAscending /* SY <-- */) it else it.reversed() }
|
||||||
.thenComparator(sortAlphabetically)
|
.thenComparator(sortAlphabetically)
|
||||||
|
|
||||||
value.sortedWith(comparator)
|
value.sortedWith(comparator)
|
||||||
|
@ -7,6 +7,7 @@ import tachiyomi.domain.library.model.LibraryGroup
|
|||||||
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,
|
||||||
@ -22,6 +23,9 @@ class SetSortModeForCategory(
|
|||||||
// SY <--
|
// SY <--
|
||||||
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.randomSortSeed().set(Random.nextInt())
|
||||||
|
}
|
||||||
if (category != null && preferences.categorizedDisplaySettings().get()) {
|
if (category != null && preferences.categorizedDisplaySettings().get()) {
|
||||||
categoryRepository.updatePartial(
|
categoryRepository.updatePartial(
|
||||||
CategoryUpdate(
|
CategoryUpdate(
|
||||||
|
@ -30,7 +30,8 @@ data class LibrarySort(
|
|||||||
data object LatestChapter : Type(0b00010100)
|
data object LatestChapter : Type(0b00010100)
|
||||||
data object ChapterFetchDate : Type(0b00011000)
|
data object ChapterFetchDate : Type(0b00011000)
|
||||||
data object DateAdded : Type(0b00011100)
|
data object DateAdded : Type(0b00011100)
|
||||||
data object TrackerMean : Type(0b000100000)
|
data object TrackerMean : Type(0b00100000)
|
||||||
|
data object Random : Type(0b00111100)
|
||||||
|
|
||||||
// SY -->
|
// SY -->
|
||||||
data object TagList : Type(0b00100100)
|
data object TagList : Type(0b00100100)
|
||||||
@ -81,6 +82,7 @@ data class LibrarySort(
|
|||||||
Type.ChapterFetchDate,
|
Type.ChapterFetchDate,
|
||||||
Type.DateAdded,
|
Type.DateAdded,
|
||||||
Type.TrackerMean,
|
Type.TrackerMean,
|
||||||
|
Type.Random,
|
||||||
/* SY -->*/ Type.TagList, /* SY <--*/
|
/* SY -->*/ Type.TagList, /* SY <--*/
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -109,6 +111,7 @@ data class LibrarySort(
|
|||||||
"CHAPTER_FETCH_DATE" -> Type.ChapterFetchDate
|
"CHAPTER_FETCH_DATE" -> Type.ChapterFetchDate
|
||||||
"DATE_ADDED" -> Type.DateAdded
|
"DATE_ADDED" -> Type.DateAdded
|
||||||
"TRACKER_MEAN" -> Type.TrackerMean
|
"TRACKER_MEAN" -> Type.TrackerMean
|
||||||
|
"RANDOM" -> Type.Random
|
||||||
// SY -->
|
// SY -->
|
||||||
"TAG_LIST" -> Type.TagList
|
"TAG_LIST" -> Type.TagList
|
||||||
// SY <--
|
// SY <--
|
||||||
@ -133,6 +136,7 @@ data class LibrarySort(
|
|||||||
Type.ChapterFetchDate -> "CHAPTER_FETCH_DATE"
|
Type.ChapterFetchDate -> "CHAPTER_FETCH_DATE"
|
||||||
Type.DateAdded -> "DATE_ADDED"
|
Type.DateAdded -> "DATE_ADDED"
|
||||||
Type.TrackerMean -> "TRACKER_MEAN"
|
Type.TrackerMean -> "TRACKER_MEAN"
|
||||||
|
Type.Random -> "RANDOM"
|
||||||
// SY -->
|
// SY -->
|
||||||
Type.TagList -> "TAG_LIST"
|
Type.TagList -> "TAG_LIST"
|
||||||
// SY <--
|
// SY <--
|
||||||
|
@ -28,6 +28,8 @@ class LibraryPreferences(
|
|||||||
LibrarySort.Serializer::deserialize,
|
LibrarySort.Serializer::deserialize,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun randomSortSeed() = 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)
|
||||||
|
@ -12,7 +12,7 @@ class LibraryFlagsTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `Check the amount of flags`() {
|
fun `Check the amount of flags`() {
|
||||||
LibraryDisplayMode.values.size shouldBe 4
|
LibraryDisplayMode.values.size shouldBe 4
|
||||||
LibrarySort.types.size shouldBe 9
|
LibrarySort.types.size shouldBe 10
|
||||||
LibrarySort.directions.size shouldBe 2
|
LibrarySort.directions.size shouldBe 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +69,7 @@
|
|||||||
<string name="action_sort_chapter_fetch_date">Chapter fetch date</string>
|
<string name="action_sort_chapter_fetch_date">Chapter fetch date</string>
|
||||||
<string name="action_sort_date_added">Date added</string>
|
<string name="action_sort_date_added">Date added</string>
|
||||||
<string name="action_sort_tracker_score">Tracker score</string>
|
<string name="action_sort_tracker_score">Tracker score</string>
|
||||||
|
<string name="action_sort_random">Random</string>
|
||||||
<string name="action_search">Search</string>
|
<string name="action_search">Search</string>
|
||||||
<string name="action_search_hint">Search…</string>
|
<string name="action_search_hint">Search…</string>
|
||||||
<string name="action_search_settings">Search settings</string>
|
<string name="action_search_settings">Search settings</string>
|
||||||
|
@ -99,12 +99,21 @@ fun SortItem(label: String, sortDescending: Boolean?, onClick: () -> Unit) {
|
|||||||
null -> null
|
null -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BaseSortItem(
|
||||||
|
label = label,
|
||||||
|
icon = arrowIcon,
|
||||||
|
onClick = onClick,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun BaseSortItem(label: String, icon: ImageVector?, onClick: () -> Unit) {
|
||||||
BaseSettingsItem(
|
BaseSettingsItem(
|
||||||
label = label,
|
label = label,
|
||||||
widget = {
|
widget = {
|
||||||
if (arrowIcon != null) {
|
if (icon != null) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = arrowIcon,
|
imageVector = icon,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
tint = MaterialTheme.colorScheme.primary,
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user