New avatar placeholder drawable generator.

This commit is contained in:
Anton Chekulaev 2020-09-03 22:15:03 +10:00
parent 0da8613075
commit c2c4c9f41a
15 changed files with 181 additions and 66 deletions

View File

@ -6,6 +6,4 @@
<solid android:color="@color/unimportant" /> <solid android:color="@color/unimportant" />
<corners android:radius="23dp" /> <corners android:radius="23dp" />
<stroke android:width="@dimen/profile_picture_border_thickness" android:color="@color/border" />
</shape> </shape>

View File

@ -6,6 +6,4 @@
<solid android:color="#353535" /> <solid android:color="#353535" />
<corners android:radius="23dp" /> <corners android:radius="23dp" />
<stroke android:width="@dimen/profile_picture_border_thickness" android:color="@color/border" />
</shape> </shape>

View File

@ -6,6 +6,4 @@
<solid android:color="@color/unimportant" /> <solid android:color="@color/unimportant" />
<corners android:radius="18dp" /> <corners android:radius="18dp" />
<stroke android:width="@dimen/profile_picture_border_thickness" android:color="@color/border" />
</shape> </shape>

View File

@ -34,7 +34,8 @@
android:layout_height="@dimen/small_profile_picture_size" android:layout_height="@dimen/small_profile_picture_size"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_marginLeft="9dp" /> android:layout_marginLeft="9dp"
android:foreground="@drawable/circle_touch_highlight_background"/>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@ -24,7 +24,8 @@
android:id="@+id/profilePictureView" android:id="@+id/profilePictureView"
android:layout_width="@dimen/large_profile_picture_size" android:layout_width="@dimen/large_profile_picture_size"
android:layout_height="@dimen/large_profile_picture_size" android:layout_height="@dimen/large_profile_picture_size"
android:layout_marginTop="@dimen/medium_spacing" /> android:layout_marginTop="@dimen/medium_spacing"
android:foreground="@drawable/circle_touch_highlight_background" />
<RelativeLayout <RelativeLayout
android:id="@+id/ctnGroupNameSection" android:id="@+id/ctnGroupNameSection"

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout <RelativeLayout
android:id="@+id/doubleModeImageViewContainer" android:id="@+id/doubleModeImageViewContainer"
@ -19,13 +19,9 @@
android:id="@+id/doubleModeImageView1" android:id="@+id/doubleModeImageView1"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:alpha="0.65"
android:background="@drawable/profile_picture_view_small_background" /> android:background="@drawable/profile_picture_view_small_background" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/profile_picture_view_small_foreground" />
</RelativeLayout> </RelativeLayout>
<RelativeLayout <RelativeLayout
@ -40,11 +36,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/profile_picture_view_small_background" /> android:background="@drawable/profile_picture_view_small_background" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/profile_picture_view_small_foreground" />
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>
@ -60,11 +51,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/profile_picture_view_medium_background" /> android:background="@drawable/profile_picture_view_medium_background" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/profile_picture_view_medium_foreground" />
</RelativeLayout> </RelativeLayout>
<ImageView <ImageView
@ -87,11 +73,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/profile_picture_view_large_background" /> android:background="@drawable/profile_picture_view_large_background" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/profile_picture_view_large_foreground" />
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>

View File

@ -107,4 +107,12 @@
<color name="default_background_start">#121212</color> <color name="default_background_start">#121212</color>
<color name="default_background_end">#171717</color> <color name="default_background_end">#171717</color>
<array name="user_pic_placeholder_primary">
<item>#18da80</item>
<item>#ee8917</item>
<item>#239edf</item>
<item>#c33fe9</item>
<item>#83b433</item>
</array>
</resources> </resources>

View File

@ -804,6 +804,7 @@ public class ConversationItem extends LinearLayout
bodyBubble.setLayoutParams(layoutParams); bodyBubble.setLayoutParams(layoutParams);
if (profilePictureView == null) return; if (profilePictureView == null) return;
profilePictureView.setPublicKey(recipient.getAddress().toString()); profilePictureView.setPublicKey(recipient.getAddress().toString());
profilePictureView.setDisplayName(recipient.getName());
profilePictureView.setAdditionalPublicKey(null); profilePictureView.setAdditionalPublicKey(null);
profilePictureView.setRSSFeed(false); profilePictureView.setRSSFeed(false);
profilePictureView.setGlide(glideRequests); profilePictureView.setGlide(glideRequests);

View File

@ -1,7 +1,6 @@
package org.thoughtcrime.securesms.loki.activities package org.thoughtcrime.securesms.loki.activities
import android.app.AlertDialog import android.app.AlertDialog
import androidx.lifecycle.Observer
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
@ -11,10 +10,6 @@ import android.net.Uri
import android.os.AsyncTask import android.os.AsyncTask
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import androidx.loader.app.LoaderManager
import androidx.loader.content.Loader
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.recyclerview.widget.LinearLayoutManager
import android.text.Spannable import android.text.Spannable
import android.text.SpannableString import android.text.SpannableString
import android.text.style.ForegroundColorSpan import android.text.style.ForegroundColorSpan
@ -22,6 +17,11 @@ import android.util.DisplayMetrics
import android.view.View import android.view.View
import android.widget.RelativeLayout import android.widget.RelativeLayout
import android.widget.Toast import android.widget.Toast
import androidx.lifecycle.Observer
import androidx.loader.app.LoaderManager
import androidx.loader.content.Loader
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.activity_home.* import kotlinx.android.synthetic.main.activity_home.*
import network.loki.messenger.R import network.loki.messenger.R
import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.ApplicationContext
@ -42,14 +42,13 @@ import org.thoughtcrime.securesms.loki.views.NewConversationButtonSetViewDelegat
import org.thoughtcrime.securesms.loki.views.SeedReminderViewDelegate import org.thoughtcrime.securesms.loki.views.SeedReminderViewDelegate
import org.thoughtcrime.securesms.mms.GlideApp import org.thoughtcrime.securesms.mms.GlideApp
import org.thoughtcrime.securesms.mms.GlideRequests import org.thoughtcrime.securesms.mms.GlideRequests
import org.thoughtcrime.securesms.util.GroupUtil
import org.thoughtcrime.securesms.util.TextSecurePreferences import org.thoughtcrime.securesms.util.TextSecurePreferences
import org.thoughtcrime.securesms.util.Util import org.thoughtcrime.securesms.util.Util
import org.whispersystems.signalservice.loki.api.fileserver.FileServerAPI import org.whispersystems.signalservice.loki.api.fileserver.FileServerAPI
import org.whispersystems.signalservice.loki.protocol.mentions.MentionsManager import org.whispersystems.signalservice.loki.protocol.mentions.MentionsManager
import org.whispersystems.signalservice.loki.protocol.meta.SessionMetaProtocol import org.whispersystems.signalservice.loki.protocol.meta.SessionMetaProtocol
import org.whispersystems.signalservice.loki.protocol.shelved.multidevice.MultiDeviceProtocol
import org.whispersystems.signalservice.loki.protocol.sessionmanagement.SessionManagementProtocol import org.whispersystems.signalservice.loki.protocol.sessionmanagement.SessionManagementProtocol
import org.whispersystems.signalservice.loki.protocol.shelved.multidevice.MultiDeviceProtocol
import org.whispersystems.signalservice.loki.protocol.shelved.syncmessages.SyncMessagesProtocol import org.whispersystems.signalservice.loki.protocol.shelved.syncmessages.SyncMessagesProtocol
import org.whispersystems.signalservice.loki.utilities.toHexString import org.whispersystems.signalservice.loki.utilities.toHexString
@ -98,6 +97,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
// Set up toolbar buttons // Set up toolbar buttons
profileButton.glide = glide profileButton.glide = glide
profileButton.publicKey = publicKey profileButton.publicKey = publicKey
profileButton.displayName = TextSecurePreferences.getProfileName(this)
profileButton.update() profileButton.update()
profileButton.setOnClickListener { openSettings() } profileButton.setOnClickListener { openSettings() }
pathStatusViewContainer.setOnClickListener { showPath() } pathStatusViewContainer.setOnClickListener { showPath() }

View File

@ -74,14 +74,17 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
setContentView(R.layout.activity_settings) setContentView(R.layout.activity_settings)
val origUserDisplayName = DatabaseFactory.getLokiUserDatabase(this).getDisplayName(hexEncodedPublicKey)
glide = GlideApp.with(this) glide = GlideApp.with(this)
profilePictureView.glide = glide profilePictureView.glide = glide
profilePictureView.publicKey = hexEncodedPublicKey profilePictureView.publicKey = hexEncodedPublicKey
profilePictureView.displayName = displayNameToBeUploaded
profilePictureView.isLarge = true profilePictureView.isLarge = true
profilePictureView.update() profilePictureView.update()
profilePictureView.setOnClickListener { showEditProfilePictureUI() } profilePictureView.setOnClickListener { showEditProfilePictureUI() }
ctnGroupNameSection.setOnClickListener { startActionMode(DisplayNameEditActionModeCallback()) } ctnGroupNameSection.setOnClickListener { startActionMode(DisplayNameEditActionModeCallback()) }
btnGroupNameDisplay.text = DatabaseFactory.getLokiUserDatabase(this).getDisplayName(hexEncodedPublicKey) btnGroupNameDisplay.text = origUserDisplayName
publicKeyTextView.text = hexEncodedPublicKey publicKeyTextView.text = hexEncodedPublicKey
copyButton.setOnClickListener { copyPublicKey() } copyButton.setOnClickListener { copyPublicKey() }
shareButton.setOnClickListener { sharePublicKey() } shareButton.setOnClickListener { sharePublicKey() }

View File

@ -0,0 +1,83 @@
package org.thoughtcrime.securesms.loki.todo
import android.content.Context
import android.graphics.*
import android.graphics.drawable.BitmapDrawable
import android.text.TextPaint
import android.text.TextUtils
import androidx.annotation.ColorInt
import androidx.core.graphics.ColorUtils
import network.loki.messenger.R
import java.util.*
object AvatarPlaceholderGenerator {
private const val EMPTY_LABEL = "0";
private val tmpFloatArray = FloatArray(3)
fun generate(context: Context, pixelSize: Int, hashString: String, displayName: String?): BitmapDrawable {
//TODO That should be replaced with a proper hash extraction code.
val hash: Long
val hexRegex = Regex("^[0-9A-Fa-f]+\$")
if (hashString.length >= 12 && hashString.matches(hexRegex)) {
hash = hashString.substring(0 until 12).toLong(16)
} else {
hash = hashString.toLong()
}
// Do not cache color array, it may be different depends on the current theme.
val colorArray = context.resources.getIntArray(R.array.user_pic_placeholder_primary)
val colorPrimary = colorArray[(hash % colorArray.size).toInt()]
val colorSecondary = changeColorHueBy(colorPrimary, 16f)
val labelText = when {
!TextUtils.isEmpty(displayName) -> extractLabel(displayName!!)
!TextUtils.isEmpty(hashString) -> extractLabel(hashString)
else -> EMPTY_LABEL
}
val bitmap = Bitmap.createBitmap(pixelSize, pixelSize, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
// Draw background/frame
val paint = Paint()
paint.isAntiAlias = true
paint.shader = LinearGradient(0f, 0f, 0f, pixelSize.toFloat(),
colorPrimary,
colorSecondary,
Shader.TileMode.REPEAT)
canvas.drawCircle(pixelSize.toFloat() / 2, pixelSize.toFloat() / 2, pixelSize.toFloat() / 2, paint)
// Draw text
val textPaint = TextPaint()
textPaint.typeface = Typeface.create(Typeface.DEFAULT, Typeface.NORMAL)
textPaint.isAntiAlias = true
textPaint.textSize = pixelSize * 0.5f
textPaint.color = Color.WHITE
val areaRect = Rect(0, 0, pixelSize, pixelSize)
val textBounds = RectF(areaRect)
textBounds.right = textPaint.measureText(labelText)
textBounds.bottom = textPaint.descent() - textPaint.ascent()
textBounds.left += (areaRect.width() - textBounds.right) * 0.5f
textBounds.top += (areaRect.height() - textBounds.bottom) * 0.5f
canvas.drawText(labelText, textBounds.left, textBounds.top - textPaint.ascent(), textPaint)
return BitmapDrawable(context.resources, bitmap)
}
@ColorInt
private fun changeColorHueBy(@ColorInt color: Int, hueDelta: Float): Int {
val hslColor = tmpFloatArray
ColorUtils.colorToHSL(color, hslColor)
hslColor[0] = (hslColor[0] + hueDelta) % 360f
return ColorUtils.HSLToColor(hslColor)
}
private fun extractLabel(content: String): String {
var content = content.trim()
if (content.isEmpty()) return EMPTY_LABEL
return content.first().toString().toUpperCase(Locale.ROOT)
}
}

View File

@ -2,12 +2,14 @@ package org.thoughtcrime.securesms.loki.views
import android.content.Context import android.content.Context
import android.graphics.Typeface import android.graphics.Typeface
import android.text.TextUtils
import android.util.AttributeSet import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.widget.LinearLayout import android.widget.LinearLayout
import kotlinx.android.synthetic.main.view_conversation.view.* import kotlinx.android.synthetic.main.view_conversation.view.*
import network.loki.messenger.R import network.loki.messenger.R
import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.database.model.ThreadRecord import org.thoughtcrime.securesms.database.model.ThreadRecord
import org.thoughtcrime.securesms.loki.utilities.MentionManagerUtilities.populateUserPublicKeyCacheIfNeeded import org.thoughtcrime.securesms.loki.utilities.MentionManagerUtilities.populateUserPublicKeyCacheIfNeeded
import org.thoughtcrime.securesms.loki.utilities.MentionUtilities.highlightMentions import org.thoughtcrime.securesms.loki.utilities.MentionUtilities.highlightMentions
@ -58,22 +60,29 @@ class ConversationView : LinearLayout {
if (thread.recipient.isGroupRecipient) { if (thread.recipient.isGroupRecipient) {
if ("Session Public Chat" == thread.recipient.name) { if ("Session Public Chat" == thread.recipient.name) {
profilePictureView.publicKey = "" profilePictureView.publicKey = ""
profilePictureView.displayName = ""
profilePictureView.additionalPublicKey = null profilePictureView.additionalPublicKey = null
profilePictureView.isRSSFeed = true profilePictureView.isRSSFeed = true
} else { } else {
val users = MentionsManager.shared.userPublicKeyCache[thread.threadId]?.toMutableList() ?: mutableListOf() val userKeys = MentionsManager.shared.userPublicKeyCache[thread.threadId]?.toMutableList() ?: mutableListOf()
users.remove(TextSecurePreferences.getLocalNumber(context)) userKeys.remove(TextSecurePreferences.getLocalNumber(context))
val masterPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context) val masterPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context)
if (masterPublicKey != null) { if (masterPublicKey != null) {
users.remove(masterPublicKey) userKeys.remove(masterPublicKey)
} }
val randomUsers = users.sorted() // Sort to provide a level of stability
profilePictureView.publicKey = randomUsers.getOrNull(0) ?: "" val sortedUserKeys = userKeys.sorted() // Sort to provide a level of stability
profilePictureView.additionalPublicKey = randomUsers.getOrNull(1) ?: "" val userKey0 = sortedUserKeys.getOrNull(0) ?: ""
val userKey1 = sortedUserKeys.getOrNull(1) ?: ""
profilePictureView.publicKey = userKey0
profilePictureView.displayName = getUserDisplayName(userKey0)
profilePictureView.additionalPublicKey = userKey1
profilePictureView.additionalDisplayName = getUserDisplayName(userKey1)
profilePictureView.isRSSFeed = thread.recipient.name == "Loki News" || thread.recipient.name == "Session Updates" profilePictureView.isRSSFeed = thread.recipient.name == "Loki News" || thread.recipient.name == "Session Updates"
} }
} else { } else {
profilePictureView.publicKey = thread.recipient.address.toString() profilePictureView.publicKey = thread.recipient.address.toString()
profilePictureView.displayName = thread.recipient.name
profilePictureView.additionalPublicKey = null profilePictureView.additionalPublicKey = null
profilePictureView.isRSSFeed = false profilePictureView.isRSSFeed = false
} }
@ -103,5 +112,10 @@ class ConversationView : LinearLayout {
else -> statusIndicatorImageView.setImageResource(R.drawable.ic_circle_check) else -> statusIndicatorImageView.setImageResource(R.drawable.ic_circle_check)
} }
} }
private fun getUserDisplayName(publicKey: String?): String? {
if (TextUtils.isEmpty(publicKey)) return null
return DatabaseFactory.getLokiUserDatabase(context).getDisplayName(publicKey!!)
}
// endregion // endregion
} }

View File

@ -32,6 +32,7 @@ class MentionCandidateView(context: Context, attrs: AttributeSet?, defStyleAttr:
private fun update() { private fun update() {
btnGroupNameDisplay.text = mentionCandidate.displayName btnGroupNameDisplay.text = mentionCandidate.displayName
profilePictureView.publicKey = mentionCandidate.publicKey profilePictureView.publicKey = mentionCandidate.publicKey
profilePictureView.displayName = mentionCandidate.displayName
profilePictureView.additionalPublicKey = null profilePictureView.additionalPublicKey = null
profilePictureView.isRSSFeed = false profilePictureView.isRSSFeed = false
profilePictureView.glide = glide!! profilePictureView.glide = glide!!

View File

@ -1,18 +1,18 @@
package org.thoughtcrime.securesms.loki.views package org.thoughtcrime.securesms.loki.views
import android.content.Context import android.content.Context
import androidx.annotation.DimenRes
import android.util.AttributeSet import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.widget.ImageView import android.widget.ImageView
import android.widget.RelativeLayout import android.widget.RelativeLayout
import androidx.annotation.DimenRes
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
import kotlinx.android.synthetic.main.view_profile_picture.view.* import kotlinx.android.synthetic.main.view_profile_picture.view.*
import network.loki.messenger.R import network.loki.messenger.R
import org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto import org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto
import org.thoughtcrime.securesms.database.Address import org.thoughtcrime.securesms.database.Address
import org.thoughtcrime.securesms.loki.todo.JazzIdenticonDrawable import org.thoughtcrime.securesms.loki.todo.AvatarPlaceholderGenerator
import org.thoughtcrime.securesms.mms.GlideRequests import org.thoughtcrime.securesms.mms.GlideRequests
import org.thoughtcrime.securesms.recipients.Recipient import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.util.TextSecurePreferences import org.thoughtcrime.securesms.util.TextSecurePreferences
@ -22,7 +22,9 @@ import org.thoughtcrime.securesms.util.TextSecurePreferences
class ProfilePictureView : RelativeLayout { class ProfilePictureView : RelativeLayout {
lateinit var glide: GlideRequests lateinit var glide: GlideRequests
var publicKey: String? = null var publicKey: String? = null
var displayName: String? = null
var additionalPublicKey: String? = null var additionalPublicKey: String? = null
var additionalDisplayName: String? = null
var isRSSFeed = false var isRSSFeed = false
var isLarge = false var isLarge = false
@ -58,28 +60,51 @@ class ProfilePictureView : RelativeLayout {
singleModeImageViewContainer.visibility = if (additionalPublicKey == null && !isRSSFeed && !isLarge) View.VISIBLE else View.INVISIBLE singleModeImageViewContainer.visibility = if (additionalPublicKey == null && !isRSSFeed && !isLarge) View.VISIBLE else View.INVISIBLE
largeSingleModeImageViewContainer.visibility = if (additionalPublicKey == null && !isRSSFeed && isLarge) View.VISIBLE else View.INVISIBLE largeSingleModeImageViewContainer.visibility = if (additionalPublicKey == null && !isRSSFeed && isLarge) View.VISIBLE else View.INVISIBLE
rssImageView.visibility = if (isRSSFeed) View.VISIBLE else View.INVISIBLE rssImageView.visibility = if (isRSSFeed) View.VISIBLE else View.INVISIBLE
fun setProfilePictureIfNeeded(imageView: ImageView, hexEncodedPublicKey: String, @DimenRes sizeID: Int) {
glide.clear(imageView) setProfilePictureIfNeeded(
if (hexEncodedPublicKey.isNotEmpty()) { doubleModeImageView1,
val recipient = Recipient.from(context, Address.fromSerialized(hexEncodedPublicKey), false); publicKey,
val signalProfilePicture = recipient.contactPhoto displayName,
if (signalProfilePicture != null && (signalProfilePicture as? ProfileContactPhoto)?.avatarObject != "0" && (signalProfilePicture as? ProfileContactPhoto)?.avatarObject != "") { R.dimen.small_profile_picture_size)
glide.load(signalProfilePicture).diskCacheStrategy(DiskCacheStrategy.ALL).circleCrop().into(imageView) setProfilePictureIfNeeded(
} else { doubleModeImageView2,
val size = resources.getDimensionPixelSize(sizeID) additionalPublicKey ?: "",
val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context) additionalDisplayName,
val hepk = if (recipient.isLocalNumber && masterHexEncodedPublicKey != null) masterHexEncodedPublicKey else hexEncodedPublicKey R.dimen.small_profile_picture_size)
val jazzIcon = JazzIdenticonDrawable(size, size, hepk) setProfilePictureIfNeeded(
glide.load(jazzIcon).diskCacheStrategy(DiskCacheStrategy.ALL).circleCrop().into(imageView) singleModeImageView,
} publicKey,
displayName,
R.dimen.medium_profile_picture_size)
setProfilePictureIfNeeded(
largeSingleModeImageView,
publicKey,
displayName,
R.dimen.large_profile_picture_size)
}
private fun setProfilePictureIfNeeded(imageView: ImageView, hexEncodedPublicKey: String, displayName: String?, @DimenRes sizeResId: Int) {
glide.clear(imageView)
if (hexEncodedPublicKey.isNotEmpty()) {
val recipient = Recipient.from(context, Address.fromSerialized(hexEncodedPublicKey), false);
val signalProfilePicture = recipient.contactPhoto
if (signalProfilePicture != null && (signalProfilePicture as? ProfileContactPhoto)?.avatarObject != "0" && (signalProfilePicture as? ProfileContactPhoto)?.avatarObject != "") {
glide.load(signalProfilePicture).diskCacheStrategy(DiskCacheStrategy.ALL).circleCrop().into(imageView)
} else { } else {
imageView.setImageDrawable(null) val sizePx = resources.getDimensionPixelSize(sizeResId)
val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context)
val hepk = if (recipient.isLocalNumber && masterHexEncodedPublicKey != null) masterHexEncodedPublicKey else hexEncodedPublicKey
// val jazzIcon = JazzIdenticonDrawable(size, size, hepk)
glide.load(AvatarPlaceholderGenerator.generate(
context,
sizePx,
hepk,
displayName
)).diskCacheStrategy(DiskCacheStrategy.ALL).circleCrop().into(imageView)
} }
} else {
imageView.setImageDrawable(null)
} }
setProfilePictureIfNeeded(doubleModeImageView1, publicKey, R.dimen.small_profile_picture_size)
setProfilePictureIfNeeded(doubleModeImageView2, additionalPublicKey ?: "", R.dimen.small_profile_picture_size)
setProfilePictureIfNeeded(singleModeImageView, publicKey, R.dimen.medium_profile_picture_size)
setProfilePictureIfNeeded(largeSingleModeImageView, publicKey, R.dimen.large_profile_picture_size)
} }
// endregion // endregion
} }

View File

@ -51,6 +51,7 @@ class UserView : LinearLayout {
if (user.isGroupRecipient) { if (user.isGroupRecipient) {
if ("Session Public Chat" == user.name || user.address.isRSSFeed) { if ("Session Public Chat" == user.name || user.address.isRSSFeed) {
profilePictureView.publicKey = "" profilePictureView.publicKey = ""
profilePictureView.displayName = null
profilePictureView.additionalPublicKey = null profilePictureView.additionalPublicKey = null
profilePictureView.isRSSFeed = true profilePictureView.isRSSFeed = true
} else { } else {
@ -58,11 +59,13 @@ class UserView : LinearLayout {
val users = MentionsManager.shared.userPublicKeyCache[threadID]?.toList() ?: listOf() val users = MentionsManager.shared.userPublicKeyCache[threadID]?.toList() ?: listOf()
val randomUsers = users.sorted() // Sort to provide a level of stability val randomUsers = users.sorted() // Sort to provide a level of stability
profilePictureView.publicKey = randomUsers.getOrNull(0) ?: "" profilePictureView.publicKey = randomUsers.getOrNull(0) ?: ""
profilePictureView.displayName = null
profilePictureView.additionalPublicKey = randomUsers.getOrNull(1) ?: "" profilePictureView.additionalPublicKey = randomUsers.getOrNull(1) ?: ""
profilePictureView.isRSSFeed = false profilePictureView.isRSSFeed = false
} }
} else { } else {
profilePictureView.publicKey = address profilePictureView.publicKey = address
profilePictureView.displayName = null
profilePictureView.additionalPublicKey = null profilePictureView.additionalPublicKey = null
profilePictureView.isRSSFeed = false profilePictureView.isRSSFeed = false
} }