mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 13:01:50 +01:00
add start download now (#5386)
* add start download now download now for selected chapter from j2k Co-Authored-By: Jays2Kings <jays@outlook.com> * change string to action * move to bottom * oopsie Co-authored-by: Jays2Kings <jays@outlook.com>
This commit is contained in:
parent
848d387ec4
commit
05771ddf6d
@ -95,6 +95,23 @@ class DownloadManager(private val context: Context) {
|
||||
downloader.clearQueue(isNotification)
|
||||
}
|
||||
|
||||
fun startDownloadNow(chapter: Chapter) {
|
||||
val download = downloader.queue.find { it.chapter.id == chapter.id } ?: return
|
||||
val queue = downloader.queue.toMutableList()
|
||||
queue.remove(download)
|
||||
queue.add(0, download)
|
||||
reorderQueue(queue)
|
||||
if (isPaused()) {
|
||||
if (DownloadService.isRunning(context)) {
|
||||
downloader.start()
|
||||
} else {
|
||||
DownloadService.start(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun isPaused() = downloader.isPaused()
|
||||
|
||||
/**
|
||||
* Reorders the download queue.
|
||||
*
|
||||
|
@ -19,6 +19,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.util.lang.plusAssign
|
||||
import eu.kanade.tachiyomi.util.system.acquireWakeLock
|
||||
import eu.kanade.tachiyomi.util.system.connectivityManager
|
||||
import eu.kanade.tachiyomi.util.system.isServiceRunning
|
||||
import eu.kanade.tachiyomi.util.system.notification
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
@ -58,6 +59,16 @@ class DownloadService : Service() {
|
||||
fun stop(context: Context) {
|
||||
context.stopService(Intent(context, DownloadService::class.java))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status of the service.
|
||||
*
|
||||
* @param context the application context.
|
||||
* @return true if the service is running, false otherwise.
|
||||
*/
|
||||
fun isRunning(context: Context): Boolean {
|
||||
return context.isServiceRunning(DownloadService::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
private val downloadManager: DownloadManager by injectLazy()
|
||||
|
@ -157,6 +157,11 @@ class Downloader(
|
||||
notifier.paused = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if downloader is paused
|
||||
*/
|
||||
fun isPaused() = !isRunning
|
||||
|
||||
/**
|
||||
* Removes everything from the queue.
|
||||
*
|
||||
|
@ -1057,6 +1057,11 @@ class MangaController :
|
||||
Timber.e(error)
|
||||
}
|
||||
|
||||
override fun startDownloadNow(position: Int) {
|
||||
val chapter = chaptersAdapter?.getItem(position) ?: return
|
||||
presenter.startDownloadingNow(chapter)
|
||||
}
|
||||
|
||||
// OVERFLOW MENU DIALOGS
|
||||
|
||||
private fun downloadChapters(choice: Int) {
|
||||
|
@ -517,6 +517,10 @@ class MangaPresenter(
|
||||
}
|
||||
}
|
||||
|
||||
fun startDownloadingNow(chapter: Chapter) {
|
||||
downloadManager.startDownloadNow(chapter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the selected chapter list as read/unread.
|
||||
* @param selectedChapters the list of selected chapters.
|
||||
|
@ -26,9 +26,16 @@ open class BaseChapterHolder(
|
||||
|
||||
// Download.State.DOWNLOADING, Download.State.QUEUE
|
||||
findItem(R.id.cancel_download).isVisible = item.status != Download.State.DOWNLOADED
|
||||
|
||||
// Download.State.QUEUE
|
||||
findItem(R.id.start_download).isVisible = item.status == Download.State.QUEUE
|
||||
},
|
||||
onMenuItemClick = {
|
||||
adapter.clickListener.deleteChapter(position)
|
||||
if (itemId == R.id.start_download) {
|
||||
adapter.clickListener.startDownloadNow(position)
|
||||
} else {
|
||||
adapter.clickListener.deleteChapter(position)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -18,5 +18,6 @@ abstract class BaseChaptersAdapter<T : IFlexible<*>>(
|
||||
interface OnChapterClickListener {
|
||||
fun downloadChapter(position: Int)
|
||||
fun deleteChapter(position: Int)
|
||||
fun startDownloadNow(position: Int)
|
||||
}
|
||||
}
|
||||
|
@ -318,6 +318,11 @@ class UpdatesController :
|
||||
adapter?.updateItem(item)
|
||||
}
|
||||
|
||||
override fun startDownloadNow(position: Int) {
|
||||
val chapter = adapter?.getItem(position) as? UpdatesItem ?: return
|
||||
presenter.startDownloadingNow(chapter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when ActionMode created.
|
||||
* @param mode the ActionMode object
|
||||
|
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.recent.updates
|
||||
|
||||
import android.os.Bundle
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.MangaChapter
|
||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
@ -134,6 +135,10 @@ class UpdatesPresenter(
|
||||
}
|
||||
}
|
||||
|
||||
fun startDownloadingNow(chapter: Chapter) {
|
||||
downloadManager.startDownloadNow(chapter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark selected chapter as read
|
||||
*
|
||||
|
@ -1,6 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/start_download"
|
||||
android:title="@string/action_start_downloading_now" />
|
||||
|
||||
<item
|
||||
android:id="@+id/delete_download"
|
||||
android:title="@string/action_delete" />
|
||||
|
@ -120,6 +120,7 @@
|
||||
<string name="action_webview_back">Back</string>
|
||||
<string name="action_webview_forward">Forward</string>
|
||||
<string name="action_webview_refresh">Refresh</string>
|
||||
<string name="action_start_downloading_now">Start downloading now</string>
|
||||
|
||||
<!-- Operations -->
|
||||
<string name="loading">Loading…</string>
|
||||
|
Loading…
Reference in New Issue
Block a user