Minor code improvement

This commit is contained in:
Naveen Singh 2025-03-23 22:44:01 +05:30
parent 6531f9f104
commit 8f0cbac572
No known key found for this signature in database
GPG key ID: AF5D43C216778C0B

View file

@ -89,7 +89,7 @@ class ManageBlockedKeywordsActivity : SimpleActivity(), RefreshRecyclerViewListe
} }
} }
private val exportActivityResultLauncher = private val createDocument =
registerForActivityResult(ActivityResultContracts.CreateDocument("text/plain")) { uri -> registerForActivityResult(ActivityResultContracts.CreateDocument("text/plain")) { uri ->
try { try {
val outputStream = uri?.let { contentResolver.openOutputStream(it) } val outputStream = uri?.let { contentResolver.openOutputStream(it) }
@ -101,7 +101,7 @@ class ManageBlockedKeywordsActivity : SimpleActivity(), RefreshRecyclerViewListe
} }
} }
private val importActivityResultLauncher = private val getContent =
registerForActivityResult(ActivityResultContracts.GetContent()) { uri -> registerForActivityResult(ActivityResultContracts.GetContent()) { uri ->
try { try {
if (uri != null) { if (uri != null) {
@ -115,8 +115,8 @@ class ManageBlockedKeywordsActivity : SimpleActivity(), RefreshRecyclerViewListe
private fun tryImportBlockedKeywords() { private fun tryImportBlockedKeywords() {
val mimeType = "text/plain" val mimeType = "text/plain"
try { try {
importActivityResultLauncher.launch(mimeType) getContent.launch(mimeType)
} catch (e: ActivityNotFoundException) { } catch (_: ActivityNotFoundException) {
toast(org.fossify.commons.R.string.system_service_disabled, Toast.LENGTH_LONG) toast(org.fossify.commons.R.string.system_service_disabled, Toast.LENGTH_LONG)
} catch (e: Exception) { } catch (e: Exception) {
showErrorToast(e) showErrorToast(e)
@ -179,10 +179,14 @@ class ManageBlockedKeywordsActivity : SimpleActivity(), RefreshRecyclerViewListe
} }
private fun tryExportBlockedNumbers() { private fun tryExportBlockedNumbers() {
ExportBlockedKeywordsDialog(this, config.lastBlockedKeywordExportPath, true) { file -> ExportBlockedKeywordsDialog(
activity = this,
path = config.lastBlockedKeywordExportPath,
hidePath = true
) { file ->
try { try {
exportActivityResultLauncher.launch(file.name) createDocument.launch(file.name)
} catch (e: ActivityNotFoundException) { } catch (_: ActivityNotFoundException) {
toast( toast(
org.fossify.commons.R.string.system_service_disabled, org.fossify.commons.R.string.system_service_disabled,
Toast.LENGTH_LONG Toast.LENGTH_LONG