From b6290c7c5ea6971e0b4b05d7c3b6e7dac45c973a Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 7 Aug 2017 22:24:07 +0200 Subject: [PATCH] add password protection for showing hidden items --- app/build.gradle | 2 +- .../filemanager/activities/MainActivity.kt | 13 +++++++- .../activities/SettingsActivity.kt | 32 +++++++++++++++++-- app/src/main/res/layout/activity_settings.xml | 20 ++++++++++++ 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c6b09cf5..26655df6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,7 +32,7 @@ android { } dependencies { - compile 'com.simplemobiletools:commons:2.22.7' + compile 'com.simplemobiletools:commons:2.25.3' 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/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt index 61fe405b..1a7948fe 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt @@ -184,8 +184,19 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br } private fun temporarilyShowHidden() { - config.temporarilyShowHidden = true + if (config.temporarilyShowHidden) { + toggleTemporarilyShowHidden(false) + } else { + handleHiddenFolderPasswordProtection { + toggleTemporarilyShowHidden(true) + } + } + } + + private fun toggleTemporarilyShowHidden(show: Boolean) { + config.temporarilyShowHidden = show openPath(currentPath) + invalidateOptionsMenu() } private fun launchAbout() { diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/SettingsActivity.kt index 9d7ae47d..0fc181b8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/SettingsActivity.kt @@ -2,7 +2,10 @@ package com.simplemobiletools.filemanager.activities import android.content.Intent import android.os.Bundle +import com.simplemobiletools.commons.dialogs.SecurityDialog +import com.simplemobiletools.commons.extensions.handleHiddenFolderPasswordProtection import com.simplemobiletools.commons.extensions.updateTextColors +import com.simplemobiletools.commons.helpers.SHOW_ALL_TABS import com.simplemobiletools.filemanager.R import com.simplemobiletools.filemanager.extensions.config import kotlinx.android.synthetic.main.activity_settings.* @@ -19,6 +22,7 @@ class SettingsActivity : SimpleActivity() { setupCustomizeColors() setupManageFavorites() setupShowHidden() + setupPasswordProtection() updateTextColors(settings_holder) } @@ -37,8 +41,32 @@ class SettingsActivity : SimpleActivity() { private fun setupShowHidden() { settings_show_hidden.isChecked = config.showHidden settings_show_hidden_holder.setOnClickListener { - settings_show_hidden.toggle() - config.showHidden = settings_show_hidden.isChecked + if (config.showHidden) { + toggleShowHidden() + } else { + handleHiddenFolderPasswordProtection { + toggleShowHidden() + } + } + } + } + + private fun toggleShowHidden() { + settings_show_hidden.toggle() + config.showHidden = settings_show_hidden.isChecked + } + + private fun setupPasswordProtection() { + settings_password_protection.isChecked = config.isPasswordProtectionOn + settings_password_protection_holder.setOnClickListener { + val tabToShow = if (config.isPasswordProtectionOn) config.protectionType else SHOW_ALL_TABS + SecurityDialog(this, config.passwordHash, tabToShow) { hash, type -> + val hasPasswordProtection = config.isPasswordProtectionOn + settings_password_protection.isChecked = !hasPasswordProtection + config.isPasswordProtectionOn = !hasPasswordProtection + config.passwordHash = if (hasPasswordProtection) "" else hash + config.protectionType = type + } } } } diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 2e7cfc55..abc1672b 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -68,5 +68,25 @@ android:text="@string/show_hidden"/> + + + + + +