mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-17 14:09:17 +01:00
Handle download cancelation from icon properly (fixes #4241)
This commit is contained in:
parent
271489bdfd
commit
f85194ec46
@ -212,8 +212,19 @@ class DownloadManager(private val context: Context) {
|
|||||||
fun deleteChapters(chapters: List<Chapter>, manga: Manga, source: Source): List<Chapter> {
|
fun deleteChapters(chapters: List<Chapter>, manga: Manga, source: Source): List<Chapter> {
|
||||||
val filteredChapters = getChaptersToDelete(chapters)
|
val filteredChapters = getChaptersToDelete(chapters)
|
||||||
|
|
||||||
|
val wasRunning = downloader.isRunning
|
||||||
|
downloader.pause()
|
||||||
|
|
||||||
|
downloader.queue.remove(filteredChapters)
|
||||||
queue.remove(filteredChapters)
|
queue.remove(filteredChapters)
|
||||||
|
|
||||||
|
if (downloader.queue.isEmpty()) {
|
||||||
|
DownloadService.stop(context)
|
||||||
|
downloader.stop()
|
||||||
|
} else if (wasRunning && downloader.queue.isNotEmpty()) {
|
||||||
|
downloader.start()
|
||||||
|
}
|
||||||
|
|
||||||
val chapterDirs = provider.findChapterDirs(filteredChapters, manga, source)
|
val chapterDirs = provider.findChapterDirs(filteredChapters, manga, source)
|
||||||
chapterDirs.forEach { it.delete() }
|
chapterDirs.forEach { it.delete() }
|
||||||
cache.removeChapters(filteredChapters, manga)
|
cache.removeChapters(filteredChapters, manga)
|
||||||
|
@ -165,6 +165,8 @@ internal class DownloadNotifier(private val context: Context) {
|
|||||||
* This function shows a notification to inform download tasks are done.
|
* This function shows a notification to inform download tasks are done.
|
||||||
*/
|
*/
|
||||||
fun onComplete() {
|
fun onComplete() {
|
||||||
|
dismissProgress()
|
||||||
|
|
||||||
if (!errorThrown) {
|
if (!errorThrown) {
|
||||||
// Create notification
|
// Create notification
|
||||||
with(completeNotificationBuilder) {
|
with(completeNotificationBuilder) {
|
||||||
|
@ -134,15 +134,16 @@ class Downloader(
|
|||||||
|
|
||||||
if (reason != null) {
|
if (reason != null) {
|
||||||
notifier.onWarning(reason)
|
notifier.onWarning(reason)
|
||||||
} else {
|
return
|
||||||
if (notifier.paused) {
|
}
|
||||||
notifier.paused = false
|
|
||||||
|
if (notifier.paused && !queue.isEmpty()) {
|
||||||
notifier.onPaused()
|
notifier.onPaused()
|
||||||
} else {
|
} else {
|
||||||
notifier.dismissProgress()
|
|
||||||
notifier.onComplete()
|
notifier.onComplete()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
notifier.paused = false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,7 +20,9 @@ class ChapterHolder(
|
|||||||
private val binding = ChaptersItemBinding.bind(view)
|
private val binding = ChaptersItemBinding.bind(view)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
binding.download.setOnClickListener { onDownloadClick(it) }
|
binding.download.setOnClickListener {
|
||||||
|
onDownloadClick(it, bindingAdapterPosition)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun bind(item: ChapterItem, manga: Manga) {
|
fun bind(item: ChapterItem, manga: Manga) {
|
||||||
|
@ -11,11 +11,11 @@ open class BaseChapterHolder(
|
|||||||
private val adapter: BaseChaptersAdapter<*>
|
private val adapter: BaseChaptersAdapter<*>
|
||||||
) : FlexibleViewHolder(view, adapter) {
|
) : FlexibleViewHolder(view, adapter) {
|
||||||
|
|
||||||
fun onDownloadClick(view: View) {
|
fun onDownloadClick(view: View, position: Int) {
|
||||||
val item = adapter.getItem(bindingAdapterPosition) as? BaseChapterItem<*, *> ?: return
|
val item = adapter.getItem(position) as? BaseChapterItem<*, *> ?: return
|
||||||
when (item.status) {
|
when (item.status) {
|
||||||
Download.State.NOT_DOWNLOADED, Download.State.ERROR -> {
|
Download.State.NOT_DOWNLOADED, Download.State.ERROR -> {
|
||||||
adapter.clickListener.downloadChapter(bindingAdapterPosition)
|
adapter.clickListener.downloadChapter(position)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
view.popupMenu(
|
view.popupMenu(
|
||||||
@ -28,7 +28,7 @@ open class BaseChapterHolder(
|
|||||||
findItem(R.id.cancel_download).isVisible = item.status != Download.State.DOWNLOADED
|
findItem(R.id.cancel_download).isVisible = item.status != Download.State.DOWNLOADED
|
||||||
},
|
},
|
||||||
onMenuItemClick = {
|
onMenuItemClick = {
|
||||||
adapter.clickListener.deleteChapter(bindingAdapterPosition)
|
adapter.clickListener.deleteChapter(position)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -32,7 +32,9 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter)
|
|||||||
adapter.coverClickListener.onCoverClick(bindingAdapterPosition)
|
adapter.coverClickListener.onCoverClick(bindingAdapterPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.download.setOnClickListener { onDownloadClick(it) }
|
binding.download.setOnClickListener {
|
||||||
|
onDownloadClick(it, bindingAdapterPosition)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun bind(item: UpdatesItem) {
|
fun bind(item: UpdatesItem) {
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="44dp"
|
android:layout_width="42dp"
|
||||||
android:layout_height="44dp"
|
android:layout_height="42dp"
|
||||||
android:padding="8dp"
|
android:padding="8dp"
|
||||||
android:background="?selectableItemBackgroundBorderless">
|
android:background="?selectableItemBackgroundBorderless">
|
||||||
|
|
||||||
@ -36,7 +36,7 @@
|
|||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
app:indicatorColor="@color/material_on_surface_emphasis_medium"
|
app:indicatorColor="@color/material_on_surface_emphasis_medium"
|
||||||
app:indicatorInset="0dp"
|
app:indicatorInset="0dp"
|
||||||
app:indicatorSize="26dp"
|
app:indicatorSize="24dp"
|
||||||
app:trackThickness="2dp" />
|
app:trackThickness="2dp" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
|
Loading…
Reference in New Issue
Block a user