From 1f158c5ca6f5b88df0ff0a6234299bf839581c04 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Wed, 13 Nov 2019 11:34:57 +0530 Subject: Add option to show hidden folders (#571) * Add option to show hidden folders Fixes #446 * Simplify filtering Signed-off-by: Harsh Shandilya --- .../java/com/zeapo/pwdstore/utils/PasswordRepository.kt | 14 +++++++++----- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/preference.xml | 6 ++++++ 3 files changed, 17 insertions(+), 5 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt index 22d9046f..d10a5d59 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt @@ -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() + 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 { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9ac5a850..c0c4c3fd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -274,4 +274,6 @@ The store is on the sdcard but the app does not have permission to access it. Please give permission. Your public key Error while trying to generate the ssh-key + Show hidden folders + Include hidden directories in the password list diff --git a/app/src/main/res/xml/preference.xml b/app/src/main/res/xml/preference.xml index 3f05af08..b03bfa5b 100644 --- a/app/src/main/res/xml/preference.xml +++ b/app/src/main/res/xml/preference.xml @@ -89,6 +89,12 @@ android:entries="@array/sort_order_entries" android:entryValues="@array/sort_order_values" android:persistent="true" /> +