Simplified implementation of UA spinner
This commit is contained in:
@@ -447,12 +447,12 @@ class AccountActivity : AppCompatActivity() {
|
|||||||
if (regCheck.isChecked) {
|
if (regCheck.isChecked) {
|
||||||
if (acc.regint != 3600) {
|
if (acc.regint != 3600) {
|
||||||
newRegint = 3600
|
newRegint = 3600
|
||||||
ua.updateStatus(R.drawable.dot_yellow)
|
ua.status = R.drawable.dot_yellow
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (acc.regint != 0) {
|
if (acc.regint != 0) {
|
||||||
Api.ua_unregister(ua.uap)
|
Api.ua_unregister(ua.uap)
|
||||||
ua.updateStatus(R.drawable.dot_white)
|
ua.status = R.drawable.dot_white
|
||||||
newRegint = 0
|
newRegint = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -592,9 +592,7 @@ class AccountActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
if (defaultCheck.isChecked && (uaIndex > 0)) {
|
if (defaultCheck.isChecked && (uaIndex > 0)) {
|
||||||
BaresipService.uas.add(0, BaresipService.uas[uaIndex])
|
BaresipService.uas.add(0, BaresipService.uas[uaIndex])
|
||||||
BaresipService.status.add(0, BaresipService.status[uaIndex])
|
|
||||||
BaresipService.uas.removeAt(uaIndex + 1)
|
BaresipService.uas.removeAt(uaIndex + 1)
|
||||||
BaresipService.status.removeAt(uaIndex + 1)
|
|
||||||
save = true
|
save = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ class AccountsActivity : AppCompatActivity() {
|
|||||||
newAorView.setText("")
|
newAorView.setText("")
|
||||||
newAorView.hint = getString(R.string.user_domain)
|
newAorView.hint = getString(R.string.user_domain)
|
||||||
newAorView.clearFocus()
|
newAorView.clearFocus()
|
||||||
ua.add(R.drawable.dot_white)
|
ua.add()
|
||||||
generateAccounts()
|
generateAccounts()
|
||||||
alAdapter.notifyDataSetChanged()
|
alAdapter.notifyDataSetChanged()
|
||||||
saveAccounts()
|
saveAccounts()
|
||||||
|
|||||||
@@ -533,18 +533,18 @@ class BaresipService: Service() {
|
|||||||
@Keep
|
@Keep
|
||||||
fun uaAdd(uap: Long) {
|
fun uaAdd(uap: Long) {
|
||||||
val ua = UserAgent(uap)
|
val ua = UserAgent(uap)
|
||||||
Log.d(TAG, "uaAdd ${ua.account.aor} at BaresipService")
|
ua.status = if (Api.ua_isregistered(uap)) {
|
||||||
uas.add(ua)
|
|
||||||
if (Api.ua_isregistered(uap)) {
|
|
||||||
Log.d(TAG, "Ua ${ua.account.aor} is registered")
|
Log.d(TAG, "Ua ${ua.account.aor} is registered")
|
||||||
status.add(R.drawable.dot_green)
|
R.drawable.dot_green
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Ua ${ua.account.aor} is NOT registered")
|
Log.d(TAG, "Ua ${ua.account.aor} is NOT registered")
|
||||||
if (ua.account.regint == 0)
|
if (ua.account.regint == 0)
|
||||||
status.add(R.drawable.dot_white)
|
R.drawable.dot_white
|
||||||
else
|
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")
|
@SuppressLint("UnspecifiedImmutableFlag")
|
||||||
@@ -579,17 +579,17 @@ class BaresipService: Service() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
"registered" -> {
|
"registered" -> {
|
||||||
if (ua.account.regint == 0)
|
ua.status = if (ua.account.regint == 0)
|
||||||
status[account_index] = R.drawable.dot_white
|
R.drawable.dot_white
|
||||||
else
|
else
|
||||||
status[account_index] = R.drawable.dot_green
|
R.drawable.dot_green
|
||||||
updateStatusNotification()
|
updateStatusNotification()
|
||||||
if (isMainVisible)
|
if (isMainVisible)
|
||||||
registrationUpdate.postValue(System.currentTimeMillis())
|
registrationUpdate.postValue(System.currentTimeMillis())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
"registering failed" -> {
|
"registering failed" -> {
|
||||||
status[account_index] = R.drawable.dot_red
|
ua.status = R.drawable.dot_red
|
||||||
updateStatusNotification()
|
updateStatusNotification()
|
||||||
if (isMainVisible)
|
if (isMainVisible)
|
||||||
registrationUpdate.postValue(System.currentTimeMillis())
|
registrationUpdate.postValue(System.currentTimeMillis())
|
||||||
@@ -606,7 +606,7 @@ class BaresipService: Service() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
"unregistering" -> {
|
"unregistering" -> {
|
||||||
status[account_index] = R.drawable.dot_white
|
ua.status = R.drawable.dot_white
|
||||||
updateStatusNotification()
|
updateStatusNotification()
|
||||||
if (isMainVisible)
|
if (isMainVisible)
|
||||||
registrationUpdate.postValue(System.currentTimeMillis())
|
registrationUpdate.postValue(System.currentTimeMillis())
|
||||||
@@ -1113,14 +1113,14 @@ class BaresipService: Service() {
|
|||||||
val contentView = RemoteViews(packageName, R.layout.status_notification)
|
val contentView = RemoteViews(packageName, R.layout.status_notification)
|
||||||
for (i: Int in 0..5) {
|
for (i: Int in 0..5) {
|
||||||
val resID = resources.getIdentifier("status$i", "id", packageName)
|
val resID = resources.getIdentifier("status$i", "id", packageName)
|
||||||
if (i < status.size) {
|
if (i < uas.size) {
|
||||||
contentView.setImageViewResource(resID, status[i])
|
contentView.setImageViewResource(resID, uas[i].status)
|
||||||
contentView.setViewVisibility(resID, View.VISIBLE)
|
contentView.setViewVisibility(resID, View.VISIBLE)
|
||||||
} else {
|
} else {
|
||||||
contentView.setViewVisibility(resID, View.INVISIBLE)
|
contentView.setViewVisibility(resID, View.INVISIBLE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (status.size > 4)
|
if (uas.size > 4)
|
||||||
contentView.setViewVisibility(R.id.etc, View.VISIBLE)
|
contentView.setViewVisibility(R.id.etc, View.VISIBLE)
|
||||||
else
|
else
|
||||||
contentView.setViewVisibility(R.id.etc, View.INVISIBLE)
|
contentView.setViewVisibility(R.id.etc, View.INVISIBLE)
|
||||||
@@ -1447,7 +1447,6 @@ class BaresipService: Service() {
|
|||||||
stopRinging()
|
stopRinging()
|
||||||
stopMediaPlayer()
|
stopMediaPlayer()
|
||||||
uas.clear()
|
uas.clear()
|
||||||
status.clear()
|
|
||||||
callHistory.clear()
|
callHistory.clear()
|
||||||
messages.clear()
|
messages.clear()
|
||||||
if (this::nm.isInitialized)
|
if (this::nm.isInitialized)
|
||||||
@@ -1483,7 +1482,6 @@ class BaresipService: Service() {
|
|||||||
var isMicMuted = false
|
var isMicMuted = false
|
||||||
|
|
||||||
val uas = ArrayList<UserAgent>()
|
val uas = ArrayList<UserAgent>()
|
||||||
val status = ArrayList<Int>()
|
|
||||||
val calls = ArrayList<Call>()
|
val calls = ArrayList<Call>()
|
||||||
var callHistory = ArrayList<NewCallHistory>()
|
var callHistory = ArrayList<NewCallHistory>()
|
||||||
var messages = ArrayList<Message>()
|
var messages = ArrayList<Message>()
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uaAdapter = UaSpinnerAdapter(applicationContext, BaresipService.uas, BaresipService.status)
|
uaAdapter = UaSpinnerAdapter(applicationContext, BaresipService.uas)
|
||||||
aorSpinner.adapter = uaAdapter
|
aorSpinner.adapter = uaAdapter
|
||||||
aorSpinner.setSelection(-1)
|
aorSpinner.setSelection(-1)
|
||||||
aorSpinner.tag = ""
|
aorSpinner.tag = ""
|
||||||
|
|||||||
@@ -9,9 +9,8 @@ import android.widget.ArrayAdapter
|
|||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
|
||||||
class UaSpinnerAdapter(cxt: Context, private val uas: ArrayList<UserAgent>,
|
class UaSpinnerAdapter(cxt: Context, private val uas: ArrayList<UserAgent>) :
|
||||||
private val images: ArrayList<Int>) :
|
ArrayAdapter<UserAgent>(cxt, android.R.layout.simple_spinner_item, uas) {
|
||||||
ArrayAdapter<Int>(cxt, android.R.layout.simple_spinner_item, images) {
|
|
||||||
|
|
||||||
private val layoutInflater = LayoutInflater.from(context)
|
private val layoutInflater = LayoutInflater.from(context)
|
||||||
|
|
||||||
@@ -47,7 +46,7 @@ class UaSpinnerAdapter(cxt: Context, private val uas: ArrayList<UserAgent>,
|
|||||||
viewHolder.textView.textSize = 17f
|
viewHolder.textView.textSize = 17f
|
||||||
if (UserAgent.uas().size > 1 && ua.calls().isNotEmpty())
|
if (UserAgent.uas().size > 1 && ua.calls().isNotEmpty())
|
||||||
viewHolder.textView.setTypeface(null, Typeface.BOLD)
|
viewHolder.textView.setTypeface(null, Typeface.BOLD)
|
||||||
viewHolder.imageView.setImageResource(images[position])
|
viewHolder.imageView.setImageResource(ua.status)
|
||||||
|
|
||||||
return rowView
|
return rowView
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,20 +3,14 @@ package com.tutpro.baresip
|
|||||||
class UserAgent(val uap: Long) {
|
class UserAgent(val uap: Long) {
|
||||||
|
|
||||||
val account = Account(Api.ua_account(uap))
|
val account = Account(Api.ua_account(uap))
|
||||||
|
var status = R.drawable.dot_white
|
||||||
|
|
||||||
fun add(status: Int) {
|
fun add() {
|
||||||
BaresipService.uas.add(this)
|
BaresipService.uas.add(this)
|
||||||
BaresipService.status.add(status)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun remove() {
|
fun remove() {
|
||||||
val index = BaresipService.uas.indexOf(this)
|
|
||||||
BaresipService.uas.remove(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> {
|
fun calls(dir: String = ""): ArrayList<Call> {
|
||||||
@@ -39,10 +33,6 @@ class UserAgent(val uap: Long) {
|
|||||||
return BaresipService.uas
|
return BaresipService.uas
|
||||||
}
|
}
|
||||||
|
|
||||||
fun status(): ArrayList<Int> {
|
|
||||||
return BaresipService.status
|
|
||||||
}
|
|
||||||
|
|
||||||
fun ofAor(aor: String): UserAgent? {
|
fun ofAor(aor: String): UserAgent? {
|
||||||
for (ua in BaresipService.uas)
|
for (ua in BaresipService.uas)
|
||||||
if (ua.account.aor == aor) return ua
|
if (ua.account.aor == aor) return ua
|
||||||
|
|||||||
Reference in New Issue
Block a user