Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library sort download count #1014

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ private fun ColumnScope.SortPage(
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_date_added to LibrarySort.Type.DateAdded,
MR.strings.action_sort_download_count to LibrarySort.Type.DownloadCount,
).plus(trackerSortOption).map { (titleRes, mode) ->
SortItem(
label = stringResource(titleRes),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ class LibraryScreenModel(
val item2Score = trackerScores[i2.libraryManga.id] ?: defaultTrackerScoreSortValue
item1Score.compareTo(item2Score)
}
LibrarySort.Type.DownloadCount -> {
i1.downloadCount.compareTo(i2.downloadCount)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ data class LibrarySort(
val isAscending: Boolean
get() = direction == Direction.Ascending

@Suppress("MagicNumber")
sealed class Type(
override val flag: Long,
) : FlagWithMask {
Expand All @@ -31,6 +32,7 @@ data class LibrarySort(
data object ChapterFetchDate : Type(0b00011000)
data object DateAdded : Type(0b00011100)
data object TrackerMean : Type(0b000100000)
data object DownloadCount : Type(0b000100100)

companion object {
fun valueOf(flag: Long): Type {
Expand Down Expand Up @@ -77,6 +79,7 @@ data class LibrarySort(
Type.ChapterFetchDate,
Type.DateAdded,
Type.TrackerMean,
Type.DownloadCount,
)
}
val directions by lazy { setOf(Direction.Ascending, Direction.Descending) }
Expand All @@ -90,6 +93,7 @@ data class LibrarySort(
)
}

@Suppress("CyclomaticComplexMethod")
fun deserialize(serialized: String): LibrarySort {
if (serialized.isEmpty()) return default
return try {
Expand All @@ -104,6 +108,7 @@ data class LibrarySort(
"CHAPTER_FETCH_DATE" -> Type.ChapterFetchDate
"DATE_ADDED" -> Type.DateAdded
"TRACKER_MEAN" -> Type.TrackerMean
"DOWNLOAD_COUNT" -> Type.DownloadCount
else -> Type.Alphabetical
}
val ascending = if (values[1] == "ASCENDING") Direction.Ascending else Direction.Descending
Expand All @@ -125,6 +130,7 @@ data class LibrarySort(
Type.ChapterFetchDate -> "CHAPTER_FETCH_DATE"
Type.DateAdded -> "DATE_ADDED"
Type.TrackerMean -> "TRACKER_MEAN"
Type.DownloadCount -> "DOWNLOAD_COUNT"
}
val direction = if (direction == Direction.Ascending) "ASCENDING" else "DESCENDING"
return "$type,$direction"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions i18n/src/commonMain/moko-resources/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<string name="action_sort_chapter_fetch_date">Chapter fetch date</string>
<string name="action_sort_date_added">Date added</string>
<string name="action_sort_tracker_score">Tracker score</string>
<string name="action_sort_download_count">Download count</string>
<string name="action_search">Search</string>
<string name="action_search_hint">Search…</string>
<string name="action_search_settings">Search settings</string>
Expand Down