Title updates now rename downloads
Auto d/l now starts after metadata refresh
This commit is contained in:
parent
f3b96c430e
commit
86992a02d8
@ -1,6 +1,9 @@
|
|||||||
package eu.kanade.tachiyomi.data.database.models
|
package eu.kanade.tachiyomi.data.database.models
|
||||||
|
|
||||||
|
import eu.kanade.tachiyomi.data.download.DownloadProvider
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
|
import uy.kohesive.injekt.Injekt
|
||||||
|
import uy.kohesive.injekt.api.get
|
||||||
|
|
||||||
open class MangaImpl : Manga {
|
open class MangaImpl : Manga {
|
||||||
|
|
||||||
@ -37,13 +40,15 @@ open class MangaImpl : Manga {
|
|||||||
override var hide_title: Boolean = false
|
override var hide_title: Boolean = false
|
||||||
|
|
||||||
override fun copyFrom(other: SManga) {
|
override fun copyFrom(other: SManga) {
|
||||||
if (other is MangaImpl && (other as MangaImpl)::title.isInitialized && !other.title
|
if (other is MangaImpl && (other as MangaImpl)::title.isInitialized &&
|
||||||
.isBlank()) {
|
!other.title.isBlank() && other.title != originalTitle()) {
|
||||||
|
val oldTitle = originalTitle()
|
||||||
title = if (currentTitle() != originalTitle()) {
|
title = if (currentTitle() != originalTitle()) {
|
||||||
val customTitle = currentTitle()
|
val customTitle = currentTitle()
|
||||||
val trueTitle = other.title
|
val trueTitle = other.title
|
||||||
"${customTitle}${SManga.splitter}${trueTitle}"
|
"${customTitle}${SManga.splitter}${trueTitle}"
|
||||||
} else other.title
|
} else other.title
|
||||||
|
Injekt.get<DownloadProvider>().renameMangaFolder(oldTitle, title, source)
|
||||||
}
|
}
|
||||||
super.copyFrom(other)
|
super.copyFrom(other)
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
|||||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
import eu.kanade.tachiyomi.source.Source
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
|
import eu.kanade.tachiyomi.util.DiskUtil
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
@ -101,7 +102,9 @@ class DownloadCache(
|
|||||||
if (sourceDir != null) {
|
if (sourceDir != null) {
|
||||||
val mangaDir = sourceDir.files[provider.getMangaDirName(manga)]
|
val mangaDir = sourceDir.files[provider.getMangaDirName(manga)]
|
||||||
if (mangaDir != null) {
|
if (mangaDir != null) {
|
||||||
return mangaDir.files.size
|
return mangaDir.files
|
||||||
|
.filter { !it.endsWith(Downloader.TMP_DIR_SUFFIX) }
|
||||||
|
.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
@ -227,6 +230,20 @@ class DownloadCache(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun renameFolder(from: String, to: String, source: Long) {
|
||||||
|
val sourceDir = rootDir.files[source] ?: return
|
||||||
|
val list = sourceDir.files.toMutableMap()
|
||||||
|
val mangaFiles = sourceDir.files[DiskUtil.buildValidFilename(from)] ?: return
|
||||||
|
val newDir = MangaDirectory(
|
||||||
|
UniFile.fromUri(
|
||||||
|
context, Uri.parse(sourceDir.dir.filePath + "/" + DiskUtil.buildValidFilename(to))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
newDir.files = mangaFiles.files
|
||||||
|
list.remove(DiskUtil.buildValidFilename(from))
|
||||||
|
list[to] = newDir
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a manga that has been deleted from this cache.
|
* Removes a manga that has been deleted from this cache.
|
||||||
|
@ -132,6 +132,16 @@ class DownloadProvider(private val context: Context) {
|
|||||||
cache.renew()
|
cache.renew()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun renameMangaFolder(from: String, to: String, sourceId: Long) {
|
||||||
|
val sourceManager by injectLazy<SourceManager>()
|
||||||
|
val source = sourceManager.get(sourceId) ?: return
|
||||||
|
val sourceDir = findSourceDir(source)
|
||||||
|
val mangaDir = sourceDir?.findFile(DiskUtil.buildValidFilename(from))
|
||||||
|
mangaDir?.renameTo(to)
|
||||||
|
val cache = DownloadCache(context, this, sourceManager)
|
||||||
|
cache.renameFolder(from, to, sourceId)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of all files in manga directory
|
* Returns a list of all files in manga directory
|
||||||
*
|
*
|
||||||
|
@ -493,4 +493,8 @@ class Downloader(
|
|||||||
return queue.none { it.status <= Download.DOWNLOADING }
|
return queue.none { it.status <= Download.DOWNLOADING }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TMP_DIR_SUFFIX = "_tmp"
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -329,13 +329,20 @@ class LibraryUpdateService(
|
|||||||
.doOnCompleted {
|
.doOnCompleted {
|
||||||
if (newUpdates.isNotEmpty()) {
|
if (newUpdates.isNotEmpty()) {
|
||||||
showResultNotification(newUpdates)
|
showResultNotification(newUpdates)
|
||||||
if (downloadNew && hasDownloads) {
|
|
||||||
DownloadService.start(this)
|
|
||||||
}
|
|
||||||
if (preferences.refreshCoversToo().getOrDefault()) {
|
if (preferences.refreshCoversToo().getOrDefault()) {
|
||||||
updateDetails(newUpdates.map { it.first }).observeOn(Schedulers.io())
|
updateDetails(newUpdates.map { it.first }).observeOn(Schedulers.io())
|
||||||
|
.doOnCompleted {
|
||||||
|
cancelProgressNotification()
|
||||||
|
if (downloadNew && hasDownloads) {
|
||||||
|
DownloadService.start(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
.subscribeOn(Schedulers.io()).subscribe {}
|
.subscribeOn(Schedulers.io()).subscribe {}
|
||||||
}
|
}
|
||||||
|
else if (downloadNew && hasDownloads) {
|
||||||
|
DownloadService.start(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (failedUpdates.isNotEmpty()) {
|
if (failedUpdates.isNotEmpty()) {
|
||||||
@ -391,7 +398,6 @@ class LibraryUpdateService(
|
|||||||
fun updateDetails(mangaToUpdate: List<LibraryManga>): Observable<LibraryManga> {
|
fun updateDetails(mangaToUpdate: List<LibraryManga>): Observable<LibraryManga> {
|
||||||
// Initialize the variables holding the progress of the updates.
|
// Initialize the variables holding the progress of the updates.
|
||||||
val count = AtomicInteger(0)
|
val count = AtomicInteger(0)
|
||||||
val coverCache by injectLazy<CoverCache>()
|
|
||||||
|
|
||||||
// Emit each manga and update it sequentially.
|
// Emit each manga and update it sequentially.
|
||||||
return Observable.from(mangaToUpdate)
|
return Observable.from(mangaToUpdate)
|
||||||
@ -406,7 +412,6 @@ class LibraryUpdateService(
|
|||||||
.map { networkManga ->
|
.map { networkManga ->
|
||||||
manga.copyFrom(networkManga)
|
manga.copyFrom(networkManga)
|
||||||
db.insertManga(manga).executeAsBlocking()
|
db.insertManga(manga).executeAsBlocking()
|
||||||
coverCache.deleteFromCache(manga.thumbnail_url)
|
|
||||||
MangaImpl.setLastCoverFetch(manga.id!!, Date().time)
|
MangaImpl.setLastCoverFetch(manga.id!!, Date().time)
|
||||||
manga
|
manga
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,6 @@ class MangaInfoPresenter(
|
|||||||
manga.copyFrom(networkManga)
|
manga.copyFrom(networkManga)
|
||||||
manga.initialized = true
|
manga.initialized = true
|
||||||
db.insertManga(manga).executeAsBlocking()
|
db.insertManga(manga).executeAsBlocking()
|
||||||
coverCache.deleteFromCache(manga.thumbnail_url)
|
|
||||||
MangaImpl.setLastCoverFetch(manga.id!!, Date().time)
|
MangaImpl.setLastCoverFetch(manga.id!!, Date().time)
|
||||||
manga
|
manga
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user