Add option to show hidden folders (#571)
* Add option to show hidden folders Fixes #446 * Simplify filtering Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
This commit is contained in:
parent
4c751a175f
commit
1f158c5ca6
3 changed files with 17 additions and 5 deletions
|
@ -47,6 +47,7 @@ open class PasswordRepository protected constructor() {
|
|||
companion object {
|
||||
|
||||
private var repository: Repository? = null
|
||||
private lateinit var settings: SharedPreferences
|
||||
|
||||
/**
|
||||
* Returns the git repository
|
||||
|
@ -139,7 +140,6 @@ open class PasswordRepository protected constructor() {
|
|||
|
||||
@JvmStatic
|
||||
fun getRepositoryDirectory(context: Context): File {
|
||||
val settings = PreferenceManager.getDefaultSharedPreferences(context.applicationContext)
|
||||
return if (settings.getBoolean("git_external", false)) {
|
||||
val externalRepo = settings.getString("git_external_repo", null)
|
||||
File(requireNotNull(externalRepo))
|
||||
|
@ -150,9 +150,8 @@ open class PasswordRepository protected constructor() {
|
|||
|
||||
@JvmStatic
|
||||
fun initialize(context: Context): Repository? {
|
||||
settings = PreferenceManager.getDefaultSharedPreferences(context.applicationContext)
|
||||
val dir = getRepositoryDirectory(context)
|
||||
val settings = PreferenceManager.getDefaultSharedPreferences(context.applicationContext)
|
||||
|
||||
// uninitialize the repo if the dir does not exist or is absolutely empty
|
||||
if (!dir.exists() || !dir.isDirectory || dir.listFiles()!!.isEmpty()) {
|
||||
settings.edit().putBoolean("repository_initialized", false).apply()
|
||||
|
@ -207,10 +206,15 @@ open class PasswordRepository protected constructor() {
|
|||
// We need to recover the passwords then parse the files
|
||||
val passList = getFilesList(path).also { it.sortBy { f -> f.name } }
|
||||
val passwordList = ArrayList<PasswordItem>()
|
||||
val showHiddenDirs = settings.getBoolean("show_hidden_folders", false)
|
||||
|
||||
if (passList.size == 0) return passwordList
|
||||
|
||||
passList.filter { !it.isHidden }.forEach { file ->
|
||||
if (showHiddenDirs) {
|
||||
passList.filter { !(it.isFile && it.isHidden) }.toCollection(passList.apply { clear() })
|
||||
} else {
|
||||
passList.filter { !it.isHidden }.toCollection(passList.apply { clear() })
|
||||
}
|
||||
passList.forEach { file ->
|
||||
passwordList.add(if (file.isFile) {
|
||||
PasswordItem.newPassword(file.name, file, rootDir)
|
||||
} else {
|
||||
|
|
|
@ -274,4 +274,6 @@
|
|||
<string name="access_sdcard_text">The store is on the sdcard but the app does not have permission to access it. Please give permission.</string>
|
||||
<string name="your_public_key">Your public key</string>
|
||||
<string name="error_generate_ssh_key">Error while trying to generate the ssh-key</string>
|
||||
<string name="pref_show_hidden_title">Show hidden folders</string>
|
||||
<string name="pref_show_hidden_summary">Include hidden directories in the password list</string>
|
||||
</resources>
|
||||
|
|
|
@ -89,6 +89,12 @@
|
|||
android:entries="@array/sort_order_entries"
|
||||
android:entryValues="@array/sort_order_values"
|
||||
android:persistent="true" />
|
||||
<androidx.preference.SwitchPreferenceCompat
|
||||
android:title="@string/pref_show_hidden_title"
|
||||
android:summary="@string/pref_show_hidden_summary"
|
||||
android:key="show_hidden_folders"
|
||||
android:defaultValue="false"
|
||||
android:persistent="true" />
|
||||
<androidx.preference.SwitchPreferenceCompat
|
||||
android:key="biometric_auth"
|
||||
android:title="@string/biometric_auth_title"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue