diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallListAdapter.kt b/app/src/main/kotlin/com/tutpro/baresip/CallListAdapter.kt index 38617d4f..b5f77928 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallListAdapter.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallListAdapter.kt @@ -36,9 +36,8 @@ class CallListAdapter(private val cxt: Context, private val rows: ArrayList - val i = Intent(this@CallsActivity, ChatActivity::class.java) - val b = Bundle() - b.putString("aor", aor) - b.putString("peer", uaHistory[pos].peerURI) - i.putExtras(b) - startActivityForResult(i, MainActivity.MESSAGE_CODE) + listView.adapter = adapter + listView.isLongClickable = true + + listView.onItemClickListener = AdapterView.OnItemClickListener { _, _, pos, _ -> + val peerUri = uaHistory[pos].peerURI + var peerName = ContactsActivity.contactName(peerUri) + if (peerName.startsWith("sip:")) + peerName = Utils.friendlyUri(peerName, Utils.aorDomain(aor)) + val dialogClickListener = DialogInterface.OnClickListener { _, which -> + when (which) { + DialogInterface.BUTTON_NEUTRAL, DialogInterface.BUTTON_NEGATIVE -> { + val i = Intent(this@CallsActivity, 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) + i.putExtra("action", "call") + else + i.putExtra("action", "message") + i.putExtra("uap", ua.uap) + i.putExtra("peer", peerUri) + startActivity(i) + } + DialogInterface.BUTTON_POSITIVE -> { + } + } + } + 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) + .show() } - listview.onItemLongClickListener = AdapterView.OnItemLongClickListener { _, _, pos, _ -> + listView.onItemLongClickListener = AdapterView.OnItemLongClickListener { _, _, pos, _ -> + val peerUri = uaHistory[pos].peerURI + var peerName = ContactsActivity.contactName(peerUri) val dialogClickListener = DialogInterface.OnClickListener { _, which -> when (which) { DialogInterface.BUTTON_NEUTRAL -> { val i = Intent(this, ContactActivity::class.java) val b = Bundle() b.putBoolean("new", true) - b.putString("uri", uaHistory[pos].peerURI) + b.putString("uri", peerUri) i.putExtras(b) startActivityForResult(i, MainActivity.CONTACT_CODE) } @@ -71,23 +97,25 @@ class CallsActivity : AppCompatActivity() { } } } + val callText: String + if (uaHistory[pos].directions.size > 1) callText = "Calls" else callText = "Call" val builder = AlertDialog.Builder(this@CallsActivity, R.style.Theme_AppCompat) - if (ContactsActivity.contactName(uaHistory[pos].peerURI).startsWith("sip:")) - builder.setMessage("Do you want to add ${uaHistory[pos].peerURI} to contacs or " + - "delete call from history?") + 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 Call", dialogClickListener) + .setNegativeButton("Delete $callText", dialogClickListener) .setNeutralButton("Add Contact", dialogClickListener) .show() else - builder.setMessage("Do you want to delete call from history?") + builder.setMessage("Do you want to delete ${callText.toLowerCase()} from history?") .setPositiveButton("Cancel", dialogClickListener) - .setNegativeButton("Delete Call", dialogClickListener) + .setNegativeButton("Delete $callText", dialogClickListener) .show() true } - listview.isLongClickable = true ua!!.account.missedCalls = false } diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt index 94696470..882690d0 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt @@ -33,7 +33,7 @@ class ChatActivity : AppCompatActivity() { aor = intent.extras.getString("aor") peerUri = intent.extras.getString("peer") - val reply = intent.extras.getBoolean("reply") + val focus = intent.extras.getBoolean("focus") val userAgent = Account.findUa(aor) if (userAgent == null) { @@ -106,7 +106,7 @@ class ChatActivity : AppCompatActivity() { } newMessage = findViewById(R.id.text) as EditText - if (reply) newMessage.requestFocus() + if (focus) newMessage.requestFocus() sendButton = findViewById(R.id.sendButton) as ImageButton sendButton.setOnClickListener { diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatsActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatsActivity.kt index 9c262356..5dbf4373 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatsActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatsActivity.kt @@ -80,13 +80,14 @@ class ChatsActivity: AppCompatActivity() { val builder = AlertDialog.Builder(this@ChatsActivity, R.style.Theme_AppCompat) val peer = ContactsActivity.contactName(uaMessages[pos].peerUri) if (peer.startsWith("sip:")) - builder.setMessage("Do you want to delete chat with $peer or add peer to contacts?") + builder.setMessage("Do you want to delete chat with peer '" + + "${Utils.friendlyUri(peer, Utils.aorDomain(aor))}' or add peer to contacts?") .setPositiveButton("Cancel", dialogClickListener) .setNegativeButton("Delete Chat", dialogClickListener) .setNeutralButton("Add Contact", dialogClickListener) .show() else - builder.setMessage("Do you want to delete chat with $peer?") + builder.setMessage("Do you want to delete chat with '$peer'?") .setPositiveButton("Cancel", dialogClickListener) .setNegativeButton("Delete Chat", dialogClickListener) .show() @@ -130,6 +131,7 @@ class ChatsActivity: AppCompatActivity() { val b = Bundle() b.putString("aor", aor) b.putString("peer", peer) + b.putBoolean("focus", intent.extras.getBoolean("focus")) i.putExtras(b) startActivityForResult(i, MainActivity.MESSAGE_CODE) } diff --git a/app/src/main/kotlin/com/tutpro/baresip/ContactListAdapter.kt b/app/src/main/kotlin/com/tutpro/baresip/ContactListAdapter.kt index b5186a54..60c4f91e 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ContactListAdapter.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ContactListAdapter.kt @@ -6,6 +6,7 @@ import android.content.DialogInterface import android.content.Intent import android.os.Bundle import android.support.v7.app.AlertDialog +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -19,8 +20,8 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList(cxt, R.layout.contact_row, rows) { - override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { - val row = rows[position] + override fun getView(pos: Int, convertView: View?, parent: ViewGroup): View { + val row = rows[pos] val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater val rowView = inflater.inflate(R.layout.contact_row, parent, false) val nameView = rowView.findViewById(R.id.contactName) as TextView @@ -31,31 +32,30 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList val dialogClickListener = DialogInterface.OnClickListener { _, which -> when (which) { - DialogInterface.BUTTON_NEUTRAL -> { - val intent = Intent(cxt, MainActivity::class.java) - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or + DialogInterface.BUTTON_NEUTRAL, 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) - intent.putExtra("action", "call") - intent.putExtra("uap", Account.findUa(aor)!!.uap) - intent.putExtra("peer", ContactsActivity.contacts[position].uri) - (cxt as Activity).startActivity(intent) - } - DialogInterface.BUTTON_NEGATIVE -> { - val intent = Intent(cxt, ChatsActivity::class.java) - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - val b = Bundle() - b.putString("aor", aor) - b.putString("peer", ContactsActivity.contacts[position].uri) - intent.putExtras(b) - (cxt as Activity).startActivity(intent) + if (which == DialogInterface.BUTTON_NEUTRAL) + i.putExtra("action", "call") + else + i.putExtra("action", "message") + val ua = Account.findUa(aor) + if (ua == null) { + Log.e("Baresip", "onClickListener did not find AoR $aor") + } else { + i.putExtra("uap", ua.uap) + i.putExtra("peer", ContactsActivity.contacts[pos].uri) + (cxt as Activity).startActivity(i) + } } DialogInterface.BUTTON_POSITIVE -> { } } } val builder = AlertDialog.Builder(cxt, R.style.Theme_AppCompat) - builder.setMessage("Do you want to call or send message to " + - "${ContactsActivity.contacts[position].name}?") + builder.setMessage("Do you want to call or send message to '" + + "${ContactsActivity.contacts[pos].name}'?") .setNeutralButton("Call", dialogClickListener) .setNegativeButton("Send Message", dialogClickListener) .setPositiveButton("Cancel", dialogClickListener) @@ -66,7 +66,7 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList when (which) { DialogInterface.BUTTON_NEGATIVE -> { - ContactsActivity.contacts.removeAt(position) + ContactsActivity.contacts.removeAt(pos) ContactsActivity.saveContacts() this.notifyDataSetChanged() } @@ -75,7 +75,8 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList { - val i = Intent(this@MainActivity, ChatActivity::class.java) + val i = Intent(this@MainActivity, ChatsActivity::class.java) val b = Bundle() if (ua != uas[aorSpinner.selectedItemPosition]) { for (account_index in uas.indices) { @@ -751,9 +753,9 @@ class MainActivity : AppCompatActivity() { } b.putString("aor", aor) b.putString("peer", intent.getStringExtra("peer")) - b.putBoolean("reply", true) + b.putBoolean("focus", true) i.putExtras(b) - startActivityForResult(i, MESSAGE_CODE) + startActivityForResult(i, MESSAGES_CODE) } "save" -> { ChatsActivity.saveUaMessage(ua.account.aor, @@ -768,6 +770,16 @@ class MainActivity : AppCompatActivity() { } nm.cancel(BaresipService.MESSAGE_NOTIFICATION_ID) } + "message" -> { + val ua = UserAgent.find(MainActivity.uas, intent.getStringExtra("uap"))!! + val i = Intent(applicationContext, ChatsActivity::class.java) + val b = Bundle() + b.putString("aor", ua.account.aor) + b.putString("peer", intent.getStringExtra("peer")) + b.putBoolean("focus", true) + i.putExtras(b) + startActivity(i) + } } } diff --git a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt index 2de786fd..4e6574d8 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt @@ -94,6 +94,16 @@ object Utils { return uri.substringAfter(":").substringBefore("@") } + fun friendlyUri(uri: String, domain: String): String { + val user = uriUserPart(uri) + val host = uriHostPart(uri) + if (host == domain) return user else return "$user@$host" + } + + fun aorDomain(aor: String): String { + return aor.substringAfter("@") + } + fun checkUserID(id: String): Boolean { return Regex("^[a-zA-Z]([._-]|[a-zA-Z0-9]){1,49}\$").matches(id) }