aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt17
1 files changed, 17 insertions, 0 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 dcede7da..6ba03743 100644
--- a/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt
@@ -59,6 +59,23 @@ fun Activity.snackbar(
fun File.listFilesRecursively() = walkTopDown().filter { !it.isDirectory }.toList()
+/**
+ * Checks whether this [File] is a directory that contains [other].
+ */
+fun File.contains(other: File): Boolean {
+ if (!isDirectory)
+ return false
+ if (!other.exists())
+ return false
+ val relativePath = try {
+ other.relativeTo(this)
+ } catch (e: Exception) {
+ return false
+ }
+ // Direct containment is equivalent to the relative path being equal to the filename.
+ return relativePath.path == other.name
+}
+
fun Context.resolveAttribute(attr: Int): Int {
val typedValue = TypedValue()
this.theme.resolveAttribute(attr, typedValue, true)