store: ctx -> context

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2025-02-22 11:47:07 +08:00
parent 302c232ad1
commit 9b23b18b3e
2 changed files with 27 additions and 17 deletions

View File

@@ -37,7 +37,7 @@ import java.util.Calendar
@Composable
fun BlacklistScreen(onNavigateUp: () -> Unit, viewModel: BlacklistViewModel = hiltViewModel()) {
val ctx = LocalContext.current
val context = LocalContext.current
val packages by viewModel.filteredPackages.collectAsStateWithLifecycle()
ScreenContent(
@@ -46,12 +46,12 @@ fun BlacklistScreen(onNavigateUp: () -> Unit, viewModel: BlacklistViewModel = hi
isPackageBlacklisted = { pkgName -> pkgName in viewModel.blacklist },
isPackageFiltered = { pkgInfo -> viewModel.isFiltered(pkgInfo) },
onBlacklistImport = { uri ->
viewModel.importBlacklist(ctx, uri)
ctx.toast(R.string.toast_black_import_success)
viewModel.importBlacklist(context, uri)
context.toast(R.string.toast_black_import_success)
},
onBlacklistExport = { uri ->
viewModel.exportBlacklist(ctx, uri)
ctx.toast(R.string.toast_black_export_success)
viewModel.exportBlacklist(context, uri)
context.toast(R.string.toast_black_export_success)
},
onBlacklist = { packageName -> viewModel.blacklist(packageName) },
onBlacklistAll = { viewModel.blacklistAll() },
@@ -76,17 +76,25 @@ private fun ScreenContent(
onSearch: (query: String) -> Unit = {}
) {
val ctx = LocalContext.current
val context = LocalContext.current
val docImportLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.OpenDocument(),
onResult = {
if (it != null) onBlacklistImport(it) else ctx.toast(R.string.toast_black_import_failed)
if (it != null) {
onBlacklistImport(it)
} else {
context.toast(R.string.toast_black_import_failed)
}
}
)
val docExportLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.CreateDocument(Constants.JSON_MIME_TYPE),
onResult = {
if (it != null) onBlacklistExport(it) else ctx.toast(R.string.toast_black_export_failed)
if (it != null) {
onBlacklistExport(it)
} else {
context.toast(R.string.toast_black_export_failed)
}
}
)
@@ -129,8 +137,8 @@ private fun ScreenContent(
val isBlacklisted = isPackageBlacklisted(pkg.packageName)
val isFiltered = isPackageFiltered(pkg)
BlackListComposable(
icon = PackageUtil.getIconForPackage(ctx, pkg.packageName)!!,
displayName = pkg.applicationInfo!!.loadLabel(ctx.packageManager).toString(),
icon = PackageUtil.getIconForPackage(context, pkg.packageName)!!,
displayName = pkg.applicationInfo!!.loadLabel(context.packageManager).toString(),
packageName = pkg.packageName,
versionName = pkg.versionName!!,
versionCode = PackageInfoCompat.getLongVersionCode(pkg),

View File

@@ -45,25 +45,27 @@ class UpdatesRestrictionsDialog : DialogFragment() {
super.onDestroy()
}
private fun setupRestrictions(ctx: Context) {
private fun setupRestrictions(context: Context) {
dialog?.findViewById<MaterialCheckBox>(R.id.checkboxMetered)?.apply {
isChecked = Preferences.getBoolean(ctx, PREFERENCES_UPDATES_RESTRICTIONS_METERED, true)
isChecked =
Preferences.getBoolean(context, PREFERENCES_UPDATES_RESTRICTIONS_METERED, true)
setOnCheckedChangeListener { _, isChecked ->
Preferences.putBoolean(ctx, PREFERENCES_UPDATES_RESTRICTIONS_METERED, isChecked)
Preferences.putBoolean(context, PREFERENCES_UPDATES_RESTRICTIONS_METERED, isChecked)
}
}
dialog?.findViewById<MaterialCheckBox>(R.id.checkboxIdle)?.apply {
isChecked = Preferences.getBoolean(ctx, PREFERENCES_UPDATES_RESTRICTIONS_IDLE, true)
isChecked = Preferences.getBoolean(context, PREFERENCES_UPDATES_RESTRICTIONS_IDLE, true)
setOnCheckedChangeListener { _, isChecked ->
Preferences.putBoolean(ctx, PREFERENCES_UPDATES_RESTRICTIONS_IDLE, isChecked)
Preferences.putBoolean(context, PREFERENCES_UPDATES_RESTRICTIONS_IDLE, isChecked)
}
}
dialog?.findViewById<MaterialCheckBox>(R.id.checkboxBattery)?.apply {
isChecked = Preferences.getBoolean(ctx, PREFERENCES_UPDATES_RESTRICTIONS_BATTERY, true)
isChecked =
Preferences.getBoolean(context, PREFERENCES_UPDATES_RESTRICTIONS_BATTERY, true)
setOnCheckedChangeListener { _, isChecked ->
Preferences.putBoolean(ctx, PREFERENCES_UPDATES_RESTRICTIONS_BATTERY, isChecked)
Preferences.putBoolean(context, PREFERENCES_UPDATES_RESTRICTIONS_BATTERY, isChecked)
}
}
}