This reverts commit 9919f716a7
.
Co-authored-by: fanchao <git@fanchao.dev>
pull/1633/head
parent
9919f716a7
commit
8fc6679178
@ -0,0 +1,87 @@
|
|||||||
|
package org.thoughtcrime.securesms.conversation.v2.components
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.BaseAdapter
|
||||||
|
import android.widget.ListView
|
||||||
|
import org.session.libsession.messaging.mentions.Mention
|
||||||
|
import org.thoughtcrime.securesms.dependencies.DatabaseComponent
|
||||||
|
import com.bumptech.glide.RequestManager
|
||||||
|
import org.thoughtcrime.securesms.util.toPx
|
||||||
|
|
||||||
|
class MentionCandidateSelectionView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : ListView(context, attrs, defStyleAttr) {
|
||||||
|
private var mentionCandidates = listOf<Mention>()
|
||||||
|
set(newValue) { field = newValue; mentionCandidateSelectionViewAdapter.mentionCandidates = newValue }
|
||||||
|
var glide: RequestManager? = null
|
||||||
|
set(newValue) { field = newValue; mentionCandidateSelectionViewAdapter.glide = newValue }
|
||||||
|
var openGroupServer: String? = null
|
||||||
|
set(newValue) { field = newValue; mentionCandidateSelectionViewAdapter.openGroupServer = openGroupServer }
|
||||||
|
var openGroupRoom: String? = null
|
||||||
|
set(newValue) { field = newValue; mentionCandidateSelectionViewAdapter.openGroupRoom = openGroupRoom }
|
||||||
|
var onMentionCandidateSelected: ((Mention) -> Unit)? = null
|
||||||
|
|
||||||
|
private val mentionCandidateSelectionViewAdapter by lazy { Adapter(context) }
|
||||||
|
|
||||||
|
private class Adapter(private val context: Context) : BaseAdapter() {
|
||||||
|
var mentionCandidates = listOf<Mention>()
|
||||||
|
set(newValue) { field = newValue; notifyDataSetChanged() }
|
||||||
|
var glide: RequestManager? = null
|
||||||
|
var openGroupServer: String? = null
|
||||||
|
var openGroupRoom: String? = null
|
||||||
|
|
||||||
|
override fun getCount(): Int {
|
||||||
|
return mentionCandidates.count()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemId(position: Int): Long {
|
||||||
|
return position.toLong()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItem(position: Int): Mention {
|
||||||
|
return mentionCandidates[position]
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getView(position: Int, cellToBeReused: View?, parent: ViewGroup): View {
|
||||||
|
val cell = cellToBeReused as MentionCandidateView? ?: MentionCandidateView(context)
|
||||||
|
val mentionCandidate = getItem(position)
|
||||||
|
cell.glide = glide
|
||||||
|
cell.mentionCandidate = mentionCandidate
|
||||||
|
cell.openGroupServer = openGroupServer
|
||||||
|
cell.openGroupRoom = openGroupRoom
|
||||||
|
return cell
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
||||||
|
constructor(context: Context) : this(context, null)
|
||||||
|
|
||||||
|
init {
|
||||||
|
clipToOutline = true
|
||||||
|
adapter = mentionCandidateSelectionViewAdapter
|
||||||
|
mentionCandidateSelectionViewAdapter.mentionCandidates = mentionCandidates
|
||||||
|
setOnItemClickListener { _, _, position, _ ->
|
||||||
|
onMentionCandidateSelected?.invoke(mentionCandidates[position])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun show(mentionCandidates: List<Mention>, threadID: Long) {
|
||||||
|
val openGroup = DatabaseComponent.get(context).lokiThreadDatabase().getOpenGroupChat(threadID)
|
||||||
|
if (openGroup != null) {
|
||||||
|
openGroupServer = openGroup.server
|
||||||
|
openGroupRoom = openGroup.room
|
||||||
|
}
|
||||||
|
this.mentionCandidates = mentionCandidates
|
||||||
|
val layoutParams = this.layoutParams as ViewGroup.LayoutParams
|
||||||
|
layoutParams.height = toPx(Math.min(mentionCandidates.count(), 4) * 44, resources)
|
||||||
|
this.layoutParams = layoutParams
|
||||||
|
}
|
||||||
|
|
||||||
|
fun hide() {
|
||||||
|
val layoutParams = this.layoutParams as ViewGroup.LayoutParams
|
||||||
|
layoutParams.height = 0
|
||||||
|
this.layoutParams = layoutParams
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package org.thoughtcrime.securesms.conversation.v2.components
|
||||||
|
|
||||||
|
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
|
||||||
|
import org.session.libsession.messaging.mentions.Mention
|
||||||
|
import org.thoughtcrime.securesms.groups.OpenGroupManager
|
||||||
|
import com.bumptech.glide.RequestManager
|
||||||
|
|
||||||
|
class MentionCandidateView : LinearLayout {
|
||||||
|
private lateinit var binding: ViewMentionCandidateBinding
|
||||||
|
var mentionCandidate = Mention("", "")
|
||||||
|
set(newValue) { field = newValue; update() }
|
||||||
|
var glide: RequestManager? = null
|
||||||
|
var openGroupServer: String? = null
|
||||||
|
var openGroupRoom: String? = null
|
||||||
|
|
||||||
|
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() }
|
||||||
|
|
||||||
|
private fun initialize() {
|
||||||
|
binding = ViewMentionCandidateBinding.inflate(LayoutInflater.from(context), this, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun update() = with(binding) {
|
||||||
|
mentionCandidateNameTextView.text = mentionCandidate.displayName
|
||||||
|
profilePictureView.publicKey = mentionCandidate.publicKey
|
||||||
|
profilePictureView.displayName = mentionCandidate.displayName
|
||||||
|
profilePictureView.additionalPublicKey = null
|
||||||
|
profilePictureView.update()
|
||||||
|
if (openGroupServer != null && openGroupRoom != null) {
|
||||||
|
val isUserModerator = OpenGroupManager.isUserModerator(context, "$openGroupRoom.$openGroupServer", mentionCandidate.publicKey)
|
||||||
|
moderatorIconImageView.visibility = if (isUserModerator) View.VISIBLE else View.GONE
|
||||||
|
} else {
|
||||||
|
moderatorIconImageView.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<org.thoughtcrime.securesms.conversation.v2.components.MentionCandidateView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="44dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingStart="@dimen/medium_spacing"
|
||||||
|
android:paddingEnd="@dimen/medium_spacing"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:background="@drawable/mention_candidate_view_background">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="26dp"
|
||||||
|
android:layout_height="32dp">
|
||||||
|
|
||||||
|
<org.thoughtcrime.securesms.components.ProfilePictureView
|
||||||
|
android:id="@+id/profilePictureView"
|
||||||
|
android:layout_width="@dimen/very_small_profile_picture_size"
|
||||||
|
android:layout_height="@dimen/very_small_profile_picture_size"
|
||||||
|
android:layout_marginTop="3dp" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/moderatorIconImageView"
|
||||||
|
android:layout_width="16dp"
|
||||||
|
android:layout_height="16dp"
|
||||||
|
android:src="@drawable/ic_crown"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_alignParentBottom="true" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/mentionCandidateNameTextView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="@dimen/medium_spacing"
|
||||||
|
android:textSize="@dimen/small_font_size"
|
||||||
|
android:textColor="?android:textColorPrimary"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:ellipsize="end" />
|
||||||
|
|
||||||
|
</org.thoughtcrime.securesms.conversation.v2.components.MentionCandidateView>
|
Loading…
Reference in New Issue