From 1c9f7971ce006d349c4cf8c1dee441c4188d5d58 Mon Sep 17 00:00:00 2001 From: Fabian Henneke Date: Wed, 1 Jul 2020 18:18:21 +0200 Subject: Scroll to files and enter folders when created (#909) --- .../main/java/com/zeapo/pwdstore/utils/Extensions.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'app/src/main/java/com/zeapo/pwdstore/utils') 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) -- cgit v1.2.3