old dtmf watcher needs to be removed before new is added

This commit is contained in:
Juha Heinanen
2018-05-03 18:22:28 +03:00
parent 69e4b47950
commit 46079ae67d
2 changed files with 18 additions and 19 deletions

View File

@ -1,5 +1,8 @@
package com.tutpro.baresip
class Call(val ua: String, val call: String, val peerURI: String, var status: String) {
import android.text.TextWatcher
class Call(val ua: String, val call: String, val peerURI: String, var status: String,
val dtmfWatcher: TextWatcher?) {
var hold: Boolean = false
}

View File

@ -28,12 +28,6 @@ import android.text.TextWatcher
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
class MainActivity : AppCompatActivity() {
internal lateinit var appContext: Context
@ -351,7 +345,16 @@ class MainActivity : AppCompatActivity() {
val call = ua_connect(ua, uri)
if (call != "") {
Log.i("Baresip", "Adding outgoing call $ua / $call / $uri")
callsOut.add(Call(ua, call, uri, "Cancel"))
val dtmfWatcher = object: TextWatcher {
override fun beforeTextChanged(sequence: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(sequence: CharSequence, start: Int, before: Int, count: Int) {
val digit = sequence.subSequence(start, start+count).toString()
Log.d("Baresip", "Got DTMF digit '" + digit + "'")
if (digit.isNotEmpty()) call_send_digit(call, digit[0])
}
override fun afterTextChanged(sequence: Editable) {}
}
callsOut.add(Call(ua, call, uri, "Cancel", dtmfWatcher))
(findViewById(R.id.callButton) as Button).text = "Cancel"
(findViewById(R.id.holdButton) as Button).visibility = View.INVISIBLE
}
@ -561,15 +564,7 @@ class MainActivity : AppCompatActivity() {
dtmf.hint = "DTMF"
dtmf.visibility = View.VISIBLE
dtmf.requestFocus()
dtmf.addTextChangedListener(object: TextWatcher {
override fun beforeTextChanged(sequence: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(sequence: CharSequence, start: Int, before: Int, count: Int) {
val digit = sequence.subSequence(start, start+count).toString()
Log.d("Baresip", "Got DTMF digit '" + digit + "'")
if (digit.isNotEmpty()) call_send_digit(call, digit[0])
}
override fun afterTextChanged(sequence: Editable) {}
})
dtmf.addTextChangedListener(callsOut[out_index].dtmfWatcher)
}
}
HistoryActivity.History.add(History(ua, call, aor, call_peeruri(call),
@ -591,7 +586,7 @@ class MainActivity : AppCompatActivity() {
val peer_uri = call_peeruri(call)
Log.d("Baresip", "Incoming call " + ua + "/" + call + "/" +
peer_uri)
val new_call = Call(ua, call, peer_uri, "Answer")
val new_call = Call(ua, call, peer_uri, "Answer", null)
callsIn.add(new_call)
this@MainActivity.runOnUiThread {
if (ua == aor_ua(aors[aorSpinner.selectedItemPosition])) {
@ -636,7 +631,6 @@ class MainActivity : AppCompatActivity() {
if (call_index != -1) {
Log.d("Baresip", "Removing outgoing call " + ua + "/" +
call + "/" + callsOut[call_index].peerURI)
callsOut.removeAt(call_index)
this@MainActivity.runOnUiThread {
if (ua == aor_ua(aors[aorSpinner.selectedItemPosition])) {
callButton.text = "Call"
@ -648,9 +642,11 @@ class MainActivity : AppCompatActivity() {
if (this.currentFocus == dtmf) {
imm.hideSoftInputFromWindow(dtmf.getWindowToken(), 0)
}
dtmf.removeTextChangedListener(callsOut[call_index].dtmfWatcher)
dtmf.visibility = View.INVISIBLE
}
}
callsOut.removeAt(call_index)
if (!HistoryActivity.callHasHistory(ua, call)) {
if (HistoryActivity.aorHistory(aor) > HISTORY_SIZE)
HistoryActivity.aorRemoveHistory(aor)