From 667dc4bf2e86004116ba11b6818b104ff1bc91a3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 22 Feb 2017 19:13:18 +0100 Subject: [PATCH] replace fake folder hiding with .nomedia check --- .../gallery/activities/MediaActivity.kt | 5 +--- .../gallery/adapters/DirectoryAdapter.kt | 8 ++---- .../asynctasks/GetDirectoriesAsynctask.kt | 3 ++- .../gallery/extensions/context.kt | 7 ----- .../gallery/extensions/file.kt | 3 +++ .../gallery/helpers/Config.kt | 26 ------------------- .../gallery/helpers/Constants.kt | 3 ++- 7 files changed, 10 insertions(+), 45 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 7f167836b..a7956d83e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -94,7 +94,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu_media, menu) - val isFolderHidden = config.getIsFolderHidden(mPath) + val isFolderHidden = File(mPath).containsNoMedia() menu.apply { findItem(R.id.hide_folder).isVisible = !isFolderHidden && !mShowAll findItem(R.id.unhide_folder).isVisible = isFolderHidden && !mShowAll @@ -147,8 +147,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun hideFolder() { - config.addHiddenFolder(mPath) - if (!config.showHiddenFolders) finish() else @@ -156,7 +154,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun unhideFolder() { - config.removeHiddenFolder(mPath) invalidateOptionsMenu() } 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 9927b0799..378334093 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -24,6 +24,7 @@ import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.dialogs.CopyDialog import com.simplemobiletools.gallery.dialogs.RenameDirectoryDialog import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.extensions.containsNoMedia import com.simplemobiletools.gallery.extensions.createSelector import com.simplemobiletools.gallery.models.Directory import kotlinx.android.synthetic.main.directory_item.view.* @@ -114,7 +115,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList { fun Context.filterDirectories(dirs: ArrayList) { if (!config.showHiddenFolders) { - removeHiddenFolders(dirs) removeNoMediaFolders(dirs) } } -fun Context.removeHiddenFolders(paths: MutableList) { - val hiddenPaths = config.hiddenFolders - val ignorePaths = paths.filter { hiddenPaths.contains(it) } - paths.removeAll(ignorePaths) -} - private fun removeNoMediaFolders(paths: MutableList) { val ignorePaths = ArrayList() for (path in paths) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/file.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/file.kt index 0a0fbc2ba..b990dfc56 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/file.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/file.kt @@ -1,6 +1,7 @@ package com.simplemobiletools.gallery.extensions import android.graphics.Bitmap +import com.simplemobiletools.gallery.helpers.NOMEDIA import java.io.File fun File.getCompressionFormat(): Bitmap.CompressFormat { @@ -10,3 +11,5 @@ fun File.getCompressionFormat(): Bitmap.CompressFormat { else -> Bitmap.CompressFormat.JPEG } } + +fun File.containsNoMedia() = isDirectory && File(this, NOMEDIA).exists() 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 a48e45a92..1af19597a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -46,38 +46,12 @@ class Config(context: Context) : BaseConfig(context) { pinnedFolders = currPinnedFolders } - fun addHiddenFolder(path: String) { - addHiddenFolders(HashSet(Arrays.asList(path))) - } - - fun addHiddenFolders(paths: Set) { - val currHiddenFolders = HashSet(hiddenFolders) - currHiddenFolders.addAll(paths) - hiddenFolders = currHiddenFolders - } - - fun removeHiddenFolder(path: String) { - removeHiddenFolders(HashSet(Arrays.asList(path))) - } - - fun removeHiddenFolders(paths: Set) { - val currHiddenFolders = HashSet(hiddenFolders) - currHiddenFolders.removeAll(paths) - hiddenFolders = currHiddenFolders - } - - fun getIsFolderHidden(path: String) = hiddenFolders.contains(path) - fun saveFolderMedia(path: String, json: String) { prefs.edit().putString(SAVE_FOLDER_PREFIX + path, json).apply() } fun loadFolderMedia(path: String) = prefs.getString(SAVE_FOLDER_PREFIX + path, "") - var hiddenFolders: MutableSet - get() = prefs.getStringSet(HIDDEN_FOLDERS, HashSet()) - set(hiddenFolders) = prefs.edit().remove(HIDDEN_FOLDERS).putStringSet(HIDDEN_FOLDERS, hiddenFolders).apply() - var autoplayVideos: Boolean get() = prefs.getBoolean(AUTOPLAY_VIDEOS, false) set(autoplay) = prefs.edit().putBoolean(AUTOPLAY_VIDEOS, autoplay).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 9f406f00f..56cb2605b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -4,7 +4,6 @@ package com.simplemobiletools.gallery.helpers val IS_SAME_SORTING = "is_same_sorting" val SORT_ORDER = "sort_order" val DIRECTORY_SORT_ORDER = "directory_sort_order" -val HIDDEN_FOLDERS = "hidden_folders" val SHOW_HIDDEN_FOLDERS = "show_hidden_folders" val AUTOPLAY_VIDEOS = "autoplay_videos" val LOOP_VIDEOS = "loop_videos" @@ -16,6 +15,8 @@ val SHOW_ALL = "show_all" // display images and videos from all folders togeth val SHOW_MEDIA = "show_media" val SAVE_FOLDER_PREFIX = "folder_" +val NOMEDIA = ".nomedia" + // sorting val SORT_BY_NAME = 1 val SORT_BY_DATE_MODIFIED = 2