From 419c1f501b87112aec913fd2d253992797848542 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 21 Jun 2017 23:16:23 +0200 Subject: [PATCH] add a menu button for temporarily showing hidden items --- app/build.gradle | 2 +- .../com/simplemobiletools/filemanager/Config.kt | 6 ++++++ .../com/simplemobiletools/filemanager/Constants.kt | 1 + .../filemanager/activities/FavoritesActivity.kt | 2 +- .../filemanager/activities/MainActivity.kt | 12 ++++++++++++ .../filemanager/adapters/ItemsAdapter.kt | 8 ++++---- .../filemanager/fragments/ItemsFragment.kt | 4 ++-- app/src/main/res/menu/menu.xml | 4 ++++ 8 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 960217b4..fdc77062 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,7 +32,7 @@ android { } dependencies { - compile 'com.simplemobiletools:commons:2.21.10' + compile 'com.simplemobiletools:commons:2.21.11' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/Config.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/Config.kt index c4747aa9..eaedfafc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/Config.kt @@ -16,6 +16,12 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getBoolean(SHOW_HIDDEN, false) set(show) = prefs.edit().putBoolean(SHOW_HIDDEN, show).apply() + var temporarilyShowHidden: Boolean + get() = prefs.getBoolean(TEMPORARILY_SHOW_HIDDEN, false) + set(temporarilyShowHidden) = prefs.edit().putBoolean(TEMPORARILY_SHOW_HIDDEN, temporarilyShowHidden).apply() + + var shouldShowHidden = showHidden || temporarilyShowHidden + var homeFolder: String get(): String { var home = prefs.getString(HOME_FOLDER, "") diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/Constants.kt index 36675e9c..097c9bd8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/Constants.kt @@ -9,3 +9,4 @@ val HOME_FOLDER = "home_folder" val FAVORITES = "favorites" val SORT_ORDER = "sort_order" val SORT_FOLDER_PREFIX = "sort_folder_" +val TEMPORARILY_SHOW_HIDDEN = "temporarily_show_hidden" diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/FavoritesActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/FavoritesActivity.kt index 98aab317..adff3d4c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/FavoritesActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/FavoritesActivity.kt @@ -56,7 +56,7 @@ class FavoritesActivity : SimpleActivity() { } private fun addFavorite() { - FilePickerDialog(this, pickFile = false, showHidden = config.showHidden) { + FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden) { config.addFavorite(it) updateFavorites() } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt index 5f367a0f..5b1d657b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt @@ -66,6 +66,11 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br mStoredTextColor = config.textColor } + override fun onDestroy() { + super.onDestroy() + config.temporarilyShowHidden = false + } + private fun tryInitFileManager() { if (hasWriteStoragePermission()) { initRootFileManager() @@ -109,6 +114,7 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br findItem(R.id.add_favorite).isVisible = !favorites.contains(currentPath) findItem(R.id.remove_favorite).isVisible = favorites.contains(currentPath) findItem(R.id.go_to_favorite).isVisible = favorites.isNotEmpty() + menu.findItem(R.id.temporarily_show_hidden).isVisible = !config.showHidden } return true @@ -122,6 +128,7 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br R.id.remove_favorite -> removeFavorite() R.id.go_to_favorite -> goToFavorite() R.id.set_as_home -> setAsHome() + R.id.temporarily_show_hidden -> temporarilyShowHidden() R.id.settings -> startActivity(Intent(this, SettingsActivity::class.java)) R.id.about -> launchAbout() else -> return super.onOptionsItemSelected(item) @@ -176,6 +183,11 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br toast(R.string.home_folder_updated) } + private fun temporarilyShowHidden() { + config.temporarilyShowHidden = true + openPath(currentPath) + } + private fun launchAbout() { startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_MULTISELECT, BuildConfig.VERSION_NAME) } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt index 4418ea14..48e1eb2c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt @@ -125,11 +125,11 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList() selectedPositions.forEach { paths.add(mItems[it].path) } - PropertiesDialog(activity, paths, config.showHidden) + PropertiesDialog(activity, paths, config.shouldShowHidden) } } @@ -157,7 +157,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList) { if (file.isDirectory) { - file.listFiles()?.filter { if (config.showHidden) true else !it.isHidden }?.forEach { + file.listFiles()?.filter { if (config.shouldShowHidden) true else !it.isHidden }?.forEach { addFileUris(it, uris) } } else { @@ -183,7 +183,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList +