Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Initial support for sim colors #27

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions app/src/main/kotlin/org/fossify/phone/activities/CallActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -585,14 +585,15 @@ class CallActivity : SimpleActivity() {
@SuppressLint("MissingPermission")
private fun checkCalledSIMCard() {
try {
val accounts = telecomManager.callCapablePhoneAccounts
if (accounts.size > 1) {
accounts.forEachIndexed { index, account ->
if (account == CallManager.getPrimaryCall()?.details?.accountHandle) {
val simLabels = getAvailableSIMCardLabels()
if (simLabels.size > 1) {
simLabels.forEachIndexed { index, sim ->
if (sim.handle == CallManager.getPrimaryCall()?.details?.accountHandle) {
binding.apply {
callSimId.text = "${index + 1}"
callSimId.text = sim.id.toString()
callSimId.beVisible()
callSimImage.beVisible()
callSimImage.applyColorFilter(sim.color.adjustSimColorForBackground(getProperBackgroundColor()))
}

val acceptDrawableId = when (index) {
Expand Down
26 changes: 16 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 @@ -154,26 +154,32 @@ 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()
if (areMultipleSIMsAvailable()) {
val simInfo = getAvailableSIMCardLabels()
val callColor1 = if (simInfo.size > 1) simInfo[0].color.adjustSimColorForBackground(properBackgroundColor) else properPrimaryColor
val callColor2 = if (simInfo.size > 1) simInfo[1].color.adjustSimColorForBackground(properBackgroundColor) else properPrimaryColor
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
Expand Up @@ -330,8 +330,8 @@ 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())
itemRecentsSimImage.applyColorFilter(call.simColor.adjustSimColorForBackground(backgroundColor))
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
13 changes: 13 additions & 0 deletions app/src/main/kotlin/org/fossify/phone/extensions/Int.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.fossify.phone.extensions

import android.graphics.Color
import org.fossify.commons.extensions.lightenColor

fun Int.adjustSimColorForBackground(bg: Int): Int {
val hsv = FloatArray(3)
Color.colorToHSV(bg, hsv)
if (hsv[2] < 0.5) {
return this.lightenColor(24)
}
return this
}
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