Hide broken database links

This commit is contained in:
J-Jamet
2020-02-23 13:15:09 +01:00
parent 8925c86afd
commit 7650db81a4
5 changed files with 28 additions and 2 deletions

View File

@@ -277,8 +277,18 @@ class FileDatabaseSelectActivity : StylishActivity(),
// Construct adapter with listeners
if (PreferencesUtil.showRecentFiles(this)) {
mFileDatabaseHistoryAction?.getAllFileDatabaseHistories { databaseFileHistoryList ->
databaseFileHistoryList?.let {
mAdapterDatabaseHistory?.addDatabaseFileHistoryList(it)
databaseFileHistoryList?.let { historyList ->
val hideBrokenLocations = PreferencesUtil.hideBrokenLocations(this@FileDatabaseSelectActivity)
mAdapterDatabaseHistory?.addDatabaseFileHistoryList(
// Show only uri accessible
historyList.filter {
if (hideBrokenLocations) {
UriUtil.parse(it.databaseUri)?.let { historyUri ->
UriUtil.isUriAccessible(contentResolver, historyUri)
} ?: false
} else
true
})
mAdapterDatabaseHistory?.notifyDataSetChanged()
updateFileListVisibility()
}

View File

@@ -40,6 +40,12 @@ object PreferencesUtil {
context.resources.getBoolean(R.bool.show_recent_files_default))
}
fun hideBrokenLocations(context: Context): Boolean {
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.hide_broken_locations_key),
context.resources.getBoolean(R.bool.hide_broken_locations_default))
}
fun rememberKeyFileLocations(context: Context): Boolean {
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.remember_keyfile_locations_key),

View File

@@ -87,6 +87,8 @@
<bool name="remember_database_locations_default" translatable="false">true</bool>
<string name="show_recent_files_key" translatable="false">show_recent_files_key</string>
<bool name="show_recent_files_default" translatable="false">true</bool>
<string name="hide_broken_locations_key" translatable="false">hide_broken_locations_key</string>
<bool name="hide_broken_locations_default" translatable="false">true</bool>
<string name="remember_keyfile_locations_key" translatable="false">remember_keyfile_locations_key</string>
<bool name="remember_keyfile_locations_default" translatable="false">true</bool>
<string name="advanced_unlock_explanation_key" translatable="false">advanced_unlock_explanation_key</string>

View File

@@ -207,6 +207,8 @@
<string name="remember_database_locations_summary">Remember the location of databases</string>
<string name="show_recent_files_title">Show recent files</string>
<string name="show_recent_files_summary">Show locations of recent databases</string>
<string name="hide_broken_locations_title">Hide broken database links</string>
<string name="hide_broken_locations_summary">Hide broken links in the list of recent databases</string>
<string name="remember_keyfile_locations_title">Save location of keyfiles</string>
<string name="remember_keyfile_locations_summary">Remember the location of databases keyfiles</string>
<string name="root">Root</string>

View File

@@ -131,6 +131,12 @@
android:summary="@string/show_recent_files_summary"
android:dependency="@string/remember_database_locations_key"
android:defaultValue="@bool/show_recent_files_default"/>
<SwitchPreference
android:key="@string/hide_broken_locations_key"
android:title="@string/hide_broken_locations_title"
android:summary="@string/hide_broken_locations_summary"
android:dependency="@string/show_recent_files_key"
android:defaultValue="@bool/hide_broken_locations_default"/>
<SwitchPreference
android:key="@string/remember_keyfile_locations_key"
android:title="@string/remember_keyfile_locations_title"