From c061c5d2f9f5545b978d8ffb51e9821f05e7a194 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Fri, 10 May 2019 12:00:36 +0300 Subject: [PATCH] - More work on strings. --- .../com/tutpro/baresip/AccountListAdapter.kt | 3 +- .../com/tutpro/baresip/AccountsActivity.kt | 42 ++++++------- .../kotlin/com/tutpro/baresip/ChatActivity.kt | 2 +- .../com/tutpro/baresip/ChatsActivity.kt | 2 +- .../com/tutpro/baresip/ContactListAdapter.kt | 8 +-- .../com/tutpro/baresip/ContactsActivity.kt | 19 +++--- .../kotlin/com/tutpro/baresip/MainActivity.kt | 6 +- app/src/main/res/values/strings.xml | 59 +++++++++++++------ 8 files changed, 80 insertions(+), 61 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/AccountListAdapter.kt b/app/src/main/kotlin/com/tutpro/baresip/AccountListAdapter.kt index cb914dc9..4377d87c 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/AccountListAdapter.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/AccountListAdapter.kt @@ -39,7 +39,8 @@ class AccountListAdapter(private val cxt: Context, private val rows: ArrayList Log.d("Baresip", "Delete button clicked") val deleteDialog = AlertDialog.Builder(cxt) - deleteDialog.setMessage("${cxt.getString(R.string.delete_account)} ${ua.account.aor}?") + deleteDialog.setMessage(String.format(cxt.getString(R.string.delete_account), + ua.account.aor)) deleteDialog.setPositiveButton(cxt.getText(R.string.cancel)) { dialog, _ -> dialog.dismiss() } diff --git a/app/src/main/kotlin/com/tutpro/baresip/AccountsActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/AccountsActivity.kt index e85fd0e0..f0751533 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/AccountsActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/AccountsActivity.kt @@ -39,21 +39,21 @@ class AccountsActivity : AppCompatActivity() { if (!aor.startsWith("sip:")) aor = "sip:$aor" if (!Utils.checkAorUri(aor)) { Log.d("Baresip", "Invalid SIP Address of Record $aor") - Utils.alertView(this, "Notice", - "Invalid SIP Address of Record: $aor") + Utils.alertView(this, getString(R.string.notice), + String.format(getString(R.string.invalid_aor), aor)) } else if (Account.exists(aor)) { Log.d("Baresip", "Account $aor already exists") - Utils.alertView(this, "Notice", - "Account $aor already exists") + Utils.alertView(this, getString(R.string.notice), + String.format(getString(R.string.account_exists), aor)) } else { val ua = UserAgent.uaAlloc("<$aor>;stunserver=\"stun:stun.l.google.com:19302\";regq=0.5;pubint=0;regint=0") if (ua == null) { Log.e("Baresip", "Failed to allocate UA for $aor") - Utils.alertView(this, "Notice", - "Failed to allocate new account.") + Utils.alertView(this, getString(R.string.notice), + getString(R.string.account_allocation_failure)) } else { newAorView.setText("") - newAorView.hint = "SIP URI user@domain" + newAorView.hint = getString(R.string.sip_uri_user_domain) newAorView.clearFocus() UserAgent.add(ua, R.drawable.dot_yellow) generateAccounts() @@ -88,14 +88,13 @@ class AccountsActivity : AppCompatActivity() { R.id.export_accounts -> { if (Utils.requestPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) - askPassword("Encrypt Password") + askPassword(getString(R.string.encrypt_password)) } R.id.import_accounts -> { if (Utils.requestPermission(this, - android.Manifest.permission.READ_EXTERNAL_STORAGE)) { - askPassword("Decrypt Password") + android.Manifest.permission.READ_EXTERNAL_STORAGE)) + askPassword(getString(R.string.decrypt_password)) - } } android.R.id.home -> { Log.d("Baresip", "Back array was pressed at Accounts") @@ -120,23 +119,20 @@ class AccountsActivity : AppCompatActivity() { dialog.dismiss() password = input.text.toString() if (password != "") { - if (title == "Encrypt Password") { + if (title == getString(R.string.encrypt_password)) { if (exportAccounts(dir, password)) - Utils.alertView(this, "Info", - "Exported accounts to Download folder file 'accounts.bs'.") + Utils.alertView(this, getString(R.string.info), + getString(R.string.exported_accounts)) else - Utils.alertView(this, "Error", - "Failed to export accounts to Download folder.") + Utils.alertView(this, getString(R.string.error), + getString(R.string.export_accounts_error)) } else { if (importAccounts(dir, password)) - Utils.alertView(this, "Info", - "Imported accounts from Download folder file " + - "'accounts.bs'. You need to restart baresip.") + Utils.alertView(this, getString(R.string.info), + getString(R.string.imported_accounts)) else - Utils.alertView(this, "Error", - "Failed to import accounts from Download folder. " + - "Either file 'accounts.bs' doesn't exist or " + - "you gave wrong Decrypt Password.") + Utils.alertView(this, getString(R.string.error), + getString(R.string.import_accounts_error)) } } } diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt index 2375af3c..78a72fc5 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt @@ -59,7 +59,7 @@ class ChatActivity : AppCompatActivity() { else chatPeer = chatPeer.substring(4) } - setTitle("${getString(R.string.chat_with)} $chatPeer") + setTitle(String.format(getString(R.string.chat_with), chatPeer)) val headerView = findViewById(R.id.account) as TextView val headerText = "${getString(R.string.account)} ${aor.substringAfter(":")}" diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatsActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatsActivity.kt index c624dd10..913c2adb 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatsActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatsActivity.kt @@ -91,7 +91,7 @@ class ChatsActivity: AppCompatActivity() { .setNeutralButton(getText(R.string.add_contact), dialogClickListener) .show() else - builder.setMessage("${getString(R.string.short_chat_question)} '$peer'?") + builder.setMessage(String.format(getString(R.string.short_chat_question), peer)) .setPositiveButton(getText(R.string.cancel), dialogClickListener) .setNegativeButton(getText(R.string.delete), dialogClickListener) .show() diff --git a/app/src/main/kotlin/com/tutpro/baresip/ContactListAdapter.kt b/app/src/main/kotlin/com/tutpro/baresip/ContactListAdapter.kt index 400755b1..759ed3cd 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ContactListAdapter.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ContactListAdapter.kt @@ -53,8 +53,8 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList= Contact.CONTACTS_SIZE) { - Utils.alertView(this, "Notice", - "Your maximum number of contacts " + - "(${Contact.CONTACTS_SIZE}) has been exceeded.") + Utils.alertView(this, getString(R.string.notice), + String.format(getString(R.string.contacts_exceeded), Contact.CONTACTS_SIZE)) } else { val i = Intent(this, ContactActivity::class.java) val b = Bundle() @@ -58,12 +57,10 @@ class ContactsActivity : AppCompatActivity() { when (item.itemId) { R.id.export_contacts -> { if (saveContacts(dir)) - Utils.alertView(this,"", - "Exported contacts to Download folder as 'contacts.bs'.") + Utils.alertView(this,"", getString(R.string.exported_contacts)) else - Utils.alertView(this,"Error", - "Failed to export contacts to Download folder. " + - "Check Apps -> baresip -> Permissions -> Storage.") + Utils.alertView(this,getString(R.string.error), + getString(R.string.export_error)) } R.id.import_contacts -> { if (restoreContacts(dir)) { @@ -72,10 +69,8 @@ class ContactsActivity : AppCompatActivity() { clAdapter.notifyDataSetChanged() saveContacts(applicationContext.filesDir) } else - Utils.alertView(this,"Error", - "Failed to import contacts from Download folder. " + - "Check Apps -> baresip -> Permissions -> Storage and that " + - "the file exists in the folder.") + Utils.alertView(this,getString(R.string.error), + getString(R.string.import_error)) } android.R.id.home -> { Log.d("Baresip", "Back array was pressed at Contacts") diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index ebb8f186..c42e46b5 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -703,7 +703,8 @@ class MainActivity : AppCompatActivity() { } val verifyDialog = AlertDialog.Builder(this@MainActivity) verifyDialog.setTitle(getString(R.string.verify)) - verifyDialog.setMessage("${getString(R.string.verify_sas)} <${ev[1]}> <${ev[2]}>?") + verifyDialog.setMessage(String.format(getString(R.string.verify_sas), + ev[1], ev[2])) verifyDialog.setPositiveButton(getString(R.string.yes)) { dialog, _ -> val security: Int if (Api.cmd_exec("zrtp_verify ${ev[3]}") != 0) { @@ -760,7 +761,8 @@ class MainActivity : AppCompatActivity() { val transferDialog = AlertDialog.Builder(this) val target = Utils.friendlyUri(ContactsActivity.contactName(ev[1]), Utils.aorDomain(aor)) - transferDialog.setMessage("${getString(R.string.transfer_query)} $target?") + transferDialog.setMessage(String.format(getString(R.string.transfer_query), + target)) transferDialog.setPositiveButton(getString(R.string.yes)) { dialog, _ -> if (call in Call.calls()) Api.ua_hangup(uap, callp, 0, "") diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1c0a0fa6..aa829c87 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,7 +1,7 @@ - baresip + baresip About baresip @@ -78,10 +78,25 @@ Accounts - SIP URI user@domain + SIP Address user@domain + Invalid SIP Addess \'%1$s\'. + Account \'%1$s\' already exists. + "Failed to allocate new account. + Encrypt Password + Decrypt Password Export + Exported accounts to Download folder file \'accounts.bs\'. + "Failed to export accounts to Download folder. + Check Apps -> baresip -> Permissions -> Storage." + Import - Do you want to delete account + Imported accounts from Download folder. You need to restart + baresip. + Failed to import accounts from Download folder file. + Check Apps -> baresip -> Permissions -> Storage and that file \'contacts.bs\' exists in + the folder and, if so, you gave correct Decrypt Password." + + Do you want to delete account \'%1$s\'? Answer @@ -95,9 +110,9 @@ Chat Messages - Chat with + Chat with %1$s New message - Do you want to delete message or add peer %1$s to contacts? + Do you want to delete message or add peer \'%1$s\' to contacts? Do you want to delete message? Add Contact Sending of message failed @@ -105,9 +120,9 @@ Chat History New Chat Peer - Do you want to delete chat with peer %1$s or + Do you want to delete chat with peer \'%1$s\' or add peer to contacts? - Do you want to delete chat with + Do you want to delete chat with \'%1$s\'? Configuration @@ -120,7 +135,7 @@ available addresses. If left empty (factory default), baresip listens at port 5060 of all available addresses. - 0.0.0.0:5060 + 0.0.0.0:5060 Prefer IPv6 Prefer IPv6 if both IPv4 and IPv6 are available. DNS Servers @@ -128,11 +143,11 @@ \'server:port\'. If server is an IPv6 address, the address must be written inside brackets []. Factory default value is \'8.8.8.8:53,[2001:4860:4860::8888]:53\' pointing to public Google DNS servers. - 8.8.8.8:53 + 8.8.8.8:53 Opus Bit Rate Average maximum bit rate used by Opus audio stream. Valid value are 6000-510000. Factory default is 28000. - 28000 + 28000 ICE Lite Mode If checked, ICE Lite Mode is used. Default Call Volume @@ -150,9 +165,18 @@ Contacts - Do you want to call or send message to + Do you want to call or send message to \'%1$s\'? Send Message - Do you want to delete contact + Do you want to delete contact \'%1$s\'? + Your maximum number of contacts %1%d has been exceeded. + Exported contacts to Download folder file \'contacts.bs\'. + "Failed to export contacts to Download folder. + Check Apps -> baresip -> Permissions -> Storage." + + Imported contacts from Download folder. + Failed to import contacts from Download folder. Check Apps -> + baresip -> Permissions -> Storage and that file \'contacts.bs\' exists in the folder. + Alert @@ -167,13 +191,14 @@ Deny User ID Password - SIP URI + SIP URI Add Delete Edit Send Status - + Error + About @@ -198,11 +223,11 @@ You already have an active call! Baresip failed to start! Listen Address was reset. Restart baresip. - Registering of %1$s failed + Registering of \`%1$s\` failed. You have not granted microphone permission. Verify - Do you want to verify SAS - Do you accept to transfer call to + Do you want to verify SAS <%1$s> <%2$s>? + Do you accept to transfer call to \'%1$s\'? Call failed Call closed You need to restart baresip in order to activate the new config!