From dd72c6bcd2bcbb83dbd486204f06ab4cc1f1f098 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Mon, 11 Jun 2018 11:00:47 +0300 Subject: [PATCH] added possibility to add uri found in call history to contacts --- .../com/tutpro/baresip/HistoryActivity.kt | 33 +++++++++++++++---- .../kotlin/com/tutpro/baresip/HistoryRow.kt | 3 +- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/HistoryActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/HistoryActivity.kt index d9b336a1..fa2c2f38 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/HistoryActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/HistoryActivity.kt @@ -43,7 +43,22 @@ class HistoryActivity : AppCompatActivity() { listview.onItemLongClickListener = AdapterView.OnItemLongClickListener { _, _, pos, _ -> val dialogClickListener = DialogInterface.OnClickListener { _, which -> when (which) { - DialogInterface.BUTTON_POSITIVE -> { + DialogInterface.BUTTON_NEUTRAL -> { + ContactsActivity.contactNames.add("New Name") + if (uaHistory[pos].peerDomain == "") + ContactsActivity.contactURIs.add(uaHistory[pos].peerURI) + else + ContactsActivity.contactURIs.add("sip:${uaHistory[pos].peerURI}" + + "@" + uaHistory[pos].peerDomain) + ContactsActivity.posAtContacts.add(ContactsActivity.contactNames.size) + ContactsActivity.saveContacts() + val i = Intent(this, ContactActivity::class.java) + val b = Bundle() + b.putInt("index", ContactsActivity.contactNames.size - 1) + i.putExtras(b) + startActivityForResult(i, MainActivity.CONTACT_CODE) + } + DialogInterface.BUTTON_NEGATIVE -> { removeUaHistoryAt(pos) if (uaHistory.size == 0) { val i = Intent() @@ -52,16 +67,18 @@ class HistoryActivity : AppCompatActivity() { } adapter.notifyDataSetChanged() } - DialogInterface.BUTTON_NEGATIVE -> { + DialogInterface.BUTTON_POSITIVE -> { } } } val builder = AlertDialog.Builder(this@HistoryActivity, R.style.Theme_AppCompat) - builder.setMessage("Do you want to delete " + - uaHistory[pos].peerURI + " call history?") - .setPositiveButton("Yes", dialogClickListener) - .setNegativeButton("No", dialogClickListener).show() + builder.setMessage("Do you want to add ${uaHistory[pos].peerURI} to contacs or " + + "delete it from call history?") + .setPositiveButton("Cancel", dialogClickListener) + .setNegativeButton("Delete History", dialogClickListener) + .setNeutralButton("Add Contact", dialogClickListener) + .show() true } @@ -86,8 +103,10 @@ class HistoryActivity : AppCompatActivity() { val h = MainActivity.history[i] if (h.aor == aor) { var peer_uri = h.peerURI + var peer_domain = "" if (Utils.uriHostPart(peer_uri) == Utils.uriHostPart(aor)) { peer_uri = Utils.uriUserPart(peer_uri) + peer_domain = Utils.uriHostPart(aor) } var direction: Int if (h.direction == "in") @@ -112,7 +131,7 @@ class HistoryActivity : AppCompatActivity() { val fmt = SimpleDateFormat("dd.MM") time = fmt.format(h.time.time) } - uaHistory.add(HistoryRow(peer_uri, direction, time, i)) + uaHistory.add(HistoryRow(peer_uri, peer_domain, direction, time, i)) } } } diff --git a/app/src/main/kotlin/com/tutpro/baresip/HistoryRow.kt b/app/src/main/kotlin/com/tutpro/baresip/HistoryRow.kt index 7b731646..b1eb6f49 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/HistoryRow.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/HistoryRow.kt @@ -1,6 +1,7 @@ package com.tutpro.baresip -class HistoryRow(val peerURI: String, val direction: Int, val time: String, val index: Int) { +class HistoryRow(val peerURI: String, val peerDomain: String, val direction: Int, val time: String, + val index: Int) { val directions = ArrayList() val indexes = ArrayList()