Skip to content

Commit

Permalink
Improve info shown when collection directory is not accessible
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lukstbit committed Oct 15, 2024
1 parent 28de3ba commit ce419d0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
31 changes: 28 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 -> {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions AnkiDroid/src/main/res/values/02-strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,6 @@ opening the system text to speech settings fails">

<string name="show_shortcuts_message">Press Alt+K to show keyboard shortcuts</string>
<string name="missing_user_action_dialog_message" comment="%s is the user action number">User action %s is not set in this notetype. Please configure it</string>

<string name="directory_inaccessible_info">Learn more about how to restore access here %s or go to settings to update collection folder.</string>
</resources>
1 change: 1 addition & 0 deletions AnkiDroid/src/main/res/values/constants.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
<string name="link_install_non_play_store_install">https://github.com/ankidroid/Anki-Android/wiki/Full-Storage-Access</string>
<string name="link_custom_sync_server_help_learn_more_en">https://docs.ankidroid.org/#_custom_sync_server</string>
<string name="link_set_due_date_help">https://docs.ankiweb.net/browsing.html#cards</string>
<string name="link_full_storage_access">https://github.com/ankidroid/Anki-Android/wiki/Full-Storage-Access</string>

<string-array name="cram_deck_conf_order_values">
<item>0</item>
Expand Down

0 comments on commit ce419d0

Please sign in to comment.