mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 14:37:59 +01:00
require the pattern for disabling password protection
This commit is contained in:
parent
fff519b521
commit
f039afaca6
20 changed files with 56 additions and 53 deletions
|
@ -144,16 +144,11 @@ class SettingsActivity : SimpleActivity() {
|
|||
private fun setupPasswordProtection() {
|
||||
settings_password_protection.isChecked = config.isPasswordProtectionOn
|
||||
settings_password_protection_holder.setOnClickListener {
|
||||
PatternDialog(this) {
|
||||
if (config.isPasswordProtectionOn) {
|
||||
settings_password_protection.isChecked = false
|
||||
config.isPasswordProtectionOn = false
|
||||
config.passwordHash = ""
|
||||
} else {
|
||||
settings_password_protection.isChecked = true
|
||||
config.isPasswordProtectionOn = true
|
||||
config.passwordHash = it
|
||||
}
|
||||
PatternDialog(this, config.passwordHash) {
|
||||
val hasPasswordProtection = config.isPasswordProtectionOn
|
||||
settings_password_protection.isChecked = !hasPasswordProtection
|
||||
config.isPasswordProtectionOn = !hasPasswordProtection
|
||||
config.passwordHash = if (hasPasswordProtection) "" else it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,39 +13,19 @@ import com.simplemobiletools.gallery.activities.SimpleActivity
|
|||
import com.simplemobiletools.gallery.extensions.config
|
||||
import kotlinx.android.synthetic.main.dialog_pattern.view.*
|
||||
|
||||
class PatternDialog(val activity: SimpleActivity, val callback: (hash: String) -> Unit) {
|
||||
class PatternDialog(val activity: SimpleActivity, val requiredHash: String, val callback: (hash: String) -> Unit) {
|
||||
var dialog: AlertDialog? = null
|
||||
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_pattern, null)
|
||||
|
||||
var hash = requiredHash
|
||||
|
||||
init {
|
||||
var hash = ""
|
||||
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_pattern, null)
|
||||
view.apply {
|
||||
pattern_lock_view.correctStateColor = activity.config.primaryColor
|
||||
pattern_lock_view.normalStateColor = activity.config.textColor
|
||||
pattern_lock_view.addPatternLockListener(object : PatternLockViewListener {
|
||||
override fun onComplete(pattern: MutableList<PatternLockView.Dot>?) {
|
||||
if (hash.isEmpty()) {
|
||||
hash = PatternLockUtils.patternToSha1(pattern_lock_view, pattern)
|
||||
pattern_lock_view.clearPattern()
|
||||
pattern_dialog_title.setText(R.string.repeat_pattern)
|
||||
} else {
|
||||
val newHash = PatternLockUtils.patternToSha1(pattern_lock_view, pattern)
|
||||
if (hash == newHash) {
|
||||
pattern_lock_view.setViewMode(PatternLockView.PatternViewMode.CORRECT)
|
||||
Handler().postDelayed({
|
||||
callback(hash)
|
||||
dialog!!.dismiss()
|
||||
}, 300)
|
||||
} else {
|
||||
pattern_lock_view.setViewMode(PatternLockView.PatternViewMode.WRONG)
|
||||
activity.toast(R.string.wrong_pattern)
|
||||
Handler().postDelayed({
|
||||
hash = ""
|
||||
pattern_lock_view.clearPattern()
|
||||
pattern_dialog_title.setText(R.string.select_pattern)
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
receivedHash(PatternLockUtils.patternToSha1(pattern_lock_view, pattern))
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
|
@ -65,4 +45,32 @@ class PatternDialog(val activity: SimpleActivity, val callback: (hash: String) -
|
|||
activity.setupDialogStuff(view, this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun receivedHash(newHash: String) {
|
||||
view.apply {
|
||||
if (hash.isEmpty()) {
|
||||
hash = newHash
|
||||
pattern_lock_view.clearPattern()
|
||||
pattern_dialog_title.setText(R.string.repeat_pattern)
|
||||
} else {
|
||||
if (hash == newHash) {
|
||||
pattern_lock_view.setViewMode(PatternLockView.PatternViewMode.CORRECT)
|
||||
Handler().postDelayed({
|
||||
callback(hash)
|
||||
dialog!!.dismiss()
|
||||
}, 300)
|
||||
} else {
|
||||
pattern_lock_view.setViewMode(PatternLockView.PatternViewMode.WRONG)
|
||||
activity.toast(R.string.wrong_pattern)
|
||||
Handler().postDelayed({
|
||||
pattern_lock_view.clearPattern()
|
||||
if (requiredHash.isEmpty()) {
|
||||
hash = ""
|
||||
pattern_dialog_title.setText(R.string.insert_pattern)
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:text="@string/select_pattern"/>
|
||||
android:text="@string/insert_pattern"/>
|
||||
|
||||
<com.andrognito.patternlockview.PatternLockView
|
||||
android:id="@+id/pattern_lock_view"
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="insert_pattern">Insert pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="insert_pattern">Insert pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="insert_pattern">Insert pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="insert_pattern">Insert pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="insert_pattern">Insert pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="insert_pattern">Insert pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="insert_pattern">Insert pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="insert_pattern">Insert pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="insert_pattern">Insert pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="insert_pattern">Insert pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="insert_pattern">Insert pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<string name="wrong_pin">Nesprávny PIN</string>
|
||||
<string name="repeat_pin">Zopakujte PIN</string>
|
||||
<string name="pattern">Vzor</string>
|
||||
<string name="select_pattern">Zvoľte vzor</string>
|
||||
<string name="insert_pattern">Zadajte vzor</string>
|
||||
<string name="wrong_pattern">Nesprávny vzor</string>
|
||||
<string name="repeat_pattern">Zopakujte vzor</string>
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="insert_pattern">Insert pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="insert_pattern">Insert pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="insert_pattern">Insert pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="insert_pattern">Insert pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="insert_pattern">Insert pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
Loading…
Reference in a new issue