Skip to content

Commit

Permalink
Initial support for sim colors
Browse files Browse the repository at this point in the history
  • Loading branch information
derrohrbach committed Jan 22, 2024
1 parent 7f07e9b commit fa8499e
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 20 deletions.
33 changes: 23 additions & 10 deletions app/src/main/kotlin/org/fossify/phone/activities/DialpadActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.content.Intent
import android.database.Cursor
import android.graphics.Color
import android.net.Uri
import android.os.Build
import android.os.Bundle
Expand Down Expand Up @@ -154,26 +155,38 @@ class DialpadActivity : SimpleActivity() {
}

val properPrimaryColor = getProperPrimaryColor()
val callIconId = if (areMultipleSIMsAvailable()) {
val callIcon = resources.getColoredDrawableWithColor(R.drawable.ic_phone_two_vector, properPrimaryColor.getContrastColor())
val properBackgroundColor = getProperBackgroundColor()
val hsv = FloatArray(3)
Color.colorToHSV(properBackgroundColor, hsv)
if (areMultipleSIMsAvailable()) {
val simInfo = getAvailableSIMCardLabels()
var callColor1 = if (simInfo.size > 1) simInfo[0].color else properPrimaryColor
var callColor2 = if (simInfo.size > 1) simInfo[1].color else properPrimaryColor
if (hsv[2] < 0.5) {
callColor1 = callColor1.lightenColor(24)
callColor2 = callColor2.lightenColor(24)
}
val callIcon1 = resources.getColoredDrawableWithColor(R.drawable.ic_phone_one_vector, callColor1.getContrastColor())
val callIcon2 = resources.getColoredDrawableWithColor(R.drawable.ic_phone_two_vector, callColor2.getContrastColor())
binding.apply {
dialpadCallTwoButton.setImageDrawable(callIcon)
dialpadCallTwoButton.background.applyColorFilter(properPrimaryColor)
dialpadCallButton.setImageDrawable(callIcon1)
dialpadCallButton.background.applyColorFilter(callColor1)
dialpadCallTwoButton.setImageDrawable(callIcon2)
dialpadCallTwoButton.background.applyColorFilter(callColor2)
dialpadCallTwoButton.beVisible()
dialpadCallTwoButton.setOnClickListener {
initCall(dialpadInput.value, 1)
}
}

R.drawable.ic_phone_one_vector
} else {
R.drawable.ic_phone_vector
binding.apply {
val callIcon1 = resources.getColoredDrawableWithColor(R.drawable.ic_phone_vector, properPrimaryColor.getContrastColor())
dialpadCallButton.setImageDrawable(callIcon1)
dialpadCallButton.background.applyColorFilter(properPrimaryColor)
}
}

binding.apply {
val callIcon = resources.getColoredDrawableWithColor(callIconId, properPrimaryColor.getContrastColor())
dialpadCallButton.setImageDrawable(callIcon)
dialpadCallButton.background.applyColorFilter(properPrimaryColor)

letterFastscroller.textColor = getProperTextColor().getColorStateList()
letterFastscroller.pressedTextColor = properPrimaryColor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.fossify.phone.adapters

import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.provider.CallLog.Calls
import android.text.SpannableString
Expand Down Expand Up @@ -330,8 +331,11 @@ class RecentCallsAdapter(
itemRecentsSimImage.beVisibleIf(areMultipleSIMsAvailable && call.simID != -1)
itemRecentsSimId.beVisibleIf(areMultipleSIMsAvailable && call.simID != -1)
if (areMultipleSIMsAvailable && call.simID != -1) {
itemRecentsSimImage.applyColorFilter(textColor)
itemRecentsSimId.setTextColor(textColor.getContrastColor())
val hsv = FloatArray(3)
Color.colorToHSV(backgroundColor, hsv)
val simColor = if (hsv[2] > 0.5) call.simColor else call.simColor.lightenColor(24)
itemRecentsSimImage.applyColorFilter(simColor)
itemRecentsSimId.setTextColor(backgroundColor)
itemRecentsSimId.text = call.simID.toString()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fun Context.getAvailableSIMCardLabels(): List<SIMAccount> {
label += " ($address)"
}

val SIM = SIMAccount(index + 1, phoneAccount.accountHandle, label, address.substringAfter("tel:"))
val SIM = SIMAccount(index + 1, phoneAccount.accountHandle, label, address.substringAfter("tel:"), phoneAccount.highlightColor)
SIMAccounts.add(SIM)
}
} catch (ignored: Exception) {
Expand Down
14 changes: 8 additions & 6 deletions app/src/main/kotlin/org/fossify/phone/helpers/RecentsHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.fossify.phone.R
import org.fossify.phone.activities.SimpleActivity
import org.fossify.phone.extensions.getAvailableSIMCardLabels
import org.fossify.phone.models.RecentCall
import org.fossify.phone.models.SIMAccount

class RecentsHelper(private val context: Context) {
private val COMPARABLE_PHONE_NUMBER_LENGTH = 9
Expand Down Expand Up @@ -56,9 +57,9 @@ class RecentsHelper(private val context: Context) {
Calls.PHONE_ACCOUNT_ID
)

val accountIdToSimIDMap = HashMap<String, Int>()
val accountIdToSimAccountMap = HashMap<String, SIMAccount>()
context.getAvailableSIMCardLabels().forEach {
accountIdToSimIDMap[it.handle.id] = it.id
accountIdToSimAccountMap[it.handle.id] = it
}

val cursor = if (isNougatPlus()) {
Expand Down Expand Up @@ -150,7 +151,7 @@ class RecentsHelper(private val context: Context) {
val duration = cursor.getIntValue(Calls.DURATION)
val type = cursor.getIntValue(Calls.TYPE)
val accountId = cursor.getStringValue(Calls.PHONE_ACCOUNT_ID)
val simID = accountIdToSimIDMap[accountId] ?: -1
val simAccount = accountIdToSimAccountMap[accountId]
val neighbourIDs = mutableListOf<Int>()
var specificNumber = ""
var specificType = ""
Expand All @@ -174,20 +175,21 @@ class RecentsHelper(private val context: Context) {
duration = duration,
type = type,
neighbourIDs = neighbourIDs,
simID = simID,
simID = simAccount?.id ?: -1,
simColor = simAccount?.color ?: -1,
specificNumber = specificNumber,
specificType = specificType,
isUnknownNumber = isUnknownNumber
)

// if we have multiple missed calls from the same number, show it just once
if (!groupSubsequentCalls || "$number$name$simID" != previousRecentCallFrom) {
if (!groupSubsequentCalls || "$number$name${simAccount?.id ?: -1}" != previousRecentCallFrom) {
recentCalls.add(recentCall)
} else {
recentCalls.lastOrNull()?.neighbourIDs?.add(id)
}

previousRecentCallFrom = "$number$name$simID"
previousRecentCallFrom = "$number$name${simAccount?.id ?: -1}"
} while (cursor.moveToNext() && recentCalls.size < maxSize)
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/kotlin/org/fossify/phone/models/RecentCall.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ data class RecentCall(
val type: Int,
val neighbourIDs: MutableList<Int>,
val simID: Int,
val simColor: Int,
val specificNumber: String,
val specificType: String,
val isUnknownNumber: Boolean,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/org/fossify/phone/models/SIMAccount.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package org.fossify.phone.models

import android.telecom.PhoneAccountHandle

data class SIMAccount(val id: Int, val handle: PhoneAccountHandle, val label: String, val phoneNumber: String)
data class SIMAccount(val id: Int, val handle: PhoneAccountHandle, val label: String, val phoneNumber: String, val color: Int)
1 change: 1 addition & 0 deletions app/src/main/res/layout/item_recent_call.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
android:gravity="center"
android:textColor="@color/md_grey_black"
android:textSize="@dimen/small_text_size"
android:textStyle="bold"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/item_recents_sim_image"
app:layout_constraintEnd_toEndOf="@+id/item_recents_sim_image"
Expand Down

0 comments on commit fa8499e

Please sign in to comment.