mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 18:01:49 +01:00
Fixes to the download status/fab/errors in ui
This commit is contained in:
parent
e669f4eba5
commit
5927ca6976
@ -6,6 +6,7 @@ import android.util.AttributeSet
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.widget.LinearLayout
|
||||
import androidx.core.view.isInvisible
|
||||
import androidx.core.view.isVisible
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import eu.kanade.tachiyomi.R
|
||||
@ -87,12 +88,13 @@ class DownloadBottomSheet @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
binding.downloadFab.setOnClickListener {
|
||||
if (!isRunning) {
|
||||
if (controller.presenter.downloadManager.isPaused()) {
|
||||
DownloadService.start(context)
|
||||
} else {
|
||||
DownloadService.stop(context)
|
||||
presenter.pauseDownloads()
|
||||
}
|
||||
updateFab()
|
||||
}
|
||||
update()
|
||||
setInformationView()
|
||||
@ -105,7 +107,7 @@ class DownloadBottomSheet @JvmOverloads constructor(
|
||||
fun update() {
|
||||
presenter.getItems()
|
||||
onQueueStatusChange(!presenter.downloadManager.isPaused())
|
||||
binding.downloadFab.isVisible = presenter.downloadQueue.isNotEmpty()
|
||||
binding.downloadFab.isInvisible = presenter.downloadQueue.isEmpty()
|
||||
}
|
||||
|
||||
private fun updateDLTitle() {
|
||||
@ -125,7 +127,8 @@ class DownloadBottomSheet @JvmOverloads constructor(
|
||||
private fun onQueueStatusChange(running: Boolean) {
|
||||
val oldRunning = isRunning
|
||||
isRunning = running
|
||||
binding.downloadFab.isVisible = presenter.downloadQueue.isNotEmpty()
|
||||
binding.downloadFab.isInvisible = presenter.downloadQueue.isEmpty()
|
||||
updateFab()
|
||||
if (oldRunning != running) {
|
||||
activity?.invalidateOptionsMenu()
|
||||
|
||||
@ -191,9 +194,7 @@ class DownloadBottomSheet @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
fun prepareMenu(menu: Menu) {
|
||||
binding.downloadFab.text = context.getString(if (isRunning) R.string.pause else R.string.resume)
|
||||
binding.downloadFab.setIconResource(if (isRunning) R.drawable.ic_pause_24dp else R.drawable.ic_play_arrow_24dp)
|
||||
|
||||
updateFab()
|
||||
// Set clear button visibility.
|
||||
menu.findItem(R.id.clear_queue)?.isVisible = !presenter.downloadQueue.isEmpty()
|
||||
|
||||
@ -201,6 +202,11 @@ class DownloadBottomSheet @JvmOverloads constructor(
|
||||
menu.findItem(R.id.reorder)?.isVisible = !presenter.downloadQueue.isEmpty()
|
||||
}
|
||||
|
||||
private fun updateFab() {
|
||||
binding.downloadFab.text = context.getString(if (isRunning) R.string.pause else R.string.resume)
|
||||
binding.downloadFab.setIconResource(if (isRunning) R.drawable.ic_pause_24dp else R.drawable.ic_play_arrow_24dp)
|
||||
}
|
||||
|
||||
fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
val context = activity ?: return false
|
||||
when (item.itemId) {
|
||||
@ -263,6 +269,7 @@ class DownloadBottomSheet @JvmOverloads constructor(
|
||||
val adapter = adapter ?: return
|
||||
val downloads = (0 until adapter.itemCount).mapNotNull { adapter.getItem(it)?.download }
|
||||
presenter.reorder(downloads)
|
||||
controller.updateChapterDownload(download, false)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -304,6 +304,7 @@ class RecentsController(bundle: Bundle? = null) :
|
||||
}
|
||||
|
||||
if (presenter.downloadManager.hasQueue()) {
|
||||
binding.downloadBottomSheet.downloadFab.alpha = 1f
|
||||
if (state == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
binding.downloadBottomSheet.downloadFab.show()
|
||||
} else {
|
||||
@ -488,16 +489,22 @@ class RecentsController(bundle: Bundle? = null) :
|
||||
}
|
||||
}
|
||||
|
||||
fun updateChapterDownload(download: Download) {
|
||||
fun updateChapterDownload(download: Download, updateDLSheet: Boolean = true) {
|
||||
if (view == null) return
|
||||
binding.downloadBottomSheet.dlBottomSheet.update()
|
||||
binding.downloadBottomSheet.dlBottomSheet.onUpdateProgress(download)
|
||||
binding.downloadBottomSheet.dlBottomSheet.onUpdateDownloadedPages(download)
|
||||
if (updateDLSheet) {
|
||||
binding.downloadBottomSheet.dlBottomSheet.update()
|
||||
binding.downloadBottomSheet.dlBottomSheet.onUpdateProgress(download)
|
||||
binding.downloadBottomSheet.dlBottomSheet.onUpdateDownloadedPages(download)
|
||||
}
|
||||
val id = download.chapter.id ?: return
|
||||
val holder = binding.recycler.findViewHolderForItemId(id) as? RecentMangaHolder ?: return
|
||||
holder.notifyStatus(download.status, download.progress, download.chapter.read, true)
|
||||
}
|
||||
|
||||
fun updateDownloadStatus() {
|
||||
binding.downloadBottomSheet.dlBottomSheet.update()
|
||||
}
|
||||
|
||||
private fun refreshItem(chapterId: Long) {
|
||||
val recentItemPos = adapter.currentItems.indexOfFirst {
|
||||
it is RecentMangaItem &&
|
||||
|
@ -7,6 +7,8 @@ import eu.kanade.tachiyomi.data.database.models.HistoryImpl
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory
|
||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
import eu.kanade.tachiyomi.data.download.DownloadService
|
||||
import eu.kanade.tachiyomi.data.download.DownloadServiceListener
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.data.download.model.DownloadQueue
|
||||
import eu.kanade.tachiyomi.data.library.LibraryServiceListener
|
||||
@ -37,7 +39,7 @@ class RecentsPresenter(
|
||||
val preferences: PreferencesHelper = Injekt.get(),
|
||||
val downloadManager: DownloadManager = Injekt.get(),
|
||||
private val db: DatabaseHelper = Injekt.get()
|
||||
) : BaseCoroutinePresenter(), DownloadQueue.DownloadListener, LibraryServiceListener {
|
||||
) : BaseCoroutinePresenter(), DownloadQueue.DownloadListener, LibraryServiceListener, DownloadServiceListener {
|
||||
|
||||
private var recentsJob: Job? = null
|
||||
var recentItems = listOf<RecentMangaItem>()
|
||||
@ -75,6 +77,7 @@ class RecentsPresenter(
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
downloadManager.addListener(this)
|
||||
DownloadService.addListener(this)
|
||||
LibraryUpdateService.setListener(this)
|
||||
if (lastRecents != null) {
|
||||
if (recentItems.isEmpty()) {
|
||||
@ -329,6 +332,7 @@ class RecentsPresenter(
|
||||
super.onDestroy()
|
||||
downloadManager.removeListener(this)
|
||||
LibraryUpdateService.removeListener(this)
|
||||
DownloadService.removeListener(this)
|
||||
lastRecents = recentItems
|
||||
}
|
||||
|
||||
@ -367,6 +371,15 @@ class RecentsPresenter(
|
||||
setDownloadedChapters(recentItems)
|
||||
withContext(Dispatchers.Main) {
|
||||
controller?.showLists(recentItems, true)
|
||||
controller?.updateDownloadStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun downloadStatusChanged(downloading: Boolean) {
|
||||
presenterScope.launch {
|
||||
withContext(Dispatchers.Main) {
|
||||
controller?.updateDownloadStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user