From 51f07c9fa61a1f6637069d3b4c03c990605ee68d Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 2 Aug 2017 22:14:05 +0200 Subject: [PATCH] store the protection type too, pattern/pin --- .../gallery/activities/SettingsActivity.kt | 5 +++-- .../com/simplemobiletools/gallery/dialogs/SecurityDialog.kt | 6 +++--- .../com/simplemobiletools/gallery/extensions/activity.kt | 2 +- .../kotlin/com/simplemobiletools/gallery/helpers/Config.kt | 4 ++++ .../com/simplemobiletools/gallery/helpers/Constants.kt | 6 ++++++ .../simplemobiletools/gallery/interfaces/HashListener.kt | 2 +- .../com/simplemobiletools/gallery/views/PatternTab.kt | 3 ++- .../kotlin/com/simplemobiletools/gallery/views/PinTab.kt | 3 ++- 8 files changed, 22 insertions(+), 9 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 4e26b5f8b..c7da656d8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt @@ -155,11 +155,12 @@ class SettingsActivity : SimpleActivity() { private fun setupPasswordProtection() { settings_password_protection.isChecked = config.isPasswordProtectionOn settings_password_protection_holder.setOnClickListener { - SecurityDialog(this, config.passwordHash) { + SecurityDialog(this, config.passwordHash) { hash, type -> val hasPasswordProtection = config.isPasswordProtectionOn settings_password_protection.isChecked = !hasPasswordProtection config.isPasswordProtectionOn = !hasPasswordProtection - config.passwordHash = if (hasPasswordProtection) "" else it + config.passwordHash = if (hasPasswordProtection) "" else hash + config.protectionType = PROTECTION_PATTERN } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SecurityDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SecurityDialog.kt index 1f9cbd59c..f6a6a6b15 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SecurityDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SecurityDialog.kt @@ -13,7 +13,7 @@ import com.simplemobiletools.gallery.interfaces.HashListener import com.simplemobiletools.gallery.views.MyDialogViewPager import kotlinx.android.synthetic.main.dialog_security.view.* -class SecurityDialog(val activity: SimpleActivity, val requiredHash: String, val callback: (hash: String) -> Unit) : HashListener { +class SecurityDialog(val activity: SimpleActivity, val requiredHash: String, val callback: (hash: String, type: Int) -> Unit) : HashListener { var dialog: AlertDialog? = null val view = LayoutInflater.from(activity).inflate(R.layout.dialog_security, null) @@ -60,8 +60,8 @@ class SecurityDialog(val activity: SimpleActivity, val requiredHash: String, val } } - override fun receivedHash(hash: String) { - callback(hash) + override fun receivedHash(hash: String, type: Int) { + callback(hash, type) dialog!!.dismiss() } } 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 fa035db0e..cc914d82e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -335,7 +335,7 @@ fun Activity.loadStaticGif(path: String, target: MySquareImageView) { fun SimpleActivity.handleHiddenFolderPasswordProtection(callback: () -> Unit) { if (config.isPasswordProtectionOn) { - SecurityDialog(this, config.passwordHash) { + SecurityDialog(this, config.passwordHash) { hash, type -> callback() } } else { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index d02c78187..89037e81b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -240,4 +240,8 @@ class Config(context: Context) : BaseConfig(context) { var passwordHash: String get() = prefs.getString(PASSWORD_HASH, "") set(passwordHash) = prefs.edit().putString(PASSWORD_HASH, passwordHash).apply() + + var protectionType: Int + get() = prefs.getInt(PROTECTION_TYPE, PROTECTION_PATTERN) + set(protectionType) = prefs.edit().putInt(PROTECTION_TYPE, protectionType).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index 01d829cc2..0dbfbbf1f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -35,6 +35,7 @@ val HIDE_SYSTEM_UI = "hide_system_ui" val REPLACE_SHARE_WITH_ROTATE = "replace_share_with_rotate" val IS_PASSWORD_PROTECTION = "password_protection" val PASSWORD_HASH = "password_hash" +val PROTECTION_TYPE = "protection_type" val NOMEDIA = ".nomedia" @@ -64,3 +65,8 @@ val ORIENT_PORTRAIT = 0 val ORIENT_LANDSCAPE_LEFT = 1 val ORIENT_LANDSCAPE_RIGHT = 2 val ORIENT_UPSIDE_DOWN = 3 + +// security +val PROTECTION_PATTERN = 1 +val PROTECTION_PIN = 2 +val PROTECTION_FINGERPRINT = 3 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/HashListener.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/HashListener.kt index e8145070c..2549eb4db 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/HashListener.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/HashListener.kt @@ -1,5 +1,5 @@ package com.simplemobiletools.gallery.interfaces interface HashListener { - fun receivedHash(hash: String) + fun receivedHash(hash: String, type: Int) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/views/PatternTab.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/views/PatternTab.kt index 0ca2b3aab..9200f797e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/views/PatternTab.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/views/PatternTab.kt @@ -11,6 +11,7 @@ import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.updateTextColors import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.helpers.PROTECTION_PATTERN import com.simplemobiletools.gallery.interfaces.HashListener import com.simplemobiletools.gallery.interfaces.SecurityTab import kotlinx.android.synthetic.main.tab_pattern.view.* @@ -56,7 +57,7 @@ class PatternTab(context: Context, attrs: AttributeSet) : RelativeLayout(context } else if (hash == newHash) { pattern_lock_view.setViewMode(PatternLockView.PatternViewMode.CORRECT) Handler().postDelayed({ - hashListener.receivedHash(hash) + hashListener.receivedHash(hash, PROTECTION_PATTERN) }, 300) } else { pattern_lock_view.setViewMode(PatternLockView.PatternViewMode.WRONG) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/views/PinTab.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/views/PinTab.kt index a7b7a24f2..68614824d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/views/PinTab.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/views/PinTab.kt @@ -6,6 +6,7 @@ import android.widget.RelativeLayout import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.updateTextColors import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.helpers.PROTECTION_PIN import com.simplemobiletools.gallery.interfaces.HashListener import com.simplemobiletools.gallery.interfaces.SecurityTab import kotlinx.android.synthetic.main.tab_pin.view.* @@ -66,7 +67,7 @@ class PinTab(context: Context, attrs: AttributeSet) : RelativeLayout(context, at resetPin() pin_lock_title.setText(R.string.repeat_pin) } else if (hash == newHash) { - hashListener.receivedHash(hash) + hashListener.receivedHash(hash, PROTECTION_PIN) } else { resetPin() context.toast(R.string.wrong_pin)