Settings: Update AppLock API
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
This commit is contained in:
@@ -34,8 +34,7 @@
|
||||
<SwitchPreferenceCompat
|
||||
android:key="hide_from_launcher"
|
||||
android:title="@string/hide_from_launcher_title"
|
||||
android:summary="@string/hide_from_launcher_summary"
|
||||
android:dependency="main_switch" />
|
||||
android:summary="@string/hide_from_launcher_summary" />
|
||||
|
||||
<com.android.settingslib.widget.FooterPreference
|
||||
android:title="@string/app_lock_footer_text"
|
||||
|
||||
@@ -99,7 +99,11 @@ class AppLockPackageListFragment : DashboardFragment() {
|
||||
|
||||
private suspend fun getSelectedPackages(): Set<String> {
|
||||
return withContext(Dispatchers.IO) {
|
||||
appLockManager.packageData.map { it.packageName }.toSet()
|
||||
appLockManager.packageData.filter {
|
||||
it.shouldProtectApp == true
|
||||
}.map {
|
||||
it.packageName
|
||||
}.toSet()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,11 +120,7 @@ class AppLockPackageListFragment : DashboardFragment() {
|
||||
isChecked = isProtected
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
if (newValue as Boolean) {
|
||||
appLockManager.addPackage(packageInfo.packageName)
|
||||
} else {
|
||||
appLockManager.removePackage(packageInfo.packageName)
|
||||
}
|
||||
appLockManager.setShouldProtectApp(packageInfo.packageName, newValue as Boolean)
|
||||
}
|
||||
return@setOnPreferenceChangeListener true
|
||||
}
|
||||
|
||||
@@ -43,9 +43,9 @@ class AppLockPackageProtectionPC(
|
||||
init {
|
||||
coroutineScope.launch {
|
||||
isProtected = withContext(Dispatchers.Default) {
|
||||
appLockManager.packageData.any {
|
||||
appLockManager.packageData.find {
|
||||
it.packageName == packageName
|
||||
}
|
||||
}?.shouldProtectApp == true
|
||||
}
|
||||
preference?.let {
|
||||
updateState(it)
|
||||
@@ -61,11 +61,7 @@ class AppLockPackageProtectionPC(
|
||||
if (isProtected == checked) return false
|
||||
isProtected = checked
|
||||
coroutineScope.launch(Dispatchers.Default) {
|
||||
if (isProtected) {
|
||||
appLockManager.addPackage(packageName)
|
||||
} else {
|
||||
appLockManager.removePackage(packageName)
|
||||
}
|
||||
appLockManager.setShouldProtectApp(packageName, isProtected)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -98,7 +98,9 @@ class AppLockSettingsPreferenceController(
|
||||
preference.apply {
|
||||
if (getAvailabilityStatus() == AVAILABLE) {
|
||||
setEnabled(true)
|
||||
summary = getSummaryForListSize(appLockManager.packageData.size)
|
||||
summary = getSummaryForListSize(appLockManager.packageData.filter {
|
||||
it.shouldProtectApp == true
|
||||
}.size)
|
||||
} else {
|
||||
setEnabled(false)
|
||||
summary = mContext.getString(R.string.disabled_because_no_backup_security)
|
||||
|
||||
Reference in New Issue
Block a user