From 669a0b5a967033f00ab42c227dd5fb3681070d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Tue, 25 Jul 2023 10:44:57 +0200 Subject: [PATCH] Check parent folders too when displaying unhide warning --- .../gallery/pro/adapters/DirectoryAdapter.kt | 2 +- .../gallery/pro/extensions/String.kt | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index 9dd69ccaa..83410e998 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -305,7 +305,7 @@ class DirectoryAdapter( } } } else { - if (selectedPaths.any { File(it).isHidden }) { + if (selectedPaths.any { it.isThisOrParentFolderHidden() }) { ConfirmationDialog(activity, "", R.string.cant_unhide_folder, R.string.ok, 0) {} return } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt index 569b383e5..dee1aef64 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt @@ -91,3 +91,18 @@ fun String.getDistinctPath(): String { } fun String.isDownloadsFolder() = equals(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString(), true) + +fun String.isThisOrParentFolderHidden(): Boolean { + var curFile = File(this) + while (true) { + if (curFile.isHidden) { + return true + } + + curFile = curFile.parentFile ?: break + if (curFile.absolutePath == "/") { + break + } + } + return false +}