mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 14:37:59 +01:00
store the protection type too, pattern/pin
This commit is contained in:
parent
f0ace2f57d
commit
51f07c9fa6
8 changed files with 22 additions and 9 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package com.simplemobiletools.gallery.interfaces
|
||||
|
||||
interface HashListener {
|
||||
fun receivedHash(hash: String)
|
||||
fun receivedHash(hash: String, type: Int)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue