PasswordRepository: Rewrite and micro-optimize password loader
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
This commit is contained in:
parent
a520b3db64
commit
13a4bf12c3
1 changed files with 8 additions and 13 deletions
|
@ -215,22 +215,17 @@ open class PasswordRepository protected constructor() {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getPasswords(path: File, rootDir: File, sortOrder: PasswordSortOrder): ArrayList<PasswordItem> {
|
fun getPasswords(path: File, rootDir: File, sortOrder: PasswordSortOrder): ArrayList<PasswordItem> {
|
||||||
// We need to recover the passwords then parse the files
|
// We need to recover the passwords then parse the files
|
||||||
val passList = getFilesList(path)
|
val passList = getFilesList(path).also { it.sortBy { f -> f.name } }
|
||||||
|
|
||||||
if (passList.size == 0) return ArrayList()
|
|
||||||
|
|
||||||
val passwordList = ArrayList<PasswordItem>()
|
val passwordList = ArrayList<PasswordItem>()
|
||||||
|
|
||||||
for (file in passList) {
|
if (passList.size == 0) return passwordList
|
||||||
if (file.isFile) {
|
|
||||||
if (!file.isHidden) {
|
passList.filter { !it.isHidden }.forEach { file ->
|
||||||
passwordList.add(PasswordItem.newPassword(file.name, file, rootDir))
|
passwordList.add(if (file.isFile) {
|
||||||
}
|
PasswordItem.newPassword(file.name, file, rootDir)
|
||||||
} else {
|
} else {
|
||||||
if (!file.isHidden) {
|
PasswordItem.newCategory(file.name, file, rootDir)
|
||||||
passwordList.add(PasswordItem.newCategory(file.name, file, rootDir))
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
passwordList.sortWith(sortOrder.comparator)
|
passwordList.sortWith(sortOrder.comparator)
|
||||||
return passwordList
|
return passwordList
|
||||||
|
|
Loading…
Reference in a new issue