Improve downloads list
This commit is contained in:
@@ -7,6 +7,7 @@ import androidx.work.WorkInfo
|
||||
import coil.ImageLoader
|
||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.ui.image.TrimTransformation
|
||||
import org.koitharu.kotatsu.core.util.ext.disposeImageRequest
|
||||
import org.koitharu.kotatsu.core.util.ext.enqueueWith
|
||||
import org.koitharu.kotatsu.core.util.ext.newImageRequest
|
||||
@@ -53,6 +54,7 @@ fun downloadItemAD(
|
||||
fallback(R.drawable.ic_placeholder)
|
||||
error(R.drawable.ic_error_placeholder)
|
||||
allowRgb565(true)
|
||||
transformations(TrimTransformation())
|
||||
source(item.manga.source)
|
||||
enqueueWith(coil)
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.koitharu.kotatsu.list.ui.model.LoadingState
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.util.mapToSet
|
||||
import java.util.Date
|
||||
import java.util.LinkedList
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
@@ -181,16 +182,34 @@ class DownloadsViewModel @Inject constructor(
|
||||
if (isEmpty()) {
|
||||
return emptyStateList()
|
||||
}
|
||||
val destination = ArrayList<ListModel>((size * 1.4).toInt())
|
||||
val queued = LinkedList<ListModel>()
|
||||
val running = LinkedList<ListModel>()
|
||||
val destination = ArrayDeque<ListModel>((size * 1.4).toInt())
|
||||
var prevDate: DateTimeAgo? = null
|
||||
for (item in this) {
|
||||
val date = timeAgo(item.timestamp)
|
||||
if (prevDate != date) {
|
||||
destination += ListHeader(date)
|
||||
when (item.workState) {
|
||||
WorkInfo.State.RUNNING -> running += item
|
||||
WorkInfo.State.BLOCKED,
|
||||
WorkInfo.State.ENQUEUED -> queued += item
|
||||
|
||||
else -> {
|
||||
val date = timeAgo(item.timestamp)
|
||||
if (prevDate != date) {
|
||||
destination += ListHeader(date)
|
||||
}
|
||||
prevDate = date
|
||||
destination += item
|
||||
}
|
||||
}
|
||||
prevDate = date
|
||||
destination += item
|
||||
}
|
||||
if (running.isNotEmpty()) {
|
||||
running.addFirst(ListHeader(R.string.in_progress))
|
||||
}
|
||||
destination.addAll(0, running)
|
||||
if (queued.isNotEmpty()) {
|
||||
queued.addFirst(ListHeader(R.string.queued))
|
||||
}
|
||||
destination.addAll(0, queued)
|
||||
return destination
|
||||
}
|
||||
|
||||
|
||||
@@ -471,4 +471,5 @@
|
||||
<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>
|
||||
<string name="in_progress">In progress</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user