|
|
|
@ -5,7 +5,6 @@ import android.graphics.Typeface
|
|
|
|
|
import android.util.AttributeSet
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
|
import android.view.View
|
|
|
|
|
import android.view.ViewGroup
|
|
|
|
|
import android.widget.LinearLayout
|
|
|
|
|
import kotlinx.android.synthetic.main.conversation_view.view.*
|
|
|
|
|
import network.loki.messenger.R
|
|
|
|
@ -13,26 +12,34 @@ import org.thoughtcrime.securesms.database.model.ThreadRecord
|
|
|
|
|
import org.thoughtcrime.securesms.loki.LokiAPIUtilities.populateUserHexEncodedPublicKeyCacheIfNeeded
|
|
|
|
|
import org.thoughtcrime.securesms.loki.MentionUtilities.highlightMentions
|
|
|
|
|
import org.thoughtcrime.securesms.util.DateUtils
|
|
|
|
|
import org.whispersystems.signalservice.loki.api.LokiAPI
|
|
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
|
|
class ConversationView : LinearLayout {
|
|
|
|
|
var thread: ThreadRecord? = null
|
|
|
|
|
|
|
|
|
|
// region Lifecycle
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
|
|
fun get(context: Context, parent: ViewGroup?): ConversationView {
|
|
|
|
|
return LayoutInflater.from(context).inflate(R.layout.conversation_view, parent, false) as ConversationView
|
|
|
|
|
}
|
|
|
|
|
constructor(context: Context) : super(context) {
|
|
|
|
|
setUpViewHierarchy()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor(context: Context) : super(context)
|
|
|
|
|
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
|
|
|
|
|
setUpViewHierarchy()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
|
|
|
|
|
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
|
|
|
|
|
setUpViewHierarchy()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
|
|
|
|
|
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
|
|
|
|
|
setUpViewHierarchy()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes)
|
|
|
|
|
private fun setUpViewHierarchy() {
|
|
|
|
|
val inflater = context.applicationContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
|
|
|
|
val contentView = inflater.inflate(R.layout.conversation_view, null)
|
|
|
|
|
addView(contentView)
|
|
|
|
|
}
|
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
|
|
// region Updating
|
|
|
|
@ -40,6 +47,18 @@ class ConversationView : LinearLayout {
|
|
|
|
|
this.thread = thread
|
|
|
|
|
populateUserHexEncodedPublicKeyCacheIfNeeded(thread.threadId, context) // FIXME: This is a terrible place to do this
|
|
|
|
|
unreadMessagesIndicatorView.visibility = if (thread.unreadCount > 0) View.VISIBLE else View.INVISIBLE
|
|
|
|
|
if (thread.recipient.isGroupRecipient) {
|
|
|
|
|
val users = LokiAPI.userHexEncodedPublicKeyCache[thread.threadId]?.toList() ?: listOf()
|
|
|
|
|
val randomUsers = users.sorted() // Sort to provide a level of stability
|
|
|
|
|
profilePictureView.hexEncodedPublicKey = randomUsers.getOrNull(0) ?: ""
|
|
|
|
|
profilePictureView.additionalHexEncodedPublicKey = randomUsers.getOrNull(1) ?: ""
|
|
|
|
|
profilePictureView.isRSSFeed = thread.recipient.name == "Loki News" || thread.recipient.name == "Loki Messenger Updates"
|
|
|
|
|
} else {
|
|
|
|
|
profilePictureView.hexEncodedPublicKey = thread.recipient.address.toString()
|
|
|
|
|
profilePictureView.additionalHexEncodedPublicKey = null
|
|
|
|
|
profilePictureView.isRSSFeed = false
|
|
|
|
|
}
|
|
|
|
|
profilePictureView.update()
|
|
|
|
|
val senderDisplayName = if (thread.recipient.isLocalNumber) context.getString(R.string.note_to_self) else thread.recipient.name
|
|
|
|
|
displayNameTextView.text = senderDisplayName
|
|
|
|
|
timestampTextView.text = DateUtils.getBriefRelativeTimeSpanString(context, Locale.getDefault(), thread.date)
|
|
|
|
|