Use map to select circle drawable based on colorblind setting

This commit is contained in:
Juha Heinanen
2025-07-11 08:38:49 +03:00
parent 63affe027b
commit c61bab983c
3 changed files with 18 additions and 28 deletions
@@ -676,7 +676,7 @@ class BaresipService: Service() {
ua.status = if (ua.account.regint == 0) ua.status = if (ua.account.regint == 0)
R.drawable.circle_white R.drawable.circle_white
else else
Utils.circleYellow() circleYellow.getValue(colorblind)
ua.add() ua.add()
val acc = ua.account val acc = ua.account
@@ -773,7 +773,7 @@ class BaresipService: Service() {
when (ev[0]) { when (ev[0]) {
"registering", "unregistering" -> { "registering", "unregistering" -> {
updateStatusNotification() updateStatusNotification()
ua.uaUpdateStatus(Utils.circleYellow()) ua.uaUpdateStatus(circleYellow.getValue(colorblind))
if (isMainVisible) if (isMainVisible)
registrationUpdate.postValue(System.currentTimeMillis()) registrationUpdate.postValue(System.currentTimeMillis())
return return
@@ -783,7 +783,8 @@ class BaresipService: Service() {
if (Api.account_regint(ua.account.accp) == 0) if (Api.account_regint(ua.account.accp) == 0)
R.drawable.circle_white R.drawable.circle_white
else else
Utils.circleGreen()) circleGreen.getValue(colorblind)
)
updateStatusNotification() updateStatusNotification()
if (isMainVisible) if (isMainVisible)
registrationUpdate.postValue(System.currentTimeMillis()) registrationUpdate.postValue(System.currentTimeMillis())
@@ -793,7 +794,8 @@ class BaresipService: Service() {
ua.uaUpdateStatus(if (Api.account_regint(ua.account.accp) == 0) ua.uaUpdateStatus(if (Api.account_regint(ua.account.accp) == 0)
R.drawable.circle_white R.drawable.circle_white
else else
Utils.circleRed()) circleRed.getValue(colorblind)
)
updateStatusNotification() updateStatusNotification()
if (isMainVisible) if (isMainVisible)
registrationUpdate.postValue(System.currentTimeMillis()) registrationUpdate.postValue(System.currentTimeMillis())
@@ -1733,7 +1735,6 @@ class BaresipService: Service() {
var contactsMode = "baresip" var contactsMode = "baresip"
var addressFamily = "" var addressFamily = ""
var dnsServers = listOf<InetAddress>() var dnsServers = listOf<InetAddress>()
var colorblind = false
// <aor, password> of those accounts that have auth username without auth password // <aor, password> of those accounts that have auth username without auth password
val aorPasswords = mutableMapOf<String, String>() val aorPasswords = mutableMapOf<String, String>()
var audioFocusRequest: AudioFocusRequestCompat? = null var audioFocusRequest: AudioFocusRequestCompat? = null
@@ -1742,6 +1743,14 @@ class BaresipService: Service() {
var agcAvailable = false var agcAvailable = false
var rt: Ringtone? = null var rt: Ringtone? = null
var colorblind = false
val circleGreen = mapOf(true to R.drawable.circle_green_blind,
false to R.drawable.circle_green)
val circleYellow = mapOf(true to R.drawable.circle_yellow_blind,
false to R.drawable.circle_yellow)
val circleRed = mapOf(true to R.drawable.circle_red_blind,
false to R.drawable.circle_red)
private var agc: AutomaticGainControl? = null private var agc: AutomaticGainControl? = null
private val nsAvailable = NoiseSuppressor.isAvailable() private val nsAvailable = NoiseSuppressor.isAvailable()
private var ns: NoiseSuppressor? = null private var ns: NoiseSuppressor? = null
@@ -1,5 +1,7 @@
package com.tutpro.baresip package com.tutpro.baresip
import com.tutpro.baresip.BaresipService.Companion.circleYellow
import com.tutpro.baresip.BaresipService.Companion.colorblind
import com.tutpro.baresip.BaresipService.Companion.uas import com.tutpro.baresip.BaresipService.Companion.uas
import com.tutpro.baresip.BaresipService.Companion.uasStatus import com.tutpro.baresip.BaresipService.Companion.uasStatus
@@ -46,7 +48,7 @@ class UserAgent(val uap: Long) {
} }
fun reRegister() { fun reRegister() {
this.status = Utils.circleYellow() this.status = circleYellow.getValue(colorblind)
if (this.account.regint == 0) if (this.account.regint == 0)
Api.ua_unregister(this.uap) Api.ua_unregister(this.uap)
else else
@@ -109,7 +111,7 @@ class UserAgent(val uap: Long) {
val updatedUas = uas.value.toMutableList() val updatedUas = uas.value.toMutableList()
for (ua in updatedUas) for (ua in updatedUas)
ua.status = ua.status =
if (BaresipService.colorblind) if (colorblind)
when (ua.status) { when (ua.status) {
R.drawable.circle_green -> R.drawable.circle_green_blind R.drawable.circle_green -> R.drawable.circle_green_blind
R.drawable.circle_yellow -> R.drawable.circle_yellow_blind R.drawable.circle_yellow -> R.drawable.circle_yellow_blind
@@ -996,27 +996,6 @@ object Utils {
} }
fun circleGreen(): Int {
return if (BaresipService.colorblind)
R.drawable.circle_green_blind
else
R.drawable.circle_green
}
fun circleYellow(): Int {
return if (BaresipService.colorblind)
R.drawable.circle_yellow_blind
else
R.drawable.circle_yellow
}
fun circleRed(): Int {
return if (BaresipService.colorblind)
R.drawable.circle_red_blind
else
R.drawable.circle_red
}
/*fun listFilesInDirectory(directoryPath: String): List<File> { /*fun listFilesInDirectory(directoryPath: String): List<File> {
val directory = File(directoryPath) val directory = File(directoryPath)
if (!directory.exists()) { if (!directory.exists()) {