protect toggling Show hidden media with the pattern when appropriate

This commit is contained in:
tibbi 2017-07-29 21:48:55 +02:00
parent f039afaca6
commit 2b518ec4f2
2 changed files with 24 additions and 2 deletions

View file

@ -9,6 +9,7 @@ import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.dialogs.PatternDialog import com.simplemobiletools.gallery.dialogs.PatternDialog
import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.extensions.handleHiddenFolderPasswordProtection
import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.helpers.*
import kotlinx.android.synthetic.main.activity_settings.* import kotlinx.android.synthetic.main.activity_settings.*
@ -64,11 +65,21 @@ class SettingsActivity : SimpleActivity() {
private fun setupShowHiddenFolders() { private fun setupShowHiddenFolders() {
settings_show_hidden_folders.isChecked = config.showHiddenMedia settings_show_hidden_folders.isChecked = config.showHiddenMedia
settings_show_hidden_folders_holder.setOnClickListener { settings_show_hidden_folders_holder.setOnClickListener {
settings_show_hidden_folders.toggle() if (config.showHiddenMedia) {
config.showHiddenMedia = settings_show_hidden_folders.isChecked toggleHiddenFolders()
} else {
handleHiddenFolderPasswordProtection {
toggleHiddenFolders()
}
}
} }
} }
private fun toggleHiddenFolders() {
settings_show_hidden_folders.toggle()
config.showHiddenMedia = settings_show_hidden_folders.isChecked
}
private fun setupAutoplayVideos() { private fun setupAutoplayVideos() {
settings_autoplay_videos.isChecked = config.autoplayVideos settings_autoplay_videos.isChecked = config.autoplayVideos
settings_autoplay_videos_holder.setOnClickListener { settings_autoplay_videos_holder.setOnClickListener {

View file

@ -24,6 +24,7 @@ import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.gallery.BuildConfig import com.simplemobiletools.gallery.BuildConfig
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.activities.SimpleActivity
import com.simplemobiletools.gallery.dialogs.PatternDialog
import com.simplemobiletools.gallery.helpers.NOMEDIA import com.simplemobiletools.gallery.helpers.NOMEDIA
import com.simplemobiletools.gallery.helpers.REQUEST_EDIT_IMAGE import com.simplemobiletools.gallery.helpers.REQUEST_EDIT_IMAGE
import com.simplemobiletools.gallery.helpers.REQUEST_SET_AS import com.simplemobiletools.gallery.helpers.REQUEST_SET_AS
@ -332,6 +333,16 @@ fun Activity.loadStaticGif(path: String, target: MySquareImageView) {
builder.apply(options).into(target) builder.apply(options).into(target)
} }
fun SimpleActivity.handleHiddenFolderPasswordProtection(callback: () -> Unit) {
if (config.isPasswordProtectionOn) {
PatternDialog(this, config.passwordHash) {
callback()
}
} else {
callback()
}
}
fun Activity.getCachedDirectories(): ArrayList<Directory> { fun Activity.getCachedDirectories(): ArrayList<Directory> {
val token = object : TypeToken<List<Directory>>() {}.type val token = object : TypeToken<List<Directory>>() {}.type
return Gson().fromJson<ArrayList<Directory>>(config.directories, token) ?: ArrayList<Directory>(1) return Gson().fromJson<ArrayList<Directory>>(config.directories, token) ?: ArrayList<Directory>(1)