mirror of
https://github.com/mihonapp/mihon.git
synced 2025-07-01 13:37:50 +02:00
Add option to disable auto lock and add manual locking
This commit is contained in:
@ -34,7 +34,7 @@ class FingerLockPreference @JvmOverloads constructor(context: Context, attrs: At
|
||||
|
||||
val useFingerprint
|
||||
get() = fingerprintSupported
|
||||
&& prefs.lockUseFingerprint().getOrDefault()
|
||||
&& prefs.eh_lockUseFingerprint().getOrDefault()
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
override fun onAttached() {
|
||||
@ -45,7 +45,7 @@ class FingerLockPreference @JvmOverloads constructor(context: Context, attrs: At
|
||||
if(it as Boolean)
|
||||
tryChange()
|
||||
else
|
||||
prefs.lockUseFingerprint().set(false)
|
||||
prefs.eh_lockUseFingerprint().set(false)
|
||||
!it
|
||||
}
|
||||
} else {
|
||||
@ -121,7 +121,7 @@ class FingerLockPreference @JvmOverloads constructor(context: Context, attrs: At
|
||||
when (result.status) {
|
||||
AuthenticationResult.Status.SUCCESS -> {
|
||||
iconView.setState(SwirlView.State.ON)
|
||||
prefs.lockUseFingerprint().set(true)
|
||||
prefs.eh_lockUseFingerprint().set(true)
|
||||
dialog.dismiss()
|
||||
updateSummary()
|
||||
}
|
||||
|
@ -41,12 +41,12 @@ class LockController : NucleusController<LockPresenter>() {
|
||||
//Setup pin lock
|
||||
pin_lock_view.attachIndicatorDots(indicator_dots)
|
||||
|
||||
pin_lock_view.pinLength = prefs.lockLength().getOrDefault()
|
||||
pin_lock_view.pinLength = prefs.eh_lockLength().getOrDefault()
|
||||
pin_lock_view.setPinLockListener(object : PinLockListener {
|
||||
override fun onEmpty() {}
|
||||
|
||||
override fun onComplete(pin: String) {
|
||||
if (sha512(pin, prefs.lockSalt().get()!!) == prefs.lockHash().get()) {
|
||||
if (sha512(pin, prefs.eh_lockSalt().get()!!) == prefs.eh_lockHash().get()) {
|
||||
//Yay!
|
||||
closeLock()
|
||||
} else {
|
||||
@ -120,7 +120,7 @@ class LockController : NucleusController<LockPresenter>() {
|
||||
|
||||
private fun resolvColor(color: Int): Int {
|
||||
val typedVal = TypedValue()
|
||||
activity!!.theme!!.resolveAttribute(android.R.attr.windowBackground, typedVal, true)
|
||||
activity!!.theme!!.resolveAttribute(color, typedVal, true)
|
||||
return typedVal.data
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
package exh.ui.lock
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v7.preference.Preference
|
||||
import android.support.v7.preference.SwitchPreference
|
||||
import android.support.v7.preference.SwitchPreferenceCompat
|
||||
import android.text.InputType
|
||||
import android.util.AttributeSet
|
||||
@ -87,8 +85,8 @@ class LockPreference @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
hash = sha512(password, salt)
|
||||
length = password.length
|
||||
}
|
||||
prefs.lockSalt().set(salt)
|
||||
prefs.lockHash().set(hash)
|
||||
prefs.lockLength().set(length)
|
||||
prefs.eh_lockSalt().set(salt)
|
||||
prefs.eh_lockHash().set(hash)
|
||||
prefs.eh_lockLength().set(length)
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,6 @@ class LockPresenter: BasePresenter<LockController>() {
|
||||
get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||
&& Reprint.isHardwarePresent()
|
||||
&& Reprint.hasFingerprintRegistered()
|
||||
&& prefs.lockUseFingerprint().getOrDefault()
|
||||
&& prefs.eh_lockUseFingerprint().getOrDefault()
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package exh.ui.lock
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.app.Activity
|
||||
import android.app.AppOpsManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
@ -40,17 +39,20 @@ fun sha512(passwordToHash: String, salt: String): String {
|
||||
* Check if lock is enabled
|
||||
*/
|
||||
fun lockEnabled(prefs: PreferencesHelper = Injekt.get())
|
||||
= prefs.lockHash().get() != null
|
||||
&& prefs.lockSalt().get() != null
|
||||
&& prefs.lockLength().getOrDefault() != -1
|
||||
= prefs.eh_lockHash().get() != null
|
||||
&& prefs.eh_lockSalt().get() != null
|
||||
&& prefs.eh_lockLength().getOrDefault() != -1
|
||||
|
||||
/**
|
||||
* Check if the lock will function properly
|
||||
*
|
||||
* @return true if action is required, false if lock is working properly
|
||||
*/
|
||||
fun notifyLockSecurity(context: Context): Boolean {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !hasAccessToUsageStats(context)) {
|
||||
fun notifyLockSecurity(context: Context,
|
||||
prefs: PreferencesHelper = Injekt.get()): Boolean {
|
||||
if (!prefs.eh_lockManually().getOrDefault()
|
||||
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
|
||||
&& !hasAccessToUsageStats(context)) {
|
||||
MaterialDialog.Builder(context)
|
||||
.title("Permission required")
|
||||
.content("${context.getString(R.string.app_name)} requires the usage stats permission to detect when you leave the app. " +
|
||||
|
Reference in New Issue
Block a user