aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/utils
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/utils')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt3
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/FileUtils.kt47
2 files changed, 3 insertions, 47 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt b/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt
index 4820d8bf..d10bdaab 100644
--- a/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt
@@ -17,6 +17,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.core.content.getSystemService
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKeys
+import java.io.File
infix fun Int.hasFlag(flag: Int): Boolean {
return this and flag == flag
@@ -32,6 +33,8 @@ fun CharArray.clear() {
}
}
+fun File.listFilesRecursively() = walkTopDown().filter { !it.isDirectory }.toList()
+
fun Context.resolveAttribute(attr: Int): Int {
val typedValue = TypedValue()
this.theme.resolveAttribute(attr, typedValue, true)
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/FileUtils.kt b/app/src/main/java/com/zeapo/pwdstore/utils/FileUtils.kt
deleted file mode 100644
index 867ec0aa..00000000
--- a/app/src/main/java/com/zeapo/pwdstore/utils/FileUtils.kt
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-package com.zeapo.pwdstore.utils
-
-import java.io.File
-
-object FileUtils {
- @JvmStatic
- fun listFiles(dir: File, recursive: Boolean): Collection<File> {
- val res = ArrayList<File>()
- val files = dir.listFiles()
-
- if (files != null && files.isNotEmpty()) {
-
- files.forEach { file ->
- // Check if the file is a directory and recursive add
- if (file.isDirectory && recursive) {
- res.addAll(listFiles(file, recursive))
- } else if (!file.isDirectory) {
- res.add(file)
- }
- }
- }
- return res
- }
-
- @JvmStatic
- fun getBaseName(filename: String): String {
- // Take the file name along with its extension
- val indexName = filename.lastIndexOf('/')
- val nameWithExtension = filename.substring(indexName + 1)
-
- // Find the final '.' character in the previously calculated nameWithExtension
- val indexExt = nameWithExtension.lastIndexOf('.')
-
- // If no '.' is found in the name, we assume this is a directory and return the previously
- // derived nameWithExtensions as-is, otherwise we slice out a substring from the first character
- // to the last occurrence of '.' which we found earlier.
- return if (indexExt == -1)
- nameWithExtension
- else
- nameWithExtension.substring(0, indexExt)
- }
-}