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