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 java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class HistoryListViewModel(
|
||||
private val repository: HistoryRepository,
|
||||
@@ -81,8 +80,11 @@ class HistoryListViewModel(
|
||||
grouped: Boolean,
|
||||
mode: ListMode
|
||||
): 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
|
||||
if (!grouped) {
|
||||
result += ListHeader(null, R.string.history)
|
||||
}
|
||||
for ((manga, history) in list) {
|
||||
if (grouped) {
|
||||
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) {
|
||||
|
||||
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
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
|
||||
data class ListHeader(
|
||||
val text: CharSequence,
|
||||
val text: CharSequence?,
|
||||
@StringRes val textRes: Int,
|
||||
) : ListModel
|
||||
@@ -33,7 +33,7 @@ class LocalListViewModel(
|
||||
val onMangaRemoved = SingleLiveEvent<Manga>()
|
||||
private val listError = MutableStateFlow<Throwable?>(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(
|
||||
mangaList,
|
||||
|
||||
@@ -27,7 +27,7 @@ class RemoteListViewModel(
|
||||
private val listError = MutableStateFlow<Throwable?>(null)
|
||||
private var appliedFilter: MangaFilter? = 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(
|
||||
mangaList,
|
||||
|
||||
Reference in New Issue
Block a user