fix: manga opening

This commit is contained in:
rebel onion 2025-01-04 04:49:49 -06:00
parent 1bb5f4d0ab
commit 986d0fa4a8
11 changed files with 94 additions and 71 deletions

View file

@ -60,7 +60,7 @@ class DownloadsManager(private val context: Context) {
onFinished: () -> Unit
) {
removeDownloadCompat(context, downloadedType, toast)
downloadsList.remove(downloadedType)
downloadsList.removeAll { it.titleName == downloadedType.titleName && it.chapterName == downloadedType.chapterName }
CoroutineScope(Dispatchers.IO).launch {
removeDirectory(downloadedType, toast)
withContext(Dispatchers.Main) {
@ -234,7 +234,7 @@ class DownloadsManager(private val context: Context) {
val directory =
baseDirectory?.findFolder(downloadedType.titleName)
?.findFolder(downloadedType.chapterName)
downloadsList.remove(downloadedType)
downloadsList.removeAll { it.titleName == downloadedType.titleName && it.chapterName == downloadedType.chapterName }
// Check if the directory exists and delete it recursively
if (directory?.exists() == true) {
val deleted = directory.deleteRecursively(context, false)
@ -401,10 +401,13 @@ data class DownloadedType(
@Deprecated("use pTitle instead")
private val title: String? = null,
@Deprecated("use pChapter instead")
private val chapter: String? = null
private val chapter: String? = null,
val scanlator: String = "Unknown"
) : Serializable {
val titleName: String
get() = title ?: pTitle.findValidName()
val chapterName: String
get() = chapter ?: pChapter.findValidName()
val uniqueName: String
get() = "$chapterName-${scanlator}"
}

View file

@ -243,7 +243,7 @@ class MangaDownloaderService : Service() {
builder.setProgress(task.imageData.size, farthest, false)
broadcastDownloadProgress(
task.chapter,
task.uniqueName,
farthest * 100 / task.imageData.size
)
if (notifi) {
@ -270,17 +270,18 @@ class MangaDownloaderService : Service() {
DownloadedType(
task.title,
task.chapter,
MediaType.MANGA
MediaType.MANGA,
scanlator = task.scanlator,
)
)
broadcastDownloadFinished(task.chapter)
broadcastDownloadFinished(task.uniqueName)
snackString("${task.title} - ${task.chapter} Download finished")
}
} catch (e: Exception) {
Logger.log("Exception while downloading file: ${e.message}")
snackString("Exception while downloading file: ${e.message}")
Injekt.get<CrashlyticsInterface>().logException(e)
broadcastDownloadFailed(task.chapter)
broadcastDownloadFailed(task.uniqueName)
}
}
@ -423,11 +424,15 @@ class MangaDownloaderService : Service() {
data class DownloadTask(
val title: String,
val chapter: String,
val scanlator: String,
val imageData: List<ImageData>,
val sourceMedia: Media? = null,
val retries: Int = 2,
val simultaneousDownloads: Int = 2,
)
) {
val uniqueName: String
get() = "$chapter-$scanlator"
}
companion object {
private const val NOTIFICATION_ID = 1103