From ce419d0123275326c3792f503289fc3084e7c46d Mon Sep 17 00:00:00 2001 From: lukstbit <52494258+lukstbit@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:35:53 +0300 Subject: [PATCH] Improve info shown when collection directory is not accessible Instead of the previous toast + going to settings, the code now shows a dialog with an action to go to settings plus a link to the wiki related to full storage access. --- .../main/java/com/ichi2/anki/DeckPicker.kt | 31 +++++++++++++++++-- AnkiDroid/src/main/res/values/02-strings.xml | 2 ++ AnkiDroid/src/main/res/values/constants.xml | 1 + 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt b/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt index b6f45370b0c6..51cb63a91bd9 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt @@ -36,6 +36,7 @@ import android.net.Uri import android.os.Build import android.os.Bundle import android.os.Message +import android.text.util.Linkify import android.util.TypedValue import android.view.KeyEvent import android.view.Menu @@ -180,6 +181,7 @@ import com.ichi2.utils.SyncStatus import com.ichi2.utils.VersionUtils import com.ichi2.utils.cancelable import com.ichi2.utils.checkBoxPrompt +import com.ichi2.utils.customView import com.ichi2.utils.message import com.ichi2.utils.negativeButton import com.ichi2.utils.neutralButton @@ -736,9 +738,7 @@ open class DeckPicker : if (ScopedStorageService.collectionWasMadeInaccessibleAfterUninstall(this)) { showDatabaseErrorDialog(DatabaseErrorDialogType.DIALOG_STORAGE_UNAVAILABLE_AFTER_UNINSTALL) } else { - val i = AdvancedSettingsFragment.getSubscreenIntent(this) - requestPathUpdateLauncher.launch(i) - showThemedToast(this, R.string.directory_inaccessible, false) + showDirectoryNotAccessibleDialog() } } FUTURE_ANKIDROID_VERSION -> { @@ -768,6 +768,31 @@ open class DeckPicker : } } + private fun showDirectoryNotAccessibleDialog() { + val contentView = TextView(this).apply { + autoLinkMask = Linkify.WEB_URLS + linksClickable = true + text = getString( + R.string.directory_inaccessible_info, + getString(R.string.link_full_storage_access) + ) + } + AlertDialog.Builder(this).show { + title(R.string.directory_inaccessible) + customView( + contentView, + convertDpToPixel(16F, this@DeckPicker).toInt(), + 0, + convertDpToPixel(32F, this@DeckPicker).toInt(), + convertDpToPixel(32F, this@DeckPicker).toInt() + ) + positiveButton(R.string.open_settings) { + val settingsIntent = AdvancedSettingsFragment.getSubscreenIntent(this@DeckPicker) + requestPathUpdateLauncher.launch(settingsIntent) + } + } + } + private fun displayDatabaseFailure() { Timber.i("Displaying database failure") showDatabaseErrorDialog(DatabaseErrorDialogType.DIALOG_LOAD_FAILED) diff --git a/AnkiDroid/src/main/res/values/02-strings.xml b/AnkiDroid/src/main/res/values/02-strings.xml index 5182051c79fc..87fcd7bf1a1f 100644 --- a/AnkiDroid/src/main/res/values/02-strings.xml +++ b/AnkiDroid/src/main/res/values/02-strings.xml @@ -423,4 +423,6 @@ opening the system text to speech settings fails"> Press Alt+K to show keyboard shortcuts User action %s is not set in this notetype. Please configure it + + Learn more about how to restore access here %s or go to settings to update collection folder. diff --git a/AnkiDroid/src/main/res/values/constants.xml b/AnkiDroid/src/main/res/values/constants.xml index 0d1e2d09021c..92e6206dbc5b 100644 --- a/AnkiDroid/src/main/res/values/constants.xml +++ b/AnkiDroid/src/main/res/values/constants.xml @@ -153,6 +153,7 @@ https://github.com/ankidroid/Anki-Android/wiki/Full-Storage-Access https://docs.ankidroid.org/#_custom_sync_server https://docs.ankiweb.net/browsing.html#cards + https://github.com/ankidroid/Anki-Android/wiki/Full-Storage-Access 0