Minor code improvement
This commit is contained in:
parent
6531f9f104
commit
8f0cbac572
1 changed files with 11 additions and 7 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue