Add mention candidates view
parent
7c3b1b22d7
commit
efc752e3a1
@ -0,0 +1,47 @@
|
|||||||
|
package org.thoughtcrime.securesms.conversation.v2.input_bar.mentions
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.RelativeLayout
|
||||||
|
import kotlinx.android.synthetic.main.view_mention_candidate.view.*
|
||||||
|
import network.loki.messenger.R
|
||||||
|
import org.session.libsession.messaging.mentions.Mention
|
||||||
|
import org.session.libsession.messaging.open_groups.OpenGroupAPIV2
|
||||||
|
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||||
|
|
||||||
|
class MentionCandidateView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : RelativeLayout(context, attrs, defStyleAttr) {
|
||||||
|
var candidate = Mention("", "")
|
||||||
|
set(newValue) { field = newValue; update() }
|
||||||
|
var glide: GlideRequests? = null
|
||||||
|
var openGroupServer: String? = null
|
||||||
|
var openGroupRoom: String? = null
|
||||||
|
|
||||||
|
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
||||||
|
constructor(context: Context) : this(context, null)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
fun inflate(layoutInflater: LayoutInflater, parent: ViewGroup): MentionCandidateView {
|
||||||
|
return layoutInflater.inflate(R.layout.view_mention_candidate_v2, parent, false) as MentionCandidateView
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun update() {
|
||||||
|
mentionCandidateNameTextView.text = candidate.displayName
|
||||||
|
profilePictureView.publicKey = candidate.publicKey
|
||||||
|
profilePictureView.displayName = candidate.displayName
|
||||||
|
profilePictureView.additionalPublicKey = null
|
||||||
|
profilePictureView.glide = glide!!
|
||||||
|
profilePictureView.update()
|
||||||
|
if (openGroupServer != null && openGroupRoom != null) {
|
||||||
|
val isUserModerator = OpenGroupAPIV2.isUserModerator(candidate.publicKey, openGroupRoom!!, openGroupServer!!)
|
||||||
|
moderatorIconImageView.visibility = if (isUserModerator) View.VISIBLE else View.GONE
|
||||||
|
} else {
|
||||||
|
moderatorIconImageView.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
package org.thoughtcrime.securesms.conversation.v2.input_bar.mentions
|
||||||
|
|
||||||
|
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.thoughtcrime.securesms.database.DatabaseFactory
|
||||||
|
import org.thoughtcrime.securesms.loki.utilities.toPx
|
||||||
|
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||||
|
import org.session.libsession.messaging.mentions.Mention
|
||||||
|
|
||||||
|
class MentionCandidatesView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : ListView(context, attrs, defStyleAttr) {
|
||||||
|
private var candidates = listOf<Mention>()
|
||||||
|
set(newValue) { field = newValue; snAdapter.mentionCandidates = newValue }
|
||||||
|
var glide: GlideRequests? = null
|
||||||
|
set(newValue) { field = newValue; snAdapter.glide = newValue }
|
||||||
|
var openGroupServer: String? = null
|
||||||
|
set(newValue) { field = newValue; snAdapter.openGroupServer = openGroupServer }
|
||||||
|
var openGroupRoom: String? = null
|
||||||
|
set(newValue) { field = newValue; snAdapter.openGroupRoom = openGroupRoom }
|
||||||
|
var onCandidateSelected: ((Mention) -> Unit)? = null
|
||||||
|
|
||||||
|
private val snAdapter by lazy { Adapter(context) }
|
||||||
|
|
||||||
|
private class Adapter(private val context: Context) : BaseAdapter() {
|
||||||
|
var mentionCandidates = listOf<Mention>()
|
||||||
|
set(newValue) { field = newValue; notifyDataSetChanged() }
|
||||||
|
var glide: GlideRequests? = 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.inflate(LayoutInflater.from(context), parent)
|
||||||
|
val mentionCandidate = getItem(position)
|
||||||
|
cell.glide = glide
|
||||||
|
cell.candidate = 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 = snAdapter
|
||||||
|
snAdapter.mentionCandidates = candidates
|
||||||
|
setOnItemClickListener { _, _, position, _ ->
|
||||||
|
onCandidateSelected?.invoke(candidates[position])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun show(mentionCandidates: List<Mention>, threadID: Long) {
|
||||||
|
val openGroup = DatabaseFactory.getLokiThreadDatabase(context).getOpenGroupChat(threadID)
|
||||||
|
if (openGroup != null) {
|
||||||
|
openGroupServer = openGroup.server
|
||||||
|
openGroupRoom = openGroup.room
|
||||||
|
}
|
||||||
|
this.candidates = 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
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<ripple
|
<ripple
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:color="@color/cell_selected">
|
android:color="@color/mention_candidates_view_background_ripple">
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<color android:color="@color/compose_view_background" />
|
<color android:color="@color/mention_candidates_view_background" />
|
||||||
</item>
|
</item>
|
||||||
</ripple>
|
</ripple>
|
@ -0,0 +1,54 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<org.thoughtcrime.securesms.conversation.v2.input_bar.mentions.MentionCandidateView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="44dp"
|
||||||
|
android:background="@drawable/mention_candidate_view_background">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:paddingStart="@dimen/medium_spacing"
|
||||||
|
android:paddingEnd="@dimen/medium_spacing"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="26dp"
|
||||||
|
android:layout_height="32dp">
|
||||||
|
|
||||||
|
<org.thoughtcrime.securesms.loki.views.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="@color/text"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:ellipsize="end" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1px"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:background="@color/separator" />
|
||||||
|
|
||||||
|
</org.thoughtcrime.securesms.conversation.v2.input_bar.mentions.MentionCandidateView>
|
Loading…
Reference in New Issue