renamed some class variables/values according to naming conventions

This commit is contained in:
Juha Heinanen
2018-03-18 20:23:01 +13:00
parent 0f4ae4ff8b
commit c2a3f65ea1
2 changed files with 81 additions and 81 deletions

View File

@ -48,7 +48,7 @@ class EditContactsActivity : AppCompatActivity() {
Log.d("Baresip", "Updated contacts file") Log.d("Baresip", "Updated contacts file")
MainActivity.contacts_remove() MainActivity.contacts_remove()
updateContactsAndNames(path) updateContactsAndNames(path)
// MainActivity.CalleeAdapter.notifyDataSetChanged(); does not work // MainActivity.calleeAdapter.notifyDataSetChanged(); does not work
setResult(RESULT_OK, i) setResult(RESULT_OK, i)
finish() finish()
return true return true

View File

@ -11,6 +11,7 @@ import android.support.v4.content.ContextCompat
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.support.annotation.UiThread
import android.widget.* import android.widget.*
import android.widget.RelativeLayout.LayoutParams import android.widget.RelativeLayout.LayoutParams
import android.widget.AutoCompleteTextView import android.widget.AutoCompleteTextView
@ -34,19 +35,17 @@ class MainActivity : AppCompatActivity() {
callButton = findViewById(R.id.callButton) as Button callButton = findViewById(R.id.callButton) as Button
holdButton = findViewById(R.id.holdButton) as Button holdButton = findViewById(R.id.holdButton) as Button
AoRSpinner = findViewById(R.id.AoRList) as Spinner aorSpinner = findViewById(R.id.AoRList) as Spinner
accountAdapter = AccountSpinnerAdapter(applicationContext, aors, images)
Log.i("Baresip", "Setting AccountAdapter") aorSpinner.adapter = accountAdapter
AccountAdapter = AccountSpinnerAdapter(applicationContext, AoRs, Images) aorSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
AoRSpinner.adapter = AccountAdapter
AoRSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) { override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
val aor = AoRs[position] val aor = aors[position]
val callee = findViewById(R.id.callee) as AutoCompleteTextView val callee = findViewById(R.id.callee) as AutoCompleteTextView
val callButton = findViewById(R.id.callButton) as Button val callButton = findViewById(R.id.callButton) as Button
val holdButton = findViewById(R.id.holdButton) as Button val holdButton = findViewById(R.id.holdButton) as Button
Log.i("Baresip", "Setting $aor current") Log.i("Baresip", "Setting $aor current")
val out = uaCalls(Out, aor_ua(aor)) val out = uaCalls(callsOut, aor_ua(aor))
if (out.size == 0) { if (out.size == 0) {
callee.text.clear() callee.text.clear()
callee.hint = "Callee" callee.hint = "Callee"
@ -71,14 +70,14 @@ class MainActivity : AppCompatActivity() {
holdButton.visibility = View.INVISIBLE holdButton.visibility = View.INVISIBLE
} }
} }
val `in` = uaCalls(In, aor_ua(aor)) val `in` = uaCalls(callsIn, aor_ua(aor))
val view_count = layout.childCount val view_count = layout.childCount
Log.d("Baresip", "View count is $view_count") Log.d("Baresip", "View count is $view_count")
if (view_count > 5) { if (view_count > 5) {
layout.removeViews(5, view_count - 5) layout.removeViews(5, view_count - 5)
} }
for (c in `in`) { for (c in `in`) {
for (call_index in In.indices) { for (call_index in callsIn.indices) {
addCallViews(c, (call_index + 1) * 10) addCallViews(c, (call_index + 1) * 10)
} }
} }
@ -138,21 +137,22 @@ class MainActivity : AppCompatActivity() {
} }
EditContactsActivity.updateContactsAndNames(applicationContext.filesDir.absolutePath + "/contacts") EditContactsActivity.updateContactsAndNames(applicationContext.filesDir.absolutePath + "/contacts")
CalleeAdapter = ArrayAdapter(this, android.R.layout.select_dialog_item, EditContactsActivity.Names)
calleeAdapter = ArrayAdapter(this, android.R.layout.select_dialog_item, EditContactsActivity.Names)
callee.threshold = 2 callee.threshold = 2
callee.setAdapter<ArrayAdapter<String>>(CalleeAdapter) callee.setAdapter<ArrayAdapter<String>>(calleeAdapter)
callButton.text = "Call" callButton.text = "Call"
callButton.setOnClickListener { callButton.setOnClickListener {
Log.d("Baresip", "AoR at position is " + AoRs[AoRSpinner.selectedItemPosition]) Log.d("Baresip", "AoR at position is " + aors[aorSpinner.selectedItemPosition])
val aor = AoRs[AoRSpinner.selectedItemPosition] val aor = aors[aorSpinner.selectedItemPosition]
if (callButton.text.toString() == "Call") { if (callButton.text.toString() == "Call") {
call(aor, (findViewById(R.id.callee) as EditText).text.toString()) call(aor, (findViewById(R.id.callee) as EditText).text.toString())
} else { } else {
Log.i("Baresip", "Canceling UA " + aor_ua(aor) + " call " + Log.i("Baresip", "Canceling UA " + aor_ua(aor) + " call " +
Out[0].call + " to " + callsOut[0].call + " to " +
(findViewById(R.id.callee) as EditText).text) (findViewById(R.id.callee) as EditText).text)
ua_hangup(aor_ua(aor), Out[0].call, 486, "Rejected") ua_hangup(aor_ua(aor), callsOut[0].call, 486, "Rejected")
} }
} }
@ -161,20 +161,20 @@ class MainActivity : AppCompatActivity() {
when (holdButton.text.toString()) { when (holdButton.text.toString()) {
"Hold" -> { "Hold" -> {
Log.i("Baresip", "Holding up " + (findViewById(R.id.callee) as EditText).text) Log.i("Baresip", "Holding up " + (findViewById(R.id.callee) as EditText).text)
call_hold(Out[0].call) call_hold(callsOut[0].call)
Out[0].hold = true callsOut[0].hold = true
holdButton.text = "Unhold" holdButton.text = "Unhold"
} }
"Unhold" -> { "Unhold" -> {
Log.i("Baresip", "Unholding " + (findViewById(R.id.callee) as EditText).text) Log.i("Baresip", "Unholding " + (findViewById(R.id.callee) as EditText).text)
call_unhold(Out[0].call) call_unhold(callsOut[0].call)
Out[0].hold = false callsOut[0].hold = false
holdButton.text = "Hold" holdButton.text = "Hold"
} }
"History" -> { "History" -> {
val i = Intent(this@MainActivity, HistoryActivity::class.java) val i = Intent(this@MainActivity, HistoryActivity::class.java)
val b = Bundle() val b = Bundle()
b.putString("aor", AoRs[AoRSpinner.selectedItemPosition]) b.putString("aor", aors[aorSpinner.selectedItemPosition])
i.putExtras(b) i.putExtras(b)
startActivityForResult(i, HISTORY_CODE) startActivityForResult(i, HISTORY_CODE)
} }
@ -296,7 +296,7 @@ class MainActivity : AppCompatActivity() {
} }
if (resultCode == RESULT_CANCELED) { if (resultCode == RESULT_CANCELED) {
Log.d("Baresip", "History canceled") Log.d("Baresip", "History canceled")
if (!aorHasHistory(AoRs[AoRSpinner.selectedItemPosition])) { if (!aorHasHistory(aors[aorSpinner.selectedItemPosition])) {
(findViewById(R.id.holdButton) as Button).visibility = View.INVISIBLE (findViewById(R.id.holdButton) as Button).visibility = View.INVISIBLE
} }
} }
@ -309,10 +309,10 @@ class MainActivity : AppCompatActivity() {
fun addAccount(ua: String) { fun addAccount(ua: String) {
val aor = ua_aor(ua) val aor = ua_aor(ua)
Log.d("Baresip", "Adding account $ua with AoR $aor") Log.d("Baresip", "Adding account $ua with AoR $aor")
Accounts.add(Account(ua, aor, "")) accounts.add(Account(ua, aor, ""))
AoRs.add(aor) aors.add(aor)
Images.add(R.drawable.yellow) images.add(R.drawable.yellow)
runOnUiThread { AccountAdapter.notifyDataSetChanged() } runOnUiThread { accountAdapter.notifyDataSetChanged() }
} }
private fun call(aor: String, callee: String) { private fun call(aor: String, callee: String) {
@ -329,7 +329,7 @@ class MainActivity : AppCompatActivity() {
val call = ua_connect(ua, uri) val call = ua_connect(ua, uri)
if (call != "") { if (call != "") {
Log.i("Baresip", "Adding outgoing call $ua / $call / $uri") Log.i("Baresip", "Adding outgoing call $ua / $call / $uri")
Out.add(Call(ua, call, uri, "Cancel")) callsOut.add(Call(ua, call, uri, "Cancel"))
(findViewById(R.id.callButton) as Button).text = "Cancel" (findViewById(R.id.callButton) as Button).text = "Cancel"
(findViewById(R.id.holdButton) as Button).visibility = View.INVISIBLE (findViewById(R.id.holdButton) as Button).visibility = View.INVISIBLE
} }
@ -356,8 +356,8 @@ class MainActivity : AppCompatActivity() {
private fun addCallViews(call: Call, id: Int) { private fun addCallViews(call: Call, id: Int) {
Log.d("Baresip", "Creating new Incoming textview at $id") Log.d("Baresip", "Creating new Incoming textview at $id")
//val caller_heading = TextView(mainActivityContext)
val caller_heading = TextView(mainActivityContext) val caller_heading = TextView(mainActivityContext)
caller_heading.text = "Incoming call from ..." caller_heading.text = "Incoming call from ..."
caller_heading.setTextColor(Color.BLACK) caller_heading.setTextColor(Color.BLACK)
caller_heading.textSize = 20f caller_heading.textSize = 20f
@ -373,7 +373,7 @@ class MainActivity : AppCompatActivity() {
layout.addView(caller_heading) layout.addView(caller_heading)
val caller_uri = TextView(mainActivityContext) val caller_uri = TextView(mainActivityContext)
caller_uri.text = In[In.size - 1].peerURI caller_uri.text = callsIn[callsIn.size - 1].peerURI
caller_uri.setTextColor(Color.GREEN) caller_uri.setTextColor(Color.GREEN)
caller_uri.textSize = 20f caller_uri.textSize = 20f
caller_uri.setPadding(10, 10, 0, 10) caller_uri.setPadding(10, 10, 0, 10)
@ -399,11 +399,11 @@ class MainActivity : AppCompatActivity() {
Log.i("Baresip", "UA " + call_ua + " accepting incoming call " + Log.i("Baresip", "UA " + call_ua + " accepting incoming call " +
call_call) call_call)
ua_answer(call_ua, call_call) ua_answer(call_ua, call_call)
val final_in_index = callIndex(In, call_ua, call_call) val final_in_index = callIndex(callsIn, call_ua, call_call)
if (final_in_index >= 0) { if (final_in_index >= 0) {
Log.d("Baresip", "Updating Hangup and Hold") Log.d("Baresip", "Updating Hangup and Hold")
In[final_in_index].status = "Hangup" callsIn[final_in_index].status = "Hangup"
In[final_in_index].hold = false callsIn[final_in_index].hold = false
runOnUiThread { runOnUiThread {
val answer_id = (final_in_index + 1) * 10 + 2 val answer_id = (final_in_index + 1) * 10 + 2
val answer_but = layout.findViewById(answer_id) as Button val answer_but = layout.findViewById(answer_id) as Button
@ -506,36 +506,36 @@ class MainActivity : AppCompatActivity() {
Log.d("Baresip", "Handling event " + event + " for " + ua + "/" + call + "/" + Log.d("Baresip", "Handling event " + event + " for " + ua + "/" + call + "/" +
aor) aor)
for (account_index in Accounts.indices) { for (account_index in accounts.indices) {
if (Accounts[account_index].aoR == aor) { if (accounts[account_index].aoR == aor) {
Log.d("Baresip", "Found AoR at index $account_index") Log.d("Baresip", "Found AoR at index $account_index")
when (event) { when (event) {
"registering", "unregistering" -> { "registering", "unregistering" -> {
} }
"registered" -> { "registered" -> {
Log.d("Baresip", "Setting status to green") Log.d("Baresip", "Setting status to green")
Accounts[account_index].status = "OK" accounts[account_index].status = "OK"
AoRs[account_index] = aor aors[account_index] = aor
Images[account_index] = R.drawable.green images[account_index] = R.drawable.green
runOnUiThread { AccountAdapter.notifyDataSetChanged() } runOnUiThread { accountAdapter.notifyDataSetChanged() }
} }
"registering failed" -> { "registering failed" -> {
Log.d("Baresip", "Setting status to red") Log.d("Baresip", "Setting status to red")
Accounts[account_index].status = "FAIL" accounts[account_index].status = "FAIL"
AoRs[account_index] = aor aors[account_index] = aor
Images[account_index] = R.drawable.red images[account_index] = R.drawable.red
runOnUiThread { AccountAdapter.notifyDataSetChanged() } runOnUiThread { accountAdapter.notifyDataSetChanged() }
} }
"call ringing" -> { "call ringing" -> {
} }
"call established" -> { "call established" -> {
val out_index = callIndex(Out, ua, call) val out_index = callIndex(callsOut, ua, call)
if (out_index >= 0) { if (out_index >= 0) {
Log.d("Baresip", "Outbound call " + call + " established") Log.d("Baresip", "Outbound call " + call + " established")
Out[out_index].status = "Hangup" callsOut[out_index].status = "Hangup"
Out[out_index].hold = false callsOut[out_index].hold = false
runOnUiThread { runOnUiThread {
if (ua == aor_ua(AoRs[AoRSpinner.selectedItemPosition])) { if (ua == aor_ua(aors[aorSpinner.selectedItemPosition])) {
callButton.text = "Hangup" callButton.text = "Hangup"
holdButton.text = "Hold" holdButton.text = "Hold"
holdButton.visibility = View.VISIBLE holdButton.visibility = View.VISIBLE
@ -554,48 +554,48 @@ class MainActivity : AppCompatActivity() {
Log.d("Baresip", "Incoming call " + ua + "/" + call + "/" + Log.d("Baresip", "Incoming call " + ua + "/" + call + "/" +
peer_uri) peer_uri)
val new_call = Call(ua, call, peer_uri, "Answer") val new_call = Call(ua, call, peer_uri, "Answer")
In.add(new_call) callsIn.add(new_call)
this@MainActivity.runOnUiThread { this@MainActivity.runOnUiThread {
if (ua == aor_ua(AoRs[AoRSpinner.selectedItemPosition])) { if (ua == aor_ua(aors[aorSpinner.selectedItemPosition])) {
addCallViews(new_call, In.size * 10) addCallViews(new_call, callsIn.size * 10)
} }
} }
} }
"call closed" -> { "call closed" -> {
call_index = callIndex(In, ua, call) call_index = callIndex(callsIn, ua, call)
if (call_index != -1) { if (call_index != -1) {
Log.d("Baresip", "Removing inbound call " + ua + "/" + Log.d("Baresip", "Removing inbound call " + ua + "/" +
call + "/" + In[call_index].peerURI) call + "/" + callsIn[call_index].peerURI)
val view_id = (call_index + 1) * 10 val view_id = (call_index + 1) * 10
val remove_count = In.size - call_index val remove_count = callsIn.size - call_index
In.removeAt(call_index) callsIn.removeAt(call_index)
this@MainActivity.runOnUiThread { this@MainActivity.runOnUiThread {
if (ua == aor_ua(AoRs[AoRSpinner.selectedItemPosition])) { if (ua == aor_ua(aors[aorSpinner.selectedItemPosition])) {
if (callButton.text == "Call") { if (callButton.text == "Call") {
holdButton.text = "History" holdButton.text = "History"
holdButton.visibility = View.VISIBLE holdButton.visibility = View.VISIBLE
} }
val caller_heading = layout.findViewById(view_id) val caller_heading = layout.findViewById(view_id)
val view_index = layout.indexOfChild(caller_heading) val view_index = layout.indexOfChild(caller_heading)
Log.d("Baresip", "Index of caller heading is $view_index") Log.d("Baresip", "Index of caller heading is $view_index")
layout.removeViews(view_index, 4 * remove_count) layout.removeViews(view_index, 4 * remove_count)
for (i in call_index until In.size) { for (i in call_index until callsIn.size) {
this@MainActivity.addCallViews(In[i], (i + 1) * 10) this@MainActivity.addCallViews(callsIn[i], (i + 1) * 10)
}
} }
} }
}
if (!callHasHistory(ua, call)) { if (!callHasHistory(ua, call)) {
HistoryActivity.History.add(History(ua, call, aor, call_peeruri(call), HistoryActivity.History.add(History(ua, call, aor, call_peeruri(call),
"in", false)) "in", false))
} }
} else { } else {
call_index = callIndex(Out, ua, call) call_index = callIndex(callsOut, ua, call)
if (call_index != -1) { if (call_index != -1) {
Log.d("Baresip", "Removing outgoing call " + ua + "/" + Log.d("Baresip", "Removing outgoing call " + ua + "/" +
call + "/" + Out[call_index].peerURI) call + "/" + callsOut[call_index].peerURI)
Out.removeAt(call_index) callsOut.removeAt(call_index)
runOnUiThread { runOnUiThread {
if (ua == aor_ua(AoRs[AoRSpinner.selectedItemPosition])) { if (ua == aor_ua(aors[aorSpinner.selectedItemPosition])) {
callButton.text = "Call" callButton.text = "Call"
callButton.isEnabled = true callButton.isEnabled = true
callee.setText("") callee.setText("")
@ -627,8 +627,8 @@ class MainActivity : AppCompatActivity() {
external fun aor_ua(aor: String): String external fun aor_ua(aor: String): String
external fun ua_connect(ua: String, peer_uri: String): String external fun ua_connect(ua: String, peer_uri: String): String
external fun ua_answer(ua: String, call: String) external fun ua_answer(ua: String, call: String)
external fun call_hold(call: String): Int? external fun call_hold(call: String): Int
external fun call_unhold(call: String): Int? external fun call_unhold(call: String): Int
external fun ua_hangup(ua: String, call: String, code: Int, reason: String) external fun ua_hangup(ua: String, call: String, code: Int, reason: String)
external fun reload_config(): Int external fun reload_config(): Int
@ -639,16 +639,16 @@ class MainActivity : AppCompatActivity() {
internal lateinit var callee: AutoCompleteTextView internal lateinit var callee: AutoCompleteTextView
internal lateinit var callButton: Button internal lateinit var callButton: Button
internal lateinit var holdButton: Button internal lateinit var holdButton: Button
internal lateinit var AccountAdapter: AccountSpinnerAdapter internal lateinit var accountAdapter: AccountSpinnerAdapter
internal lateinit var AoRSpinner: Spinner internal lateinit var aorSpinner: Spinner
internal lateinit var calleeAdapter: ArrayAdapter<String>
internal var running: Boolean = false internal var running: Boolean = false
internal var Accounts = ArrayList<Account>() internal var accounts = ArrayList<Account>()
internal var AoRs = ArrayList<String>() internal var aors = ArrayList<String>()
internal var Images = ArrayList<Int>() internal var images = ArrayList<Int>()
internal var CalleeAdapter: ArrayAdapter<String>? = null internal var callsIn = ArrayList<Call>()
internal var In = ArrayList<Call>() internal var callsOut = ArrayList<Call>()
internal var Out = ArrayList<Call>()
const val RECORD_AUDIO_PERMISSION = 1 const val RECORD_AUDIO_PERMISSION = 1
const val EDIT_ACCOUNTS_CODE = 1 const val EDIT_ACCOUNTS_CODE = 1