contact and call history improvements
This commit is contained in:
@ -36,9 +36,8 @@ class CallListAdapter(private val cxt: Context, private val rows: ArrayList<Call
|
||||
}
|
||||
val peerURIView = rowView.findViewById(R.id.peer_uri) as TextView
|
||||
val contactName = ContactsActivity.contactName(row.peerURI)
|
||||
if (contactName.startsWith("sip:") &&
|
||||
(Utils.uriHostPart(row.peerURI) == Utils.uriHostPart(row.aor)))
|
||||
peerURIView.text = Utils.uriUserPart(row.peerURI)
|
||||
if (contactName.startsWith("sip:"))
|
||||
peerURIView.text = Utils.friendlyUri(contactName, Utils.aorDomain(row.aor))
|
||||
else
|
||||
peerURIView.text = contactName
|
||||
val timeView = rowView.findViewById(R.id.time) as TextView
|
||||
|
||||
@ -30,31 +30,57 @@ class CallsActivity : AppCompatActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_calls)
|
||||
|
||||
val listview = findViewById(R.id.calls) as ListView
|
||||
val listView = findViewById(R.id.calls) as ListView
|
||||
|
||||
val aor = intent.extras.getString("aor")
|
||||
val ua = Account.findUa(aor)
|
||||
val ua = Account.findUa(aor)!!
|
||||
|
||||
aorGenerateHistory(aor)
|
||||
|
||||
val adapter = CallListAdapter(this, uaHistory)
|
||||
listview.adapter = adapter
|
||||
listview.onItemClickListener = AdapterView.OnItemClickListener { _, _, pos, _ ->
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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<C
|
||||
private val aor: String) :
|
||||
ArrayAdapter<Contact>(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<C
|
||||
nameView.setOnClickListener { _ ->
|
||||
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<C
|
||||
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
||||
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<C
|
||||
}
|
||||
}
|
||||
val builder = AlertDialog.Builder(cxt, R.style.Theme_AppCompat)
|
||||
builder.setMessage("Do you want to delete ${ContactsActivity.contacts[position].name}?")
|
||||
builder.setMessage("Do you want to delete contact '" +
|
||||
"${ContactsActivity.contacts[pos].name}'?")
|
||||
.setPositiveButton("Cancel", dialogClickListener)
|
||||
.setNegativeButton("Delete Contact", dialogClickListener)
|
||||
.show()
|
||||
@ -86,7 +87,7 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<C
|
||||
val i = Intent(cxt, ContactActivity::class.java)
|
||||
val b = Bundle()
|
||||
b.putBoolean("new", false)
|
||||
b.putInt("index", position)
|
||||
b.putInt("index", pos)
|
||||
i.putExtras(b)
|
||||
(cxt as Activity).startActivityForResult(i, MainActivity.CONTACT_CODE)
|
||||
}
|
||||
|
||||
@ -331,6 +331,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val b = Bundle()
|
||||
b.putString("aor", uas[aorSpinner.selectedItemPosition].account.aor)
|
||||
b.putString("peer", "")
|
||||
b.putBoolean("focus", false)
|
||||
i.putExtras(b)
|
||||
startActivityForResult(i, MESSAGES_CODE)
|
||||
}
|
||||
@ -659,6 +660,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val b = Bundle()
|
||||
b.putString("aor", ua.account.aor)
|
||||
b.putString("peer", peerUri)
|
||||
b.putBoolean("focus", false)
|
||||
i.putExtras(b)
|
||||
startActivity(i)
|
||||
}
|
||||
@ -739,7 +741,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val aor = ua.account.aor
|
||||
when (action) {
|
||||
"reply" -> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user