Updated UserView

This commit is contained in:
Mikunj 2020-04-15 13:06:10 +10:00
parent 361dab24d6
commit dd9b134dab
3 changed files with 27 additions and 8 deletions

View File

@ -53,7 +53,7 @@ class ContactSelectionListAdapter(private val context: Context, private val isMu
item as ContactSelectionListLoaderItem.Contact
viewHolder.view.setOnClickListener { contactClickListener?.onContactClick(item.recipient) }
val isSelected = selectedContacts.contains(item.recipient)
viewHolder.view.bind(item.recipient.address.serialize(), isSelected, glide)
viewHolder.view.bind(item.recipient, isSelected, glide)
} else if (viewHolder is DividerViewHolder) {
item as ContactSelectionListLoaderItem.Header
viewHolder.view.label.text = item.name

View File

@ -3,8 +3,10 @@ package org.thoughtcrime.securesms.loki.redesign.activities
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.ViewGroup
import org.thoughtcrime.securesms.database.Address
import org.thoughtcrime.securesms.loki.redesign.views.UserView
import org.thoughtcrime.securesms.mms.GlideRequests
import org.thoughtcrime.securesms.recipients.Recipient
class CreateClosedGroupAdapter(private val context: Context) : RecyclerView.Adapter<CreateClosedGroupAdapter.ViewHolder>() {
lateinit var glide: GlideRequests
@ -28,7 +30,7 @@ class CreateClosedGroupAdapter(private val context: Context) : RecyclerView.Adap
val member = members[position]
viewHolder.view.setOnClickListener { memberClickListener?.onMemberClick(member) }
val isSelected = selectedMembers.contains(member)
viewHolder.view.bind(member, isSelected, glide)
viewHolder.view.bind(Recipient.from(context, Address.fromSerialized(member), false), isSelected, glide)
}
fun onMemberClick(member: String) {

View File

@ -7,9 +7,10 @@ import android.widget.LinearLayout
import kotlinx.android.synthetic.main.view_conversation.view.profilePictureView
import kotlinx.android.synthetic.main.view_user.view.*
import network.loki.messenger.R
import org.thoughtcrime.securesms.database.Address
import org.thoughtcrime.securesms.groups.GroupManager
import org.thoughtcrime.securesms.mms.GlideRequests
import org.thoughtcrime.securesms.recipients.Recipient
import org.whispersystems.signalservice.loki.api.LokiAPI
class UserView : LinearLayout {
var user: String? = null
@ -39,13 +40,29 @@ class UserView : LinearLayout {
// endregion
// region Updating
fun bind(user: String, isSelected: Boolean, glide: GlideRequests) {
profilePictureView.hexEncodedPublicKey = user
profilePictureView.additionalHexEncodedPublicKey = null
profilePictureView.isRSSFeed = false
fun bind(user: Recipient, isSelected: Boolean, glide: GlideRequests) {
val address = user.address.serialize()
if (user.isGroupRecipient) {
if (user.address.isPublicChat || user.address.isRSSFeed) {
profilePictureView.hexEncodedPublicKey = ""
profilePictureView.additionalHexEncodedPublicKey = null
profilePictureView.isRSSFeed = true
} else {
val threadId = GroupManager.getThreadIdFromGroupId(address, context)
val users = LokiAPI.userHexEncodedPublicKeyCache[threadId]?.toList() ?: listOf()
val randomUsers = users.sorted() // Sort to provide a level of stability
profilePictureView.hexEncodedPublicKey = randomUsers.getOrNull(0) ?: ""
profilePictureView.additionalHexEncodedPublicKey = randomUsers.getOrNull(1) ?: ""
profilePictureView.isRSSFeed = false
}
} else {
profilePictureView.hexEncodedPublicKey = address
profilePictureView.additionalHexEncodedPublicKey = null
profilePictureView.isRSSFeed = false
}
profilePictureView.glide = glide
profilePictureView.update()
nameTextView.text = Recipient.from(context, Address.fromSerialized(user), false).name ?: "Unknown Contact"
nameTextView.text = user.name ?: "Unknown Contact"
tickImageView.setImageResource(if (isSelected) R.drawable.ic_circle_check else R.drawable.ic_circle)
}
// endregion