Simplified implementation of UA spinner

This commit is contained in:
Juha Heinanen
2022-03-13 14:33:49 +02:00
parent 892e955fbf
commit 3c9205bd9e
6 changed files with 23 additions and 38 deletions

View File

@ -447,12 +447,12 @@ class AccountActivity : AppCompatActivity() {
if (regCheck.isChecked) {
if (acc.regint != 3600) {
newRegint = 3600
ua.updateStatus(R.drawable.dot_yellow)
ua.status = R.drawable.dot_yellow
}
} else {
if (acc.regint != 0) {
Api.ua_unregister(ua.uap)
ua.updateStatus(R.drawable.dot_white)
ua.status = R.drawable.dot_white
newRegint = 0
}
}
@ -592,9 +592,7 @@ class AccountActivity : AppCompatActivity() {
if (defaultCheck.isChecked && (uaIndex > 0)) {
BaresipService.uas.add(0, BaresipService.uas[uaIndex])
BaresipService.status.add(0, BaresipService.status[uaIndex])
BaresipService.uas.removeAt(uaIndex + 1)
BaresipService.status.removeAt(uaIndex + 1)
save = true
}

View File

@ -73,7 +73,7 @@ class AccountsActivity : AppCompatActivity() {
newAorView.setText("")
newAorView.hint = getString(R.string.user_domain)
newAorView.clearFocus()
ua.add(R.drawable.dot_white)
ua.add()
generateAccounts()
alAdapter.notifyDataSetChanged()
saveAccounts()

View File

@ -533,18 +533,18 @@ class BaresipService: Service() {
@Keep
fun uaAdd(uap: Long) {
val ua = UserAgent(uap)
Log.d(TAG, "uaAdd ${ua.account.aor} at BaresipService")
uas.add(ua)
if (Api.ua_isregistered(uap)) {
ua.status = if (Api.ua_isregistered(uap)) {
Log.d(TAG, "Ua ${ua.account.aor} is registered")
status.add(R.drawable.dot_green)
R.drawable.dot_green
} else {
Log.d(TAG, "Ua ${ua.account.aor} is NOT registered")
if (ua.account.regint == 0)
status.add(R.drawable.dot_white)
R.drawable.dot_white
else
status.add(R.drawable.dot_yellow)
R.drawable.dot_yellow
}
Log.d(TAG, "uaAdd ${ua.account.aor} at BaresipService")
uas.add(ua)
}
@SuppressLint("UnspecifiedImmutableFlag")
@ -579,17 +579,17 @@ class BaresipService: Service() {
return
}
"registered" -> {
if (ua.account.regint == 0)
status[account_index] = R.drawable.dot_white
ua.status = if (ua.account.regint == 0)
R.drawable.dot_white
else
status[account_index] = R.drawable.dot_green
R.drawable.dot_green
updateStatusNotification()
if (isMainVisible)
registrationUpdate.postValue(System.currentTimeMillis())
return
}
"registering failed" -> {
status[account_index] = R.drawable.dot_red
ua.status = R.drawable.dot_red
updateStatusNotification()
if (isMainVisible)
registrationUpdate.postValue(System.currentTimeMillis())
@ -606,7 +606,7 @@ class BaresipService: Service() {
return
}
"unregistering" -> {
status[account_index] = R.drawable.dot_white
ua.status = R.drawable.dot_white
updateStatusNotification()
if (isMainVisible)
registrationUpdate.postValue(System.currentTimeMillis())
@ -1113,14 +1113,14 @@ class BaresipService: Service() {
val contentView = RemoteViews(packageName, R.layout.status_notification)
for (i: Int in 0..5) {
val resID = resources.getIdentifier("status$i", "id", packageName)
if (i < status.size) {
contentView.setImageViewResource(resID, status[i])
if (i < uas.size) {
contentView.setImageViewResource(resID, uas[i].status)
contentView.setViewVisibility(resID, View.VISIBLE)
} else {
contentView.setViewVisibility(resID, View.INVISIBLE)
}
}
if (status.size > 4)
if (uas.size > 4)
contentView.setViewVisibility(R.id.etc, View.VISIBLE)
else
contentView.setViewVisibility(R.id.etc, View.INVISIBLE)
@ -1447,7 +1447,6 @@ class BaresipService: Service() {
stopRinging()
stopMediaPlayer()
uas.clear()
status.clear()
callHistory.clear()
messages.clear()
if (this::nm.isInitialized)
@ -1483,7 +1482,6 @@ class BaresipService: Service() {
var isMicMuted = false
val uas = ArrayList<UserAgent>()
val status = ArrayList<Int>()
val calls = ArrayList<Call>()
var callHistory = ArrayList<NewCallHistory>()
var messages = ArrayList<Message>()

View File

@ -197,7 +197,7 @@ class MainActivity : AppCompatActivity() {
}
}
uaAdapter = UaSpinnerAdapter(applicationContext, BaresipService.uas, BaresipService.status)
uaAdapter = UaSpinnerAdapter(applicationContext, BaresipService.uas)
aorSpinner.adapter = uaAdapter
aorSpinner.setSelection(-1)
aorSpinner.tag = ""

View File

@ -9,9 +9,8 @@ import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.TextView
class UaSpinnerAdapter(cxt: Context, private val uas: ArrayList<UserAgent>,
private val images: ArrayList<Int>) :
ArrayAdapter<Int>(cxt, android.R.layout.simple_spinner_item, images) {
class UaSpinnerAdapter(cxt: Context, private val uas: ArrayList<UserAgent>) :
ArrayAdapter<UserAgent>(cxt, android.R.layout.simple_spinner_item, uas) {
private val layoutInflater = LayoutInflater.from(context)
@ -47,7 +46,7 @@ class UaSpinnerAdapter(cxt: Context, private val uas: ArrayList<UserAgent>,
viewHolder.textView.textSize = 17f
if (UserAgent.uas().size > 1 && ua.calls().isNotEmpty())
viewHolder.textView.setTypeface(null, Typeface.BOLD)
viewHolder.imageView.setImageResource(images[position])
viewHolder.imageView.setImageResource(ua.status)
return rowView
}

View File

@ -3,20 +3,14 @@ package com.tutpro.baresip
class UserAgent(val uap: Long) {
val account = Account(Api.ua_account(uap))
var status = R.drawable.dot_white
fun add(status: Int) {
fun add() {
BaresipService.uas.add(this)
BaresipService.status.add(status)
}
fun remove() {
val index = BaresipService.uas.indexOf(this)
BaresipService.uas.remove(this)
BaresipService.status.removeAt(index)
}
fun updateStatus(status: Int) {
BaresipService.status[BaresipService.uas.indexOf(this)] = status
}
fun calls(dir: String = ""): ArrayList<Call> {
@ -39,10 +33,6 @@ class UserAgent(val uap: Long) {
return BaresipService.uas
}
fun status(): ArrayList<Int> {
return BaresipService.status
}
fun ofAor(aor: String): UserAgent? {
for (ua in BaresipService.uas)
if (ua.account.aor == aor) return ua