Light novel support
This commit is contained in:
parent
32f918450a
commit
c7bc1ffe9e
39 changed files with 2537 additions and 91 deletions
|
@ -91,9 +91,9 @@ class MangaDownloaderService : Service() {
|
|||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
ServiceDataSingleton.downloadQueue.clear()
|
||||
MangaServiceDataSingleton.downloadQueue.clear()
|
||||
downloadJobs.clear()
|
||||
ServiceDataSingleton.isServiceRunning = false
|
||||
MangaServiceDataSingleton.isServiceRunning = false
|
||||
unregisterReceiver(cancelReceiver)
|
||||
}
|
||||
|
||||
|
@ -114,8 +114,8 @@ class MangaDownloaderService : Service() {
|
|||
|
||||
private fun processQueue() {
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
while (ServiceDataSingleton.downloadQueue.isNotEmpty()) {
|
||||
val task = ServiceDataSingleton.downloadQueue.poll()
|
||||
while (MangaServiceDataSingleton.downloadQueue.isNotEmpty()) {
|
||||
val task = MangaServiceDataSingleton.downloadQueue.poll()
|
||||
if (task != null) {
|
||||
val job = launch { download(task) }
|
||||
mutex.withLock {
|
||||
|
@ -127,7 +127,7 @@ class MangaDownloaderService : Service() {
|
|||
}
|
||||
updateNotification() // Update the notification after each task is completed
|
||||
}
|
||||
if (ServiceDataSingleton.downloadQueue.isEmpty()) {
|
||||
if (MangaServiceDataSingleton.downloadQueue.isEmpty()) {
|
||||
withContext(Dispatchers.Main) {
|
||||
stopSelf() // Stop the service when the queue is empty
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ class MangaDownloaderService : Service() {
|
|||
mutex.withLock {
|
||||
downloadJobs[chapter]?.cancel()
|
||||
downloadJobs.remove(chapter)
|
||||
ServiceDataSingleton.downloadQueue.removeAll { it.chapter == chapter }
|
||||
MangaServiceDataSingleton.downloadQueue.removeAll { it.chapter == chapter }
|
||||
updateNotification() // Update the notification after cancellation
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ class MangaDownloaderService : Service() {
|
|||
|
||||
private fun updateNotification() {
|
||||
// Update the notification to reflect the current state of the queue
|
||||
val pendingDownloads = ServiceDataSingleton.downloadQueue.size
|
||||
val pendingDownloads = MangaServiceDataSingleton.downloadQueue.size
|
||||
val text = if (pendingDownloads > 0) {
|
||||
"Pending downloads: $pendingDownloads"
|
||||
} else {
|
||||
|
@ -381,7 +381,7 @@ class MangaDownloaderService : Service() {
|
|||
}
|
||||
}
|
||||
|
||||
object ServiceDataSingleton {
|
||||
object MangaServiceDataSingleton {
|
||||
var imageData: List<ImageData> = listOf()
|
||||
var sourceMedia: Media? = null
|
||||
var downloadQueue: Queue<MangaDownloaderService.DownloadTask> = ConcurrentLinkedQueue()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue