From ff1f29b1f81c7c6f0793bcfa22096f560b1ca756 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 17 Mar 2017 23:01:53 +0100 Subject: [PATCH] add a menu button for adding included folders --- .../activities/IncludedFoldersActivity.kt | 23 +++++++++++++++++++ .../gallery/helpers/Config.kt | 20 ++++++++++++---- .../gallery/helpers/Constants.kt | 1 + .../main/res/menu/menu_included_folders.xml | 9 ++++++++ 4 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/menu/menu_included_folders.xml diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt index 772245168..5103a6d8e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/IncludedFoldersActivity.kt @@ -1,11 +1,34 @@ package com.simplemobiletools.gallery.activities import android.os.Bundle +import android.view.Menu +import android.view.MenuItem +import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.extensions.config class IncludedFoldersActivity : SimpleActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_included_folders) } + + override fun onCreateOptionsMenu(menu: Menu?): Boolean { + menuInflater.inflate(R.menu.menu_included_folders, menu) + return true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.add_folder -> addIncludedFolder() + else -> return super.onOptionsItemSelected(item) + } + return true + } + + private fun addIncludedFolder() { + FilePickerDialog(this, pickFile = false, showHidden = config.showHiddenFolders) { + config.addIncludedFolder(it) + } + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index 65b14e4cf..e0b9dfb15 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -78,14 +78,26 @@ class Config(context: Context) : BaseConfig(context) { excludedFolders = currExcludedFolders } - fun removeAllExcludedFolders() { - prefs.edit().remove(EXCLUDED_FOLDERS).apply() - } - var excludedFolders: MutableSet get() = prefs.getStringSet(EXCLUDED_FOLDERS, HashSet()) set(excludedFolders) = prefs.edit().remove(EXCLUDED_FOLDERS).putStringSet(EXCLUDED_FOLDERS, excludedFolders).apply() + fun addIncludedFolder(path: String) { + val currIncludedFolders = HashSet(includedFolders) + currIncludedFolders.add(path) + includedFolders = currIncludedFolders + } + + fun removeIncludedFolder(path: String) { + val currIncludedFolders = HashSet(includedFolders) + currIncludedFolders.remove(path) + includedFolders = currIncludedFolders + } + + var includedFolders: MutableSet + get() = prefs.getStringSet(INCLUDED_FOLDERS, HashSet()) + set(includedFolders) = prefs.edit().remove(INCLUDED_FOLDERS).putStringSet(INCLUDED_FOLDERS, includedFolders).apply() + fun saveFolderMedia(path: String, json: String) { prefs.edit().putString(SAVE_FOLDER_PREFIX + path, json).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index e4208e8c8..97e62c430 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -18,6 +18,7 @@ val SHOW_MEDIA = "show_media" val SAVE_FOLDER_PREFIX = "folder_" val HIDE_FOLDER_TOOLTIP_SHOWN = "hide_folder_tooltip_shown" val EXCLUDED_FOLDERS = "excluded_folders" +val INCLUDED_FOLDERS = "included_folders" val NOMEDIA = ".nomedia" diff --git a/app/src/main/res/menu/menu_included_folders.xml b/app/src/main/res/menu/menu_included_folders.xml new file mode 100644 index 000000000..4671dcd0f --- /dev/null +++ b/app/src/main/res/menu/menu_included_folders.xml @@ -0,0 +1,9 @@ + + + +