DownloadProvider: Only provide necessary info and not whole chapter/manga class (#7411)
(cherry picked from commit e1525a5125f83fb419d5e5f05834cffcbcd7fa07) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt # app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt
This commit is contained in:
parent
299ac1ca2d
commit
8bf3426afd
@ -97,7 +97,7 @@ class SyncChaptersWithSource(
|
|||||||
toAdd.add(toAddChapter)
|
toAdd.add(toAddChapter)
|
||||||
} else {
|
} else {
|
||||||
if (shouldUpdateDbChapter.await(dbChapter, chapter)) {
|
if (shouldUpdateDbChapter.await(dbChapter, chapter)) {
|
||||||
if (dbChapter.name != chapter.name && downloadManager.isChapterDownloaded(dbChapter.toDbChapter(), manga.toDbManga())) {
|
if (dbChapter.name != chapter.name && downloadManager.isChapterDownloaded(dbChapter.name, dbChapter.scanlator, /* SY --> */ manga.ogTitle /* SY <-- */, manga.source)) {
|
||||||
downloadManager.renameChapter(source, manga.toDbManga(), dbChapter.toDbChapter(), chapter.toDbChapter())
|
downloadManager.renameChapter(source, manga.toDbManga(), dbChapter.toDbChapter(), chapter.toDbChapter())
|
||||||
}
|
}
|
||||||
var toChangeChapter = dbChapter.copy(
|
var toChangeChapter = dbChapter.copy(
|
||||||
|
@ -65,23 +65,31 @@ class DownloadCache(
|
|||||||
/**
|
/**
|
||||||
* Returns true if the chapter is downloaded.
|
* Returns true if the chapter is downloaded.
|
||||||
*
|
*
|
||||||
* @param chapter the chapter to check.
|
* @param chapterName the name of the chapter to query.
|
||||||
* @param manga the manga of the chapter.
|
* @param chapterScanlator scanlator of the chapter to query
|
||||||
|
* @param mangaTitle the title of the manga to query.
|
||||||
|
* @param sourceId the id of the source of the chapter.
|
||||||
* @param skipCache whether to skip the directory cache and check in the filesystem.
|
* @param skipCache whether to skip the directory cache and check in the filesystem.
|
||||||
*/
|
*/
|
||||||
fun isChapterDownloaded(chapter: Chapter, manga: Manga, skipCache: Boolean): Boolean {
|
fun isChapterDownloaded(
|
||||||
|
chapterName: String,
|
||||||
|
chapterScanlator: String?,
|
||||||
|
mangaTitle: String,
|
||||||
|
sourceId: Long,
|
||||||
|
skipCache: Boolean,
|
||||||
|
): Boolean {
|
||||||
if (skipCache) {
|
if (skipCache) {
|
||||||
val source = sourceManager.getOrStub(manga.source)
|
val source = sourceManager.getOrStub(sourceId)
|
||||||
return provider.findChapterDir(chapter, manga, source) != null
|
return provider.findChapterDir(chapterName, chapterScanlator, mangaTitle, source) != null
|
||||||
}
|
}
|
||||||
|
|
||||||
checkRenew()
|
checkRenew()
|
||||||
|
|
||||||
val sourceDir = rootDir.files[manga.source]
|
val sourceDir = rootDir.files[sourceId]
|
||||||
if (sourceDir != null) {
|
if (sourceDir != null) {
|
||||||
val mangaDir = sourceDir.files[provider.getMangaDirName(manga)]
|
val mangaDir = sourceDir.files[provider.getMangaDirName(mangaTitle)]
|
||||||
if (mangaDir != null) {
|
if (mangaDir != null) {
|
||||||
return provider.getValidChapterDirNames(chapter).any { it in mangaDir.files }
|
return provider.getValidChapterDirNames(chapterName, chapterScanlator).any { it in mangaDir.files }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@ -97,7 +105,7 @@ class DownloadCache(
|
|||||||
|
|
||||||
val sourceDir = rootDir.files[manga.source]
|
val sourceDir = rootDir.files[manga.source]
|
||||||
if (sourceDir != null) {
|
if (sourceDir != null) {
|
||||||
val mangaDir = sourceDir.files[provider.getMangaDirName(manga)]
|
val mangaDir = sourceDir.files[provider.getMangaDirName(/* SY --> */ manga.originalTitle /* SY <-- */)]
|
||||||
if (mangaDir != null) {
|
if (mangaDir != null) {
|
||||||
return mangaDir.files
|
return mangaDir.files
|
||||||
.filter { !it.endsWith(Downloader.TMP_DIR_SUFFIX) }
|
.filter { !it.endsWith(Downloader.TMP_DIR_SUFFIX) }
|
||||||
@ -176,7 +184,7 @@ class DownloadCache(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve the cached manga directory or cache a new one
|
// Retrieve the cached manga directory or cache a new one
|
||||||
val mangaDirName = provider.getMangaDirName(manga)
|
val mangaDirName = provider.getMangaDirName(/* SY --> */ manga.originalTitle /* SY <-- */)
|
||||||
var mangaDir = sourceDir.files[mangaDirName]
|
var mangaDir = sourceDir.files[mangaDirName]
|
||||||
if (mangaDir == null) {
|
if (mangaDir == null) {
|
||||||
mangaDir = MangaDirectory(mangaUniFile)
|
mangaDir = MangaDirectory(mangaUniFile)
|
||||||
@ -196,8 +204,8 @@ class DownloadCache(
|
|||||||
@Synchronized
|
@Synchronized
|
||||||
fun removeChapter(chapter: Chapter, manga: Manga) {
|
fun removeChapter(chapter: Chapter, manga: Manga) {
|
||||||
val sourceDir = rootDir.files[manga.source] ?: return
|
val sourceDir = rootDir.files[manga.source] ?: return
|
||||||
val mangaDir = sourceDir.files[provider.getMangaDirName(manga)] ?: return
|
val mangaDir = sourceDir.files[provider.getMangaDirName(/* SY --> */ manga.originalTitle /* SY <-- */)] ?: return
|
||||||
provider.getValidChapterDirNames(chapter).forEach {
|
provider.getValidChapterDirNames(chapter.name, chapter.scanlator).forEach {
|
||||||
if (it in mangaDir.files) {
|
if (it in mangaDir.files) {
|
||||||
mangaDir.files -= it
|
mangaDir.files -= it
|
||||||
}
|
}
|
||||||
@ -207,7 +215,7 @@ class DownloadCache(
|
|||||||
// SY -->
|
// SY -->
|
||||||
fun removeFolders(folders: List<String>, manga: Manga) {
|
fun removeFolders(folders: List<String>, manga: Manga) {
|
||||||
val sourceDir = rootDir.files[manga.source] ?: return
|
val sourceDir = rootDir.files[manga.source] ?: return
|
||||||
val mangaDir = sourceDir.files[provider.getMangaDirName(manga)] ?: return
|
val mangaDir = sourceDir.files[provider.getMangaDirName(manga.originalTitle)] ?: return
|
||||||
folders.forEach { chapter ->
|
folders.forEach { chapter ->
|
||||||
if (chapter in mangaDir.files) {
|
if (chapter in mangaDir.files) {
|
||||||
mangaDir.files -= chapter
|
mangaDir.files -= chapter
|
||||||
@ -226,9 +234,9 @@ class DownloadCache(
|
|||||||
@Synchronized
|
@Synchronized
|
||||||
fun removeChapters(chapters: List<Chapter>, manga: Manga) {
|
fun removeChapters(chapters: List<Chapter>, manga: Manga) {
|
||||||
val sourceDir = rootDir.files[manga.source] ?: return
|
val sourceDir = rootDir.files[manga.source] ?: return
|
||||||
val mangaDir = sourceDir.files[provider.getMangaDirName(manga)] ?: return
|
val mangaDir = sourceDir.files[provider.getMangaDirName(/* SY --> */ manga.originalTitle /* SY <-- */)] ?: return
|
||||||
chapters.forEach { chapter ->
|
chapters.forEach { chapter ->
|
||||||
provider.getValidChapterDirNames(chapter).forEach {
|
provider.getValidChapterDirNames(chapter.name, chapter.scanlator).forEach {
|
||||||
if (it in mangaDir.files) {
|
if (it in mangaDir.files) {
|
||||||
mangaDir.files -= it
|
mangaDir.files -= it
|
||||||
}
|
}
|
||||||
@ -244,7 +252,7 @@ class DownloadCache(
|
|||||||
@Synchronized
|
@Synchronized
|
||||||
fun removeManga(manga: Manga) {
|
fun removeManga(manga: Manga) {
|
||||||
val sourceDir = rootDir.files[manga.source] ?: return
|
val sourceDir = rootDir.files[manga.source] ?: return
|
||||||
val mangaDirName = provider.getMangaDirName(manga)
|
val mangaDirName = provider.getMangaDirName(/* SY --> */ manga.originalTitle /* SY <-- */)
|
||||||
if (mangaDirName in sourceDir.files) {
|
if (mangaDirName in sourceDir.files) {
|
||||||
sourceDir.files -= mangaDirName
|
sourceDir.files -= mangaDirName
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ class DownloadManager(
|
|||||||
* @return an observable containing the list of pages from the chapter.
|
* @return an observable containing the list of pages from the chapter.
|
||||||
*/
|
*/
|
||||||
fun buildPageList(source: Source, manga: Manga, chapter: Chapter): Observable<List<Page>> {
|
fun buildPageList(source: Source, manga: Manga, chapter: Chapter): Observable<List<Page>> {
|
||||||
return buildPageList(provider.findChapterDir(chapter, manga, source))
|
return buildPageList(provider.findChapterDir(chapter.name, chapter.scanlator, /* SY --> */ manga.originalTitle /* SY <-- */, source))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -193,12 +193,20 @@ class DownloadManager(
|
|||||||
/**
|
/**
|
||||||
* Returns true if the chapter is downloaded.
|
* Returns true if the chapter is downloaded.
|
||||||
*
|
*
|
||||||
* @param chapter the chapter to check.
|
* @param chapterName the name of the chapter to query.
|
||||||
* @param manga the manga of the chapter.
|
* @param chapterScanlator scanlator of the chapter to query
|
||||||
|
* @param mangaTitle the title of the manga to query.
|
||||||
|
* @param sourceId the id of the source of the chapter.
|
||||||
* @param skipCache whether to skip the directory cache and check in the filesystem.
|
* @param skipCache whether to skip the directory cache and check in the filesystem.
|
||||||
*/
|
*/
|
||||||
fun isChapterDownloaded(chapter: Chapter, manga: Manga, skipCache: Boolean = false): Boolean {
|
fun isChapterDownloaded(
|
||||||
return cache.isChapterDownloaded(chapter, manga, skipCache)
|
chapterName: String,
|
||||||
|
chapterScanlator: String?,
|
||||||
|
mangaTitle: String,
|
||||||
|
sourceId: Long,
|
||||||
|
skipCache: Boolean = false,
|
||||||
|
): Boolean {
|
||||||
|
return cache.isChapterDownloaded(chapterName, chapterScanlator, mangaTitle, sourceId, skipCache)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -304,7 +312,7 @@ class DownloadManager(
|
|||||||
var cleaned = 0
|
var cleaned = 0
|
||||||
|
|
||||||
if (removeNonFavorite && !manga.favorite) {
|
if (removeNonFavorite && !manga.favorite) {
|
||||||
val mangaFolder = provider.getMangaDir(manga, source)
|
val mangaFolder = provider.getMangaDir(manga.originalTitle, source)
|
||||||
cleaned += 1 + mangaFolder.listFiles().orEmpty().size
|
cleaned += 1 + mangaFolder.listFiles().orEmpty().size
|
||||||
mangaFolder.delete()
|
mangaFolder.delete()
|
||||||
cache.removeManga(manga)
|
cache.removeManga(manga)
|
||||||
@ -325,12 +333,12 @@ class DownloadManager(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cache.getDownloadCount(manga) == 0) {
|
if (cache.getDownloadCount(manga) == 0) {
|
||||||
val mangaFolder = provider.getMangaDir(manga, source)
|
val mangaFolder = provider.getMangaDir(manga.originalTitle, source)
|
||||||
if (!mangaFolder.listFiles().isNullOrEmpty()) {
|
if (!mangaFolder.listFiles().isNullOrEmpty()) {
|
||||||
mangaFolder.delete()
|
mangaFolder.delete()
|
||||||
cache.removeManga(manga)
|
cache.removeManga(manga)
|
||||||
} else {
|
} else {
|
||||||
xLogE("Cache and download folder doesn't match for " + manga.title)
|
xLogE("Cache and download folder doesn't match for " + manga.originalTitle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cleaned
|
return cleaned
|
||||||
@ -346,7 +354,7 @@ class DownloadManager(
|
|||||||
fun deleteManga(manga: Manga, source: Source) {
|
fun deleteManga(manga: Manga, source: Source) {
|
||||||
launchIO {
|
launchIO {
|
||||||
downloader.queue.remove(manga)
|
downloader.queue.remove(manga)
|
||||||
provider.findMangaDir(manga, source)?.delete()
|
provider.findMangaDir(/* SY --> */ manga.originalTitle /* SY <-- */, source)?.delete()
|
||||||
cache.removeManga(manga)
|
cache.removeManga(manga)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -381,15 +389,15 @@ class DownloadManager(
|
|||||||
* @param newChapter the target chapter with the new name.
|
* @param newChapter the target chapter with the new name.
|
||||||
*/
|
*/
|
||||||
fun renameChapter(source: Source, manga: Manga, oldChapter: Chapter, newChapter: Chapter) {
|
fun renameChapter(source: Source, manga: Manga, oldChapter: Chapter, newChapter: Chapter) {
|
||||||
val oldNames = provider.getValidChapterDirNames(oldChapter)
|
val oldNames = provider.getValidChapterDirNames(oldChapter.name, oldChapter.scanlator)
|
||||||
val mangaDir = provider.getMangaDir(manga, source)
|
val mangaDir = provider.getMangaDir(/* SY --> */ manga.originalTitle /* SY <-- */, source)
|
||||||
|
|
||||||
// Assume there's only 1 version of the chapter name formats present
|
// Assume there's only 1 version of the chapter name formats present
|
||||||
val oldDownload = oldNames.asSequence()
|
val oldDownload = oldNames.asSequence()
|
||||||
.mapNotNull { mangaDir.findFile(it) }
|
.mapNotNull { mangaDir.findFile(it) }
|
||||||
.firstOrNull() ?: return
|
.firstOrNull() ?: return
|
||||||
|
|
||||||
var newName = provider.getChapterDirName(newChapter)
|
var newName = provider.getChapterDirName(newChapter.name, newChapter.scanlator)
|
||||||
if (oldDownload.isFile && oldDownload.name?.endsWith(".cbz") == true) {
|
if (oldDownload.isFile && oldDownload.name?.endsWith(".cbz") == true) {
|
||||||
newName += ".cbz"
|
newName += ".cbz"
|
||||||
}
|
}
|
||||||
|
@ -46,14 +46,14 @@ class DownloadProvider(private val context: Context) {
|
|||||||
/**
|
/**
|
||||||
* Returns the download directory for a manga. For internal use only.
|
* Returns the download directory for a manga. For internal use only.
|
||||||
*
|
*
|
||||||
* @param manga the manga to query.
|
* @param mangaTitle the title of the manga to query.
|
||||||
* @param source the source of the manga.
|
* @param source the source of the manga.
|
||||||
*/
|
*/
|
||||||
internal fun getMangaDir(manga: Manga, source: Source): UniFile {
|
internal fun getMangaDir(mangaTitle: String, source: Source): UniFile {
|
||||||
try {
|
try {
|
||||||
return downloadsDir
|
return downloadsDir
|
||||||
.createDirectory(getSourceDirName(source))
|
.createDirectory(getSourceDirName(source))
|
||||||
.createDirectory(getMangaDirName(manga))
|
.createDirectory(getMangaDirName(mangaTitle))
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
logcat(LogPriority.ERROR, e) { "Invalid download directory" }
|
logcat(LogPriority.ERROR, e) { "Invalid download directory" }
|
||||||
throw Exception(context.getString(R.string.invalid_download_dir))
|
throw Exception(context.getString(R.string.invalid_download_dir))
|
||||||
@ -72,24 +72,25 @@ class DownloadProvider(private val context: Context) {
|
|||||||
/**
|
/**
|
||||||
* Returns the download directory for a manga if it exists.
|
* Returns the download directory for a manga if it exists.
|
||||||
*
|
*
|
||||||
* @param manga the manga to query.
|
* @param mangaTitle the title of the manga to query.
|
||||||
* @param source the source of the manga.
|
* @param source the source of the manga.
|
||||||
*/
|
*/
|
||||||
fun findMangaDir(manga: Manga, source: Source): UniFile? {
|
fun findMangaDir(mangaTitle: String, source: Source): UniFile? {
|
||||||
val sourceDir = findSourceDir(source)
|
val sourceDir = findSourceDir(source)
|
||||||
return sourceDir?.findFile(getMangaDirName(manga), true)
|
return sourceDir?.findFile(getMangaDirName(mangaTitle), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the download directory for a chapter if it exists.
|
* Returns the download directory for a chapter if it exists.
|
||||||
*
|
*
|
||||||
* @param chapter the chapter to query.
|
* @param chapterName the name of the chapter to query.
|
||||||
* @param manga the manga of the chapter.
|
* @param chapterScanlator scanlator of the chapter to query
|
||||||
|
* @param mangaTitle the title of the manga to query.
|
||||||
* @param source the source of the chapter.
|
* @param source the source of the chapter.
|
||||||
*/
|
*/
|
||||||
fun findChapterDir(chapter: Chapter, manga: Manga, source: Source): UniFile? {
|
fun findChapterDir(chapterName: String, chapterScanlator: String?, mangaTitle: String, source: Source): UniFile? {
|
||||||
val mangaDir = findMangaDir(manga, source)
|
val mangaDir = findMangaDir(mangaTitle, source)
|
||||||
return getValidChapterDirNames(chapter).asSequence()
|
return getValidChapterDirNames(chapterName, chapterScanlator).asSequence()
|
||||||
.mapNotNull { mangaDir?.findFile(it, true) }
|
.mapNotNull { mangaDir?.findFile(it, true) }
|
||||||
.firstOrNull()
|
.firstOrNull()
|
||||||
}
|
}
|
||||||
@ -102,9 +103,9 @@ class DownloadProvider(private val context: Context) {
|
|||||||
* @param source the source of the chapter.
|
* @param source the source of the chapter.
|
||||||
*/
|
*/
|
||||||
fun findChapterDirs(chapters: List<Chapter>, manga: Manga, source: Source): List<UniFile> {
|
fun findChapterDirs(chapters: List<Chapter>, manga: Manga, source: Source): List<UniFile> {
|
||||||
val mangaDir = findMangaDir(manga, source) ?: return emptyList()
|
val mangaDir = findMangaDir(/* SY --> */ manga.originalTitle /* SY <-- */, source) ?: return emptyList()
|
||||||
return chapters.mapNotNull { chapter ->
|
return chapters.mapNotNull { chapter ->
|
||||||
getValidChapterDirNames(chapter).asSequence()
|
getValidChapterDirNames(chapter.name, chapter.scanlator).asSequence()
|
||||||
.mapNotNull { mangaDir.findFile(it) }
|
.mapNotNull { mangaDir.findFile(it) }
|
||||||
.firstOrNull()
|
.firstOrNull()
|
||||||
}
|
}
|
||||||
@ -123,10 +124,10 @@ class DownloadProvider(private val context: Context) {
|
|||||||
manga: Manga,
|
manga: Manga,
|
||||||
source: Source,
|
source: Source,
|
||||||
): List<UniFile> {
|
): List<UniFile> {
|
||||||
val mangaDir = findMangaDir(manga, source) ?: return emptyList()
|
val mangaDir = findMangaDir(manga.originalTitle, source) ?: return emptyList()
|
||||||
return mangaDir.listFiles().orEmpty().asList().filter {
|
return mangaDir.listFiles().orEmpty().asList().filter {
|
||||||
chapters.find { chp ->
|
chapters.find { chp ->
|
||||||
getValidChapterDirNames(chp).any { dir ->
|
getValidChapterDirNames(chp.name, chp.scanlator).any { dir ->
|
||||||
mangaDir.findFile(dir) != null
|
mangaDir.findFile(dir) != null
|
||||||
}
|
}
|
||||||
} == null || it.name?.endsWith(Downloader.TMP_DIR_SUFFIX) == true
|
} == null || it.name?.endsWith(Downloader.TMP_DIR_SUFFIX) == true
|
||||||
@ -146,24 +147,23 @@ class DownloadProvider(private val context: Context) {
|
|||||||
/**
|
/**
|
||||||
* Returns the download directory name for a manga.
|
* Returns the download directory name for a manga.
|
||||||
*
|
*
|
||||||
* @param manga the manga to query.
|
* @param mangaTitle the title of the manga to query.
|
||||||
*/
|
*/
|
||||||
fun getMangaDirName(manga: Manga): String {
|
fun getMangaDirName(mangaTitle: String): String {
|
||||||
// SY -->
|
return DiskUtil.buildValidFilename(mangaTitle)
|
||||||
return DiskUtil.buildValidFilename(manga.originalTitle)
|
|
||||||
// SY <--
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the chapter directory name for a chapter.
|
* Returns the chapter directory name for a chapter.
|
||||||
*
|
*
|
||||||
* @param chapter the chapter to query.
|
* @param chapterName the name of the chapter to query.
|
||||||
|
* @param chapterScanlator scanlator of the chapter to query
|
||||||
*/
|
*/
|
||||||
fun getChapterDirName(chapter: Chapter): String {
|
fun getChapterDirName(chapterName: String, chapterScanlator: String?): String {
|
||||||
return DiskUtil.buildValidFilename(
|
return DiskUtil.buildValidFilename(
|
||||||
when {
|
when {
|
||||||
chapter.scanlator != null -> "${chapter.scanlator}_${chapter.name}"
|
chapterScanlator != null -> "${chapterScanlator}_$chapterName"
|
||||||
else -> chapter.name
|
else -> chapterName
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -171,19 +171,20 @@ class DownloadProvider(private val context: Context) {
|
|||||||
/**
|
/**
|
||||||
* Returns valid downloaded chapter directory names.
|
* Returns valid downloaded chapter directory names.
|
||||||
*
|
*
|
||||||
* @param chapter the chapter to query.
|
* @param chapterName the name of the chapter to query.
|
||||||
|
* @param chapterScanlator scanlator of the chapter to query
|
||||||
*/
|
*/
|
||||||
fun getValidChapterDirNames(chapter: Chapter): List<String> {
|
fun getValidChapterDirNames(chapterName: String, chapterScanlator: String?): List<String> {
|
||||||
val chapterName = getChapterDirName(chapter)
|
val chapterDirName = getChapterDirName(chapterName, chapterScanlator)
|
||||||
return listOf(
|
return listOf(
|
||||||
// Folder of images
|
// Folder of images
|
||||||
chapterName,
|
chapterDirName,
|
||||||
|
|
||||||
// Archived chapters
|
// Archived chapters
|
||||||
"$chapterName.cbz",
|
"$chapterDirName.cbz",
|
||||||
|
|
||||||
// Legacy chapter directory name used in v0.9.2 and before
|
// Legacy chapter directory name used in v0.9.2 and before
|
||||||
DiskUtil.buildValidFilename(chapter.name),
|
DiskUtil.buildValidFilename(chapterName),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -254,7 +254,7 @@ class Downloader(
|
|||||||
val chaptersWithoutDir = async {
|
val chaptersWithoutDir = async {
|
||||||
chapters
|
chapters
|
||||||
// Filter out those already downloaded.
|
// Filter out those already downloaded.
|
||||||
.filter { provider.findChapterDir(it, manga, source) == null }
|
.filter { provider.findChapterDir(it.name, it.scanlator, /* SY --> */ manga.originalTitle /* SY <-- */, source) == null }
|
||||||
// Add chapters to queue from the start.
|
// Add chapters to queue from the start.
|
||||||
.sortedByDescending { it.source_order }
|
.sortedByDescending { it.source_order }
|
||||||
}
|
}
|
||||||
@ -305,7 +305,7 @@ class Downloader(
|
|||||||
* @param download the chapter to be downloaded.
|
* @param download the chapter to be downloaded.
|
||||||
*/
|
*/
|
||||||
private fun downloadChapter(download: Download): Observable<Download> = Observable.defer {
|
private fun downloadChapter(download: Download): Observable<Download> = Observable.defer {
|
||||||
val mangaDir = provider.getMangaDir(download.manga, download.source)
|
val mangaDir = provider.getMangaDir(/* SY --> */ download.manga.originalTitle /* SY <-- */, download.source)
|
||||||
|
|
||||||
val availSpace = DiskUtil.getAvailableStorageSpace(mangaDir)
|
val availSpace = DiskUtil.getAvailableStorageSpace(mangaDir)
|
||||||
if (availSpace != -1L && availSpace < MIN_DISK_SPACE) {
|
if (availSpace != -1L && availSpace < MIN_DISK_SPACE) {
|
||||||
@ -314,7 +314,7 @@ class Downloader(
|
|||||||
return@defer Observable.just(download)
|
return@defer Observable.just(download)
|
||||||
}
|
}
|
||||||
|
|
||||||
val chapterDirname = provider.getChapterDirName(download.chapter)
|
val chapterDirname = provider.getChapterDirName(download.chapter.name, download.chapter.scanlator)
|
||||||
val tmpDir = mangaDir.createDirectory(chapterDirname + TMP_DIR_SUFFIX)
|
val tmpDir = mangaDir.createDirectory(chapterDirname + TMP_DIR_SUFFIX)
|
||||||
|
|
||||||
val pageListObservable = if (download.pages == null) {
|
val pageListObservable = if (download.pages == null) {
|
||||||
|
@ -474,6 +474,7 @@ class LibrarySettingsSheet(
|
|||||||
item.checked = !item.checked
|
item.checked = !item.checked
|
||||||
when (item) {
|
when (item) {
|
||||||
startReadingButton -> preferences.startReadingButton().set((item.checked))
|
startReadingButton -> preferences.startReadingButton().set((item.checked))
|
||||||
|
else -> Unit
|
||||||
}
|
}
|
||||||
adapter.notifyItemChanged(item)
|
adapter.notifyItemChanged(item)
|
||||||
}
|
}
|
||||||
|
@ -783,11 +783,14 @@ class MangaPresenter(
|
|||||||
private fun List<DomainChapter>.toChapterItems(manga: DomainManga, mergedData: MergedMangaData?): List<ChapterItem> {
|
private fun List<DomainChapter>.toChapterItems(manga: DomainManga, mergedData: MergedMangaData?): List<ChapterItem> {
|
||||||
return map { chapter ->
|
return map { chapter ->
|
||||||
val activeDownload = downloadManager.queue.find { chapter.id == it.chapter.id }
|
val activeDownload = downloadManager.queue.find { chapter.id == it.chapter.id }
|
||||||
|
val chapter = chapter.let { if (mergedData != null) it.toMergedDownloadedChapter() else it }
|
||||||
|
val manga = mergedData?.manga?.get(chapter.mangaId) ?: manga
|
||||||
val downloaded = downloadManager.isChapterDownloaded(
|
val downloaded = downloadManager.isChapterDownloaded(
|
||||||
// SY -->
|
// SY -->
|
||||||
chapter.let { if (mergedData != null) it.toMergedDownloadedChapter() else it }
|
chapter.name,
|
||||||
.toDbChapter(),
|
chapter.scanlator,
|
||||||
(mergedData?.manga?.get(chapter.mangaId) ?: manga).toDbManga(),
|
manga.ogTitle,
|
||||||
|
manga.source,
|
||||||
// SY <--
|
// SY <--
|
||||||
)
|
)
|
||||||
val downloadState = when {
|
val downloadState = when {
|
||||||
|
@ -163,8 +163,8 @@ class ReaderPresenter(
|
|||||||
preferences.skipFiltered() -> {
|
preferences.skipFiltered() -> {
|
||||||
(manga.readFilter == Manga.CHAPTER_SHOW_READ && !it.read) ||
|
(manga.readFilter == Manga.CHAPTER_SHOW_READ && !it.read) ||
|
||||||
(manga.readFilter == Manga.CHAPTER_SHOW_UNREAD && it.read) ||
|
(manga.readFilter == Manga.CHAPTER_SHOW_UNREAD && it.read) ||
|
||||||
(manga.downloadedFilter == Manga.CHAPTER_SHOW_DOWNLOADED && !downloadManager.isChapterDownloaded(it, manga)) ||
|
(manga.downloadedFilter == Manga.CHAPTER_SHOW_DOWNLOADED && !downloadManager.isChapterDownloaded(it.name, it.scanlator, /* SY --> */ manga.originalTitle /* SY <-- */, manga.source)) ||
|
||||||
(manga.downloadedFilter == Manga.CHAPTER_SHOW_NOT_DOWNLOADED && downloadManager.isChapterDownloaded(it, manga)) ||
|
(manga.downloadedFilter == Manga.CHAPTER_SHOW_NOT_DOWNLOADED && downloadManager.isChapterDownloaded(it.name, it.scanlator, /* SY --> */ manga.originalTitle /* SY <-- */, manga.source)) ||
|
||||||
(manga.bookmarkedFilter == Manga.CHAPTER_SHOW_BOOKMARKED && !it.bookmark) ||
|
(manga.bookmarkedFilter == Manga.CHAPTER_SHOW_BOOKMARKED && !it.bookmark) ||
|
||||||
// SY -->
|
// SY -->
|
||||||
(filteredScanlators != null && MdUtil.getScanlators(it.scanlator).none { group -> filteredScanlators.contains(group) })
|
(filteredScanlators != null && MdUtil.getScanlators(it.scanlator).none { group -> filteredScanlators.contains(group) })
|
||||||
@ -440,7 +440,8 @@ class ReaderPresenter(
|
|||||||
private fun preload(chapter: ReaderChapter) {
|
private fun preload(chapter: ReaderChapter) {
|
||||||
if (chapter.pageLoader is HttpPageLoader) {
|
if (chapter.pageLoader is HttpPageLoader) {
|
||||||
val manga = manga ?: return
|
val manga = manga ?: return
|
||||||
val isDownloaded = downloadManager.isChapterDownloaded(chapter.chapter, manga)
|
val dbChapter = chapter.chapter
|
||||||
|
val isDownloaded = downloadManager.isChapterDownloaded(dbChapter.name, dbChapter.scanlator, /* SY --> */ manga.originalTitle /* SY <-- */, manga.source)
|
||||||
if (isDownloaded) {
|
if (isDownloaded) {
|
||||||
chapter.state = ReaderChapter.State.Wait
|
chapter.state = ReaderChapter.State.Wait
|
||||||
}
|
}
|
||||||
|
@ -87,14 +87,15 @@ class ChapterLoader(
|
|||||||
* Returns the page loader to use for this [chapter].
|
* Returns the page loader to use for this [chapter].
|
||||||
*/
|
*/
|
||||||
private fun getPageLoader(chapter: ReaderChapter): PageLoader {
|
private fun getPageLoader(chapter: ReaderChapter): PageLoader {
|
||||||
val isDownloaded = downloadManager.isChapterDownloaded(chapter.chapter, manga, true)
|
val dbChapter = chapter.chapter
|
||||||
|
val isDownloaded = downloadManager.isChapterDownloaded(dbChapter.name, dbChapter.scanlator, /* SY --> */ manga.originalTitle /* SY <-- */, manga.source, skipCache = true)
|
||||||
return when {
|
return when {
|
||||||
// SY -->
|
// SY -->
|
||||||
source is MergedSource -> {
|
source is MergedSource -> {
|
||||||
val mangaReference = mergedReferences.firstOrNull { it.mangaId == chapter.chapter.manga_id } ?: error("Merge reference null")
|
val mangaReference = mergedReferences.firstOrNull { it.mangaId == chapter.chapter.manga_id } ?: error("Merge reference null")
|
||||||
val source = sourceManager.get(mangaReference.mangaSourceId) ?: error("Source ${mangaReference.mangaSourceId} was null")
|
val source = sourceManager.get(mangaReference.mangaSourceId) ?: error("Source ${mangaReference.mangaSourceId} was null")
|
||||||
val manga = mergedManga[chapter.chapter.manga_id] ?: error("Manga for merged chapter was null")
|
val manga = mergedManga[chapter.chapter.manga_id] ?: error("Manga for merged chapter was null")
|
||||||
val isMergedMangaDownloaded = downloadManager.isChapterDownloaded(chapter.chapter, manga, true)
|
val isMergedMangaDownloaded = downloadManager.isChapterDownloaded(chapter.chapter.name, chapter.chapter.scanlator, manga.originalTitle, manga.source, true)
|
||||||
when {
|
when {
|
||||||
isMergedMangaDownloaded -> DownloadPageLoader(chapter, manga, source, downloadManager)
|
isMergedMangaDownloaded -> DownloadPageLoader(chapter, manga, source, downloadManager)
|
||||||
source is HttpSource -> HttpPageLoader(chapter, source)
|
source is HttpSource -> HttpPageLoader(chapter, source)
|
||||||
|
@ -30,7 +30,8 @@ class DownloadPageLoader(
|
|||||||
* Returns an observable containing the pages found on this downloaded chapter.
|
* Returns an observable containing the pages found on this downloaded chapter.
|
||||||
*/
|
*/
|
||||||
override fun getPages(): Observable<List<ReaderPage>> {
|
override fun getPages(): Observable<List<ReaderPage>> {
|
||||||
val chapterPath = downloadManager.provider.findChapterDir(chapter.chapter, manga, source)
|
val dbChapter = chapter.chapter
|
||||||
|
val chapterPath = downloadManager.provider.findChapterDir(dbChapter.name, dbChapter.scanlator, /* SY --> */ manga.originalTitle /* SY <-- */, source)
|
||||||
return if (chapterPath?.isFile == true) {
|
return if (chapterPath?.isFile == true) {
|
||||||
getPagesFromArchive(chapterPath)
|
getPagesFromArchive(chapterPath)
|
||||||
} else {
|
} else {
|
||||||
|
@ -121,7 +121,7 @@ class UpdatesPresenter : BasePresenter<UpdatesController>() {
|
|||||||
val manga = item.manga
|
val manga = item.manga
|
||||||
val chapter = item.chapter
|
val chapter = item.chapter
|
||||||
|
|
||||||
if (downloadManager.isChapterDownloaded(chapter, manga)) {
|
if (downloadManager.isChapterDownloaded(chapter.name, chapter.scanlator, /* SY --> */ manga.originalTitle /* SY <-- */, manga.source)) {
|
||||||
item.status = Download.State.DOWNLOADED
|
item.status = Download.State.DOWNLOADED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user