- Added Call History menu that allows deleting of account's call history

and disabling/enabling production of account's call history.
This commit is contained in:
Juha Heinanen
2019-09-30 17:58:40 +03:00
parent e5369e4b82
commit 0e8ba14deb
6 changed files with 89 additions and 22 deletions

View File

@ -20,8 +20,10 @@ class Account(val accp: String) {
var vmOld = 0
var missedCalls = false
var unreadMessages = false
var callHistory = true
init {
val stunHost = account_stun_host(accp)
if (stunHost != "") {
val stunPort = account_stun_port(accp)
@ -30,6 +32,7 @@ class Account(val accp: String) {
else
stunServer = "$stunHost:$stunPort"
}
var i = 0
while (true) {
val ob = account_outbound(accp, i)
@ -40,6 +43,7 @@ class Account(val accp: String) {
break
}
}
i = 0
while (true) {
val ac = account_audio_codec(accp, i)
@ -50,8 +54,12 @@ class Account(val accp: String) {
break
}
}
answerMode = Utils.paramValue(account_extra(accp),"answer_mode")
val extra = account_extra(accp)
answerMode = Utils.paramValue(extra,"answer_mode")
if (answerMode == "") answerMode = "manual"
callHistory = Utils.paramValue(extra,"call_history") == ""
}
fun print() : String {
@ -99,7 +107,16 @@ class Account(val accp: String) {
res = res + ";vm_uri=\"$vmUri\""
res += ";ptime=20;regint=${regint};regq=0.5;pubint=0;call_transfer=yes"
if (answerMode == "auto") res += ";extra=\"answer_mode=auto\""
var extra = ""
if (!callHistory) extra = "call_history=no"
if (answerMode == "auto") {
if (extra == "")
extra = "answer_mode=auto"
else
extra += ";answer_mode=auto"
}
res += ";extra=\"$extra\""
return res
}

View File

@ -201,8 +201,10 @@ class BaresipService: Service() {
val aor = call.ua.account.aor
Log.d(LOG_TAG, "Aor $aor rejected incoming call $callp from $peerUri")
Api.ua_hangup(call.ua.uap, callp, 486, "Rejected")
CallHistory.add(CallHistory(aor, peerUri, "in", false))
CallHistory.save(filesPath)
if (call.ua.account.callHistory) {
CallHistory.add(CallHistory(aor, peerUri, "in", false))
CallHistory.save(filesPath)
}
}
}
@ -409,9 +411,11 @@ class BaresipService: Service() {
if ((Call.calls().size > 0) || (tm.callState != TelephonyManager.CALL_STATE_IDLE)) {
Log.d(LOG_TAG, "Auto-rejecting incoming call $uap/$callp/$peerUri")
Api.ua_hangup(uap, callp, 486, "Busy Here")
CallHistory.add(CallHistory(aor, peerUri, "in", false))
CallHistory.save(filesPath)
ua.account.missedCalls = true
if (ua.account.callHistory) {
CallHistory.add(CallHistory(aor, peerUri, "in", false))
CallHistory.save(filesPath)
ua.account.missedCalls = true
}
if (!Utils.isVisible())
return
newEvent = "call rejected"
@ -486,9 +490,11 @@ class BaresipService: Service() {
Log.d(LOG_TAG, "AoR $aor call $callp established")
call.status = "connected"
call.onhold = false
CallHistory.add(CallHistory(aor, call.peerURI, call.dir, true))
CallHistory.save(filesPath)
call.hasHistory = true
if (ua.account.callHistory) {
CallHistory.add(CallHistory(aor, call.peerURI, call.dir, true))
CallHistory.save(filesPath)
call.hasHistory = true
}
if (call.dir == "in") {
stopRinging()
am.mode = AudioManager.MODE_IN_COMMUNICATION
@ -574,7 +580,7 @@ class BaresipService: Service() {
Log.d(LOG_TAG, "AoR $aor call $callp is closed")
if (call.status == "incoming") stopRinging()
calls.remove(call)
if (!call.hasHistory) {
if (ua.account.callHistory && !call.hasHistory) {
CallHistory.add(CallHistory(aor, call.peerURI, call.dir, false))
CallHistory.save(filesPath)
if (call.dir == "in") ua.account.missedCalls = true

View File

@ -30,12 +30,12 @@ class CallHistory(val aor: String, val peerURI: String, val direction: String,
}
}
fun clear(aor: String) {
BaresipService.history = ArrayList(BaresipService.history.filter{it.aor != aor})
}
fun aorHistorySize(aor: String): Int {
var size = 0;
for (h in BaresipService.history) {
if (h.aor == aor) size++
}
return size
return BaresipService.history.filter { it.aor == aor }.count()
}
fun aorLatestHistory(aor: String): CallHistory? {
@ -75,6 +75,11 @@ class CallHistory(val aor: String, val peerURI: String, val direction: String,
}
}
fun print() {
for (h in BaresipService.history)
Log.d("Baresip", "[${h.aor}, ${h.peerURI}, ${h.direction}, ${h.connected}]")
}
}
}

View File

@ -6,6 +6,7 @@ import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
import android.widget.AdapterView
import android.widget.ListView
@ -18,6 +19,9 @@ import java.util.GregorianCalendar
class CallsActivity : AppCompatActivity() {
internal lateinit var account: Account
internal lateinit var adapter: CallListAdapter
internal var uaHistory = ArrayList<CallRow>()
internal var aor = ""
@ -29,6 +33,7 @@ class CallsActivity : AppCompatActivity() {
aor = intent.getStringExtra("aor")!!
BaresipService.activities.add(0, "calls,$aor")
val ua = Account.findUa(aor)!!
account = ua.account
val headerView = findViewById(R.id.account) as TextView
val headerText = "${getString(R.string.account)} ${aor.substringAfter(":")}"
@ -36,7 +41,7 @@ class CallsActivity : AppCompatActivity() {
val listView = findViewById(R.id.calls) as ListView
aorGenerateHistory(aor)
val adapter = CallListAdapter(this, uaHistory)
adapter = CallListAdapter(this, uaHistory)
listView.adapter = adapter
listView.isLongClickable = true
@ -70,6 +75,7 @@ class CallsActivity : AppCompatActivity() {
.setPositiveButton(getString(R.string.send_message), dialogClickListener)
.show()
}
listView.onItemLongClickListener = AdapterView.OnItemLongClickListener { _, _, pos, _ ->
val peerUri = uaHistory[pos].peerURI
val peerName = ContactsActivity.contactName(peerUri)
@ -85,11 +91,6 @@ class CallsActivity : AppCompatActivity() {
}
DialogInterface.BUTTON_POSITIVE -> {
removeUaHistoryAt(pos)
if (uaHistory.size == 0) {
val i = Intent()
setResult(Activity.RESULT_CANCELED, i)
finish()
}
adapter.notifyDataSetChanged()
}
DialogInterface.BUTTON_NEUTRAL -> {
@ -121,6 +122,7 @@ class CallsActivity : AppCompatActivity() {
}
ua.account.missedCalls = false
invalidateOptionsMenu()
}
override fun onPause() {
@ -134,6 +136,19 @@ class CallsActivity : AppCompatActivity() {
when (item.itemId) {
R.id.delete_history -> {
CallHistory.clear(aor)
CallHistory.save(applicationContext.filesDir.absolutePath)
aorGenerateHistory(aor)
adapter.notifyDataSetChanged()
}
R.id.history_on_off -> {
account.callHistory = !account.callHistory
invalidateOptionsMenu()
AccountsActivity.saveAccounts()
}
android.R.id.home -> {
BaresipService.activities.removeAt(0)
val i = Intent()
@ -152,6 +167,24 @@ class CallsActivity : AppCompatActivity() {
}
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
if (account.callHistory)
menu.findItem(R.id.history_on_off).setTitle(getString(R.string.disable_history))
else
menu.findItem(R.id.history_on_off).setTitle(getString(R.string.enable_history))
return super.onPrepareOptionsMenu(menu)
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.calls_menu, menu)
return true
}
private fun aorGenerateHistory(aor: String) {
uaHistory.clear()
for (i in CallHistory.history().indices.reversed()) {

View File

@ -144,6 +144,9 @@
%2$s puheluhistoriasta?
</string>
<string name="calls_delete_question">Haluatko poistaa \'%1$s\' %2$s puheluhistoriasta?</string>
<string name="delete_history">Tyhjennä</string>
<string name="disable_history">Poista käytöstä</string>
<string name="enable_history">Ota käyttöön</string>
<!-- Chat Activity -->
<string name="chat">Viestiketju</string>
<string name="chat_with">Viestiketju %1$s</string>

View File

@ -129,6 +129,9 @@ Check Apps → baresip → Permissions → Storage and that file \'accounts.bs\'
</string>
<string name="calls_delete_question">Do you want to delete \'%1$s\' %2$s from call history?
</string>
<string name="delete_history">Delete</string>
<string name="disable_history">Disable</string>
<string name="enable_history">Enable</string>
<!-- Chat Activity -->
<string name="chat">Chat Messages</string>