From fd0014cbe6c887b328459311ba340616e54b4bc7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 24 Jul 2019 14:35:11 +0200 Subject: [PATCH] make use of some new .nomedia checking extensions --- app/build.gradle | 2 +- .../gallery/pro/activities/MediaActivity.kt | 2 +- .../gallery/pro/adapters/DirectoryAdapter.kt | 6 +++--- .../gallery/pro/extensions/Activity.kt | 1 - .../gallery/pro/extensions/Context.kt | 4 ++-- .../gallery/pro/extensions/File.kt | 20 ------------------- .../gallery/pro/extensions/String.kt | 3 ++- .../gallery/pro/helpers/Constants.kt | 1 - 8 files changed, 9 insertions(+), 30 deletions(-) delete mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/File.kt diff --git a/app/build.gradle b/app/build.gradle index 3218d7d6f..ba123d85c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -61,7 +61,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.15.1' + implementation 'com.simplemobiletools:commons:5.15.9' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'androidx.multidex:multidex:2.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt index f79e0a1f5..16de5f6fb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt @@ -207,7 +207,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu_media, menu) - val isFolderHidden = File(mPath).containsNoMedia() + val isFolderHidden = mPath.containsNoMedia() menu.apply { findItem(R.id.group).isVisible = !config.scrollHorizontally diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index cb1e7dba7..8acaf4412 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -145,8 +145,8 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList) { - menu.findItem(R.id.cab_hide).isVisible = selectedPaths.any { !File(it).doesThisOrParentHaveNoMedia() } - menu.findItem(R.id.cab_unhide).isVisible = selectedPaths.any { File(it).doesThisOrParentHaveNoMedia() } + menu.findItem(R.id.cab_hide).isVisible = selectedPaths.any { !it.doesThisOrParentHaveNoMedia() } + menu.findItem(R.id.cab_unhide).isVisible = selectedPaths.any { it.doesThisOrParentHaveNoMedia() } } private fun checkPinBtnVisibility(menu: Menu, selectedPaths: ArrayList) { @@ -308,7 +308,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList() val includedFolders = activity.config.includedFolders val newDirs = dirs.filterIndexed { index, directory -> - val removeDir = File(directory.path).doesThisOrParentHaveNoMedia() && !includedFolders.contains(directory.path) + val removeDir = directory.path.doesThisOrParentHaveNoMedia() && !includedFolders.contains(directory.path) if (removeDir) { affectedPositions.add(index) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt index 07615227b..446821787 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt @@ -30,7 +30,6 @@ import com.simplemobiletools.gallery.pro.BuildConfig import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.activities.SimpleActivity import com.simplemobiletools.gallery.pro.dialogs.PickDirectoryDialog -import com.simplemobiletools.gallery.pro.helpers.NOMEDIA import com.simplemobiletools.gallery.pro.helpers.RECYCLE_BIN import com.simplemobiletools.gallery.pro.interfaces.MediumDao import com.squareup.picasso.Picasso diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt index a27f32b1e..577cd653e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt @@ -424,7 +424,7 @@ fun Context.storeDirectoryItems(items: ArrayList, directoryDao: Direc fun Context.checkAppendingHidden(path: String, hidden: String, includedFolders: MutableSet): String { val dirName = getFolderNameFromPath(path) - return if (File(path).doesThisOrParentHaveNoMedia() && !path.isThisOrParentIncluded(includedFolders)) { + return if (path.doesThisOrParentHaveNoMedia() && !path.isThisOrParentIncluded(includedFolders)) { "$dirName $hidden" } else { dirName @@ -587,7 +587,7 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: val hiddenString = resources.getString(R.string.hidden) filteredDirectories.forEach { - it.name = if (File(it.path).doesThisOrParentHaveNoMedia() && !it.path.isThisOrParentIncluded(includedPaths)) { + it.name = if (it.path.doesThisOrParentHaveNoMedia() && !it.path.isThisOrParentIncluded(includedPaths)) { "${it.name.removeSuffix(hiddenString).trim()} $hiddenString" } else { it.name diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/File.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/File.kt deleted file mode 100644 index 90b02aac1..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/File.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.simplemobiletools.gallery.pro.extensions - -import com.simplemobiletools.gallery.pro.helpers.NOMEDIA -import java.io.File - -fun File.containsNoMedia() = isDirectory && File(this, NOMEDIA).exists() - -fun File.doesThisOrParentHaveNoMedia(): Boolean { - var curFile = this - while (true) { - if (curFile.containsNoMedia()) { - return true - } - curFile = curFile.parentFile ?: break - if (curFile.absolutePath == "/") { - break - } - } - return false -} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt index 17710e0e7..ac921defd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt @@ -1,7 +1,8 @@ package com.simplemobiletools.gallery.pro.extensions import android.media.MediaMetadataRetriever -import com.simplemobiletools.gallery.pro.helpers.NOMEDIA +import com.simplemobiletools.commons.extensions.doesThisOrParentHaveNoMedia +import com.simplemobiletools.commons.helpers.NOMEDIA import java.io.File import java.io.IOException diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt index 4b33ffecc..c7957b0bb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt @@ -97,7 +97,6 @@ const val SLIDESHOW_ANIMATION_NONE = 0 const val SLIDESHOW_ANIMATION_SLIDE = 1 const val SLIDESHOW_ANIMATION_FADE = 2 -const val NOMEDIA = ".nomedia" const val FAVORITES = "favorites" const val RECYCLE_BIN = "recycle_bin" const val SHOW_FAVORITES = "show_favorites"