From 3f0db60a999cb30ff249ae4cc6a720c2a49c319a Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 3 Sep 2023 10:02:04 -0400 Subject: [PATCH] Minor updates --- .../more/settings/screen/SettingsBackupScreen.kt | 2 +- .../java/eu/kanade/tachiyomi/data/backup/BackupManager.kt | 5 ++--- .../java/eu/kanade/tachiyomi/data/backup/models/Backup.kt | 4 +++- .../java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt | 8 ++++++-- .../kotlin/eu/kanade/tachiyomi/source/Source.kt | 6 ++++++ 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt index c790f80052..ad2a003802 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt @@ -108,7 +108,7 @@ object SettingsBackupScreen : SearchableSettings { showCreateDialog = false flag = it try { - chooseBackupDir.launch(Backup.getBackupFilename()) + chooseBackupDir.launch(Backup.getFilename()) } catch (e: ActivityNotFoundException) { flag = 0 context.toast(R.string.file_picker_error) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt index 35a9ea5987..67bb74e97a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt @@ -93,15 +93,14 @@ class BackupManager( // Delete older backups val numberOfBackups = backupPreferences.numberOfBackups().get() - val backupRegex = Regex("""tachiyomi_\d+-\d+-\d+_\d+-\d+.proto.gz""") - dir.listFiles { _, filename -> backupRegex.matches(filename) } + dir.listFiles { _, filename -> Backup.filenameRegex.matches(filename) } .orEmpty() .sortedByDescending { it.name } .drop(numberOfBackups - 1) .forEach { it.delete() } // Create new file to place backup - dir.createFile(Backup.getBackupFilename()) + dir.createFile(Backup.getFilename()) } else { UniFile.fromUri(context, uri) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/models/Backup.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/models/Backup.kt index 8a9de244d2..089e1f03cb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/models/Backup.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/models/Backup.kt @@ -16,7 +16,9 @@ data class Backup( ) { companion object { - fun getBackupFilename(): String { + val filenameRegex = """tachiyomi_\d+-\d+-\d+_\d+-\d+.proto.gz""".toRegex() + + fun getFilename(): String { val date = SimpleDateFormat("yyyy-MM-dd_HH-mm", Locale.getDefault()).format(Date()) return "tachiyomi_$date.proto.gz" } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt index 38583ee642..3f155e7f52 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt @@ -8,9 +8,11 @@ import eu.kanade.tachiyomi.util.storage.DiskUtil import eu.kanade.tachiyomi.util.storage.saveTo import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json +import logcat.LogPriority import okhttp3.Response import okio.buffer import okio.sink +import tachiyomi.core.util.system.logcat import tachiyomi.domain.chapter.model.Chapter import uy.kohesive.injekt.injectLazy import java.io.File @@ -97,6 +99,7 @@ class ChapterCache(private val context: Context) { editor.commit() editor.abortUnlessCommitted() } catch (e: Exception) { + logcat(LogPriority.WARN, e) { "Failed to put page list to cache" } // Ignore. } finally { editor?.abortUnlessCommitted() @@ -174,7 +177,7 @@ class ChapterCache(private val context: Context) { * @return status of deletion for the file. */ private fun removeFileFromCache(file: String): Boolean { - // Make sure we don't delete the journal file (keeps track of cache). + // Make sure we don't delete the journal file (keeps track of cache) if (file == "journal" || file.startsWith("journal.")) { return false } @@ -182,9 +185,10 @@ class ChapterCache(private val context: Context) { return try { // Remove the extension from the file to get the key of the cache val key = file.substringBeforeLast(".") - // Remove file from cache. + // Remove file from cache diskCache.remove(key) } catch (e: Exception) { + logcat(LogPriority.WARN, e) { "Failed to remove file from cache" } false } } diff --git a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/Source.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/Source.kt index 694dd1e8a0..f140eda74e 100644 --- a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/Source.kt +++ b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/Source.kt @@ -27,7 +27,9 @@ interface Source { /** * Get the updated details for a manga. * + * @since extensions-lib 1.4 * @param manga the manga to update. + * @return the updated manga. */ @Suppress("DEPRECATION") suspend fun getMangaDetails(manga: SManga): SManga { @@ -37,7 +39,9 @@ interface Source { /** * Get all the available chapters for a manga. * + * @since extensions-lib 1.4 * @param manga the manga to update. + * @return the chapters for the manga. */ @Suppress("DEPRECATION") suspend fun getChapterList(manga: SManga): List { @@ -48,7 +52,9 @@ interface Source { * Get the list of pages a chapter has. Pages should be returned * in the expected order; the index is ignored. * + * @since extensions-lib 1.4 * @param chapter the chapter. + * @return the pages for the chapter. */ @Suppress("DEPRECATION") suspend fun getPageList(chapter: SChapter): List {