- Tried to align alerts with material design guidelines.

- Still more work on strings.
This commit is contained in:
Juha Heinanen
2019-05-11 15:27:35 +03:00
parent c061c5d2f9
commit e4fbb71d16
20 changed files with 284 additions and 216 deletions
@@ -1,5 +1,7 @@
package com.tutpro.baresip
import android.content.Context
class Account(val accp: String) {
var displayName = account_display_name(accp)
@@ -98,28 +100,28 @@ class Account(val accp: String) {
return res
}
fun vmMessage() : String {
fun vmMessages(cxt: Context) : String {
var new = ""
var old = ""
if (vmNew > 0)
if (vmNew == 1)
new = "$vmNew new message"
new = cxt.getString(R.string.one_new_message)
else
new = "$vmNew new messages"
new = "$vmNew ${cxt.getString(R.string.new_messages)}"
if (vmOld > 0)
if (vmOld == 1)
old = "$vmOld old message"
old = cxt.getString(R.string.one_old_message)
else
old = "$vmOld old messages"
var msg = "You have"
old = "$vmOld ${cxt.getString(R.string.old_messages)}"
var msg = cxt.getString(R.string.you_have)
if (new != "") {
msg = "$msg $new"
if (old != "") msg = "$msg and $old"
if (old != "") msg = "$msg ${cxt.getString(R.string.and)} $old"
} else {
if (old != "")
msg = "$msg $old"
else
msg = "$msg no messages"
msg = cxt.getString(R.string.no_messages)
}
return "$msg."
}
@@ -57,33 +57,6 @@ class AccountActivity : AppCompatActivity() {
outbound2.setText(acc.outbound[1])
}
mediaNat = acc.mediaNat
val mediaNatSpinner = findViewById(R.id.mediaNatSpinner) as Spinner
val mediaNatKeys = arrayListOf("stun", "ice", "")
val mediaNatVals = arrayListOf("STUN", "ICE", "None")
var keyIx = mediaNatKeys.indexOf(acc.mediaNat)
var keyVal = mediaNatVals.elementAt(keyIx)
mediaNatKeys.removeAt(keyIx)
mediaNatVals.removeAt(keyIx)
mediaNatKeys.add(0, acc.mediaNat)
mediaNatVals.add(0, keyVal)
val mediaNatAdapter = ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,
mediaNatVals)
mediaNatAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
mediaNatSpinner.adapter = mediaNatAdapter
mediaNatSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
mediaNat = mediaNatKeys[mediaNatVals.indexOf(parent.selectedItem.toString())]
stunServer.isEnabled = mediaNat != ""
}
override fun onNothingSelected(parent: AdapterView<*>) {
}
}
stunServer = findViewById(R.id.StunServer) as EditText
stunServer.setText(acc.stunServer)
stunServer.isEnabled = mediaNat != ""
regCheck = findViewById(R.id.Register) as CheckBox
regCheck.isChecked = acc.regint > 0
@@ -123,10 +96,37 @@ class AccountActivity : AppCompatActivity() {
}
}
mediaNat = acc.mediaNat
val mediaNatSpinner = findViewById(R.id.mediaNatSpinner) as Spinner
val mediaNatKeys = arrayListOf("stun", "ice", "")
val mediaNatVals = arrayListOf("STUN", "ICE", "-")
var keyIx = mediaNatKeys.indexOf(acc.mediaNat)
var keyVal = mediaNatVals.elementAt(keyIx)
mediaNatKeys.removeAt(keyIx)
mediaNatVals.removeAt(keyIx)
mediaNatKeys.add(0, acc.mediaNat)
mediaNatVals.add(0, keyVal)
val mediaNatAdapter = ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,
mediaNatVals)
mediaNatAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
mediaNatSpinner.adapter = mediaNatAdapter
mediaNatSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
mediaNat = mediaNatKeys[mediaNatVals.indexOf(parent.selectedItem.toString())]
stunServer.isEnabled = mediaNat != ""
}
override fun onNothingSelected(parent: AdapterView<*>) {
}
}
stunServer = findViewById(R.id.StunServer) as EditText
stunServer.setText(acc.stunServer)
stunServer.isEnabled = mediaNat != ""
mediaEnc = acc.mediaEnc
val mediaEncSpinner = findViewById(R.id.mediaEncSpinner) as Spinner
val mediaEncKeys = arrayListOf("zrtp", "dtls_srtp", "srtp-mandf", "srtp-mand", "srtp", "")
val mediaEncVals = arrayListOf("ZRTP", "DTLS-SRTPF", "SRTP-MANDF", "SRTP-MAND", "SRTP", "None")
val mediaEncVals = arrayListOf("ZRTP", "DTLS-SRTPF", "SRTP-MANDF", "SRTP-MAND", "SRTP", "-")
keyIx = mediaEncKeys.indexOf(acc.mediaEnc)
keyVal = mediaEncVals.elementAt(keyIx)
mediaEncKeys.removeAt(keyIx)
@@ -41,10 +41,7 @@ class AccountListAdapter(private val cxt: Context, private val rows: ArrayList<A
val deleteDialog = AlertDialog.Builder(cxt)
deleteDialog.setMessage(String.format(cxt.getString(R.string.delete_account),
ua.account.aor))
deleteDialog.setPositiveButton(cxt.getText(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}
deleteDialog.setNegativeButton(cxt.getText(R.string.delete)) { dialog, _ ->
deleteDialog.setPositiveButton(cxt.getText(R.string.delete)) { dialog, _ ->
Api.ua_destroy(ua.uap)
UserAgent.remove(ua)
AccountsActivity.generateAccounts()
@@ -52,6 +49,9 @@ class AccountListAdapter(private val cxt: Context, private val rows: ArrayList<A
this.notifyDataSetChanged()
dialog.dismiss()
}
deleteDialog.setNegativeButton(cxt.getText(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}
deleteDialog.create().show()
}
return rowView
@@ -36,10 +36,9 @@ class AccountsActivity : AppCompatActivity() {
val newAorView = findViewById(R.id.newAor) as EditText
addAccountButton.setOnClickListener{
var aor = newAorView.text.toString().trim()
if (!aor.startsWith("sip:")) aor = "sip:$aor"
if (!Utils.checkAorUri(aor)) {
Log.d("Baresip", "Invalid SIP Address of Record $aor")
Utils.alertView(this, getString(R.string.notice),
if (!Utils.checkAor(aor)) {
Log.d("Baresip", "Invalid Address of Record $aor")
Utils.alertView(this, getString(R.string.error),
String.format(getString(R.string.invalid_aor), aor))
} else if (Account.exists(aor)) {
Log.d("Baresip", "Account $aor already exists")
@@ -53,7 +52,7 @@ class AccountsActivity : AppCompatActivity() {
getString(R.string.account_allocation_failure))
} else {
newAorView.setText("")
newAorView.hint = getString(R.string.sip_uri_user_domain)
newAorView.hint = getString(R.string.user_domain)
newAorView.clearFocus()
UserAgent.add(ua, R.drawable.dot_yellow)
generateAccounts()
@@ -690,6 +690,7 @@ class BaresipService: Service() {
}
private fun abandonAudioFocus() {
Log.d(LOG_TAG, "Abandonin audio focus")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (audioFocusRequest != null) {
am.abandonAudioFocusRequest(audioFocusRequest!!)
@@ -29,7 +29,7 @@ class CallsActivity : AppCompatActivity() {
val ua = Account.findUa(aor)!!
val headerView = findViewById(R.id.account) as TextView
val headerText = "Account ${aor.substringAfter(":")}"
val headerText = "${getString(R.string.account)} ${aor.substringAfter(":")}"
headerView.text = headerText
val listView = findViewById(R.id.calls) as ListView
@@ -45,10 +45,10 @@ class CallsActivity : AppCompatActivity() {
peerName = Utils.friendlyUri(peerName, Utils.aorDomain(aor))
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
when (which) {
DialogInterface.BUTTON_NEUTRAL, DialogInterface.BUTTON_NEGATIVE -> {
DialogInterface.BUTTON_POSITIVE, DialogInterface.BUTTON_NEGATIVE -> {
val i = Intent(this@CallsActivity, MainActivity::class.java)
i.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
if (which == DialogInterface.BUTTON_NEUTRAL)
if (which == DialogInterface.BUTTON_NEGATIVE)
i.putExtra("action", "call")
else
i.putExtra("action", "message")
@@ -56,15 +56,16 @@ class CallsActivity : AppCompatActivity() {
i.putExtra("peer", peerUri)
startActivity(i)
}
DialogInterface.BUTTON_POSITIVE -> {
DialogInterface.BUTTON_NEUTRAL -> {
}
}
}
val builder = AlertDialog.Builder(this@CallsActivity, R.style.Theme_AppCompat)
builder.setMessage("Do you want to call or send message to '$peerName'?")
.setNeutralButton("Call", dialogClickListener)
.setNegativeButton("Send Message", dialogClickListener)
.setPositiveButton("Cancel", dialogClickListener)
builder.setMessage(String.format(getString(R.string.calls_call_message_question),
peerName))
.setNeutralButton(getString(R.string.cancel), dialogClickListener)
.setNegativeButton(getString(R.string.call), dialogClickListener)
.setPositiveButton(getString(R.string.send_message), dialogClickListener)
.show()
}
listView.onItemLongClickListener = AdapterView.OnItemLongClickListener { _, _, pos, _ ->
@@ -72,7 +73,7 @@ class CallsActivity : AppCompatActivity() {
val peerName = ContactsActivity.contactName(peerUri)
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
when (which) {
DialogInterface.BUTTON_NEUTRAL -> {
DialogInterface.BUTTON_NEGATIVE -> {
val i = Intent(this, ContactActivity::class.java)
val b = Bundle()
b.putBoolean("new", true)
@@ -80,7 +81,7 @@ class CallsActivity : AppCompatActivity() {
i.putExtras(b)
startActivityForResult(i, MainActivity.CONTACT_CODE)
}
DialogInterface.BUTTON_NEGATIVE -> {
DialogInterface.BUTTON_POSITIVE -> {
removeUaHistoryAt(pos)
if (uaHistory.size == 0) {
val i = Intent()
@@ -89,25 +90,30 @@ class CallsActivity : AppCompatActivity() {
}
adapter.notifyDataSetChanged()
}
DialogInterface.BUTTON_POSITIVE -> {
DialogInterface.BUTTON_NEUTRAL -> {
}
}
}
val callText: String
if (uaHistory[pos].directions.size > 1) callText = "Calls" else callText = "Call"
if (uaHistory[pos].directions.size > 1)
callText = getString(R.string.calls_calls)
else
callText = getString(R.string.calls_call)
val builder = AlertDialog.Builder(this@CallsActivity, R.style.Theme_AppCompat)
if (peerName.startsWith("sip:"))
builder.setMessage("Do you want to add '" +
"${Utils.friendlyUri(peerName, Utils.aorDomain(aor))}' to contacts " +
"or delete ${callText.toLowerCase()} from history?")
.setPositiveButton("Cancel", dialogClickListener)
.setNegativeButton("Delete $callText", dialogClickListener)
.setNeutralButton("Add Contact", dialogClickListener)
builder.setMessage(String.format(getString(R.string.calls_add_delete_question),
Utils.friendlyUri(peerName, Utils.aorDomain(aor)), callText))
.setNeutralButton(getString(R.string.cancel), dialogClickListener)
.setNegativeButton(getString(R.string.add_contact), dialogClickListener)
.setPositiveButton(String.format(getString(R.string.delete), callText),
dialogClickListener)
.show()
else
builder.setMessage("Do you want to delete ${callText.toLowerCase()} from history?")
.setPositiveButton("Cancel", dialogClickListener)
.setNegativeButton("Delete $callText", dialogClickListener)
builder.setMessage(String.format(getString(R.string.calls_delete_question),
Utils.friendlyUri(peerName, Utils.aorDomain(aor)), callText))
.setNeutralButton(getString(R.string.cancel), dialogClickListener)
.setPositiveButton(String.format(getString(R.string.delete), callText),
dialogClickListener)
.show()
true
}
@@ -77,7 +77,7 @@ class ChatActivity : AppCompatActivity() {
listView.onItemLongClickListener = AdapterView.OnItemLongClickListener { _, _, pos, _ ->
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
when (which) {
DialogInterface.BUTTON_NEUTRAL -> {
DialogInterface.BUTTON_POSITIVE -> {
val i = Intent(this, ContactActivity::class.java)
val b = Bundle()
b.putBoolean("new", true)
@@ -94,7 +94,7 @@ class ChatActivity : AppCompatActivity() {
}
Message.saveMessages(applicationContext.filesDir.absolutePath)
}
DialogInterface.BUTTON_POSITIVE -> {
DialogInterface.BUTTON_NEUTRAL -> {
}
}
}
@@ -102,13 +102,13 @@ class ChatActivity : AppCompatActivity() {
if (ContactsActivity.contactName(peerUri) == peerUri)
builder.setMessage(String.format(getString(R.string.long_message_question),
chatPeer))
.setPositiveButton(getString(R.string.cancel), dialogClickListener)
.setNeutralButton(getString(R.string.cancel), dialogClickListener)
.setNegativeButton(getString(R.string.delete), dialogClickListener)
.setNeutralButton(getString(R.string.add_contact), dialogClickListener)
.setPositiveButton(getString(R.string.add_contact), dialogClickListener)
.show()
else
builder.setMessage(getText(R.string.short_message_question))
.setPositiveButton(getString(R.string.cancel), dialogClickListener)
.setNeutralButton(getString(R.string.cancel), dialogClickListener)
.setNegativeButton(getString(R.string.delete), dialogClickListener)
.show()
true
@@ -38,7 +38,7 @@ class ChatListAdapter(private val cxt: Context, private var rows: ArrayList<Mess
sender = peer
} else {
layout.setBackgroundResource(R.drawable.you_bg)
sender = "You"
sender = cxt.getString(R.string.you)
}
val peerView = chatView.findViewById(R.id.peer) as TextView
peerView.setText(peer)
@@ -53,14 +53,14 @@ class ChatListAdapter(private val cxt: Context, private var rows: ArrayList<Mess
val fmt = SimpleDateFormat("dd/MM, HH:mm")
info = fmt.format(cal.time)
}
if (info.length < 6) info = "Today $info"
if (info.length < 6) info = "${cxt.getString(R.string.today)} $info"
infoView.text = "$info - $sender"
if (message.direction == R.drawable.arrow_up_red) {
if (message.responseCode != 0)
infoView.text = "${infoView.text} - Failed: ${message.responseCode} " +
"${message.responseReason}"
infoView.text = "${infoView.text} - ${cxt.getString(R.string.message_failed)}: " +
"${message.responseCode} ${message.responseReason}"
else
infoView.text = "${infoView.text} - Sending of message failed!"
infoView.text = "${infoView.text} - ${cxt.getString(R.string.sending_failed)}"
infoView.setTextColor(ContextCompat.getColor(cxt, R.color.colorAccent))
}
val textView = chatView.findViewById(R.id.text) as TextView
@@ -35,7 +35,7 @@ class ChatsActivity: AppCompatActivity() {
aor = intent.extras!!.getString("aor")!!
val headerView = findViewById(R.id.account) as TextView
val headerText = "Account ${aor.substringAfter(":")}"
val headerText = "${getString(R.string.account)} ${aor.substringAfter(":")}"
headerView.text = headerText
uaMessages = uaMessages(aor)
@@ -55,7 +55,7 @@ class ChatsActivity: AppCompatActivity() {
listView.onItemLongClickListener = AdapterView.OnItemLongClickListener { _, _, pos, _ ->
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
when (which) {
DialogInterface.BUTTON_NEUTRAL -> {
DialogInterface.BUTTON_POSITIVE -> {
val i = Intent(this, ContactActivity::class.java)
val b = Bundle()
b.putBoolean("new", true)
@@ -76,7 +76,7 @@ class ChatsActivity: AppCompatActivity() {
Message.saveMessages(filesPath)
uaMessages = uaMessages(aor)
}
DialogInterface.BUTTON_POSITIVE -> {
DialogInterface.BUTTON_NEUTRAL -> {
}
}
}
@@ -86,13 +86,13 @@ class ChatsActivity: AppCompatActivity() {
if (peer.startsWith("sip:"))
builder.setMessage(String.format(getString(R.string.long_chat_question),
Utils.friendlyUri(peer, Utils.aorDomain(aor))))
.setPositiveButton(getText(R.string.cancel), dialogClickListener)
.setNeutralButton(getText(R.string.cancel), dialogClickListener)
.setNegativeButton(getText(R.string.delete), dialogClickListener)
.setNeutralButton(getText(R.string.add_contact), dialogClickListener)
.setPositiveButton(getText(R.string.add_contact), dialogClickListener)
.show()
else
builder.setMessage(String.format(getString(R.string.short_chat_question), peer))
.setPositiveButton(getText(R.string.cancel), dialogClickListener)
.setNeutralButton(getText(R.string.cancel), dialogClickListener)
.setNegativeButton(getText(R.string.delete), dialogClickListener)
.show()
true
@@ -115,7 +115,8 @@ class ChatsActivity: AppCompatActivity() {
}
}
if (!Utils.checkSipUri(uri)) {
Utils.alertView(this, "Notice", "Invalid SIP URI '$uri'")
Utils.alertView(this, getString(R.string.error),
getString(R.string.invalid_chat_peer_uri))
} else {
peerUri.text.clear()
peerUri.isCursorVisible = false
@@ -24,13 +24,13 @@ class ContactActivity : AppCompatActivity() {
new = intent.getBooleanExtra("new", false)
if (new) {
setTitle("New Contact")
setTitle(getString(R.string.new_contact))
nameView.setText("")
nameView.hint = "Contact name"
nameView.hint = getString(R.string.contact_name)
nameView.setSelection(nameView.text.length)
if (uri == "") {
uriView.setText("")
uriView.hint = "SIP URI"
uriView.hint = getString(R.string.sip_uri)
} else {
uriView.setText(uri)
}
@@ -58,30 +58,32 @@ class ContactActivity : AppCompatActivity() {
val newName = nameView.text.toString().trim()
if (!Utils.checkName(newName)) {
Utils.alertView(this, "Notice",
"Invalid contact name: $newName")
Utils.alertView(this, getString(R.string.error),
String.format(getString(R.string.invalid_contact), newName))
return false
}
if ((new || (Contact.contacts()[index].name != newName)) &&
ContactsActivity.nameExists(newName)) {
Utils.alertView(this, "Notice",
"Contact $newName already exists")
Utils.alertView(this, getString(R.string.error),
String.format(getString(R.string.contact_already_exists), newName))
return false
}
var newUri = uriView.text.toString().trim()
if (!newUri.startsWith("<")) {
if (!newUri.startsWith("sip:")) newUri = "sip:$newUri"
if (!Utils.checkAorUri(newUri)) {
Utils.alertView(this, "Notice","Invalid contact URI: $newUri")
if (!Utils.checkAor(newUri.substringAfter("sip:"))) {
Utils.alertView(this, getString(R.string.error),
String.format(getString(R.string.invalid_contact_uri), newUri))
return false
}
}
if (new) {
if (Contact.contacts().size >= Contact.CONTACTS_SIZE) {
Utils.alertView(this,
"Notice", "Maximum number of contacts exceeded")
Utils.alertView(this, getString(R.string.notice),
String.format(getString(R.string.contacts_exceeded),
Contact.CONTACTS_SIZE))
return true
} else {
Contact.contacts().add(Contact(newName, newUri))
@@ -31,11 +31,11 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<C
nameView.setOnClickListener { _ ->
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
when (which) {
DialogInterface.BUTTON_NEUTRAL, DialogInterface.BUTTON_NEGATIVE -> {
DialogInterface.BUTTON_POSITIVE, DialogInterface.BUTTON_NEGATIVE -> {
val i = Intent(cxt, MainActivity::class.java)
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or
Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
if (which == DialogInterface.BUTTON_NEUTRAL)
if (which == DialogInterface.BUTTON_NEGATIVE)
i.putExtra("action", "call")
else
i.putExtra("action", "message")
@@ -48,36 +48,36 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<C
(cxt as Activity).startActivity(i)
}
}
DialogInterface.BUTTON_POSITIVE -> {
DialogInterface.BUTTON_NEUTRAL -> {
}
}
}
val builder = AlertDialog.Builder(cxt, R.style.Theme_AppCompat)
builder.setMessage(String.format(cxt.getString(R.string.contact_action_question),
Contact.contacts()[pos].name))
.setNeutralButton(cxt.getText(R.string.call), dialogClickListener)
.setNegativeButton(cxt.getText(R.string.send_message), dialogClickListener)
.setPositiveButton(cxt.getText(R.string.cancel), dialogClickListener)
.setNeutralButton(cxt.getText(R.string.cancel), dialogClickListener)
.setNegativeButton(cxt.getText(R.string.call), dialogClickListener)
.setPositiveButton(cxt.getText(R.string.send_message), dialogClickListener)
.show()
}
}
nameView.setOnLongClickListener { _ ->
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
when (which) {
DialogInterface.BUTTON_NEGATIVE -> {
DialogInterface.BUTTON_POSITIVE -> {
Contact.contacts().removeAt(pos)
ContactsActivity.saveContacts(cxt.applicationContext.filesDir)
this.notifyDataSetChanged()
}
DialogInterface.BUTTON_POSITIVE -> {
DialogInterface.BUTTON_NEGATIVE -> {
}
}
}
val builder = AlertDialog.Builder(cxt, R.style.Theme_AppCompat)
builder.setMessage(String.format(cxt.getString(R.string.contact_delete_question),
Contact.contacts()[pos].name))
.setNegativeButton(cxt.getText(R.string.delete), dialogClickListener)
.setPositiveButton(cxt.getText(R.string.cancel), dialogClickListener)
.setNegativeButton(cxt.getText(R.string.cancel), dialogClickListener)
.setPositiveButton(cxt.getText(R.string.delete), dialogClickListener)
.show()
true
}
@@ -31,7 +31,8 @@ class ContactsActivity : AppCompatActivity() {
plusButton.setOnClickListener {
if (Contact.contacts().size >= Contact.CONTACTS_SIZE) {
Utils.alertView(this, getString(R.string.notice),
String.format(getString(R.string.contacts_exceeded), Contact.CONTACTS_SIZE))
String.format(getString(R.string.contacts_exceeded),
Contact.CONTACTS_SIZE))
} else {
val i = Intent(this, ContactActivity::class.java)
val b = Bundle()
@@ -57,7 +58,8 @@ class ContactsActivity : AppCompatActivity() {
when (item.itemId) {
R.id.export_contacts -> {
if (saveContacts(dir))
Utils.alertView(this,"", getString(R.string.exported_contacts))
Utils.alertView(this, "",
getString(R.string.exported_contacts))
else
Utils.alertView(this,getString(R.string.error),
getString(R.string.export_error))
@@ -65,7 +67,7 @@ class ContactsActivity : AppCompatActivity() {
R.id.import_contacts -> {
if (restoreContacts(dir)) {
Utils.alertView(this, "",
"Imported contacts from Download folder.")
getString(R.string.imported_contacts))
clAdapter.notifyDataSetChanged()
saveContacts(applicationContext.filesDir)
} else
@@ -345,7 +345,7 @@ class MainActivity : AppCompatActivity() {
if (acc.vmUri != "") {
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
when (which) {
DialogInterface.BUTTON_NEGATIVE -> {
DialogInterface.BUTTON_POSITIVE -> {
val callIntent = Intent(this, MainActivity::class.java)
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or
Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
@@ -354,16 +354,16 @@ class MainActivity : AppCompatActivity() {
callIntent.putExtra("peer", acc.vmUri)
startActivity(callIntent)
}
DialogInterface.BUTTON_POSITIVE -> {
DialogInterface.BUTTON_NEGATIVE -> {
}
}
}
val builder = AlertDialog.Builder(this@MainActivity,
R.style.Theme_AppCompat)
builder.setTitle(getString(R.string.voicemail_messages))
builder.setMessage(acc.vmMessage())
.setPositiveButton(getString(R.string.cancel), dialogClickListener)
.setNegativeButton(getString(R.string.check), dialogClickListener)
builder.setMessage(acc.vmMessages(this))
.setPositiveButton(getString(R.string.listen), dialogClickListener)
.setNegativeButton(getString(R.string.cancel), dialogClickListener)
.show()
}
}
@@ -28,7 +28,7 @@ class MessageListAdapter(private val cxt: Context, private val rows: ArrayList<M
if (up) {
lp.setMargins(75, 10, 0, 10)
layout.setBackgroundResource(R.drawable.you_bg)
peer = "You"
peer = cxt.getString(R.string.you)
} else {
lp.setMargins(0, 10, 75, 10)
layout.setBackgroundResource(R.drawable.peer_bg)
@@ -51,14 +51,14 @@ class MessageListAdapter(private val cxt: Context, private val rows: ArrayList<M
val fmt = SimpleDateFormat("dd/MM, HH:mm")
info = fmt.format(cal.time)
}
if (info.length < 6) info = "Today $info"
if (info.length < 6) info = "${cxt.getString(R.string.today)} $info"
infoView.text = "$info - $peer"
if (message.direction == R.drawable.arrow_up_red) {
if (message.responseCode != 0)
infoView.text = "${infoView.text} - Failed: ${message.responseCode} " +
"${message.responseReason}"
infoView.text = "${infoView.text} - ${cxt.getString(R.string.message_failed)}: " +
"${message.responseCode} ${message.responseReason}"
else
infoView.text = "${infoView.text} - Sending of message failed!"
infoView.text = "${infoView.text} - ${cxt.getString(R.string.sending_failed)}"
infoView.setTextColor(ContextCompat.getColor(cxt, R.color.colorAccent))
}
val textView = messageView.findViewById(R.id.text) as TextView
@@ -145,8 +145,18 @@ object Utils {
}
}
fun aorUser(aor: String): String {
val user = aor.substringBefore("@")
return if (user == aor) "" else user
}
fun aorDomain(aor: String): String {
return aor.substringAfter("@")
val domain = aor.substringAfter("@")
return if (domain == aor) "" else domain
}
fun checkAor(aor: String): Boolean {
return checkUriUser(aorUser(aor)) && checkDomain(aorDomain(aor))
}
fun checkTelNo(no: String): Boolean {
@@ -244,14 +254,6 @@ object Utils {
return false
}
fun checkAorUri(uri: String): Boolean {
if (!uri.startsWith("sip:")) return false
val userDomain = uri.replace("sip:", "").split("@")
if (userDomain.size != 2) return false
if (!checkUriUser(userDomain[0])) return false
return checkDomain(userDomain[1]) || checkIp(userDomain[1])
}
fun checkPrintAscii(s: String): Boolean {
if (s == "") return true
return Regex("^[ -~]*\$").matches(s)