Fix list headers
This commit is contained in:
@@ -20,7 +20,6 @@ import org.koitharu.kotatsu.utils.ext.daysDiff
|
|||||||
import org.koitharu.kotatsu.utils.ext.onFirst
|
import org.koitharu.kotatsu.utils.ext.onFirst
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import kotlin.collections.ArrayList
|
|
||||||
|
|
||||||
class HistoryListViewModel(
|
class HistoryListViewModel(
|
||||||
private val repository: HistoryRepository,
|
private val repository: HistoryRepository,
|
||||||
@@ -81,8 +80,11 @@ class HistoryListViewModel(
|
|||||||
grouped: Boolean,
|
grouped: Boolean,
|
||||||
mode: ListMode
|
mode: ListMode
|
||||||
): List<ListModel> {
|
): List<ListModel> {
|
||||||
val result = ArrayList<ListModel>(if (grouped) (list.size * 1.4).toInt() else list.size)
|
val result = ArrayList<ListModel>(if (grouped) (list.size * 1.4).toInt() else list.size + 1)
|
||||||
var prevDate: DateTimeAgo? = null
|
var prevDate: DateTimeAgo? = null
|
||||||
|
if (!grouped) {
|
||||||
|
result += ListHeader(null, R.string.history)
|
||||||
|
}
|
||||||
for ((manga, history) in list) {
|
for ((manga, history) in list) {
|
||||||
if (grouped) {
|
if (grouped) {
|
||||||
val date = timeAgo(history.updatedAt)
|
val date = timeAgo(history.updatedAt)
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ import org.koitharu.kotatsu.list.ui.model.ListModel
|
|||||||
fun listHeaderAD() = adapterDelegate<ListHeader, ListModel>(R.layout.item_header) {
|
fun listHeaderAD() = adapterDelegate<ListHeader, ListModel>(R.layout.item_header) {
|
||||||
|
|
||||||
bind {
|
bind {
|
||||||
(itemView as TextView).text = item.text
|
val textView = (itemView as TextView)
|
||||||
|
if (item.text != null) {
|
||||||
|
textView.text = item.text
|
||||||
|
} else {
|
||||||
|
textView.setText(item.textRes)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
package org.koitharu.kotatsu.list.ui.model
|
package org.koitharu.kotatsu.list.ui.model
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
|
||||||
data class ListHeader(
|
data class ListHeader(
|
||||||
val text: CharSequence,
|
val text: CharSequence?,
|
||||||
|
@StringRes val textRes: Int,
|
||||||
) : ListModel
|
) : ListModel
|
||||||
@@ -33,7 +33,7 @@ class LocalListViewModel(
|
|||||||
val onMangaRemoved = SingleLiveEvent<Manga>()
|
val onMangaRemoved = SingleLiveEvent<Manga>()
|
||||||
private val listError = MutableStateFlow<Throwable?>(null)
|
private val listError = MutableStateFlow<Throwable?>(null)
|
||||||
private val mangaList = MutableStateFlow<List<Manga>?>(null)
|
private val mangaList = MutableStateFlow<List<Manga>?>(null)
|
||||||
private val headerModel = ListHeader(context.getString(R.string.local_storage))
|
private val headerModel = ListHeader(null, R.string.local_storage)
|
||||||
|
|
||||||
override val content = combine(
|
override val content = combine(
|
||||||
mangaList,
|
mangaList,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class RemoteListViewModel(
|
|||||||
private val listError = MutableStateFlow<Throwable?>(null)
|
private val listError = MutableStateFlow<Throwable?>(null)
|
||||||
private var appliedFilter: MangaFilter? = null
|
private var appliedFilter: MangaFilter? = null
|
||||||
private var loadingJob: Job? = null
|
private var loadingJob: Job? = null
|
||||||
private val headerModel = ListHeader((repository as RemoteMangaRepository).title)
|
private val headerModel = ListHeader((repository as RemoteMangaRepository).title, 0)
|
||||||
|
|
||||||
override val content = combine(
|
override val content = combine(
|
||||||
mangaList,
|
mangaList,
|
||||||
|
|||||||
Reference in New Issue
Block a user