From 83130f9bf964dfce512c77803f8b5bcfb90c8f08 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 31 Dec 2023 23:33:10 -0500 Subject: [PATCH] Try to show actual path in invalid location downloader notification Instead of the class/hashCode, which doesn't mean much to a user. --- .../more/settings/screen/SettingsDataScreen.kt | 3 ++- .../eu/kanade/tachiyomi/data/backup/BackupNotifier.kt | 3 ++- .../eu/kanade/tachiyomi/data/download/DownloadProvider.kt | 8 +++++++- .../main/java/tachiyomi/core/storage/UniFileExtensions.kt | 3 +++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt index fd2491ea91..9f0d5fc604 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt @@ -42,6 +42,7 @@ import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.persistentMapOf import logcat.LogPriority import tachiyomi.core.i18n.stringResource +import tachiyomi.core.storage.displayablePath import tachiyomi.core.util.lang.launchNonCancellable import tachiyomi.core.util.lang.withUIContext import tachiyomi.core.util.system.logcat @@ -111,7 +112,7 @@ object SettingsDataScreen : SearchableSettings { return remember(storageDir) { val file = UniFile.fromUri(context, storageDir.toUri()) - file?.filePath ?: file?.uri?.toString() + file?.displayablePath } ?: stringResource(MR.strings.invalid_location, storageDir) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupNotifier.kt index be914cf5b3..817f8a2220 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupNotifier.kt @@ -14,6 +14,7 @@ import eu.kanade.tachiyomi.util.system.notificationBuilder import eu.kanade.tachiyomi.util.system.notify import tachiyomi.core.i18n.pluralStringResource import tachiyomi.core.i18n.stringResource +import tachiyomi.core.storage.displayablePath import tachiyomi.i18n.MR import uy.kohesive.injekt.injectLazy import java.io.File @@ -73,7 +74,7 @@ class BackupNotifier(private val context: Context) { with(completeNotificationBuilder) { setContentTitle(context.stringResource(MR.strings.backup_created)) - setContentText(file.filePath ?: file.name) + setContentText(file.displayablePath) clearActions() addAction( diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt index e1339f9867..f6d8e064b2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt @@ -6,6 +6,7 @@ import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.util.storage.DiskUtil import logcat.LogPriority import tachiyomi.core.i18n.stringResource +import tachiyomi.core.storage.displayablePath import tachiyomi.core.util.system.logcat import tachiyomi.domain.chapter.model.Chapter import tachiyomi.domain.manga.model.Manga @@ -41,7 +42,12 @@ class DownloadProvider( .createDirectory(getMangaDirName(mangaTitle))!! } catch (e: Throwable) { logcat(LogPriority.ERROR, e) { "Invalid download directory" } - throw Exception(context.stringResource(MR.strings.invalid_location, downloadsDir ?: "")) + throw Exception( + context.stringResource( + MR.strings.invalid_location, + downloadsDir?.displayablePath ?: "", + ), + ) } } diff --git a/core/src/main/java/tachiyomi/core/storage/UniFileExtensions.kt b/core/src/main/java/tachiyomi/core/storage/UniFileExtensions.kt index 65846ff6ed..8e2bf43fcf 100644 --- a/core/src/main/java/tachiyomi/core/storage/UniFileExtensions.kt +++ b/core/src/main/java/tachiyomi/core/storage/UniFileExtensions.kt @@ -13,6 +13,9 @@ val UniFile.extension: String? val UniFile.nameWithoutExtension: String? get() = name?.substringBeforeLast('.') +val UniFile.displayablePath: String + get() = filePath ?: uri.toString() + fun UniFile.toTempFile(context: Context): File { val inputStream = context.contentResolver.openInputStream(uri)!! val tempFile = File.createTempFile(