diff options
| author | Fabian Henneke <FabianHenneke@users.noreply.github.com> | 2020-07-01 18:18:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-01 21:48:21 +0530 |
| commit | 1c9f7971ce006d349c4cf8c1dee441c4188d5d58 (patch) | |
| tree | 504434c900c5ec67a2cff5cb9be6a75ac61ab239 /app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt | |
| parent | c5a93b8b8168eead37f3f93a8e8378211c1d240b (diff) | |
| download | HardenedPass-1c9f7971ce006d349c4cf8c1dee441c4188d5d58.tar.gz HardenedPass-1c9f7971ce006d349c4cf8c1dee441c4188d5d58.zip | |
Scroll to files and enter folders when created (#909)
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.kt | 17 |
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) |
