2020-05-11 08:19:26 +02:00
|
|
|
package org.thoughtcrime.securesms.loki.views
|
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.view.ViewGroup
|
|
|
|
import android.widget.LinearLayout
|
2020-01-16 05:15:08 +01:00
|
|
|
import kotlinx.android.synthetic.main.view_mention_candidate.view.*
|
2019-10-10 04:53:02 +02:00
|
|
|
import network.loki.messenger.R
|
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
|
2021-03-31 06:15:50 +02:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests
|
2019-10-10 04:53:02 +02:00
|
|
|
|
2020-01-16 05:15:08 +01:00
|
|
|
class MentionCandidateView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) {
|
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, attrs: AttributeSet?) : this(context, attrs, 0)
|
|
|
|
constructor(context: Context) : this(context, null)
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
2020-01-16 05:15:08 +01:00
|
|
|
fun inflate(layoutInflater: LayoutInflater, parent: ViewGroup): MentionCandidateView {
|
|
|
|
return layoutInflater.inflate(R.layout.view_mention_candidate, parent, false) as MentionCandidateView
|
2019-10-10 04:53:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun update() {
|
2020-08-14 11:26:56 +02:00
|
|
|
btnGroupNameDisplay.text = mentionCandidate.displayName
|
2020-07-15 06:26:20 +02:00
|
|
|
profilePictureView.publicKey = mentionCandidate.publicKey
|
2020-09-03 14:15:03 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|