Skip to content

Commit 7cb420b

Browse files
feat: add support for SIM colors (#27)
* Initial support for sim colors * Move color conversion to extension function * Implement sim color support in call activity * style: add empty line * style: put parameters on separate lines * revert: undo dialpad button changes The primary/secondary buttons will be removed to keep things simple: #50 --------- Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com> Co-authored-by: Naveen Singh <snaveen935@gmail.com>
1 parent cea4adb commit 7cb420b

7 files changed

Lines changed: 37 additions & 26 deletions

File tree

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -617,14 +617,15 @@ class CallActivity : SimpleActivity() {
617617
@SuppressLint("MissingPermission")
618618
private fun checkCalledSIMCard() {
619619
try {
620-
val accounts = telecomManager.callCapablePhoneAccounts
621-
if (accounts.size > 1) {
622-
accounts.forEachIndexed { index, account ->
623-
if (account == CallManager.getPrimaryCall()?.details?.accountHandle) {
620+
val simLabels = getAvailableSIMCardLabels()
621+
if (simLabels.size > 1) {
622+
simLabels.forEachIndexed { index, sim ->
623+
if (sim.handle == CallManager.getPrimaryCall()?.details?.accountHandle) {
624624
binding.apply {
625-
callSimId.text = "${index + 1}"
625+
callSimId.text = sim.id.toString()
626626
callSimId.beVisible()
627627
callSimImage.beVisible()
628+
callSimImage.applyColorFilter(sim.color.adjustSimColorForBackground(getProperBackgroundColor()))
628629
}
629630

630631
val acceptDrawableId = when (index) {

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -529,16 +529,16 @@ class RecentCallsAdapter(
529529
setTextSize(TypedValue.COMPLEX_UNIT_PX, currentFontSize * 0.8f)
530530
beVisibleIf(
531531
phoneNumber != null
532-
&& phoneNumber.countryCodeSource != Phonenumber.PhoneNumber.CountryCodeSource.FROM_DEFAULT_COUNTRY
533-
&& (location != locale.displayCountry || matchingContact == null)
532+
&& phoneNumber.countryCodeSource != Phonenumber.PhoneNumber.CountryCodeSource.FROM_DEFAULT_COUNTRY
533+
&& (location != locale.displayCountry || matchingContact == null)
534534
)
535535
}
536536

537537
itemRecentsSimImage.beVisibleIf(areMultipleSIMsAvailable && call.simID != -1)
538538
itemRecentsSimId.beVisibleIf(areMultipleSIMsAvailable && call.simID != -1)
539539
if (areMultipleSIMsAvailable && call.simID != -1) {
540-
itemRecentsSimImage.applyColorFilter(textColor)
541-
itemRecentsSimId.setTextColor(textColor.getContrastColor())
540+
itemRecentsSimImage.applyColorFilter(call.simColor.adjustSimColorForBackground(backgroundColor))
541+
itemRecentsSimId.setTextColor(backgroundColor)
542542
itemRecentsSimId.text = call.simID.toString()
543543
}
544544

@@ -614,19 +614,19 @@ class RecentCallsDiffCallback : DiffUtil.ItemCallback<CallLogItem>() {
614614
oldItem is CallLogItem.Date && newItem is CallLogItem.Date -> oldItem.timestamp == newItem.timestamp && oldItem.dayCode == newItem.dayCode
615615
oldItem is RecentCall && newItem is RecentCall -> {
616616
oldItem.phoneNumber == newItem.phoneNumber &&
617-
oldItem.name == newItem.name &&
618-
oldItem.photoUri == newItem.photoUri &&
619-
oldItem.startTS == newItem.startTS &&
620-
oldItem.duration == newItem.duration &&
621-
oldItem.type == newItem.type &&
622-
oldItem.simID == newItem.simID &&
623-
oldItem.specificNumber == newItem.specificNumber &&
624-
oldItem.specificType == newItem.specificType &&
625-
oldItem.isUnknownNumber == newItem.isUnknownNumber &&
626-
oldItem.groupedCalls?.size == newItem.groupedCalls?.size
617+
oldItem.name == newItem.name &&
618+
oldItem.photoUri == newItem.photoUri &&
619+
oldItem.startTS == newItem.startTS &&
620+
oldItem.duration == newItem.duration &&
621+
oldItem.type == newItem.type &&
622+
oldItem.simID == newItem.simID &&
623+
oldItem.specificNumber == newItem.specificNumber &&
624+
oldItem.specificType == newItem.specificType &&
625+
oldItem.isUnknownNumber == newItem.isUnknownNumber &&
626+
oldItem.groupedCalls?.size == newItem.groupedCalls?.size
627627
}
628628

629629
else -> false
630630
}
631631
}
632-
}
632+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fun Context.getAvailableSIMCardLabels(): List<SIMAccount> {
2929
label += " ($address)"
3030
}
3131

32-
val SIM = SIMAccount(index + 1, phoneAccount.accountHandle, label, address.substringAfter("tel:"))
32+
val SIM = SIMAccount(index + 1, phoneAccount.accountHandle, label, address.substringAfter("tel:"), phoneAccount.highlightColor)
3333
SIMAccounts.add(SIM)
3434
}
3535
} catch (ignored: Exception) {

app/src/main/kotlin/org/fossify/phone/helpers/RecentsHelper.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import org.fossify.phone.R
1212
import org.fossify.phone.activities.SimpleActivity
1313
import org.fossify.phone.extensions.getAvailableSIMCardLabels
1414
import org.fossify.phone.models.RecentCall
15+
import org.fossify.phone.models.SIMAccount
1516

1617
class RecentsHelper(private val context: Context) {
1718
companion object {
@@ -138,9 +139,9 @@ class RecentsHelper(private val context: Context) {
138139
Calls.PHONE_ACCOUNT_ID
139140
)
140141

141-
val accountIdToSimIDMap = HashMap<String, Int>()
142+
val accountIdToSimAccountMap = HashMap<String, SIMAccount>()
142143
context.getAvailableSIMCardLabels().forEach {
143-
accountIdToSimIDMap[it.handle.id] = it.id
144+
accountIdToSimAccountMap[it.handle.id] = it
144145
}
145146

146147
val cursor = if (isNougatPlus()) {
@@ -232,7 +233,7 @@ class RecentsHelper(private val context: Context) {
232233
val duration = cursor.getIntValue(Calls.DURATION)
233234
val type = cursor.getIntValue(Calls.TYPE)
234235
val accountId = cursor.getStringValue(Calls.PHONE_ACCOUNT_ID)
235-
val simID = accountIdToSimIDMap[accountId] ?: -1
236+
val simAccount = accountIdToSimAccountMap[accountId]
236237
var specificNumber = ""
237238
var specificType = ""
238239

@@ -255,7 +256,8 @@ class RecentsHelper(private val context: Context) {
255256
startTS = startTS,
256257
duration = duration,
257258
type = type,
258-
simID = simID,
259+
simID = simAccount?.id ?: -1,
260+
simColor = simAccount?.color ?: -1,
259261
specificNumber = specificNumber,
260262
specificType = specificType,
261263
isUnknownNumber = isUnknownNumber

app/src/main/kotlin/org/fossify/phone/models/RecentCall.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ data class RecentCall(
1818
val duration: Int,
1919
val type: Int,
2020
val simID: Int,
21+
val simColor: Int,
2122
val specificNumber: String,
2223
val specificType: String,
2324
val isUnknownNumber: Boolean,

app/src/main/kotlin/org/fossify/phone/models/SIMAccount.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@ package org.fossify.phone.models
22

33
import android.telecom.PhoneAccountHandle
44

5-
data class SIMAccount(val id: Int, val handle: PhoneAccountHandle, val label: String, val phoneNumber: String)
5+
data class SIMAccount(
6+
val id: Int,
7+
val handle: PhoneAccountHandle,
8+
val label: String,
9+
val phoneNumber: String,
10+
val color: Int,
11+
)

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

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

0 commit comments

Comments
 (0)