2020-01-31 03:57:24 +01:00
|
|
|
package org.thoughtcrime.securesms.loki.redesign.views
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.util.AttributeSet
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
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
|
2020-04-15 05:06:10 +02:00
|
|
|
import org.thoughtcrime.securesms.groups.GroupManager
|
2020-01-31 03:57:24 +01:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient
|
2020-04-15 05:06:10 +02:00
|
|
|
import org.whispersystems.signalservice.loki.api.LokiAPI
|
2020-01-31 03:57:24 +01:00
|
|
|
|
|
|
|
class UserView : LinearLayout {
|
|
|
|
var user: String? = null
|
|
|
|
|
|
|
|
// region Lifecycle
|
|
|
|
constructor(context: Context) : super(context) {
|
|
|
|
setUpViewHierarchy()
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
|
|
|
|
setUpViewHierarchy()
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
|
|
|
|
setUpViewHierarchy()
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
|
|
|
|
setUpViewHierarchy()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun setUpViewHierarchy() {
|
|
|
|
val inflater = context.applicationContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
|
|
|
val contentView = inflater.inflate(R.layout.view_user, null)
|
|
|
|
addView(contentView)
|
|
|
|
}
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
// region Updating
|
2020-04-15 05:06:10 +02:00
|
|
|
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
|
|
|
|
}
|
2020-01-31 03:57:24 +01:00
|
|
|
profilePictureView.glide = glide
|
|
|
|
profilePictureView.update()
|
2020-04-15 05:06:10 +02:00
|
|
|
nameTextView.text = user.name ?: "Unknown Contact"
|
2020-01-31 03:57:24 +01:00
|
|
|
tickImageView.setImageResource(if (isSelected) R.drawable.ic_circle_check else R.drawable.ic_circle)
|
|
|
|
}
|
|
|
|
// endregion
|
|
|
|
}
|