Add biometric lock days, fix biometric time range
This commit is contained in:
parent
114ba42af7
commit
8387492a9b
@ -359,6 +359,8 @@ object PreferenceKeys {
|
||||
|
||||
const val authenticatorTimeRanges = "biometric_time_ranges"
|
||||
|
||||
const val authenticatorDays = "biometric_days"
|
||||
|
||||
const val sortTagsForLibrary = "sort_tags_for_library"
|
||||
|
||||
const val dontDeleteFromCategories = "dont_delete_from_categories"
|
||||
|
@ -474,6 +474,8 @@ class PreferencesHelper(val context: Context) {
|
||||
|
||||
fun authenticatorTimeRanges() = flowPrefs.getStringSet(Keys.authenticatorTimeRanges, mutableSetOf())
|
||||
|
||||
fun authenticatorDays() = flowPrefs.getInt(Keys.authenticatorDays, 0x7F)
|
||||
|
||||
fun sortTagsForLibrary() = flowPrefs.getStringSet(Keys.sortTagsForLibrary, mutableSetOf())
|
||||
|
||||
fun dontDeleteFromCategories() = flowPrefs.getStringSet(Keys.dontDeleteFromCategories, emptySet())
|
||||
|
@ -8,7 +8,7 @@ import java.util.Date
|
||||
import java.util.SimpleTimeZone
|
||||
import kotlin.time.Duration
|
||||
|
||||
data class TimeRange(val startTime: Duration, val endTime: Duration) {
|
||||
data class TimeRange(private val startTime: Duration, private val endTime: Duration) {
|
||||
override fun toString(): String {
|
||||
val startHour = startTime.inWholeHours
|
||||
val startMinute = (startTime - startHour.hours).inWholeMinutes
|
||||
@ -34,6 +34,10 @@ data class TimeRange(val startTime: Duration, val endTime: Duration) {
|
||||
return startTime in other.startTime..other.endTime || endTime in other.startTime..other.endTime
|
||||
}
|
||||
|
||||
operator fun contains(other: Duration): Boolean {
|
||||
return other in startTime..endTime
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun fromPreferenceString(timeRange: String): TimeRange? {
|
||||
return timeRange.split(",").mapNotNull { it.toDoubleOrNull() }.let {
|
||||
|
@ -52,18 +52,48 @@ class SecureActivityDelegate(private val activity: FragmentActivity) {
|
||||
return false
|
||||
}
|
||||
|
||||
return preferences.lockAppAfter().get() <= 0 ||
|
||||
Date().time >= preferences.lastAppUnlock().get() + 60 * 1000 * preferences.lockAppAfter().get() &&
|
||||
preferences.authenticatorTimeRanges().get().mapNotNull { TimeRange.fromPreferenceString(it) }.let { timeRanges ->
|
||||
if (timeRanges.isNotEmpty()) {
|
||||
val today: Calendar = Calendar.getInstance()
|
||||
val now = today.get(Calendar.HOUR_OF_DAY).hours + today.get(Calendar.MINUTE).minutes
|
||||
timeRanges.any { now in it.startTime..it.endTime }
|
||||
} else true
|
||||
// SY -->
|
||||
val today: Calendar = Calendar.getInstance()
|
||||
val timeRanges = preferences.authenticatorTimeRanges().get().mapNotNull { TimeRange.fromPreferenceString(it) }
|
||||
if (timeRanges.isNotEmpty()) {
|
||||
val now = today.get(Calendar.HOUR_OF_DAY).hours + today.get(Calendar.MINUTE).minutes
|
||||
val locked = timeRanges.any { now in it }
|
||||
if (!locked) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
val lockedDays = preferences.authenticatorDays().get()
|
||||
val locked = lockedDays == LOCK_ALL_DAYS || when (today.get(Calendar.DAY_OF_WEEK)) {
|
||||
Calendar.SUNDAY -> (lockedDays and LOCK_SUNDAY) == LOCK_SUNDAY
|
||||
Calendar.MONDAY -> (lockedDays and LOCK_MONDAY) == LOCK_MONDAY
|
||||
Calendar.TUESDAY -> (lockedDays and LOCK_TUESDAY) == LOCK_TUESDAY
|
||||
Calendar.WEDNESDAY -> (lockedDays and LOCK_WEDNESDAY) == LOCK_WEDNESDAY
|
||||
Calendar.THURSDAY -> (lockedDays and LOCK_THURSDAY) == LOCK_THURSDAY
|
||||
Calendar.FRIDAY -> (lockedDays and LOCK_FRIDAY) == LOCK_FRIDAY
|
||||
Calendar.SATURDAY -> (lockedDays and LOCK_SATURDAY) == LOCK_SATURDAY
|
||||
else -> false
|
||||
}
|
||||
|
||||
if (!locked) {
|
||||
return false
|
||||
}
|
||||
// SY <--
|
||||
|
||||
return preferences.lockAppAfter().get() <= 0 ||
|
||||
Date().time >= preferences.lastAppUnlock().get() + 60 * 1000 * preferences.lockAppAfter().get()
|
||||
}
|
||||
|
||||
companion object {
|
||||
var locked: Boolean = true
|
||||
|
||||
const val LOCK_SUNDAY = 0x40
|
||||
const val LOCK_MONDAY = 0x20
|
||||
const val LOCK_TUESDAY = 0x10
|
||||
const val LOCK_WEDNESDAY = 0x8
|
||||
const val LOCK_THURSDAY = 0x4
|
||||
const val LOCK_FRIDAY = 0x2
|
||||
const val LOCK_SATURDAY = 0x1
|
||||
const val LOCK_ALL_DAYS = 0x7F
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,17 @@
|
||||
package eu.kanade.tachiyomi.ui.setting
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import androidx.preference.PreferenceScreen
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.list.listItemsMultiChoice
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
|
||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.ui.category.biometric.BiometricTimesController
|
||||
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
||||
import eu.kanade.tachiyomi.util.preference.defaultValue
|
||||
import eu.kanade.tachiyomi.util.preference.intListPreference
|
||||
import eu.kanade.tachiyomi.util.preference.onClick
|
||||
@ -14,6 +21,7 @@ import eu.kanade.tachiyomi.util.preference.switchPreference
|
||||
import eu.kanade.tachiyomi.util.preference.titleRes
|
||||
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
|
||||
|
||||
class SettingsSecurityController : SettingsController() {
|
||||
@ -62,7 +70,7 @@ class SettingsSecurityController : SettingsController() {
|
||||
key = "pref_edit_lock_times"
|
||||
titleRes = R.string.action_edit_biometric_lock_times
|
||||
|
||||
val timeRanges = preferences.authenticatorTimeRanges().get().count()
|
||||
val timeRanges = preferences.authenticatorTimeRanges().get().size
|
||||
summary = context.resources.getQuantityString(R.plurals.num_lock_times, timeRanges, timeRanges)
|
||||
|
||||
preferences.useAuthenticator().asImmediateFlow { isVisible = it }
|
||||
@ -72,5 +80,77 @@ class SettingsSecurityController : SettingsController() {
|
||||
router.pushController(BiometricTimesController().withFadeTransaction())
|
||||
}
|
||||
}
|
||||
preference {
|
||||
key = "pref_edit_lock_days"
|
||||
titleRes = R.string.biometric_lock_days
|
||||
summaryRes = R.string.biometric_lock_days_summary
|
||||
|
||||
preferences.useAuthenticator().asImmediateFlow { isVisible = it }
|
||||
.launchIn(viewScope)
|
||||
|
||||
onClick {
|
||||
SetLockedDaysDialog().showDialog(router)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SetLockedDaysDialog(bundle: Bundle? = null) : DialogController(bundle) {
|
||||
val preferences: PreferencesHelper by injectLazy()
|
||||
|
||||
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
|
||||
val activity = activity!!
|
||||
val options = arrayOf(
|
||||
R.string.sunday,
|
||||
R.string.monday,
|
||||
R.string.tuesday,
|
||||
R.string.wednesday,
|
||||
R.string.thursday,
|
||||
R.string.friday,
|
||||
R.string.saturday
|
||||
)
|
||||
.map { activity.getString(it) }
|
||||
|
||||
val lockDays = preferences.authenticatorDays().get()
|
||||
val initialSelection = List(7) {
|
||||
val locked = when (it) {
|
||||
0 -> (lockDays and SecureActivityDelegate.LOCK_SUNDAY) == SecureActivityDelegate.LOCK_SUNDAY
|
||||
1 -> (lockDays and SecureActivityDelegate.LOCK_MONDAY) == SecureActivityDelegate.LOCK_MONDAY
|
||||
2 -> (lockDays and SecureActivityDelegate.LOCK_TUESDAY) == SecureActivityDelegate.LOCK_TUESDAY
|
||||
3 -> (lockDays and SecureActivityDelegate.LOCK_WEDNESDAY) == SecureActivityDelegate.LOCK_WEDNESDAY
|
||||
4 -> (lockDays and SecureActivityDelegate.LOCK_THURSDAY) == SecureActivityDelegate.LOCK_THURSDAY
|
||||
5 -> (lockDays and SecureActivityDelegate.LOCK_FRIDAY) == SecureActivityDelegate.LOCK_FRIDAY
|
||||
6 -> (lockDays and SecureActivityDelegate.LOCK_SATURDAY) == SecureActivityDelegate.LOCK_SATURDAY
|
||||
else -> false
|
||||
}
|
||||
if (locked) {
|
||||
it
|
||||
} else null
|
||||
}.filterNotNull().toIntArray()
|
||||
|
||||
return MaterialDialog(activity)
|
||||
.title(R.string.biometric_lock_days)
|
||||
.message(R.string.biometric_lock_days_summary)
|
||||
.listItemsMultiChoice(
|
||||
items = options,
|
||||
initialSelection = initialSelection
|
||||
) { _, positions, _ ->
|
||||
var flags = 0
|
||||
positions.forEach {
|
||||
when (it) {
|
||||
0 -> flags = flags or SecureActivityDelegate.LOCK_SUNDAY
|
||||
1 -> flags = flags or SecureActivityDelegate.LOCK_MONDAY
|
||||
2 -> flags = flags or SecureActivityDelegate.LOCK_TUESDAY
|
||||
3 -> flags = flags or SecureActivityDelegate.LOCK_WEDNESDAY
|
||||
4 -> flags = flags or SecureActivityDelegate.LOCK_THURSDAY
|
||||
5 -> flags = flags or SecureActivityDelegate.LOCK_FRIDAY
|
||||
6 -> flags = flags or SecureActivityDelegate.LOCK_SATURDAY
|
||||
}
|
||||
}
|
||||
|
||||
preferences.authenticatorDays().set(flags)
|
||||
}
|
||||
.positiveButton(android.R.string.ok)
|
||||
.negativeButton(android.R.string.cancel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -224,6 +224,16 @@
|
||||
<string name="biometric_lock_end_time">Enter end time</string>
|
||||
<string name="biometric_lock_time_deleted_snack">Biometric lock time completed</string>
|
||||
<string name="biometric_lock_invalid_time_selected">Invalid time selected</string>
|
||||
<string name="biometric_lock_days">Biometric lock days</string>
|
||||
<string name="biometric_lock_days_summary">Days to have the app locked</string>
|
||||
|
||||
<string name="sunday">Sunday</string>
|
||||
<string name="monday">Monday</string>
|
||||
<string name="tuesday">Tuesday</string>
|
||||
<string name="wednesday">Wednesday</string>
|
||||
<string name="thursday">Thursday</string>
|
||||
<string name="friday">Friday</string>
|
||||
<string name="saturday">Saturday</string>
|
||||
|
||||
<!-- Reader Settings -->
|
||||
<string name="page_downloading">Page Downloading</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user