- Added UserAgent add, remove, and updateStatus methods.

This commit is contained in:
Juha Heinanen
2020-05-08 10:12:25 +03:00
parent d169991687
commit c7ce526585
4 changed files with 19 additions and 24 deletions

View File

@ -323,12 +323,12 @@ class AccountActivity : AppCompatActivity() {
if (regCheck.isChecked) {
if (acc.regint != 3600) {
newRegint = 3600
UserAgent.updateStatus(ua, R.drawable.dot_yellow)
ua.updateStatus(R.drawable.dot_yellow)
}
} else {
if (acc.regint != 0) {
Api.ua_unregister(ua.uap)
UserAgent.updateStatus(ua, R.drawable.dot_white)
ua.updateStatus(R.drawable.dot_white)
newRegint = 0
}
}

View File

@ -45,7 +45,7 @@ class AccountListAdapter(private val cxt: Context, private val rows: ArrayList<A
Api.ua_destroy(ua.uap)
CallHistory.clear(ua.account.aor)
Message.clear(ua.account.aor)
UserAgent.remove(ua)
ua.remove()
AccountsActivity.generateAccounts()
AccountsActivity.saveAccounts()
this.notifyDataSetChanged()

View File

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

View File

@ -5,6 +5,21 @@ class UserAgent(val uap: String) {
val account = Account(Api.ua_account(uap))
var registrationFailed = false
fun add(status: Int) {
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
}
companion object {
fun uas(): ArrayList<UserAgent> {
@ -15,26 +30,6 @@ class UserAgent(val uap: String) {
return BaresipService.status
}
fun add(ua: UserAgent, status: Int) {
BaresipService.uas.add(ua)
BaresipService.status.add(status)
}
fun remove(ua: UserAgent) {
val index = BaresipService.uas.indexOf(ua)
if (index != -1) {
BaresipService.uas.removeAt(index)
BaresipService.status.removeAt(index)
}
}
fun updateStatus(ua: UserAgent, status: Int) {
val index = BaresipService.uas.indexOf(ua)
if (index != -1) {
BaresipService.status[index] = status
}
}
fun ofAor(aor: String): UserAgent? {
for (ua in BaresipService.uas)
if (ua.account.aor == aor) return ua