Grouping history by progress
This commit is contained in:
@@ -12,5 +12,5 @@ enum class HistoryOrder(
|
||||
PROGRESS(R.string.progress),
|
||||
ALPHABETIC(R.string.by_name);
|
||||
|
||||
fun isGroupingSupported() = this == UPDATED || this == CREATED
|
||||
fun isGroupingSupported() = this == UPDATED || this == CREATED || this == PROGRESS
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.plus
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.MangaHistory
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.core.prefs.ListMode
|
||||
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
||||
@@ -130,14 +131,17 @@ class HistoryListViewModel @Inject constructor(
|
||||
mode: ListMode,
|
||||
): List<ListModel> {
|
||||
val result = ArrayList<ListModel>(if (grouped) (list.size * 1.4).toInt() else list.size + 1)
|
||||
var prevDate: DateTimeAgo? = null
|
||||
val order = sortOrder.value
|
||||
var prevHeader: ListHeader? = null
|
||||
for ((manga, history) in list) {
|
||||
if (grouped) {
|
||||
val date = timeAgo(history.updatedAt)
|
||||
if (prevDate != date) {
|
||||
result += ListHeader(date)
|
||||
val header = history.header(order)
|
||||
if (header != prevHeader) {
|
||||
if (header != null) {
|
||||
result += header
|
||||
}
|
||||
prevHeader = header
|
||||
}
|
||||
prevDate = date
|
||||
}
|
||||
result += when (mode) {
|
||||
ListMode.LIST -> manga.toListModel(extraProvider)
|
||||
@@ -148,6 +152,21 @@ class HistoryListViewModel @Inject constructor(
|
||||
return result
|
||||
}
|
||||
|
||||
private fun MangaHistory.header(order: HistoryOrder): ListHeader? = when (order) {
|
||||
HistoryOrder.UPDATED -> ListHeader(timeAgo(updatedAt))
|
||||
HistoryOrder.CREATED -> ListHeader(timeAgo(createdAt))
|
||||
HistoryOrder.PROGRESS -> ListHeader(
|
||||
when (percent) {
|
||||
1f -> R.string.status_completed
|
||||
in 0f..0.01f -> R.string.status_planned
|
||||
in 0f..1f -> R.string.status_reading
|
||||
else -> R.string.unknown
|
||||
},
|
||||
)
|
||||
|
||||
HistoryOrder.ALPHABETIC -> null
|
||||
}
|
||||
|
||||
private fun timeAgo(date: Date): DateTimeAgo {
|
||||
val diff = (System.currentTimeMillis() - date.time).coerceAtLeast(0L)
|
||||
val diffMinutes = TimeUnit.MILLISECONDS.toMinutes(diff).toInt()
|
||||
|
||||
@@ -470,4 +470,5 @@
|
||||
<string name="show">Show</string>
|
||||
<string name="captcha_required_summary">%s requires a captcha to be resolved to work properly</string>
|
||||
<string name="languages">Languages</string>
|
||||
<string name="unknown">Unknown</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user