mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
replace fake folder hiding with .nomedia check
This commit is contained in:
parent
2544c91859
commit
667dc4bf2e
7 changed files with 10 additions and 45 deletions
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Direc
|
|||
var hiddenCnt = 0
|
||||
var unhiddenCnt = 0
|
||||
positions.map { dirs[it].path }.forEach {
|
||||
if (config.getIsFolderHidden(it))
|
||||
if (File(it).containsNoMedia())
|
||||
hiddenCnt++
|
||||
else
|
||||
unhiddenCnt++
|
||||
|
@ -171,11 +172,6 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
|||
}
|
||||
|
||||
private fun toggleFoldersVisibility(hide: Boolean) {
|
||||
if (hide)
|
||||
config.addHiddenFolders(getSelectedPaths())
|
||||
else
|
||||
config.removeHiddenFolders(getSelectedPaths())
|
||||
|
||||
listener?.refreshItems()
|
||||
actMode?.finish()
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.simplemobiletools.commons.extensions.isImageFast
|
|||
import com.simplemobiletools.commons.extensions.isVideoFast
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.extensions.config
|
||||
import com.simplemobiletools.gallery.extensions.containsNoMedia
|
||||
import com.simplemobiletools.gallery.extensions.getHumanizedFilename
|
||||
import com.simplemobiletools.gallery.extensions.getParents
|
||||
import com.simplemobiletools.gallery.helpers.IMAGES
|
||||
|
@ -65,7 +66,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
|||
directory.addSize(size)
|
||||
} else {
|
||||
var dirName = context.getHumanizedFilename(parentDir)
|
||||
if (config.getIsFolderHidden(parentDir)) {
|
||||
if (File(parentDir).containsNoMedia()) {
|
||||
dirName += " ${context.resources.getString(R.string.hidden)}"
|
||||
}
|
||||
|
||||
|
|
|
@ -97,17 +97,10 @@ fun Context.getArgs(isPickImage: Boolean, isPickVideo: Boolean): Array<String> {
|
|||
|
||||
fun Context.filterDirectories(dirs: ArrayList<String>) {
|
||||
if (!config.showHiddenFolders) {
|
||||
removeHiddenFolders(dirs)
|
||||
removeNoMediaFolders(dirs)
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.removeHiddenFolders(paths: MutableList<String>) {
|
||||
val hiddenPaths = config.hiddenFolders
|
||||
val ignorePaths = paths.filter { hiddenPaths.contains(it) }
|
||||
paths.removeAll(ignorePaths)
|
||||
}
|
||||
|
||||
private fun removeNoMediaFolders(paths: MutableList<String>) {
|
||||
val ignorePaths = ArrayList<String>()
|
||||
for (path in paths) {
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -46,38 +46,12 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
pinnedFolders = currPinnedFolders
|
||||
}
|
||||
|
||||
fun addHiddenFolder(path: String) {
|
||||
addHiddenFolders(HashSet<String>(Arrays.asList(path)))
|
||||
}
|
||||
|
||||
fun addHiddenFolders(paths: Set<String>) {
|
||||
val currHiddenFolders = HashSet<String>(hiddenFolders)
|
||||
currHiddenFolders.addAll(paths)
|
||||
hiddenFolders = currHiddenFolders
|
||||
}
|
||||
|
||||
fun removeHiddenFolder(path: String) {
|
||||
removeHiddenFolders(HashSet<String>(Arrays.asList(path)))
|
||||
}
|
||||
|
||||
fun removeHiddenFolders(paths: Set<String>) {
|
||||
val currHiddenFolders = HashSet<String>(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<String>
|
||||
get() = prefs.getStringSet(HIDDEN_FOLDERS, HashSet<String>())
|
||||
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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue