mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 04:58:45 +00:00
Use standard avatar blur gradient algorithm.
This commit is contained in:
committed by
Cody Henthorne
parent
629f5a3a3d
commit
ca5754cff3
@@ -25,7 +25,6 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.signal.core.util.concurrent.LifecycleDisposable
|
||||
import org.signal.core.util.concurrent.SignalExecutors
|
||||
import org.signal.donations.StripeIntentAccessor
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.components.ProgressCardDialogFragment
|
||||
|
||||
@@ -2,26 +2,32 @@ package org.thoughtcrime.securesms.conversation.colors
|
||||
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import androidx.annotation.ColorInt
|
||||
import org.signal.core.util.CryptoUtil
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import kotlin.jvm.optionals.getOrNull
|
||||
import kotlin.math.abs
|
||||
|
||||
/**
|
||||
* Lists gradients used to hide profiles during message request states
|
||||
* Lists gradients used to hide profiles during message request states. Uses the same algorithm that determines avatar colors.
|
||||
*/
|
||||
object AvatarGradientColors {
|
||||
|
||||
@JvmStatic
|
||||
fun getGradientDrawable(recipient: Recipient): GradientDrawable {
|
||||
return if (recipient.serviceId.getOrNull() != null) {
|
||||
gradients[abs(recipient.requireServiceId().hashCode() % gradients.size)].getDrawable()
|
||||
forId(recipient.requireServiceId().toByteArray()).getDrawable()
|
||||
} else if (recipient.groupId.getOrNull() != null) {
|
||||
gradients[abs(recipient.requireGroupId().hashCode() % gradients.size)].getDrawable()
|
||||
forId(recipient.requireGroupId().decodedId).getDrawable()
|
||||
} else {
|
||||
gradients[0].getDrawable()
|
||||
}
|
||||
}
|
||||
|
||||
private fun forId(data: ByteArray): AvatarGradientColor {
|
||||
val hash = CryptoUtil.sha256(data)
|
||||
val firstByte: Byte = hash[0]
|
||||
return gradients[(firstByte.toUInt() % gradients.size.toUInt()).toInt()]
|
||||
}
|
||||
|
||||
private val gradients = listOf(
|
||||
AvatarGradientColor(0xFF252568.toInt(), 0xFF9C8F8F.toInt()),
|
||||
AvatarGradientColor(0xFF2A4275.toInt(), 0xFF9D9EA1.toInt()),
|
||||
|
||||
Reference in New Issue
Block a user