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 peerURIView = rowView.findViewById(R.id.peer_uri) as TextView
|
||||||
val contactName = ContactsActivity.contactName(row.peerURI)
|
val contactName = ContactsActivity.contactName(row.peerURI)
|
||||||
if (contactName.startsWith("sip:") &&
|
if (contactName.startsWith("sip:"))
|
||||||
(Utils.uriHostPart(row.peerURI) == Utils.uriHostPart(row.aor)))
|
peerURIView.text = Utils.friendlyUri(contactName, Utils.aorDomain(row.aor))
|
||||||
peerURIView.text = Utils.uriUserPart(row.peerURI)
|
|
||||||
else
|
else
|
||||||
peerURIView.text = contactName
|
peerURIView.text = contactName
|
||||||
val timeView = rowView.findViewById(R.id.time) as TextView
|
val timeView = rowView.findViewById(R.id.time) as TextView
|
||||||
|
|||||||
@@ -30,31 +30,57 @@ class CallsActivity : AppCompatActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_calls)
|
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 aor = intent.extras.getString("aor")
|
||||||
val ua = Account.findUa(aor)
|
val ua = Account.findUa(aor)!!
|
||||||
|
|
||||||
aorGenerateHistory(aor)
|
aorGenerateHistory(aor)
|
||||||
|
|
||||||
val adapter = CallListAdapter(this, uaHistory)
|
val adapter = CallListAdapter(this, uaHistory)
|
||||||
listview.adapter = adapter
|
listView.adapter = adapter
|
||||||
listview.onItemClickListener = AdapterView.OnItemClickListener { _, _, pos, _ ->
|
listView.isLongClickable = true
|
||||||
val i = Intent(this@CallsActivity, ChatActivity::class.java)
|
|
||||||
val b = Bundle()
|
listView.onItemClickListener = AdapterView.OnItemClickListener { _, _, pos, _ ->
|
||||||
b.putString("aor", aor)
|
val peerUri = uaHistory[pos].peerURI
|
||||||
b.putString("peer", uaHistory[pos].peerURI)
|
var peerName = ContactsActivity.contactName(peerUri)
|
||||||
i.putExtras(b)
|
if (peerName.startsWith("sip:"))
|
||||||
startActivityForResult(i, MainActivity.MESSAGE_CODE)
|
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 ->
|
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
||||||
when (which) {
|
when (which) {
|
||||||
DialogInterface.BUTTON_NEUTRAL -> {
|
DialogInterface.BUTTON_NEUTRAL -> {
|
||||||
val i = Intent(this, ContactActivity::class.java)
|
val i = Intent(this, ContactActivity::class.java)
|
||||||
val b = Bundle()
|
val b = Bundle()
|
||||||
b.putBoolean("new", true)
|
b.putBoolean("new", true)
|
||||||
b.putString("uri", uaHistory[pos].peerURI)
|
b.putString("uri", peerUri)
|
||||||
i.putExtras(b)
|
i.putExtras(b)
|
||||||
startActivityForResult(i, MainActivity.CONTACT_CODE)
|
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)
|
val builder = AlertDialog.Builder(this@CallsActivity, R.style.Theme_AppCompat)
|
||||||
if (ContactsActivity.contactName(uaHistory[pos].peerURI).startsWith("sip:"))
|
if (peerName.startsWith("sip:"))
|
||||||
builder.setMessage("Do you want to add ${uaHistory[pos].peerURI} to contacs or " +
|
builder.setMessage("Do you want to add '" +
|
||||||
"delete call from history?")
|
"${Utils.friendlyUri(peerName, Utils.aorDomain(aor))}' to contacts " +
|
||||||
|
"or delete ${callText.toLowerCase()} from history?")
|
||||||
.setPositiveButton("Cancel", dialogClickListener)
|
.setPositiveButton("Cancel", dialogClickListener)
|
||||||
.setNegativeButton("Delete Call", dialogClickListener)
|
.setNegativeButton("Delete $callText", dialogClickListener)
|
||||||
.setNeutralButton("Add Contact", dialogClickListener)
|
.setNeutralButton("Add Contact", dialogClickListener)
|
||||||
.show()
|
.show()
|
||||||
else
|
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)
|
.setPositiveButton("Cancel", dialogClickListener)
|
||||||
.setNegativeButton("Delete Call", dialogClickListener)
|
.setNegativeButton("Delete $callText", dialogClickListener)
|
||||||
.show()
|
.show()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
listview.isLongClickable = true
|
|
||||||
ua!!.account.missedCalls = false
|
ua!!.account.missedCalls = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class ChatActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
aor = intent.extras.getString("aor")
|
aor = intent.extras.getString("aor")
|
||||||
peerUri = intent.extras.getString("peer")
|
peerUri = intent.extras.getString("peer")
|
||||||
val reply = intent.extras.getBoolean("reply")
|
val focus = intent.extras.getBoolean("focus")
|
||||||
|
|
||||||
val userAgent = Account.findUa(aor)
|
val userAgent = Account.findUa(aor)
|
||||||
if (userAgent == null) {
|
if (userAgent == null) {
|
||||||
@@ -106,7 +106,7 @@ class ChatActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
newMessage = findViewById(R.id.text) as EditText
|
newMessage = findViewById(R.id.text) as EditText
|
||||||
if (reply) newMessage.requestFocus()
|
if (focus) newMessage.requestFocus()
|
||||||
|
|
||||||
sendButton = findViewById(R.id.sendButton) as ImageButton
|
sendButton = findViewById(R.id.sendButton) as ImageButton
|
||||||
sendButton.setOnClickListener {
|
sendButton.setOnClickListener {
|
||||||
|
|||||||
@@ -80,13 +80,14 @@ class ChatsActivity: AppCompatActivity() {
|
|||||||
val builder = AlertDialog.Builder(this@ChatsActivity, R.style.Theme_AppCompat)
|
val builder = AlertDialog.Builder(this@ChatsActivity, R.style.Theme_AppCompat)
|
||||||
val peer = ContactsActivity.contactName(uaMessages[pos].peerUri)
|
val peer = ContactsActivity.contactName(uaMessages[pos].peerUri)
|
||||||
if (peer.startsWith("sip:"))
|
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)
|
.setPositiveButton("Cancel", dialogClickListener)
|
||||||
.setNegativeButton("Delete Chat", dialogClickListener)
|
.setNegativeButton("Delete Chat", dialogClickListener)
|
||||||
.setNeutralButton("Add Contact", dialogClickListener)
|
.setNeutralButton("Add Contact", dialogClickListener)
|
||||||
.show()
|
.show()
|
||||||
else
|
else
|
||||||
builder.setMessage("Do you want to delete chat with $peer?")
|
builder.setMessage("Do you want to delete chat with '$peer'?")
|
||||||
.setPositiveButton("Cancel", dialogClickListener)
|
.setPositiveButton("Cancel", dialogClickListener)
|
||||||
.setNegativeButton("Delete Chat", dialogClickListener)
|
.setNegativeButton("Delete Chat", dialogClickListener)
|
||||||
.show()
|
.show()
|
||||||
@@ -130,6 +131,7 @@ class ChatsActivity: AppCompatActivity() {
|
|||||||
val b = Bundle()
|
val b = Bundle()
|
||||||
b.putString("aor", aor)
|
b.putString("aor", aor)
|
||||||
b.putString("peer", peer)
|
b.putString("peer", peer)
|
||||||
|
b.putBoolean("focus", intent.extras.getBoolean("focus"))
|
||||||
i.putExtras(b)
|
i.putExtras(b)
|
||||||
startActivityForResult(i, MainActivity.MESSAGE_CODE)
|
startActivityForResult(i, MainActivity.MESSAGE_CODE)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import android.content.DialogInterface
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@@ -19,8 +20,8 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<C
|
|||||||
private val aor: String) :
|
private val aor: String) :
|
||||||
ArrayAdapter<Contact>(cxt, R.layout.contact_row, rows) {
|
ArrayAdapter<Contact>(cxt, R.layout.contact_row, rows) {
|
||||||
|
|
||||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
override fun getView(pos: Int, convertView: View?, parent: ViewGroup): View {
|
||||||
val row = rows[position]
|
val row = rows[pos]
|
||||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||||
val rowView = inflater.inflate(R.layout.contact_row, parent, false)
|
val rowView = inflater.inflate(R.layout.contact_row, parent, false)
|
||||||
val nameView = rowView.findViewById(R.id.contactName) as TextView
|
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 { _ ->
|
nameView.setOnClickListener { _ ->
|
||||||
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
||||||
when (which) {
|
when (which) {
|
||||||
DialogInterface.BUTTON_NEUTRAL -> {
|
DialogInterface.BUTTON_NEUTRAL, DialogInterface.BUTTON_NEGATIVE -> {
|
||||||
val intent = Intent(cxt, MainActivity::class.java)
|
val i = Intent(cxt, MainActivity::class.java)
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or
|
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or
|
||||||
Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||||
intent.putExtra("action", "call")
|
if (which == DialogInterface.BUTTON_NEUTRAL)
|
||||||
intent.putExtra("uap", Account.findUa(aor)!!.uap)
|
i.putExtra("action", "call")
|
||||||
intent.putExtra("peer", ContactsActivity.contacts[position].uri)
|
else
|
||||||
(cxt as Activity).startActivity(intent)
|
i.putExtra("action", "message")
|
||||||
}
|
val ua = Account.findUa(aor)
|
||||||
DialogInterface.BUTTON_NEGATIVE -> {
|
if (ua == null) {
|
||||||
val intent = Intent(cxt, ChatsActivity::class.java)
|
Log.e("Baresip", "onClickListener did not find AoR $aor")
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
} else {
|
||||||
val b = Bundle()
|
i.putExtra("uap", ua.uap)
|
||||||
b.putString("aor", aor)
|
i.putExtra("peer", ContactsActivity.contacts[pos].uri)
|
||||||
b.putString("peer", ContactsActivity.contacts[position].uri)
|
(cxt as Activity).startActivity(i)
|
||||||
intent.putExtras(b)
|
}
|
||||||
(cxt as Activity).startActivity(intent)
|
|
||||||
}
|
}
|
||||||
DialogInterface.BUTTON_POSITIVE -> {
|
DialogInterface.BUTTON_POSITIVE -> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val builder = AlertDialog.Builder(cxt, R.style.Theme_AppCompat)
|
val builder = AlertDialog.Builder(cxt, R.style.Theme_AppCompat)
|
||||||
builder.setMessage("Do you want to call or send message to " +
|
builder.setMessage("Do you want to call or send message to '" +
|
||||||
"${ContactsActivity.contacts[position].name}?")
|
"${ContactsActivity.contacts[pos].name}'?")
|
||||||
.setNeutralButton("Call", dialogClickListener)
|
.setNeutralButton("Call", dialogClickListener)
|
||||||
.setNegativeButton("Send Message", dialogClickListener)
|
.setNegativeButton("Send Message", dialogClickListener)
|
||||||
.setPositiveButton("Cancel", dialogClickListener)
|
.setPositiveButton("Cancel", dialogClickListener)
|
||||||
@@ -66,7 +66,7 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<C
|
|||||||
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
||||||
when (which) {
|
when (which) {
|
||||||
DialogInterface.BUTTON_NEGATIVE -> {
|
DialogInterface.BUTTON_NEGATIVE -> {
|
||||||
ContactsActivity.contacts.removeAt(position)
|
ContactsActivity.contacts.removeAt(pos)
|
||||||
ContactsActivity.saveContacts()
|
ContactsActivity.saveContacts()
|
||||||
this.notifyDataSetChanged()
|
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)
|
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)
|
.setPositiveButton("Cancel", dialogClickListener)
|
||||||
.setNegativeButton("Delete Contact", dialogClickListener)
|
.setNegativeButton("Delete Contact", dialogClickListener)
|
||||||
.show()
|
.show()
|
||||||
@@ -86,7 +87,7 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<C
|
|||||||
val i = Intent(cxt, ContactActivity::class.java)
|
val i = Intent(cxt, ContactActivity::class.java)
|
||||||
val b = Bundle()
|
val b = Bundle()
|
||||||
b.putBoolean("new", false)
|
b.putBoolean("new", false)
|
||||||
b.putInt("index", position)
|
b.putInt("index", pos)
|
||||||
i.putExtras(b)
|
i.putExtras(b)
|
||||||
(cxt as Activity).startActivityForResult(i, MainActivity.CONTACT_CODE)
|
(cxt as Activity).startActivityForResult(i, MainActivity.CONTACT_CODE)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -331,6 +331,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val b = Bundle()
|
val b = Bundle()
|
||||||
b.putString("aor", uas[aorSpinner.selectedItemPosition].account.aor)
|
b.putString("aor", uas[aorSpinner.selectedItemPosition].account.aor)
|
||||||
b.putString("peer", "")
|
b.putString("peer", "")
|
||||||
|
b.putBoolean("focus", false)
|
||||||
i.putExtras(b)
|
i.putExtras(b)
|
||||||
startActivityForResult(i, MESSAGES_CODE)
|
startActivityForResult(i, MESSAGES_CODE)
|
||||||
}
|
}
|
||||||
@@ -659,6 +660,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val b = Bundle()
|
val b = Bundle()
|
||||||
b.putString("aor", ua.account.aor)
|
b.putString("aor", ua.account.aor)
|
||||||
b.putString("peer", peerUri)
|
b.putString("peer", peerUri)
|
||||||
|
b.putBoolean("focus", false)
|
||||||
i.putExtras(b)
|
i.putExtras(b)
|
||||||
startActivity(i)
|
startActivity(i)
|
||||||
}
|
}
|
||||||
@@ -739,7 +741,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val aor = ua.account.aor
|
val aor = ua.account.aor
|
||||||
when (action) {
|
when (action) {
|
||||||
"reply" -> {
|
"reply" -> {
|
||||||
val i = Intent(this@MainActivity, ChatActivity::class.java)
|
val i = Intent(this@MainActivity, ChatsActivity::class.java)
|
||||||
val b = Bundle()
|
val b = Bundle()
|
||||||
if (ua != uas[aorSpinner.selectedItemPosition]) {
|
if (ua != uas[aorSpinner.selectedItemPosition]) {
|
||||||
for (account_index in uas.indices) {
|
for (account_index in uas.indices) {
|
||||||
@@ -751,9 +753,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
b.putString("aor", aor)
|
b.putString("aor", aor)
|
||||||
b.putString("peer", intent.getStringExtra("peer"))
|
b.putString("peer", intent.getStringExtra("peer"))
|
||||||
b.putBoolean("reply", true)
|
b.putBoolean("focus", true)
|
||||||
i.putExtras(b)
|
i.putExtras(b)
|
||||||
startActivityForResult(i, MESSAGE_CODE)
|
startActivityForResult(i, MESSAGES_CODE)
|
||||||
}
|
}
|
||||||
"save" -> {
|
"save" -> {
|
||||||
ChatsActivity.saveUaMessage(ua.account.aor,
|
ChatsActivity.saveUaMessage(ua.account.aor,
|
||||||
@@ -768,6 +770,16 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
nm.cancel(BaresipService.MESSAGE_NOTIFICATION_ID)
|
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("@")
|
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 {
|
fun checkUserID(id: String): Boolean {
|
||||||
return Regex("^[a-zA-Z]([._-]|[a-zA-Z0-9]){1,49}\$").matches(id)
|
return Regex("^[a-zA-Z]([._-]|[a-zA-Z0-9]){1,49}\$").matches(id)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user