session-android/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/MentionCandidateView.kt

43 lines
1.9 KiB
Kotlin
Raw Normal View History

2021-07-09 03:14:21 +02:00
package org.thoughtcrime.securesms.conversation.v2.components
2019-10-10 04:53:02 +02:00
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import network.loki.messenger.databinding.ViewMentionCandidateBinding
2021-05-18 01:50:16 +02:00
import org.session.libsession.messaging.mentions.Mention
2021-05-21 07:02:34 +02:00
import org.session.libsession.messaging.open_groups.OpenGroupAPIV2
import org.thoughtcrime.securesms.mms.GlideRequests
2019-10-10 04:53:02 +02:00
class MentionCandidateView : LinearLayout {
private lateinit var binding: ViewMentionCandidateBinding
2019-10-11 07:37:28 +02:00
var mentionCandidate = Mention("", "")
2019-10-10 04:53:02 +02:00
set(newValue) { field = newValue; update() }
2020-01-16 05:15:08 +01:00
var glide: GlideRequests? = null
2021-05-21 07:02:34 +02:00
var openGroupServer: String? = null
var openGroupRoom: String? = null
2019-10-10 04:53:02 +02:00
constructor(context: Context) : this(context, null)
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { initialize() }
2019-10-10 04:53:02 +02:00
private fun initialize() {
binding = ViewMentionCandidateBinding.inflate(LayoutInflater.from(context), this, true)
2019-10-10 04:53:02 +02:00
}
private fun update() = with(binding) {
2021-06-18 03:00:52 +02:00
mentionCandidateNameTextView.text = mentionCandidate.displayName
2020-07-15 06:26:20 +02:00
profilePictureView.publicKey = mentionCandidate.publicKey
profilePictureView.displayName = mentionCandidate.displayName
2020-07-15 06:26:20 +02:00
profilePictureView.additionalPublicKey = null
2020-01-16 05:15:08 +01:00
profilePictureView.glide = glide!!
profilePictureView.update()
2021-05-21 07:02:34 +02:00
if (openGroupServer != null && openGroupRoom != null) {
val isUserModerator = OpenGroupAPIV2.isUserModerator(mentionCandidate.publicKey, openGroupRoom!!, openGroupServer!!)
2019-10-15 04:39:17 +02:00
moderatorIconImageView.visibility = if (isUserModerator) View.VISIBLE else View.GONE
} else {
moderatorIconImageView.visibility = View.GONE
}
2019-10-10 04:53:02 +02:00
}
}