More rename downloaded chapter tweaks
This commit is contained in:
parent
d7f3b399f4
commit
589464d723
@ -251,20 +251,17 @@ class DownloadManager(/* SY private */ val context: Context) {
|
|||||||
* @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 oldName = provider.getValidChapterDirNames(oldChapter)
|
val oldNames = provider.getValidChapterDirNames(oldChapter)
|
||||||
val newName = provider.getChapterDirName(newChapter)
|
val newName = provider.getChapterDirName(newChapter)
|
||||||
val mangaDir = provider.getMangaDir(manga, source)
|
val mangaDir = provider.getMangaDir(manga, source)
|
||||||
|
|
||||||
var oldFolder: UniFile? = null
|
// There should only be one folder with the chapter
|
||||||
val oldFolderName = oldName.find {
|
val oldFolder = oldNames.mapNotNull { mangaDir.findFile(it) }.firstOrNull()
|
||||||
oldFolder = mangaDir.findFile(it)
|
|
||||||
oldFolder != null
|
|
||||||
}
|
|
||||||
if (oldFolder?.renameTo(newName) == true) {
|
if (oldFolder?.renameTo(newName) == true) {
|
||||||
cache.removeChapter(oldChapter, manga)
|
cache.removeChapter(oldChapter, manga)
|
||||||
cache.addChapter(newName, mangaDir, manga)
|
cache.addChapter(newName, mangaDir, manga)
|
||||||
} else {
|
} else {
|
||||||
Timber.e("Could not rename downloaded chapter: %s.", oldFolderName)
|
Timber.e("Could not rename downloaded chapter: %s.", oldNames.joinToString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user