diff options
author | Harsh Shandilya <msfjarvis@gmail.com> | 2019-11-03 21:54:05 +0530 |
---|---|---|
committer | Harsh Shandilya <msfjarvis@gmail.com> | 2019-11-03 23:35:45 +0530 |
commit | 13a4bf12c3308c57a812406aee527e4a7ce86a25 (patch) | |
tree | 54414c73d374680355757fe7071e96cc180dc1e3 /app/src/main/java/com | |
parent | a520b3db64db564e6bd639ab2c745015c3010c43 (diff) |
PasswordRepository: Rewrite and micro-optimize password loader
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
Diffstat (limited to 'app/src/main/java/com')
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt | 21 |
1 files changed, 8 insertions, 13 deletions
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 fdcccc6c..2c13fe61 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt @@ -215,22 +215,17 @@ open class PasswordRepository protected constructor() { @JvmStatic fun getPasswords(path: File, rootDir: File, sortOrder: PasswordSortOrder): ArrayList<PasswordItem> { // We need to recover the passwords then parse the files - val passList = getFilesList(path) - - if (passList.size == 0) return ArrayList() - + val passList = getFilesList(path).also { it.sortBy { f -> f.name } } val passwordList = ArrayList<PasswordItem>() - for (file in passList) { - if (file.isFile) { - if (!file.isHidden) { - passwordList.add(PasswordItem.newPassword(file.name, file, rootDir)) - } + if (passList.size == 0) return passwordList + + passList.filter { !it.isHidden }.forEach { file -> + passwordList.add(if (file.isFile) { + PasswordItem.newPassword(file.name, file, rootDir) } else { - if (!file.isHidden) { - passwordList.add(PasswordItem.newCategory(file.name, file, rootDir)) - } - } + PasswordItem.newCategory(file.name, file, rootDir) + }) } passwordList.sortWith(sortOrder.comparator) return passwordList |