Implement group by download label
This commit is contained in:
1 parent
5676de24da
commit
18caa87512
7 files changed
+44
-31
No files matched your search
@@ -3,9 +3,9 @@ package com.hippo.ehviewer.download
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.dao.DownloadInfo
|
||||
|
||||
data class SortMode(val field: Field, val order: Order) {
|
||||
data class SortMode(val field: Field, val order: Order, val groupByDownloadLabel: Boolean = false) {
|
||||
val flag
|
||||
get() = field.value shl 1 or order.value
|
||||
get() = groupByDownloadLabel.compareTo(false) shl 4 or (field.value shl 1) or order.value
|
||||
|
||||
enum class Field(val value: Int) {
|
||||
GID(0),
|
||||
@@ -21,22 +21,28 @@ data class SortMode(val field: Field, val order: Order) {
|
||||
}
|
||||
|
||||
fun comparator(): Comparator<DownloadInfo> {
|
||||
val comparator = when (field) {
|
||||
var comparator = when (field) {
|
||||
Field.GID -> compareBy { it.gid }
|
||||
Field.TITLE -> compareBy { EhUtils.getSuitableTitle(it) }
|
||||
Field.TITLE, Field.LABEL -> compareBy { EhUtils.getSuitableTitle(it) }
|
||||
Field.TIME -> compareBy { it.time }
|
||||
Field.LABEL -> compareBy<DownloadInfo> { it.label }.thenBy { EhUtils.getSuitableTitle(it) }
|
||||
Field.PAGES -> compareBy<DownloadInfo> { it.pages }.thenBy { EhUtils.getSuitableTitle(it) }
|
||||
}
|
||||
return if (order == Order.ASC) comparator else comparator.reversed()
|
||||
if (order == Order.DESC) {
|
||||
comparator = comparator.reversed()
|
||||
}
|
||||
if (groupByDownloadLabel) {
|
||||
comparator = compareBy<DownloadInfo> { it.label }.then(comparator)
|
||||
}
|
||||
return comparator
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun from(flag: Int): SortMode {
|
||||
val field = flag shr 1
|
||||
val order = flag and 1
|
||||
val field = flag and 0xF shr 1
|
||||
val order = flag and 0x1
|
||||
val groupByDownloadLabel = flag shr 4 == 1
|
||||
require(field in Field.entries.indices && order in Order.entries.indices)
|
||||
return SortMode(Field.entries[field], Order.entries[order])
|
||||
return SortMode(Field.entries[field], Order.entries[order], groupByDownloadLabel)
|
||||
}
|
||||
val Default = SortMode(Field.TIME, Order.DESC)
|
||||
val All = listOf(
|
||||
@@ -46,8 +52,6 @@ data class SortMode(val field: Field, val order: Order) {
|
||||
SortMode(Field.GID, Order.ASC),
|
||||
SortMode(Field.TITLE, Order.ASC),
|
||||
SortMode(Field.TITLE, Order.DESC),
|
||||
SortMode(Field.LABEL, Order.ASC),
|
||||
SortMode(Field.LABEL, Order.DESC),
|
||||
SortMode(Field.PAGES, Order.ASC),
|
||||
SortMode(Field.PAGES, Order.DESC),
|
||||
)
|
||||
|
||||
@@ -564,12 +564,15 @@ fun DownloadsScreen(navigator: DestinationsNavigator) = composing(navigator) {
|
||||
withUIContext { navToReader(list.random().galleryInfo) }
|
||||
}
|
||||
onClick(Icons.AutoMirrored.Default.Sort) {
|
||||
val selected = showSingleChoice(
|
||||
val oldMode = SortMode.from(sortMode)
|
||||
val (selected, checked) = showSelectItemWithCheckBox(
|
||||
sortModes.toList(),
|
||||
SortMode.All.indexOfFirst { it.flag == sortMode },
|
||||
R.string.sort_by,
|
||||
R.string.group_by_download_label,
|
||||
SortMode.All.indexOfFirst { it.field == oldMode.field && it.order == oldMode.order },
|
||||
oldMode.groupByDownloadLabel,
|
||||
)
|
||||
val mode = SortMode.All[selected]
|
||||
val mode = SortMode.All[selected].copy(groupByDownloadLabel = checked)
|
||||
DownloadManager.sortDownloads(mode)
|
||||
sortMode = mode.flag
|
||||
invalidateKey = !invalidateKey
|
||||
|
||||
@@ -22,6 +22,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Info
|
||||
import androidx.compose.material3.AlertDialog
|
||||
@@ -487,8 +488,12 @@ class DialogState {
|
||||
items: List<String>,
|
||||
@StringRes title: Int,
|
||||
@StringRes checkBoxText: Int,
|
||||
selected: Int = -1,
|
||||
initialChecked: Boolean = false,
|
||||
): Pair<Int, Boolean> = showNoButton {
|
||||
var checked by remember { mutableStateOf(false) }
|
||||
var checked by remember { mutableStateOf(initialChecked) }
|
||||
val textStyle = MaterialTheme.typography.titleMedium
|
||||
val selectedColor = MaterialTheme.colorScheme.tertiary
|
||||
Column(modifier = Modifier.padding(vertical = 8.dp)) {
|
||||
Text(
|
||||
text = stringResource(id = title),
|
||||
@@ -497,14 +502,20 @@ class DialogState {
|
||||
)
|
||||
LazyColumn {
|
||||
itemsIndexed(items) { index, text ->
|
||||
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.tertiary) {
|
||||
Text(
|
||||
text = text,
|
||||
modifier = Modifier.clickable { dismissWith(index to checked) }.fillMaxWidth()
|
||||
.padding(horizontal = 24.dp, vertical = 16.dp),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
)
|
||||
}
|
||||
ListItem(
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = text,
|
||||
style = if (index == selected) textStyle.copy(color = selectedColor) else textStyle,
|
||||
)
|
||||
},
|
||||
modifier = Modifier.clickable { dismissWith(index to checked) }.fillMaxWidth(),
|
||||
trailingContent = {
|
||||
if (index == selected) {
|
||||
Icon(imageVector = Icons.Default.Check, contentDescription = null, tint = selectedColor)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
LabeledCheckbox(
|
||||
|
||||
@@ -462,10 +462,9 @@
|
||||
<string name="uploaded_time_asc">上传时间(升序)</string>
|
||||
<string name="title_asc">标题(升序)</string>
|
||||
<string name="title_desc">标题(降序)</string>
|
||||
<string name="download_label_asc">下载标签(升序)</string>
|
||||
<string name="download_label_desc">下载标签(降序)</string>
|
||||
<string name="page_count_asc">页数(升序)</string>
|
||||
<string name="page_count_desc">页数(降序)</string>
|
||||
<string name="group_by_download_label">按下载标签分组</string>
|
||||
<string name="download_filter">过滤</string>
|
||||
<string name="download_all">全部</string>
|
||||
<string name="download_start_all_reversed">全部开始(倒序)</string>
|
||||
|
||||
@@ -461,10 +461,9 @@
|
||||
<string name="uploaded_time_asc">上傳時間 (遞增)</string>
|
||||
<string name="title_asc">標題 (遞減)</string>
|
||||
<string name="title_desc">標題 (遞增)</string>
|
||||
<string name="download_label_asc">下載標籤 (遞減)</string>
|
||||
<string name="download_label_desc">下載標籤 (遞增)</string>
|
||||
<string name="page_count_asc">頁數 (遞減)</string>
|
||||
<string name="page_count_desc">頁數 (遞增)</string>
|
||||
<string name="group_by_download_label">按下載標籤分組</string>
|
||||
<string name="download_filter">過濾</string>
|
||||
<string name="download_all">全部</string>
|
||||
<string name="download_start_all_reversed">全部開始(倒序)</string>
|
||||
|
||||
@@ -235,8 +235,6 @@
|
||||
<item>@string/uploaded_time_asc</item>
|
||||
<item>@string/title_asc</item>
|
||||
<item>@string/title_desc</item>
|
||||
<item>@string/download_label_asc</item>
|
||||
<item>@string/download_label_desc</item>
|
||||
<item>@string/page_count_asc</item>
|
||||
<item>@string/page_count_desc</item>
|
||||
</string-array>
|
||||
|
||||
@@ -527,10 +527,9 @@
|
||||
<string name="uploaded_time_asc">Uploaded time (ascending)</string>
|
||||
<string name="title_asc">Title (ascending)</string>
|
||||
<string name="title_desc">Title (descending)</string>
|
||||
<string name="download_label_asc">Download label (ascending)</string>
|
||||
<string name="download_label_desc">Download label (descending)</string>
|
||||
<string name="page_count_asc">Page count (ascending)</string>
|
||||
<string name="page_count_desc">Page count (descending)</string>
|
||||
<string name="group_by_download_label">Group by download label</string>
|
||||
<string name="download_filter">Filter</string>
|
||||
<string name="download_all">All</string>
|
||||
<string name="download_start_all_reversed">Start all (reversed)</string>
|
||||
|
||||
Reference in new issue
Block a user