Avoid lint warnings + create empty file "restored" after restore

This commit is contained in:
Juha Heinanen
2025-12-06 08:20:43 +02:00
parent 00a778a053
commit f551048a6e
@@ -265,29 +265,32 @@ private fun MainScreen(
} }
} }
val encryptPasswordTitle = stringResource(R.string.encrypt_password)
val backupRequestLauncher = rememberLauncherForActivityResult( val backupRequestLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult() contract = ActivityResultContracts.StartActivityForResult()
) { result -> ) { result ->
if (result.resultCode == RESULT_OK) { if (result.resultCode == RESULT_OK) {
result.data?.data?.also { uri -> result.data?.data?.also { uri ->
downloadsOutputUri = uri downloadsOutputUri = uri
passwordTitle.value = ctx.getString(R.string.encrypt_password) passwordTitle.value = encryptPasswordTitle
showPasswordDialog.value = true showPasswordDialog.value = true
} }
} }
} }
val noticeTitle = stringResource(R.string.notice)
val noBackupMessage = stringResource(R.string.no_backup)
fun launchBackupRequest() { fun launchBackupRequest() {
if (Build.VERSION.SDK_INT < 29) { if (Build.VERSION.SDK_INT < 29) {
if (!Utils.checkPermissions(ctx, arrayOf(WRITE_EXTERNAL_STORAGE))) { if (!Utils.checkPermissions(ctx, arrayOf(WRITE_EXTERNAL_STORAGE))) {
alertTitle.value = ctx.getString(R.string.notice) alertTitle.value = noticeTitle
alertMessage.value = ctx.getString(R.string.no_backup) alertMessage.value = noBackupMessage
showAlert.value = true showAlert.value = true
} }
else { else {
val path = Utils.downloadsPath("baresip.bs") val path = Utils.downloadsPath("baresip.bs")
downloadsOutputUri = File(path).toUri() downloadsOutputUri = File(path).toUri()
passwordTitle.value = ctx.getString(R.string.encrypt_password) passwordTitle.value = encryptPasswordTitle
showPasswordDialog.value = true showPasswordDialog.value = true
} }
} }
@@ -308,29 +311,31 @@ private fun MainScreen(
} }
} }
val decryptPasswordTitle = stringResource(R.string.decrypt_password)
val restoreRequestLauncher = rememberLauncherForActivityResult( val restoreRequestLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult() contract = ActivityResultContracts.StartActivityForResult()
) { result -> ) { result ->
if (result.resultCode == RESULT_OK) { if (result.resultCode == RESULT_OK) {
result.data?.data?.also { uri -> result.data?.data?.also { uri ->
downloadsInputUri = uri downloadsInputUri = uri
passwordTitle.value = ctx.getString(R.string.decrypt_password) passwordTitle.value = decryptPasswordTitle
showPasswordDialog.value = true showPasswordDialog.value = true
} }
} }
} }
val noRestoreMessage = stringResource(R.string.no_restore)
fun launchRestoreRequest() { fun launchRestoreRequest() {
if (Build.VERSION.SDK_INT < 29) { if (Build.VERSION.SDK_INT < 29) {
if (!Utils.checkPermissions(ctx, arrayOf(READ_EXTERNAL_STORAGE))) { if (!Utils.checkPermissions(ctx, arrayOf(READ_EXTERNAL_STORAGE))) {
alertTitle.value = ctx.getString(R.string.notice) alertTitle.value = noticeTitle
alertMessage.value = ctx.getString(R.string.no_restore) alertMessage.value = noRestoreMessage
showAlert.value = true showAlert.value = true
} }
else { else {
val path = Utils.downloadsPath("baresip.bs") val path = Utils.downloadsPath("baresip.bs")
downloadsInputUri = File(path).toUri() downloadsInputUri = File(path).toUri()
passwordTitle.value = ctx.getString(R.string.decrypt_password) passwordTitle.value = decryptPasswordTitle
showPasswordDialog.value = true showPasswordDialog.value = true
} }
} }
@@ -403,7 +408,7 @@ private fun MainScreen(
title = passwordTitle.value, title = passwordTitle.value,
okAction = { okAction = {
if (password.value != "") { if (password.value != "") {
if (passwordTitle.value == ctx.getString(R.string.encrypt_password)) if (passwordTitle.value == encryptPasswordTitle)
backup(ctx, password.value) backup(ctx, password.value)
else else
restore(ctx, password.value, onRestartClick) restore(ctx, password.value, onRestartClick)
@@ -556,6 +561,8 @@ private fun TopAppBar(
Spacer(modifier = Modifier.width(8.dp)) Spacer(modifier = Modifier.width(8.dp))
val callRecordingTitle = stringResource(R.string.call_recording_title)
val callRecordingMessage = stringResource(R.string.call_recording_tip)
Box(contentAlignment = Alignment.Center, Box(contentAlignment = Alignment.Center,
modifier = Modifier modifier = Modifier
.size(48.dp) .size(48.dp)
@@ -575,8 +582,8 @@ private fun TopAppBar(
} }
}, },
onLongClick = { onLongClick = {
alertTitle.value = ctx.getString(R.string.call_recording_title) alertTitle.value = callRecordingTitle
alertMessage.value = ctx.getString(R.string.call_recording_tip) alertMessage.value = callRecordingMessage
showAlert.value = true showAlert.value = true
} }
) )
@@ -594,6 +601,8 @@ private fun TopAppBar(
Spacer(modifier = Modifier.width(22.dp)) Spacer(modifier = Modifier.width(22.dp))
val microPhoneTitle = stringResource(R.string.microphone_title)
val microPhoneMessage = stringResource(R.string.microphone_tip)
Box( Box(
contentAlignment = Alignment.Center, contentAlignment = Alignment.Center,
modifier = Modifier modifier = Modifier
@@ -613,8 +622,8 @@ private fun TopAppBar(
} }
}, },
onLongClick = { onLongClick = {
alertTitle.value = ctx.getString(R.string.microphone_title) alertTitle.value = microPhoneTitle
alertMessage.value = ctx.getString(R.string.microphone_tip) alertMessage.value = microPhoneMessage
showAlert.value = true showAlert.value = true
} }
) )
@@ -632,6 +641,8 @@ private fun TopAppBar(
Spacer(modifier = Modifier.width(16.dp)) Spacer(modifier = Modifier.width(16.dp))
val speakerPhoneTitle = stringResource(R.string.speakerphone_title)
val speakerPhoneMessage = stringResource(R.string.speakerphone_tip)
Box( Box(
contentAlignment = Alignment.Center, contentAlignment = Alignment.Center,
modifier = Modifier modifier = Modifier
@@ -647,8 +658,8 @@ private fun TopAppBar(
Utils.toggleSpeakerPhone(ContextCompat.getMainExecutor(ctx), am) Utils.toggleSpeakerPhone(ContextCompat.getMainExecutor(ctx), am)
}, },
onLongClick = { onLongClick = {
alertTitle.value = ctx.getString(R.string.speakerphone_title) alertTitle.value = speakerPhoneTitle
alertMessage.value = ctx.getString(R.string.speakerphone_tip) alertMessage.value = speakerPhoneMessage
showAlert.value = true showAlert.value = true
} }
) )
@@ -2674,6 +2685,8 @@ private fun restore(ctx: Context, password: String, onRestartApp: () -> Unit) {
Utils.deleteFile(it) Utils.deleteFile(it)
} }
Utils.createEmptyFile(BaresipService.filesPath + "/restored")
dialogTitle.value = ctx.getString(R.string.info) dialogTitle.value = ctx.getString(R.string.info)
dialogMessage.value = ctx.getString(R.string.restored) dialogMessage.value = ctx.getString(R.string.restored)
positiveText.value = ctx.getString(R.string.restart) positiveText.value = ctx.getString(R.string.restart)