From f6332b09c2578a3dcf544dadc77c724c8467b25a Mon Sep 17 00:00:00 2001 From: fatih ergin Date: Sun, 25 Jun 2023 13:59:13 +0300 Subject: [PATCH] fix: "shouldShowHidden" does not reflect changes on "showHidden || temporarilyShowHidden" due to its variable like definition on a singleton object --- .../filemanager/pro/activities/FavoritesActivity.kt | 2 +- .../filemanager/pro/activities/MainActivity.kt | 2 +- .../filemanager/pro/activities/MimeTypesActivity.kt | 6 +++--- .../filemanager/pro/activities/SaveAsActivity.kt | 4 ++-- .../filemanager/pro/adapters/ItemsAdapter.kt | 12 ++++++------ .../filemanager/pro/dialogs/CompressAsDialog.kt | 5 +++-- .../filemanager/pro/fragments/ItemsFragment.kt | 6 +++--- .../filemanager/pro/fragments/RecentsFragment.kt | 6 ++++-- .../filemanager/pro/fragments/StorageFragment.kt | 2 +- .../filemanager/pro/helpers/Config.kt | 2 +- .../filemanager/pro/helpers/RootHelpers.kt | 6 +++--- 11 files changed, 28 insertions(+), 25 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/FavoritesActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/FavoritesActivity.kt index 305c5ecc..911f06bc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/FavoritesActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/FavoritesActivity.kt @@ -65,7 +65,7 @@ class FavoritesActivity : SimpleActivity(), RefreshRecyclerViewListener { } private fun addFavorite() { - FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden, canAddShowHiddenButton = true) { + FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden(), canAddShowHiddenButton = true) { config.addFavorite(it) updateFavorites() } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt index fe56a0bc..590885db 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt @@ -188,7 +188,7 @@ class MainActivity : SimpleActivity() { findItem(R.id.go_home).isVisible = currentFragment is ItemsFragment && currentFragment.currentPath != config.homeFolder findItem(R.id.set_as_home).isVisible = currentFragment is ItemsFragment && currentFragment.currentPath != config.homeFolder - findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden && currentFragment !is StorageFragment + findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden() && currentFragment !is StorageFragment findItem(R.id.stop_showing_hidden).isVisible = config.temporarilyShowHidden && currentFragment !is StorageFragment findItem(R.id.column_count).isVisible = currentViewType == VIEW_TYPE_GRID && currentFragment !is StorageFragment diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt index 01ec57c8..a05b60fd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt @@ -29,7 +29,7 @@ import com.simplemobiletools.filemanager.pro.helpers.* import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener import com.simplemobiletools.filemanager.pro.models.ListItem import kotlinx.android.synthetic.main.activity_mimetypes.* -import java.util.* +import java.util.Locale class MimeTypesActivity : SimpleActivity(), ItemOperationsListener { private var isSearchOpen = false @@ -86,7 +86,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener { mimetypes_toolbar.menu.apply { findItem(R.id.toggle_filename).isVisible = currentViewType == VIEW_TYPE_GRID - findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden + findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden() findItem(R.id.stop_showing_hidden).isVisible = config.temporarilyShowHidden findItem(R.id.column_count).isVisible = currentViewType == VIEW_TYPE_GRID @@ -255,7 +255,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener { private fun getProperFileDirItems(callback: (ArrayList) -> Unit) { val fileDirItems = ArrayList() - val showHidden = config.shouldShowHidden + val showHidden = config.shouldShowHidden() val uri = MediaStore.Files.getContentUri("external") val projection = arrayOf( MediaStore.Files.FileColumns.MIME_TYPE, diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/SaveAsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/SaveAsActivity.kt index 4672bc2b..44d53f1e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/SaveAsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/SaveAsActivity.kt @@ -9,7 +9,7 @@ import com.simplemobiletools.commons.helpers.NavigationIcon import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.extensions.config -import kotlinx.android.synthetic.main.activity_save_as.* +import kotlinx.android.synthetic.main.activity_save_as.activity_save_as_toolbar import java.io.File class SaveAsActivity : SimpleActivity() { @@ -18,7 +18,7 @@ class SaveAsActivity : SimpleActivity() { setContentView(R.layout.activity_save_as) if (intent.action == Intent.ACTION_SEND && intent.extras?.containsKey(Intent.EXTRA_STREAM) == true) { - FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden, showFAB = true, showFavoritesButton = true) { + FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden(), showFAB = true, showFavoritesButton = true) { val destination = it handleSAFDialog(destination) { toast(R.string.saving) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt index 9bc7df7f..ef24564b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt @@ -249,10 +249,10 @@ class ItemsAdapter( private fun showProperties() { if (selectedKeys.size <= 1) { - PropertiesDialog(activity, getFirstSelectedItemPath(), config.shouldShowHidden) + PropertiesDialog(activity, getFirstSelectedItemPath(), config.shouldShowHidden()) } else { val paths = getSelectedFileDirItems().map { it.path } - PropertiesDialog(activity, paths, config.shouldShowHidden) + PropertiesDialog(activity, paths, config.shouldShowHidden()) } } @@ -340,7 +340,7 @@ class ItemsAdapter( @SuppressLint("NewApi") private fun addFileUris(path: String, paths: ArrayList) { if (activity.getIsPathDirectory(path)) { - val shouldShowHidden = config.shouldShowHidden + val shouldShowHidden = config.shouldShowHidden() when { activity.isRestrictedSAFOnlyRoot(path) -> { activity.getAndroidSAFFileItems(path, shouldShowHidden, false) { files -> @@ -407,9 +407,9 @@ class ItemsAdapter( val source = firstFile.getParentPath() FilePickerDialog( activity, - activity.getDefaultCopyDestinationPath(config.shouldShowHidden, source), + activity.getDefaultCopyDestinationPath(config.shouldShowHidden(), source), false, - config.shouldShowHidden, + config.shouldShowHidden(), true, true, showFavoritesButton = true @@ -418,7 +418,7 @@ class ItemsAdapter( if (activity.isPathOnRoot(it) || activity.isPathOnRoot(firstFile.path)) { copyMoveRootItems(files, it, isCopyOperation) } else { - activity.copyMoveFilesTo(files, source, it, isCopyOperation, false, config.shouldShowHidden) { + activity.copyMoveFilesTo(files, source, it, isCopyOperation, false, config.shouldShowHidden()) { if (!isCopyOperation) { files.forEach { sourceFileDir -> val sourcePath = sourceFileDir.path diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/CompressAsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/CompressAsDialog.kt index dfc37ae4..29ab70de 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/CompressAsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/CompressAsDialog.kt @@ -7,7 +7,8 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.extensions.config -import kotlinx.android.synthetic.main.dialog_compress_as.view.* +import kotlinx.android.synthetic.main.dialog_compress_as.view.filename_value +import kotlinx.android.synthetic.main.dialog_compress_as.view.folder class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val callback: (destination: String) -> Unit) { private val view = activity.layoutInflater.inflate(R.layout.dialog_compress_as, null) @@ -23,7 +24,7 @@ class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val c folder.setText(activity.humanizePath(realPath)) folder.setOnClickListener { - FilePickerDialog(activity, realPath, false, activity.config.shouldShowHidden, true, true, showFavoritesButton = true) { + FilePickerDialog(activity, realPath, false, activity.config.shouldShowHidden(), true, true, showFavoritesButton = true) { folder.setText(activity.humanizePath(it)) realPath = it } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt index 076804a7..caa8492b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt @@ -99,7 +99,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF scrollStates[currentPath] = getScrollState()!! currentPath = realPath - showHidden = context!!.config.shouldShowHidden + showHidden = context!!.config.shouldShowHidden() showProgressBar() getItems(currentPath) { originalPath, listItems -> if (currentPath != originalPath) { @@ -180,13 +180,13 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF return@handleAndroidSAFDialog } val getProperChildCount = context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_LIST - context.getAndroidSAFFileItems(path, context.config.shouldShowHidden, getProperChildCount) { fileItems -> + context.getAndroidSAFFileItems(path, context.config.shouldShowHidden(), getProperChildCount) { fileItems -> callback(path, getListItemsFromFileDirItems(fileItems)) } } } else if (context!!.isPathOnOTG(path) && config.OTGTreeUri.isNotEmpty()) { val getProperFileSize = context!!.config.getFolderSorting(currentPath) and SORT_BY_SIZE != 0 - context!!.getOTGItems(path, config.shouldShowHidden, getProperFileSize) { + context!!.getOTGItems(path, config.shouldShowHidden(), getProperFileSize) { callback(path, getListItemsFromFileDirItems(it)) } } else if (!config.enableRootAccess || !context!!.isPathOnRoot(path)) { diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt index b6df2f30..5b9778fb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt @@ -21,7 +21,9 @@ import com.simplemobiletools.filemanager.pro.extensions.config import com.simplemobiletools.filemanager.pro.helpers.MAX_COLUMN_COUNT import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener import com.simplemobiletools.filemanager.pro.models.ListItem -import kotlinx.android.synthetic.main.recents_fragment.view.* +import kotlinx.android.synthetic.main.recents_fragment.view.recents_list +import kotlinx.android.synthetic.main.recents_fragment.view.recents_placeholder +import kotlinx.android.synthetic.main.recents_fragment.view.recents_swipe_refresh import java.io.File class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), ItemOperationsListener { @@ -134,7 +136,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage } private fun getRecents(callback: (recents: ArrayList) -> Unit) { - val showHidden = context?.config?.shouldShowHidden ?: return + val showHidden = context?.config?.shouldShowHidden() ?: return val listItems = arrayListOf() val uri = Files.getContentUri("external") diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt index 5cec5bd3..7ef6187b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt @@ -318,7 +318,7 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage private fun getAllFiles(): ArrayList { val fileDirItems = ArrayList() - val showHidden = context?.config?.shouldShowHidden ?: return fileDirItems + val showHidden = context?.config?.shouldShowHidden() ?: return fileDirItems val uri = MediaStore.Files.getContentUri("external") val projection = arrayOf( MediaStore.Files.FileColumns.DATA, diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Config.kt index 57f67961..7bb5e686 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Config.kt @@ -20,7 +20,7 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getBoolean(TEMPORARILY_SHOW_HIDDEN, false) set(temporarilyShowHidden) = prefs.edit().putBoolean(TEMPORARILY_SHOW_HIDDEN, temporarilyShowHidden).apply() - var shouldShowHidden = showHidden || temporarilyShowHidden + fun shouldShowHidden() = showHidden || temporarilyShowHidden var pressBackTwice: Boolean get() = prefs.getBoolean(PRESS_BACK_TWICE, true) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/RootHelpers.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/RootHelpers.kt index 7efc5a6e..87f84cc4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/RootHelpers.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/RootHelpers.kt @@ -36,7 +36,7 @@ class RootHelpers(val activity: Activity) { val fullLines = it val files = ArrayList() - val hiddenArgument = if (activity.config.shouldShowHidden) "-A " else "" + val hiddenArgument = if (activity.config.shouldShowHidden()) "-A " else "" val cmd = "ls $hiddenArgument$path" val command = object : Command(0, cmd) { @@ -66,7 +66,7 @@ class RootHelpers(val activity: Activity) { private fun getFullLines(path: String, callback: (ArrayList) -> Unit) { val fullLines = ArrayList() - val hiddenArgument = if (activity.config.shouldShowHidden) "-Al " else "-l " + val hiddenArgument = if (activity.config.shouldShowHidden()) "-Al " else "-l " val cmd = "ls $hiddenArgument$path" val command = object : Command(0, cmd) { @@ -85,7 +85,7 @@ class RootHelpers(val activity: Activity) { } private fun getChildrenCount(files: ArrayList, path: String, callback: (originalPath: String, listItems: ArrayList) -> Unit) { - val hiddenArgument = if (activity.config.shouldShowHidden) "-A " else "" + val hiddenArgument = if (activity.config.shouldShowHidden()) "-A " else "" var cmd = "" files.filter { it.isDirectory }.forEach { cmd += "ls $hiddenArgument${it.path} |wc -l;"