diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index efa20b264..231b28dca 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -325,8 +325,8 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { R.id.change_view_type -> changeViewType() R.id.temporarily_show_hidden -> tryToggleTemporarilyShowHidden() R.id.stop_showing_hidden -> tryToggleTemporarilyShowHidden() - R.id.temporarily_show_excluded -> toggleTemporarilyShowExcluded(true) - R.id.stop_showing_excluded -> toggleTemporarilyShowExcluded(false) + R.id.temporarily_show_excluded -> tryToggleTemporarilyShowExcluded() + R.id.stop_showing_excluded -> tryToggleTemporarilyShowExcluded() R.id.create_new_folder -> createNewFolder() R.id.show_the_recycle_bin -> toggleRecycleBin(true) R.id.hide_the_recycle_bin -> toggleRecycleBin(false) @@ -577,6 +577,16 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { invalidateOptionsMenu() } + private fun tryToggleTemporarilyShowExcluded() { + if (config.temporarilyShowExcluded) { + toggleTemporarilyShowExcluded(false) + } else { + handleExcludedFolderPasswordProtection { + toggleTemporarilyShowExcluded(true) + } + } + } + private fun toggleTemporarilyShowExcluded(show: Boolean) { mLoadedInitialPhotos = false config.temporarilyShowExcluded = show diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt index 4a58c263f..7418d9764 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt @@ -58,6 +58,7 @@ class SettingsActivity : SimpleActivity() { setupScreenRotation() setupHideSystemUI() setupHiddenItemPasswordProtection() + setupExcludedItemPasswordProtection() setupAppPasswordProtection() setupFileDeletionPasswordProtection() setupDeleteEmptyFolders() @@ -201,7 +202,9 @@ class SettingsActivity : SimpleActivity() { private fun setupManageExcludedFolders() { settings_manage_excluded_folders_holder.setOnClickListener { - startActivity(Intent(this, ExcludedFoldersActivity::class.java)) + handleExcludedFolderPasswordProtection { + startActivity(Intent(this, ExcludedFoldersActivity::class.java)) + } } } @@ -337,6 +340,29 @@ class SettingsActivity : SimpleActivity() { } } + private fun setupExcludedItemPasswordProtection() { + settings_excluded_item_password_protection_holder.beGoneIf(settings_hidden_item_password_protection_holder.isVisible()) + settings_excluded_item_password_protection.isChecked = config.isExcludedPasswordProtectionOn + settings_excluded_item_password_protection_holder.setOnClickListener { + val tabToShow = if (config.isExcludedPasswordProtectionOn) config.excludedProtectionType else SHOW_ALL_TABS + SecurityDialog(this, config.excludedPasswordHash, tabToShow) { hash, type, success -> + if (success) { + val hasPasswordProtection = config.isExcludedPasswordProtectionOn + settings_excluded_item_password_protection.isChecked = !hasPasswordProtection + config.isExcludedPasswordProtectionOn = !hasPasswordProtection + config.excludedPasswordHash = if (hasPasswordProtection) "" else hash + config.excludedProtectionType = type + + if (config.isExcludedPasswordProtectionOn) { + val confirmationTextId = if (config.excludedProtectionType == PROTECTION_FINGERPRINT) + R.string.fingerprint_setup_successfully else R.string.protection_setup_successfully + ConfirmationDialog(this, "", confirmationTextId, R.string.ok, 0) { } + } + } + } + } + } + private fun setupAppPasswordProtection() { settings_app_password_protection.isChecked = config.isAppPasswordProtectionOn settings_app_password_protection_holder.setOnClickListener { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt index 1796690d0..c6e42e07e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt @@ -28,6 +28,7 @@ import com.bumptech.glide.request.RequestOptions import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog import com.simplemobiletools.commons.dialogs.ConfirmationDialog +import com.simplemobiletools.commons.dialogs.SecurityDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.models.FAQItem @@ -775,3 +776,15 @@ fun Activity.showFileOnMap(path: String) { toast(R.string.unknown_location) } } + +fun Activity.handleExcludedFolderPasswordProtection(callback: () -> Unit) { + if (config.isExcludedPasswordProtectionOn) { + SecurityDialog(this, config.excludedPasswordHash, config.excludedProtectionType) { _, _, success -> + if (success) { + callback() + } + } + } else { + callback() + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt index e82ed3838..a199602cd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt @@ -5,10 +5,7 @@ import android.content.res.Configuration import android.os.Environment import com.google.gson.Gson import com.google.gson.reflect.TypeToken -import com.simplemobiletools.commons.helpers.BaseConfig -import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED -import com.simplemobiletools.commons.helpers.SORT_DESCENDING -import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID +import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.models.AlbumCover import java.util.* @@ -125,6 +122,18 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getStringSet(EXCLUDED_FOLDERS, HashSet())!! set(excludedFolders) = prefs.edit().remove(EXCLUDED_FOLDERS).putStringSet(EXCLUDED_FOLDERS, excludedFolders).apply() + var isExcludedPasswordProtectionOn: Boolean + get() = prefs.getBoolean(EXCLUDED_PASSWORD_PROTECTION, false) + set(isExcludedPasswordProtectionOn) = prefs.edit().putBoolean(EXCLUDED_PASSWORD_PROTECTION, isExcludedPasswordProtectionOn).apply() + + var excludedPasswordHash: String + get() = prefs.getString(EXCLUDED_PASSWORD_HASH, "")!! + set(excludedPasswordHash) = prefs.edit().putString(EXCLUDED_PASSWORD_HASH, excludedPasswordHash).apply() + + var excludedProtectionType: Int + get() = prefs.getInt(EXCLUDED_PROTECTION_TYPE, PROTECTION_PATTERN) + set(excludedProtectionType) = prefs.edit().putInt(EXCLUDED_PROTECTION_TYPE, excludedProtectionType).apply() + fun addIncludedFolder(path: String) { val currIncludedFolders = HashSet(includedFolders) currIncludedFolders.add(path) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt index 276fe07dc..626de068b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt @@ -10,6 +10,9 @@ const val VIEW_TYPE_PREFIX = "view_type_folder_" const val SHOW_HIDDEN_MEDIA = "show_hidden_media" const val TEMPORARILY_SHOW_HIDDEN = "temporarily_show_hidden" const val TEMPORARILY_SHOW_EXCLUDED = "temporarily_show_excluded" +const val EXCLUDED_PASSWORD_PROTECTION = "excluded_password_protection" +const val EXCLUDED_PASSWORD_HASH = "excluded_password_hash" +const val EXCLUDED_PROTECTION_TYPE = "excluded_protection_type" const val IS_THIRD_PARTY_INTENT = "is_third_party_intent" const val AUTOPLAY_VIDEOS = "autoplay_videos" const val REMEMBER_LAST_VIDEO_POSITION = "remember_last_video_position" diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 656f5948f..9859795e2 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -738,6 +738,22 @@ + + + + + +