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