Skip to content

Commit

Permalink
Move color conversion to extension function
Browse files Browse the repository at this point in the history
  • Loading branch information
derrohrbach committed Jan 22, 2024
1 parent fa8499e commit d8ba4fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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 @@ -156,16 +155,10 @@ class DialpadActivity : SimpleActivity() {

val properPrimaryColor = getProperPrimaryColor()
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 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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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 @@ -331,10 +330,7 @@ class RecentCallsAdapter(
itemRecentsSimImage.beVisibleIf(areMultipleSIMsAvailable && call.simID != -1)
itemRecentsSimId.beVisibleIf(areMultipleSIMsAvailable && call.simID != -1)
if (areMultipleSIMsAvailable && call.simID != -1) {
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)
itemRecentsSimImage.applyColorFilter(call.simColor.adjustSimColorForBackground(backgroundColor))
itemRecentsSimId.setTextColor(backgroundColor)
itemRecentsSimId.text = call.simID.toString()
}
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
}

0 comments on commit d8ba4fa

Please sign in to comment.