Simplified string access

This commit is contained in:
Juha Heinanen
2025-04-19 19:40:45 +03:00
parent e163a6ef35
commit dc61da64cb
11 changed files with 94 additions and 92 deletions

View File

@ -69,7 +69,7 @@ class AboutActivity : ComponentActivity() {
Utils.addActivity("about")
val aboutTitle = String.format(getString(R.string.about_title))
val aboutTitle = getString(R.string.about_title)
val aboutText = String.format(getString(R.string.about_text),
BuildConfig.VERSION_NAME)

View File

@ -1248,7 +1248,7 @@ class AccountActivity : ComponentActivity() {
showPasswordDialog = showPasswordDialog,
password = password,
keyboardController = keyboardController,
title = getString(R.string.authentication_password),
title = stringResource(R.string.authentication_password),
okAction = {
if (password.value != "") {
BaresipService.aorPasswords[acc.aor] = password.value

View File

@ -115,7 +115,7 @@ class AccountsActivity : ComponentActivity() {
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
}
val title = String.format(getString(R.string.accounts))
val title = getString(R.string.accounts)
aor = intent.getStringExtra("aor")!!
Utils.addActivity("accounts,$aor")
@ -183,11 +183,11 @@ class AccountsActivity : ComponentActivity() {
AlertDialog(
showDialog = showDialog,
title = getString(R.string.confirmation),
title = stringResource(R.string.confirmation),
message = message.value,
positiveButtonText = getString(R.string.delete),
positiveButtonText = stringResource(R.string.delete),
onPositiveClicked = positiveAction.value,
negativeButtonText = getString(R.string.cancel),
negativeButtonText = stringResource(R.string.cancel),
)
if (showAlert.value) {
@ -281,7 +281,7 @@ class AccountsActivity : ComponentActivity() {
) {
OutlinedTextField(
value = newAor,
placeholder = { Text(text = getString(R.string.new_account)) },
placeholder = { Text(text = stringResource(R.string.new_account)) },
onValueChange = { newAor = it },
modifier = Modifier
.weight(1f)

View File

@ -47,6 +47,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
@ -115,7 +116,7 @@ class CallDetailsActivity : ComponentActivity() {
modifier = Modifier.fillMaxSize(),
color = LocalCustomColors.current.background
) {
CallDetailsScreen(this, getString(R.string.call_details)) { goBack() }
CallDetailsScreen(this, stringResource(R.string.call_details)) { goBack() }
}
}
}
@ -175,7 +176,7 @@ class CallDetailsActivity : ComponentActivity() {
@Composable
fun Peer(ctx: Context, peer: String, account: Account) {
val headerText = getString(R.string.peer) + " " +
val headerText = stringResource(R.string.peer) + " " +
Utils.friendlyUri(ctx, peer, account)
Text(
text = headerText,
@ -190,20 +191,20 @@ class CallDetailsActivity : ComponentActivity() {
@Composable
fun Calls(ctx: Context) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(text = getString(R.string.direction),
Text(text = stringResource(R.string.direction),
color = LocalCustomColors.current.itemText,
fontSize = 16.sp,
fontWeight = FontWeight.SemiBold,
modifier = Modifier.width(96.dp)
)
Spacer(modifier = Modifier.width(6.dp))
Text(text = getString(R.string.time),
Text(text = stringResource(R.string.time),
color = LocalCustomColors.current.itemText,
fontSize = 16.sp,
fontWeight = FontWeight.SemiBold
)
Spacer(modifier = Modifier.weight(1f))
Text(text = getString(R.string.calls_duration),
Text(text = stringResource(R.string.calls_duration),
modifier = Modifier.padding(end = 12.dp),
color = LocalCustomColors.current.itemText,
fontSize = 16.sp,
@ -232,7 +233,7 @@ class CallDetailsActivity : ComponentActivity() {
modifier = Modifier.width(64.dp)
)
Spacer(modifier = Modifier.width(38.dp))
val durationText = startTime(ctx, detail)
val durationText = startTime(detail)
Spacer(modifier = Modifier.weight(1f))
Duration(ctx, detail, durationText)
}
@ -241,14 +242,14 @@ class CallDetailsActivity : ComponentActivity() {
}
@Composable
fun startTime(ctx: Context, detail: CallRow.Details): String {
fun startTime(detail: CallRow.Details): String {
val startTime = detail.startTime
val stopTime = detail.stopTime
val startTimeText: String
val durationText: String
val stopText = if (DateUtils.isToday(stopTime.timeInMillis)) {
val fmt = DateFormat.getTimeInstance(DateFormat.MEDIUM)
ctx.getString(R.string.today) + " " + fmt.format(stopTime.time)
stringResource(R.string.today) + " " + fmt.format(stopTime.time)
} else {
val fmt = DateFormat.getDateTimeInstance()
fmt.format(stopTime.time)
@ -263,7 +264,7 @@ class CallDetailsActivity : ComponentActivity() {
} else {
val startText = if (DateUtils.isToday(startTime.timeInMillis)) {
val fmt = DateFormat.getTimeInstance(DateFormat.MEDIUM)
ctx.getString(R.string.today) + " " + fmt.format(startTime.time)
stringResource(R.string.today) + " " + fmt.format(startTime.time)
} else {
val fmt = DateFormat.getDateTimeInstance()
fmt.format(startTime.time)
@ -285,7 +286,7 @@ class CallDetailsActivity : ComponentActivity() {
AlertDialog(
showDialog = showDialog,
title = getString(R.string.playing_recording),
title = stringResource(R.string.playing_recording),
message = "",
)

View File

@ -57,6 +57,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
@ -103,7 +104,7 @@ class CallsActivity : ComponentActivity() {
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
}
val title = String.format(getString(R.string.call_history))
val title = getString(R.string.call_history)
aor = intent.getStringExtra("aor")!!
Utils.addActivity("calls,$aor")
@ -147,19 +148,19 @@ class CallsActivity : ComponentActivity() {
var expanded by remember { mutableStateOf(false) }
val delete = String.format(getString(R.string.delete))
val disable = String.format(getString(R.string.disable_history))
val enable = String.format(getString(R.string.enable_history))
val delete = stringResource(R.string.delete)
val disable = stringResource(R.string.disable_history)
val enable = stringResource(R.string.enable_history)
val showDialog = remember { mutableStateOf(false) }
val positiveAction = remember { mutableStateOf({}) }
AlertDialog(
showDialog = showDialog,
title = getString(R.string.confirmation),
message = String.format(getString(R.string.delete_history_alert), aor.substringAfter(":")),
positiveButtonText = getString(R.string.delete),
negativeButtonText = getString(R.string.cancel),
title = stringResource(R.string.confirmation),
message = String.format(stringResource(R.string.delete_history_alert), aor.substringAfter(":")),
positiveButtonText = stringResource(R.string.delete),
negativeButtonText = stringResource(R.string.cancel),
onPositiveClicked = positiveAction.value,
)
@ -234,7 +235,7 @@ class CallsActivity : ComponentActivity() {
@Composable
fun Account(account: Account) {
val headerText = getString(R.string.account) + " " +
val headerText = stringResource(R.string.account) + " " +
if (account.nickName.value != "")
account.nickName.value
else
@ -264,13 +265,13 @@ class CallsActivity : ComponentActivity() {
AlertDialog(
showDialog = showDialog,
title = getString(R.string.confirmation),
title = stringResource(R.string.confirmation),
message = message.value,
positiveButtonText = positiveButtonText.value,
onPositiveClicked = positiveAction.value,
neutralButtonText = neutralButtonText.value,
onNeutralClicked = neutralAction.value,
negativeButtonText = getString(R.string.cancel)
negativeButtonText = stringResource(R.string.cancel)
)
val lazyListState = rememberLazyListState()
@ -301,8 +302,8 @@ class CallsActivity : ComponentActivity() {
onClick = {
val peerUri = callRow.peerUri
val peerName = Utils.friendlyUri(ctx, peerUri, account)
message.value = String.format(ctx.getString(R.string.contact_action_question), peerName)
positiveButtonText.value = ctx.getString(R.string.call)
message.value = String.format(getString(R.string.contact_action_question), peerName)
positiveButtonText.value = getString(R.string.call)
positiveAction.value = {
BaresipService.activities.remove("calls,$aor")
MainActivity.activityAor = aor
@ -314,7 +315,7 @@ class CallsActivity : ComponentActivity() {
i.putExtra("peer", peerUri)
startActivity(i)
}
neutralButtonText.value = ctx.getString(R.string.send_message)
neutralButtonText.value = getString(R.string.send_message)
neutralAction.value = {
BaresipService.activities.remove("calls,$aor")
MainActivity.activityAor = aor

View File

@ -287,13 +287,13 @@ class ChatActivity : ComponentActivity() {
AlertDialog(
showDialog = showDialog,
title = getString(R.string.confirmation),
title = stringResource(R.string.confirmation),
message = dialogMessage.value,
positiveButtonText = positiveButtonText.value,
onPositiveClicked = positiveAction.value,
neutralButtonText = neutralButtonText.value,
onNeutralClicked = neutralAction.value,
negativeButtonText = getString(R.string.cancel)
negativeButtonText = stringResource(R.string.cancel)
)
val lazyListState = rememberLazyListState()
@ -336,7 +336,7 @@ class ChatActivity : ComponentActivity() {
chatPeer
}
else
ctx.getString(R.string.you)
stringResource(R.string.you)
var info: String
val cal = GregorianCalendar()
cal.timeInMillis = message.timeStamp
@ -345,12 +345,12 @@ class ChatActivity : ComponentActivity() {
else
DateFormat.getDateInstance(DateFormat.SHORT)
info = fmt.format(cal.time)
if (info.length < 6) info = "${ctx.getString(R.string.today)} $info"
if (info.length < 6) info = "${stringResource(R.string.today)} $info"
if (message.direction == MESSAGE_UP_FAIL) {
info = if (message.responseCode != 0)
"$info - ${ctx.getString(R.string.message_failed)}: " + "${message.responseCode} ${message.responseReason}"
"$info - ${stringResource(R.string.message_failed)}: " + "${message.responseCode} ${message.responseReason}"
else
"$info - ${ctx.getString(R.string.sending_failed)}"
"$info - ${stringResource(R.string.sending_failed)}"
}
Row(
verticalAlignment = Alignment.CenterVertically,
@ -359,10 +359,10 @@ class ChatActivity : ComponentActivity() {
Button(
onClick = {
if (chatPeer == peerUri) {
dialogMessage.value = String.format(ctx.getString(R.string.long_message_question),
dialogMessage.value = String.format(getString(R.string.long_message_question),
peerUri
)
positiveButtonText.value = ctx.getString(R.string.add_contact)
positiveButtonText.value = getString(R.string.add_contact)
positiveAction.value = {
val i = Intent(ctx, BaresipContactActivity::class.java)
val b = Bundle()
@ -371,15 +371,15 @@ class ChatActivity : ComponentActivity() {
i.putExtras(b)
ctx.startActivity(i)
}
neutralButtonText.value = ctx.getString(R.string.delete)
neutralButtonText.value = getString(R.string.delete)
neutralAction.value = {
message.delete()
_chatMessages.value = uaPeerMessages(aor, peerUri)
}
}
else {
dialogMessage.value = ctx.getString(R.string.short_message_question)
positiveButtonText.value = ctx.getString(R.string.delete)
dialogMessage.value = getString(R.string.short_message_question)
positiveButtonText.value = getString(R.string.delete)
positiveAction.value = {
message.delete()
_chatMessages.value = uaPeerMessages(aor, peerUri)
@ -455,9 +455,9 @@ class ChatActivity : ComponentActivity() {
AlertDialog(
showDialog = showDialog,
title = getString(R.string.notice),
title = stringResource(R.string.notice),
message = dialogMessage.value,
positiveButtonText = getString(R.string.ok),
positiveButtonText = stringResource(R.string.ok),
)
var newMessage by remember { mutableStateOf("") }
@ -470,7 +470,7 @@ class ChatActivity : ComponentActivity() {
val keyboardController = LocalSoftwareKeyboardController.current
OutlinedTextField(
value = newMessage,
placeholder = { Text(text = getString(R.string.new_message)) },
placeholder = { Text(text = stringResource(R.string.new_message)) },
onValueChange = { newMessage = it },
modifier = Modifier
.weight(1f)

View File

@ -179,21 +179,21 @@ class ChatsActivity: ComponentActivity() {
var expanded by remember { mutableStateOf(false) }
val delete = String.format(getString(R.string.delete))
val delete = stringResource(R.string.delete)
val showDialog = remember { mutableStateOf(false) }
val positiveAction = remember { mutableStateOf({}) }
AlertDialog(
showDialog = showDialog,
title = getString(R.string.confirmation),
title = stringResource(R.string.confirmation),
message = String.format(
getString(R.string.delete_chats_alert),
stringResource(R.string.delete_chats_alert),
aor.substringAfter(":")
),
positiveButtonText = getString(R.string.delete),
positiveButtonText = stringResource(R.string.delete),
onPositiveClicked = positiveAction.value,
negativeButtonText = getString(R.string.cancel),
negativeButtonText = stringResource(R.string.cancel),
)
TopAppBar(
@ -275,7 +275,7 @@ class ChatsActivity: ComponentActivity() {
@Composable
fun Account(account: Account) {
val headerText = getString(R.string.account) + " " +
val headerText = stringResource(R.string.account) + " " +
if (account.nickName.value != "")
account.nickName.value
else
@ -303,13 +303,13 @@ class ChatsActivity: ComponentActivity() {
if (showDialog.value)
AlertDialog(
showDialog = showDialog,
title = getString(R.string.confirmation),
title = stringResource(R.string.confirmation),
message = dialogMessage.value,
positiveButtonText = positiveButtonText.value,
onPositiveClicked = positiveAction.value,
neutralButtonText = neutralButtonText.value,
onNeutralClicked = neutralAction.value,
negativeButtonText = getString(R.string.cancel)
negativeButtonText = stringResource(R.string.cancel)
)
val lazyListState = rememberLazyListState()
@ -483,10 +483,10 @@ class ChatsActivity: ComponentActivity() {
SelectableAlertDialog(
openDialog = showDialog,
title = getString(R.string.choose_destination_uri),
title = stringResource(R.string.choose_destination_uri),
items = items.value,
onItemClicked = itemAction.value,
neutralButtonText = getString(R.string.cancel),
neutralButtonText = stringResource(R.string.cancel),
onNeutralClicked = {}
)
@ -558,7 +558,7 @@ class ChatsActivity: ComponentActivity() {
OutlinedTextField(
value = newPeer,
placeholder = {
Text(text = getString(R.string.new_chat_peer))
Text(text = stringResource(R.string.new_chat_peer))
},
onValueChange = {
newPeer = it

View File

@ -150,7 +150,7 @@ class CodecsActivity : ComponentActivity() {
TopAppBar(
title = {
Text(
text = getString(R.string.codecs),
text = stringResource(R.string.codecs),
color = LocalCustomColors.current.light,
fontWeight = FontWeight.Bold
)

View File

@ -219,7 +219,7 @@ class ConfigActivity : ComponentActivity() {
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
}
val title = String.format(getString(R.string.configuration))
val title = getString(R.string.configuration)
Utils.addActivity("config")
@ -672,9 +672,9 @@ class ConfigActivity : ComponentActivity() {
if (showAlertDialog.value)
AlertDialog(
showDialog = showAlertDialog,
title = getString(R.string.notice),
message = getString(R.string.no_read_permission),
positiveButtonText = getString(R.string.ok),
title = stringResource(R.string.notice),
message = stringResource(R.string.no_read_permission),
positiveButtonText = stringResource(R.string.ok),
onPositiveClicked = { requestPermissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE) },
negativeButtonText = "",
onNegativeClicked = {},
@ -1019,9 +1019,9 @@ class ConfigActivity : ComponentActivity() {
if (showAlertDialog.value)
AlertDialog(
showDialog = showAlertDialog,
title = getString(R.string.notice),
message = getString(R.string.no_android_contacts),
positiveButtonText = getString(R.string.ok),
title = stringResource(R.string.notice),
message = stringResource(R.string.no_android_contacts),
positiveButtonText = stringResource(R.string.ok),
onPositiveClicked = { requestPermissionsLauncher.launch(
arrayOf(
Manifest.permission.READ_CONTACTS,

View File

@ -112,7 +112,7 @@ class ContactsActivity : ComponentActivity() {
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
}
val title = String.format(getString(R.string.contacts))
val title = getString(R.string.contacts)
aor = intent.getStringExtra("aor")!!
Utils.addActivity("contacts,$aor")
@ -221,13 +221,13 @@ class ContactsActivity : ComponentActivity() {
if (showDialog.value)
AlertDialog(
showDialog = showDialog,
title = getString(R.string.confirmation),
title = stringResource(R.string.confirmation),
message = dialogMessage.value,
positiveButtonText = positiveText.value,
onPositiveClicked = positiveAction.value,
neutralButtonText = neutralText.value,
onNeutralClicked = neutralAction.value,
negativeButtonText = getString(R.string.cancel)
negativeButtonText = stringResource(R.string.cancel)
)
val lazyListState = rememberLazyListState()
@ -299,10 +299,10 @@ class ContactsActivity : ComponentActivity() {
.combinedClickable(
onClick = {
dialogMessage.value = String.format(
ctx.getString(R.string.contact_action_question),
getString(R.string.contact_action_question),
name
)
positiveText.value = ctx.getString(R.string.call)
positiveText.value = getString(R.string.call)
positiveAction.value = {
val i = Intent(ctx, MainActivity::class.java)
i.flags =
@ -319,7 +319,7 @@ class ContactsActivity : ComponentActivity() {
(ctx as Activity).startActivity(i)
}
}
neutralText.value = ctx.getString(R.string.send_message)
neutralText.value = getString(R.string.send_message)
neutralAction.value = {
val i = Intent(
ctx,
@ -343,10 +343,10 @@ class ContactsActivity : ComponentActivity() {
},
onLongClick = {
dialogMessage.value = String.format(
ctx.getString(R.string.contact_delete_question),
getString(R.string.contact_delete_question),
name
)
positiveText.value = ctx.getString(R.string.delete)
positiveText.value = getString(R.string.delete)
positiveAction.value = {
val id = contact.id
val avatarFile = File(
@ -416,10 +416,10 @@ class ContactsActivity : ComponentActivity() {
},
onLongClick = {
dialogMessage.value = String.format(
ctx.getString(R.string.contact_delete_question),
getString(R.string.contact_delete_question),
name
)
positiveText.value = ctx.getString(R.string.delete)
positiveText.value = getString(R.string.delete)
positiveAction.value = {
ctx.contentResolver.delete(
ContactsContract.RawContacts.CONTENT_URI,

View File

@ -517,7 +517,7 @@ class MainActivity : ComponentActivity() {
Scaffold(
modifier = Modifier.safeDrawingPadding(),
containerColor = LocalCustomColors.current.background,
topBar = { TopAppBar(ctx, String.format(getString(R.string.baresip))) },
topBar = { TopAppBar(ctx, getString(R.string.baresip)) },
bottomBar = { BottomBar(ctx) },
content = { contentPadding ->
MainContent(ctx, contentPadding)
@ -551,20 +551,20 @@ class MainActivity : ComponentActivity() {
if (showDialog.value)
AlertDialog(
showDialog = showDialog,
title = getString(R.string.confirmation),
title = stringResource(R.string.confirmation),
message = dialogMessage.value,
positiveButtonText = positiveText.value,
onPositiveClicked = onPositiveClicked.value,
negativeButtonText = getString(R.string.cancel),
negativeButtonText = stringResource(R.string.cancel),
onNegativeClicked = onNegativeClicked.value
)
SelectableAlertDialog(
openDialog = showSelectItemDialog,
title = getString(R.string.choose_destination_uri),
title = stringResource(R.string.choose_destination_uri),
items = items.value,
onItemClicked = itemAction.value,
neutralButtonText = getString(R.string.cancel),
neutralButtonText = stringResource(R.string.cancel),
onNeutralClicked = {}
)
@ -656,14 +656,14 @@ class MainActivity : ComponentActivity() {
var recImage by remember { mutableStateOf(recOffImage) }
var menuExpanded by remember { mutableStateOf(false) }
val about = String.format(getString(R.string.about))
val settings = String.format(getString(R.string.configuration))
val accounts = String.format(getString(R.string.accounts))
val backup = String.format(getString(R.string.backup))
val restore = String.format(getString(R.string.restore))
val logcat = String.format(getString(R.string.logcat))
val restart = String.format(getString(R.string.restart))
val quit = String.format(getString(R.string.quit))
val about = stringResource(R.string.about)
val settings = stringResource(R.string.configuration)
val accounts = stringResource(R.string.accounts)
val backup = stringResource(R.string.backup)
val restore = stringResource(R.string.restore)
val logcat = stringResource(R.string.logcat)
val restart = stringResource(R.string.restart)
val quit = stringResource(R.string.quit)
TopAppBar(
title = {
@ -1441,7 +1441,7 @@ class MainActivity : ComponentActivity() {
horizontalArrangement = Arrangement.Center,
) {
Text(
text = ContextCompat.getString(ctx, R.string.blind),
text = stringResource(R.string.blind),
color = LocalCustomColors.current.alert,
modifier = Modifier.padding(16.dp),
)
@ -1451,7 +1451,7 @@ class MainActivity : ComponentActivity() {
blindChecked.value = true
}
Text(
text = ContextCompat.getString(ctx, R.string.attended),
text = stringResource(R.string.attended),
color = LocalCustomColors.current.alert,
modifier = Modifier.padding(16.dp),
)
@ -1897,7 +1897,7 @@ class MainActivity : ComponentActivity() {
shape = RoundedCornerShape(20)
) {
Text(
text = getString(R.string.call_is_on_hold),
text = stringResource(R.string.call_is_on_hold),
fontSize = 18.sp,
color = LocalCustomColors.current.itemText,
)
@ -1917,8 +1917,8 @@ class MainActivity : ComponentActivity() {
showPasswordDialog = showPasswordsDialog,
password = password,
keyboardController = keyboardController,
title = getString(R.string.authentication_password),
message = getString(R.string.account) + " " + Utils.plainAor(aor),
title = stringResource(R.string.authentication_password),
message = stringResource(R.string.account) + " " + Utils.plainAor(aor),
okAction = {
if (password.value != "")
BaresipService.aorPasswords[aor] = password.value