Fix manga cover in downloads queue
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package org.koitharu.kotatsu.download.ui
|
package org.koitharu.kotatsu.download.ui
|
||||||
|
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
@@ -10,12 +11,11 @@ import org.koitharu.kotatsu.R
|
|||||||
import org.koitharu.kotatsu.databinding.ItemDownloadBinding
|
import org.koitharu.kotatsu.databinding.ItemDownloadBinding
|
||||||
import org.koitharu.kotatsu.download.domain.DownloadManager
|
import org.koitharu.kotatsu.download.domain.DownloadManager
|
||||||
import org.koitharu.kotatsu.utils.JobStateFlow
|
import org.koitharu.kotatsu.utils.JobStateFlow
|
||||||
import org.koitharu.kotatsu.utils.ext.format
|
import org.koitharu.kotatsu.utils.ext.*
|
||||||
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
|
||||||
import org.koitharu.kotatsu.utils.ext.setIndeterminateCompat
|
|
||||||
|
|
||||||
fun downloadItemAD(
|
fun downloadItemAD(
|
||||||
scope: CoroutineScope,
|
scope: CoroutineScope,
|
||||||
|
coil: ImageLoader,
|
||||||
) = adapterDelegateViewBinding<JobStateFlow<DownloadManager.State>, JobStateFlow<DownloadManager.State>, ItemDownloadBinding>(
|
) = adapterDelegateViewBinding<JobStateFlow<DownloadManager.State>, JobStateFlow<DownloadManager.State>, ItemDownloadBinding>(
|
||||||
{ inflater, parent -> ItemDownloadBinding.inflate(inflater, parent, false) }
|
{ inflater, parent -> ItemDownloadBinding.inflate(inflater, parent, false) }
|
||||||
) {
|
) {
|
||||||
@@ -24,11 +24,16 @@ fun downloadItemAD(
|
|||||||
|
|
||||||
bind {
|
bind {
|
||||||
job?.cancel()
|
job?.cancel()
|
||||||
job = item.onEach { state ->
|
job = item.onFirst { state ->
|
||||||
|
binding.imageViewCover.newImageRequest(state.manga.coverUrl)
|
||||||
|
.referer(state.manga.publicUrl)
|
||||||
|
.placeholder(state.cover)
|
||||||
|
.fallback(R.drawable.ic_placeholder)
|
||||||
|
.error(R.drawable.ic_placeholder)
|
||||||
|
.allowRgb565(true)
|
||||||
|
.enqueueWith(coil)
|
||||||
|
}.onEach { state ->
|
||||||
binding.textViewTitle.text = state.manga.title
|
binding.textViewTitle.text = state.manga.title
|
||||||
binding.imageViewCover.setImageDrawable(
|
|
||||||
state.cover ?: getDrawable(R.drawable.ic_placeholder)
|
|
||||||
)
|
|
||||||
when (state) {
|
when (state) {
|
||||||
is DownloadManager.State.Cancelling -> {
|
is DownloadManager.State.Cancelling -> {
|
||||||
binding.textViewStatus.setText(R.string.cancelling_)
|
binding.textViewStatus.setText(R.string.cancelling_)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import kotlinx.coroutines.flow.flatMapLatest
|
|||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import org.koin.android.ext.android.get
|
||||||
import org.koitharu.kotatsu.base.ui.BaseActivity
|
import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||||
import org.koitharu.kotatsu.databinding.ActivityDownloadsBinding
|
import org.koitharu.kotatsu.databinding.ActivityDownloadsBinding
|
||||||
import org.koitharu.kotatsu.download.ui.service.DownloadService
|
import org.koitharu.kotatsu.download.ui.service.DownloadService
|
||||||
@@ -22,7 +23,7 @@ class DownloadsActivity : BaseActivity<ActivityDownloadsBinding>() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(ActivityDownloadsBinding.inflate(layoutInflater))
|
setContentView(ActivityDownloadsBinding.inflate(layoutInflater))
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
val adapter = DownloadsAdapter(lifecycleScope)
|
val adapter = DownloadsAdapter(lifecycleScope, get())
|
||||||
binding.recyclerView.setHasFixedSize(true)
|
binding.recyclerView.setHasFixedSize(true)
|
||||||
binding.recyclerView.adapter = adapter
|
binding.recyclerView.adapter = adapter
|
||||||
LifecycleAwareServiceConnection.bindService(
|
LifecycleAwareServiceConnection.bindService(
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.koitharu.kotatsu.download.ui
|
package org.koitharu.kotatsu.download.ui
|
||||||
|
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
|
import coil.ImageLoader
|
||||||
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import org.koitharu.kotatsu.download.domain.DownloadManager
|
import org.koitharu.kotatsu.download.domain.DownloadManager
|
||||||
@@ -8,10 +9,11 @@ import org.koitharu.kotatsu.utils.JobStateFlow
|
|||||||
|
|
||||||
class DownloadsAdapter(
|
class DownloadsAdapter(
|
||||||
scope: CoroutineScope,
|
scope: CoroutineScope,
|
||||||
|
coil: ImageLoader,
|
||||||
) : AsyncListDifferDelegationAdapter<JobStateFlow<DownloadManager.State>>(DiffCallback()) {
|
) : AsyncListDifferDelegationAdapter<JobStateFlow<DownloadManager.State>>(DiffCallback()) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
delegatesManager.addDelegate(downloadItemAD(scope))
|
delegatesManager.addDelegate(downloadItemAD(scope, coil))
|
||||||
setHasStableIds(true)
|
setHasStableIds(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user