mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2025-01-19 06:48:00 +01:00
adding a couple improvements related to un/hiding folders
This commit is contained in:
parent
71127d45d1
commit
d91228eedf
7 changed files with 61 additions and 47 deletions
|
@ -686,6 +686,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
gotDirectories(directories, true)
|
gotDirectories(directories, true)
|
||||||
} else {
|
} else {
|
||||||
mDirs = directories
|
mDirs = directories
|
||||||
|
storeDirectories()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -181,26 +181,20 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
||||||
|
|
||||||
private fun toggleFoldersVisibility(hide: Boolean) {
|
private fun toggleFoldersVisibility(hide: Boolean) {
|
||||||
getSelectedPaths().forEach {
|
getSelectedPaths().forEach {
|
||||||
|
val path = it
|
||||||
if (hide) {
|
if (hide) {
|
||||||
if (config.wasHideFolderTooltipShown) {
|
if (config.wasHideFolderTooltipShown) {
|
||||||
hideFolder(it)
|
hideFolder(path)
|
||||||
} else {
|
} else {
|
||||||
config.wasHideFolderTooltipShown = true
|
config.wasHideFolderTooltipShown = true
|
||||||
ConfirmationDialog(activity, activity.getString(R.string.hide_folder_description)) {
|
ConfirmationDialog(activity, activity.getString(R.string.hide_folder_description)) {
|
||||||
hideFolder(it)
|
hideFolder(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
activity.removeNoMedia(it) {
|
activity.removeNoMedia(path) {
|
||||||
if (activity.config.shouldShowHidden) {
|
if (activity.config.shouldShowHidden) {
|
||||||
dirs.forEachIndexed { index, directory ->
|
updateFolderNames()
|
||||||
if (directory.path.startsWith(it, true)) {
|
|
||||||
val hidden = activity.getString(R.string.hidden)
|
|
||||||
directory.name = directory.name.removeSuffix(hidden).trim()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updateDirs(dirs)
|
|
||||||
listener?.updateDirectories(dirs.toList() as ArrayList, true)
|
|
||||||
} else {
|
} else {
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
|
@ -212,17 +206,22 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateFolderNames() {
|
||||||
|
val includedFolders = activity.config.includedFolders
|
||||||
|
val hidden = activity.getString(R.string.hidden)
|
||||||
|
dirs.forEach {
|
||||||
|
it.name = activity.checkAppendingHidden(it.path, hidden, includedFolders)
|
||||||
|
}
|
||||||
|
listener?.updateDirectories(dirs.toList() as ArrayList, false)
|
||||||
|
activity.runOnUiThread {
|
||||||
|
updateDirs(dirs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun hideFolder(path: String) {
|
private fun hideFolder(path: String) {
|
||||||
activity.addNoMedia(path) {
|
activity.addNoMedia(path) {
|
||||||
if (activity.config.shouldShowHidden) {
|
if (activity.config.shouldShowHidden) {
|
||||||
val hidden = activity.getString(R.string.hidden)
|
updateFolderNames()
|
||||||
dirs.forEachIndexed { index, directory ->
|
|
||||||
if (directory.path.startsWith(path, true)) {
|
|
||||||
directory.name += " $hidden"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updateDirs(dirs)
|
|
||||||
listener?.updateDirectories(dirs.toList() as ArrayList, true)
|
|
||||||
} else {
|
} else {
|
||||||
val affectedPositions = ArrayList<Int>()
|
val affectedPositions = ArrayList<Int>()
|
||||||
val newDirs = dirs.filterIndexed { index, directory ->
|
val newDirs = dirs.filterIndexed { index, directory ->
|
||||||
|
|
|
@ -7,8 +7,8 @@ import com.simplemobiletools.commons.helpers.OTG_PATH
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
||||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
|
import com.simplemobiletools.gallery.extensions.checkAppendingHidden
|
||||||
import com.simplemobiletools.gallery.extensions.config
|
import com.simplemobiletools.gallery.extensions.config
|
||||||
import com.simplemobiletools.gallery.extensions.doesParentHaveNoMedia
|
|
||||||
import com.simplemobiletools.gallery.extensions.sumByLong
|
import com.simplemobiletools.gallery.extensions.sumByLong
|
||||||
import com.simplemobiletools.gallery.helpers.MediaFetcher
|
import com.simplemobiletools.gallery.helpers.MediaFetcher
|
||||||
import com.simplemobiletools.gallery.models.Directory
|
import com.simplemobiletools.gallery.models.Directory
|
||||||
|
@ -50,23 +50,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var dirName = when (parentDir) {
|
val dirName = context.checkAppendingHidden(parentDir, hidden, includedFolders)
|
||||||
context.internalStoragePath -> context.getString(R.string.internal)
|
|
||||||
context.sdCardPath -> context.getString(R.string.sd_card)
|
|
||||||
OTG_PATH -> context.getString(R.string.otg)
|
|
||||||
else -> {
|
|
||||||
if (parentDir.startsWith(OTG_PATH)) {
|
|
||||||
parentDir.trimEnd('/').substringAfterLast('/')
|
|
||||||
} else {
|
|
||||||
parentDir.getFilenameFromPath()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (File(parentDir).doesParentHaveNoMedia() && !includedFolders.contains(parentDir)) {
|
|
||||||
dirName += " $hidden"
|
|
||||||
}
|
|
||||||
|
|
||||||
val lastModified = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.modified, lastItem.modified) else Math.min(firstItem.modified, lastItem.modified)
|
val lastModified = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.modified, lastItem.modified) else Math.min(firstItem.modified, lastItem.modified)
|
||||||
val dateTaken = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.taken, lastItem.taken) else Math.min(firstItem.taken, lastItem.taken)
|
val dateTaken = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.taken, lastItem.taken) else Math.min(firstItem.taken, lastItem.taken)
|
||||||
val size = curMedia.sumByLong { it.size }
|
val size = curMedia.sumByLong { it.size }
|
||||||
|
|
|
@ -120,25 +120,34 @@ fun BaseSimpleActivity.addNoMedia(path: String, callback: () -> Unit) {
|
||||||
val fileDocument = getDocumentFile(path)
|
val fileDocument = getDocumentFile(path)
|
||||||
if (fileDocument?.exists() == true && fileDocument.isDirectory) {
|
if (fileDocument?.exists() == true && fileDocument.isDirectory) {
|
||||||
fileDocument.createFile("", NOMEDIA)
|
fileDocument.createFile("", NOMEDIA)
|
||||||
|
applicationContext.scanFile(file) {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
toast(R.string.unknown_error_occurred)
|
toast(R.string.unknown_error_occurred)
|
||||||
|
callback()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
file.createNewFile()
|
file.createNewFile()
|
||||||
|
applicationContext.scanFile(file) {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
showErrorToast(e)
|
showErrorToast(e)
|
||||||
|
callback()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
applicationContext.scanFile(file) {
|
|
||||||
callback()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BaseSimpleActivity.removeNoMedia(path: String, callback: (() -> Unit)? = null) {
|
fun BaseSimpleActivity.removeNoMedia(path: String, callback: (() -> Unit)? = null) {
|
||||||
val file = File(path, NOMEDIA)
|
val file = File(path, NOMEDIA)
|
||||||
|
if (!file.exists()) {
|
||||||
|
callback?.invoke()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
deleteFile(file.toFileDirItem(applicationContext)) {
|
deleteFile(file.toFileDirItem(applicationContext)) {
|
||||||
callback?.invoke()
|
callback?.invoke()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,9 @@ import android.os.Build
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.simplemobiletools.commons.extensions.getStringValue
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.extensions.humanizePath
|
|
||||||
import com.simplemobiletools.commons.helpers.OTG_PATH
|
import com.simplemobiletools.commons.helpers.OTG_PATH
|
||||||
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.activities.SettingsActivity
|
import com.simplemobiletools.gallery.activities.SettingsActivity
|
||||||
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
|
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
|
||||||
import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
|
import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
|
||||||
|
@ -163,3 +163,24 @@ fun Context.storeDirectoryItems(items: ArrayList<Directory>) {
|
||||||
val subList = items.subList(0, Math.min(SAVE_DIRS_CNT, items.size))
|
val subList = items.subList(0, Math.min(SAVE_DIRS_CNT, items.size))
|
||||||
config.directories = Gson().toJson(subList)
|
config.directories = Gson().toJson(subList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.checkAppendingHidden(path: String, hidden: String, includedFolders: MutableSet<String>): String {
|
||||||
|
val dirName = when (path) {
|
||||||
|
internalStoragePath -> getString(R.string.internal)
|
||||||
|
sdCardPath -> getString(R.string.sd_card)
|
||||||
|
OTG_PATH -> getString(R.string.otg)
|
||||||
|
else -> {
|
||||||
|
if (path.startsWith(OTG_PATH)) {
|
||||||
|
path.trimEnd('/').substringAfterLast('/')
|
||||||
|
} else {
|
||||||
|
path.getFilenameFromPath()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return if (File(path).doesThisOrParentHaveNoMedia() && !includedFolders.contains(path)) {
|
||||||
|
"$dirName $hidden"
|
||||||
|
} else {
|
||||||
|
dirName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,13 +5,13 @@ import java.io.File
|
||||||
|
|
||||||
fun File.containsNoMedia() = isDirectory && File(this, NOMEDIA).exists()
|
fun File.containsNoMedia() = isDirectory && File(this, NOMEDIA).exists()
|
||||||
|
|
||||||
fun File.doesParentHaveNoMedia(): Boolean {
|
fun File.doesThisOrParentHaveNoMedia(): Boolean {
|
||||||
var curFile = this
|
var curFile = this
|
||||||
while (true) {
|
while (true) {
|
||||||
if (curFile.containsNoMedia()) {
|
if (curFile.containsNoMedia()) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
curFile = curFile.parentFile
|
curFile = curFile.parentFile ?: break
|
||||||
if (curFile.absolutePath == "/") {
|
if (curFile.absolutePath == "/") {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.*
|
import com.simplemobiletools.commons.helpers.*
|
||||||
import com.simplemobiletools.gallery.extensions.config
|
import com.simplemobiletools.gallery.extensions.config
|
||||||
import com.simplemobiletools.gallery.extensions.containsNoMedia
|
import com.simplemobiletools.gallery.extensions.containsNoMedia
|
||||||
import com.simplemobiletools.gallery.extensions.doesParentHaveNoMedia
|
import com.simplemobiletools.gallery.extensions.doesThisOrParentHaveNoMedia
|
||||||
import com.simplemobiletools.gallery.extensions.isPathInMediaStore
|
import com.simplemobiletools.gallery.extensions.isPathInMediaStore
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -253,7 +253,7 @@ class MediaFetcher(val context: Context) {
|
||||||
} else if (!showHidden && file.isDirectory && file.canonicalFile == file.absoluteFile) {
|
} else if (!showHidden && file.isDirectory && file.canonicalFile == file.absoluteFile) {
|
||||||
var containsNoMediaOrDot = file.containsNoMedia() || path.contains("/.")
|
var containsNoMediaOrDot = file.containsNoMedia() || path.contains("/.")
|
||||||
if (!containsNoMediaOrDot) {
|
if (!containsNoMediaOrDot) {
|
||||||
containsNoMediaOrDot = file.doesParentHaveNoMedia()
|
containsNoMediaOrDot = file.doesThisOrParentHaveNoMedia()
|
||||||
}
|
}
|
||||||
!containsNoMediaOrDot
|
!containsNoMediaOrDot
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue