Skip to content

Commit 4e0eee5

Browse files
authored
feat: improve SIM color visibility (#416)
* feat: improve SIM color visibility * style: format code
1 parent 7cb420b commit 4e0eee5

5 files changed

Lines changed: 26 additions & 9 deletions

File tree

app/src/main/kotlin/org/fossify/phone/activities/CallActivity.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,9 @@ class CallActivity : SimpleActivity() {
625625
callSimId.text = sim.id.toString()
626626
callSimId.beVisible()
627627
callSimImage.beVisible()
628-
callSimImage.applyColorFilter(sim.color.adjustSimColorForBackground(getProperBackgroundColor()))
628+
val simColor = sim.color.adjustForContrast(getProperBackgroundColor())
629+
callSimId.setTextColor(simColor.getContrastColor())
630+
callSimImage.applyColorFilter(simColor)
629631
}
630632

631633
val acceptDrawableId = when (index) {

app/src/main/kotlin/org/fossify/phone/adapters/RecentCallsAdapter.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class RecentCallsAdapter(
5757
private var durationPadding = resources.getDimension(R.dimen.normal_margin).toInt()
5858
private var phoneNumberUtilInstance: PhoneNumberUtil = PhoneNumberUtil.getInstance()
5959
private var phoneNumberOfflineGeocoderInstance: PhoneNumberOfflineGeocoder = PhoneNumberOfflineGeocoder.getInstance()
60+
private val cachedSimColors = HashMap<Pair<Int,Int>, Int>()
6061

6162
init {
6263
initDrawables()
@@ -537,8 +538,9 @@ class RecentCallsAdapter(
537538
itemRecentsSimImage.beVisibleIf(areMultipleSIMsAvailable && call.simID != -1)
538539
itemRecentsSimId.beVisibleIf(areMultipleSIMsAvailable && call.simID != -1)
539540
if (areMultipleSIMsAvailable && call.simID != -1) {
540-
itemRecentsSimImage.applyColorFilter(call.simColor.adjustSimColorForBackground(backgroundColor))
541-
itemRecentsSimId.setTextColor(backgroundColor)
541+
val simColor = getAdjustedSimColor(call.simColor)
542+
itemRecentsSimImage.applyColorFilter(simColor)
543+
itemRecentsSimId.setTextColor(simColor.getContrastColor())
542544
itemRecentsSimId.text = call.simID.toString()
543545
}
544546

@@ -583,6 +585,12 @@ class RecentCallsAdapter(
583585
}
584586
}
585587

588+
private fun getAdjustedSimColor(simColor: Int): Int {
589+
return cachedSimColors.getOrPut(simColor to backgroundColor) {
590+
simColor.adjustForContrast(backgroundColor)
591+
}
592+
}
593+
586594
private inner class RecentCallDateViewHolder(val binding: ItemRecentsDateBinding) : ViewHolder(binding.root) {
587595
fun bind(date: CallLogItem.Date) {
588596
binding.dateTextView.apply {

app/src/main/kotlin/org/fossify/phone/extensions/Context.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ val Context.powerManager: PowerManager get() = getSystemService(Context.POWER_SE
1818

1919
@SuppressLint("MissingPermission")
2020
fun Context.getAvailableSIMCardLabels(): List<SIMAccount> {
21-
val SIMAccounts = mutableListOf<SIMAccount>()
21+
val simAccounts = mutableListOf<SIMAccount>()
2222
try {
2323
telecomManager.callCapablePhoneAccounts.forEachIndexed { index, account ->
2424
val phoneAccount = telecomManager.getPhoneAccount(account)
@@ -29,12 +29,20 @@ fun Context.getAvailableSIMCardLabels(): List<SIMAccount> {
2929
label += " ($address)"
3030
}
3131

32-
val SIM = SIMAccount(index + 1, phoneAccount.accountHandle, label, address.substringAfter("tel:"), phoneAccount.highlightColor)
33-
SIMAccounts.add(SIM)
32+
simAccounts.add(
33+
SIMAccount(
34+
id = index + 1,
35+
handle = phoneAccount.accountHandle,
36+
label = label,
37+
phoneNumber = address.substringAfter("tel:"),
38+
color = phoneAccount.highlightColor
39+
)
40+
)
3441
}
3542
} catch (ignored: Exception) {
3643
}
37-
return SIMAccounts
44+
45+
return simAccounts
3846
}
3947

4048
@SuppressLint("MissingPermission")

app/src/main/res/layout/item_recent_call.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
android:gravity="center"
6464
android:textColor="@color/md_grey_black"
6565
android:textSize="@dimen/small_text_size"
66-
android:textStyle="bold"
6766
android:visibility="gone"
6867
app:layout_constraintBottom_toBottomOf="@+id/item_recents_sim_image"
6968
app:layout_constraintEnd_toEndOf="@+id/item_recents_sim_image"

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ detekt = "1.23.8"
88
#Eventbus
99
eventbus = "3.3.1"
1010
#Fossify
11-
commons = "3.0.1"
11+
commons = "3.0.3"
1212
#Gradle
1313
gradlePlugins-agp = "8.10.1"
1414
#Other

0 commit comments

Comments
 (0)