Fix appending saved chapters
This commit is contained in:
@@ -15,7 +15,7 @@ android {
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 29
|
||||
versionCode gitCommits
|
||||
versionName '0.1'
|
||||
versionName '0.1.1'
|
||||
|
||||
buildConfigField 'String', 'GIT_BRANCH', "\"${gitBranch}\""
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ class MangaIndex(source: String?) {
|
||||
|
||||
private val json: JSONObject = source?.let(::JSONObject) ?: JSONObject()
|
||||
|
||||
fun setMangaInfo(manga: Manga) {
|
||||
fun setMangaInfo(manga: Manga, append: Boolean) {
|
||||
json.put("id", manga.id)
|
||||
json.put("title", manga.title)
|
||||
json.put("title_alt", manga.altTitle)
|
||||
@@ -32,7 +32,9 @@ class MangaIndex(source: String?) {
|
||||
a.put(jo)
|
||||
}
|
||||
})
|
||||
json.put("chapters", JSONObject())
|
||||
if (!append || !json.has("chapters")) {
|
||||
json.put("chapters", JSONObject())
|
||||
}
|
||||
json.put("app_id", BuildConfig.APPLICATION_ID)
|
||||
json.put("app_version", BuildConfig.VERSION_CODE)
|
||||
}
|
||||
|
||||
@@ -17,11 +17,12 @@ class MangaZip(val file: File) {
|
||||
private val dir = file.parentFile?.sub(file.name + ".tmp")?.takeIf { it.mkdir() }
|
||||
?: throw RuntimeException("Cannot create temporary directory")
|
||||
|
||||
private val index = MangaIndex(dir.sub(INDEX_ENTRY).takeIfReadable()?.readText())
|
||||
private var index = MangaIndex(null)
|
||||
|
||||
fun prepare(manga: Manga) {
|
||||
extract()
|
||||
index.setMangaInfo(manga)
|
||||
index = MangaIndex(dir.sub(INDEX_ENTRY).takeIfReadable()?.readText())
|
||||
index.setMangaInfo(manga, append = true)
|
||||
}
|
||||
|
||||
fun cleanup() {
|
||||
|
||||
@@ -3,7 +3,10 @@ package org.koitharu.kotatsu.ui.download
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.ConnectivityManager
|
||||
import android.os.PowerManager
|
||||
import android.os.WorkSource
|
||||
import android.webkit.MimeTypeMap
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.ContextCompat
|
||||
import coil.Coil
|
||||
import coil.api.get
|
||||
@@ -27,11 +30,13 @@ import org.koitharu.kotatsu.utils.ext.retryUntilSuccess
|
||||
import org.koitharu.kotatsu.utils.ext.safe
|
||||
import org.koitharu.kotatsu.utils.ext.sub
|
||||
import java.io.File
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.math.absoluteValue
|
||||
|
||||
class DownloadService : BaseService() {
|
||||
|
||||
private lateinit var notification: DownloadNotification
|
||||
private lateinit var wakeLock: PowerManager.WakeLock
|
||||
|
||||
private val okHttp by inject<OkHttpClient>()
|
||||
private val cache by inject<PagesCache>()
|
||||
@@ -41,6 +46,8 @@ class DownloadService : BaseService() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
notification = DownloadNotification(this)
|
||||
wakeLock = (getSystemService(Context.POWER_SERVICE) as PowerManager)
|
||||
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "kotatsu:downloading")
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
@@ -50,6 +57,7 @@ class DownloadService : BaseService() {
|
||||
val chapters = intent.getLongArrayExtra(EXTRA_CHAPTERS_IDS)?.toSet()
|
||||
if (manga != null) {
|
||||
jobs[startId] = downloadManga(manga, chapters, startId)
|
||||
Toast.makeText(this, R.string.manga_downloading_, Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
stopSelf(startId)
|
||||
}
|
||||
@@ -67,6 +75,7 @@ class DownloadService : BaseService() {
|
||||
private fun downloadManga(manga: Manga, chaptersIds: Set<Long>?, startId: Int): Job {
|
||||
return launch(Dispatchers.IO) {
|
||||
mutex.lock()
|
||||
wakeLock.acquire(TimeUnit.MINUTES.toMillis(20))
|
||||
withContext(Dispatchers.Main) {
|
||||
notification.fillFrom(manga)
|
||||
notification.setCancelId(startId)
|
||||
@@ -154,6 +163,7 @@ class DownloadService : BaseService() {
|
||||
notification.dismiss()
|
||||
stopSelf(startId)
|
||||
}
|
||||
wakeLock.release()
|
||||
mutex.unlock()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user