From 2b518ec4f2ffbd834edeb9a0c9f9e36cb4bc62d8 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 29 Jul 2017 21:48:55 +0200 Subject: [PATCH] protect toggling Show hidden media with the pattern when appropriate --- .../gallery/activities/SettingsActivity.kt | 15 +++++++++++++-- .../gallery/extensions/activity.kt | 11 +++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt index 714f146fa..115ce1bd6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt @@ -9,6 +9,7 @@ import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.dialogs.PatternDialog import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.extensions.handleHiddenFolderPasswordProtection import com.simplemobiletools.gallery.helpers.* import kotlinx.android.synthetic.main.activity_settings.* @@ -64,11 +65,21 @@ class SettingsActivity : SimpleActivity() { private fun setupShowHiddenFolders() { settings_show_hidden_folders.isChecked = config.showHiddenMedia settings_show_hidden_folders_holder.setOnClickListener { - settings_show_hidden_folders.toggle() - config.showHiddenMedia = settings_show_hidden_folders.isChecked + if (config.showHiddenMedia) { + toggleHiddenFolders() + } else { + handleHiddenFolderPasswordProtection { + toggleHiddenFolders() + } + } } } + private fun toggleHiddenFolders() { + settings_show_hidden_folders.toggle() + config.showHiddenMedia = settings_show_hidden_folders.isChecked + } + private fun setupAutoplayVideos() { settings_autoplay_videos.isChecked = config.autoplayVideos settings_autoplay_videos_holder.setOnClickListener { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt index 451e2bdff..dabe6ae16 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -24,6 +24,7 @@ import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.gallery.BuildConfig import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity +import com.simplemobiletools.gallery.dialogs.PatternDialog import com.simplemobiletools.gallery.helpers.NOMEDIA import com.simplemobiletools.gallery.helpers.REQUEST_EDIT_IMAGE import com.simplemobiletools.gallery.helpers.REQUEST_SET_AS @@ -332,6 +333,16 @@ fun Activity.loadStaticGif(path: String, target: MySquareImageView) { builder.apply(options).into(target) } +fun SimpleActivity.handleHiddenFolderPasswordProtection(callback: () -> Unit) { + if (config.isPasswordProtectionOn) { + PatternDialog(this, config.passwordHash) { + callback() + } + } else { + callback() + } +} + fun Activity.getCachedDirectories(): ArrayList { val token = object : TypeToken>() {}.type return Gson().fromJson>(config.directories, token) ?: ArrayList(1)