From f480ae6e14e9d4627fdfa98dddc299d88cf9bab7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 3 Mar 2017 23:33:06 +0100 Subject: [PATCH] get a list of parents at exclude folder dialog --- .../gallery/activities/MediaActivity.kt | 5 +--- .../gallery/adapters/DirectoryAdapter.kt | 2 +- .../gallery/dialogs/ExcludeFolderDialog.kt | 24 +++++++++++++++---- .../main/res/layout/dialog_exclude_folder.xml | 4 +++- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 465425515..5e4dde7f1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -194,10 +194,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun tryExcludeFolder() { - val pathSet = HashSet(1) - pathSet.add(mPath) - - ExcludeFolderDialog(this, pathSet) { + ExcludeFolderDialog(this, arrayListOf(mPath)) { finish() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 6e9567e1a..5bfa156b7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -197,7 +197,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList, val callback: () -> Unit) { +class ExcludeFolderDialog(val activity: SimpleActivity, val selectedPaths: List, val callback: () -> Unit) { var dialog: AlertDialog? = null init { @@ -30,11 +31,24 @@ class ExcludeFolderDialog(val activity: SimpleActivity, val selectedPaths: HashS } - private fun getAlternativePaths(): ArrayList { - val parentsList = ArrayList() + private fun getAlternativePaths(): List { + val pathsList = ArrayList() if (selectedPaths.size > 1) - return parentsList + return pathsList - return parentsList + val path = selectedPaths[0] + var basePath = path.getBasePath(activity) + val relativePath = path.substring(basePath.length) + val parts = relativePath.split("/").filter(String::isNotEmpty) + if (parts.isEmpty()) + return pathsList + + pathsList.add(basePath) + for (part in parts) { + basePath += "/$part" + pathsList.add(basePath) + } + + return pathsList.reversed() } } diff --git a/app/src/main/res/layout/dialog_exclude_folder.xml b/app/src/main/res/layout/dialog_exclude_folder.xml index 7ed43c589..8cc0d5886 100644 --- a/app/src/main/res/layout/dialog_exclude_folder.xml +++ b/app/src/main/res/layout/dialog_exclude_folder.xml @@ -23,7 +23,9 @@ android:id="@+id/exclude_folder_parent" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="@string/exclude_folder_parent"/> + android:layout_marginTop="@dimen/activity_margin" + android:text="@string/exclude_folder_parent" + android:textSize="@dimen/normal_text_size"/>