2019-10-10 02:53:02 +00:00
|
|
|
package org.thoughtcrime.securesms.loki
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.graphics.Outline
|
|
|
|
import android.util.AttributeSet
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.view.ViewOutlineProvider
|
|
|
|
import android.widget.LinearLayout
|
2019-10-11 05:37:28 +00:00
|
|
|
import kotlinx.android.synthetic.main.cell_mention_candidate_selection_view.view.*
|
2019-10-10 02:53:02 +00:00
|
|
|
import network.loki.messenger.R
|
2019-10-15 02:39:17 +00:00
|
|
|
import org.whispersystems.signalservice.loki.api.LokiPublicChatAPI
|
2019-10-11 05:37:28 +00:00
|
|
|
import org.whispersystems.signalservice.loki.messaging.Mention
|
2019-10-10 02:53:02 +00:00
|
|
|
|
2019-10-11 05:37:28 +00:00
|
|
|
class MentionCandidateSelectionViewCell(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) {
|
|
|
|
var mentionCandidate = Mention("", "")
|
2019-10-10 02:53:02 +00:00
|
|
|
set(newValue) { field = newValue; update() }
|
2019-10-15 02:39:17 +00:00
|
|
|
var publicChatServer: String? = null
|
|
|
|
var publicChatChannel: Long? = null
|
2019-10-10 02:53:02 +00:00
|
|
|
|
|
|
|
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
|
|
|
constructor(context: Context) : this(context, null)
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
2019-10-11 05:37:28 +00:00
|
|
|
fun inflate(layoutInflater: LayoutInflater, parent: ViewGroup): MentionCandidateSelectionViewCell {
|
|
|
|
return layoutInflater.inflate(R.layout.cell_mention_candidate_selection_view, parent, false) as MentionCandidateSelectionViewCell
|
2019-10-10 02:53:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onFinishInflate() {
|
|
|
|
super.onFinishInflate()
|
|
|
|
profilePictureImageViewContainer.outlineProvider = object : ViewOutlineProvider() {
|
|
|
|
|
|
|
|
override fun getOutline(view: View, outline: Outline) {
|
|
|
|
outline.setOval(0, 0, view.width, view.height)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
profilePictureImageViewContainer.clipToOutline = true
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun update() {
|
2019-10-11 05:37:28 +00:00
|
|
|
displayNameTextView.text = mentionCandidate.displayName
|
|
|
|
profilePictureImageView.update(mentionCandidate.hexEncodedPublicKey)
|
2019-10-15 02:39:17 +00:00
|
|
|
if (publicChatServer != null && publicChatChannel != null) {
|
|
|
|
val isUserModerator = LokiPublicChatAPI.isUserModerator(user.first, publicChatChannel!!, publicChatServer!!)
|
|
|
|
moderatorIconImageView.visibility = if (isUserModerator) View.VISIBLE else View.GONE
|
|
|
|
} else {
|
|
|
|
moderatorIconImageView.visibility = View.GONE
|
|
|
|
}
|
2019-10-10 02:53:02 +00:00
|
|
|
}
|
|
|
|
}
|