@ -12,11 +12,8 @@ import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.view_conversation.view.*
import kotlinx.android.synthetic.main.view_conversation.view.*
import kotlinx.android.synthetic.main.view_profile_picture.view.*
import kotlinx.coroutines.*
import network.loki.messenger.R
import network.loki.messenger.R
import org.session.libsession.utilities.recipients.Recipient
import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.conversation.v2.utilities.MentionManagerUtilities.populateUserPublicKeyCacheIfNeeded
import org.thoughtcrime.securesms.conversation.v2.utilities.MentionUtilities.highlightMentions
import org.thoughtcrime.securesms.conversation.v2.utilities.MentionUtilities.highlightMentions
import org.thoughtcrime.securesms.database.RecipientDatabase
import org.thoughtcrime.securesms.database.RecipientDatabase
import org.thoughtcrime.securesms.database.model.ThreadRecord
import org.thoughtcrime.securesms.database.model.ThreadRecord
@ -42,63 +39,58 @@ class ConversationView : LinearLayout {
// region Updating
// region Updating
fun bind ( thread : ThreadRecord , isTyping : Boolean , glide : GlideRequests ) {
fun bind ( thread : ThreadRecord , isTyping : Boolean , glide : GlideRequests ) {
this . thread = thread
this . thread = thread
profilePictureView . glide = glide
val unreadCount = thread . unreadCount
post {
if ( thread . recipient . isBlocked ) {
val unreadCount = thread . unreadCount
accentView . setBackgroundResource ( R . color . destructive )
if ( thread . recipient . isBlocked ) {
accentView . visibility = View . VISIBLE
accentView . setBackgroundResource ( R . color . destructive )
} else {
accentView . visibility = View . VISIBLE
accentView . setBackgroundResource ( R . color . accent )
} else {
accentView . visibility = if ( unreadCount > 0 ) View . VISIBLE else View . INVISIBLE
accentView . setBackgroundResource ( R . color . accent )
}
accentView . visibility = if ( unreadCount > 0 ) View . VISIBLE else View . INVISIBLE
val formattedUnreadCount = if ( unreadCount < 100 ) unreadCount . toString ( ) else " 99+ "
}
unreadCountTextView . text = formattedUnreadCount
val formattedUnreadCount = if ( unreadCount < 100 ) unreadCount . toString ( ) else " 99+ "
val textSize = if ( unreadCount < 100 ) 12.0f else 9.0f
unreadCountTextView . text = formattedUnreadCount
unreadCountTextView . setTextSize ( TypedValue . COMPLEX _UNIT _DIP , textSize )
val textSize = if ( unreadCount < 100 ) 12.0f else 9.0f
unreadCountTextView . setTypeface ( Typeface . DEFAULT , if ( unreadCount < 100 ) Typeface . BOLD else Typeface . NORMAL )
unreadCountTextView . setTextSize ( TypedValue . COMPLEX _UNIT _DIP , textSize )
unreadCountIndicator . isVisible = ( unreadCount != 0 )
unreadCountTextView . setTypeface ( Typeface . DEFAULT , if ( unreadCount < 100 ) Typeface . BOLD else Typeface . NORMAL )
val senderDisplayName = getUserDisplayName ( thread . recipient )
unreadCountIndicator . isVisible = ( unreadCount != 0 )
?: thread . recipient . address . toString ( )
val senderDisplayName = getUserDisplayName ( thread . recipient )
conversationViewDisplayNameTextView . text = senderDisplayName
?: thread . recipient . address . toString ( )
timestampTextView . text = DateUtils . getDisplayFormattedTimeSpanString ( context , Locale . getDefault ( ) , thread . date )
conversationViewDisplayNameTextView . text = senderDisplayName
val recipient = thread . recipient
timestampTextView . text = DateUtils . getDisplayFormattedTimeSpanString ( context , Locale . getDefault ( ) , thread . date )
muteIndicatorImageView . isVisible = recipient . isMuted || recipient . notifyType != RecipientDatabase . NOTIFY _TYPE _ALL
val recipient = thread . recipient
val drawableRes = if ( recipient . isMuted || recipient . notifyType == RecipientDatabase . NOTIFY _TYPE _NONE ) {
muteIndicatorImageView . isVisible = recipient . isMuted || recipient . notifyType != RecipientDatabase . NOTIFY _TYPE _ALL
R . drawable . ic _outline _notifications _off _24
val drawableRes = if ( recipient . isMuted || recipient . notifyType == RecipientDatabase . NOTIFY _TYPE _NONE ) {
} else {
R . drawable . ic _outline _notifications _off _24
R . drawable . ic _notifications _mentions
} else {
}
R . drawable . ic _notifications _mentions
muteIndicatorImageView . setImageResource ( drawableRes )
}
val rawSnippet = thread . getDisplayBody ( context )
muteIndicatorImageView . setImageResource ( drawableRes )
val snippet = highlightMentions ( rawSnippet , thread . threadId , context )
val rawSnippet = thread . getDisplayBody ( context )
snippetTextView . text = snippet
val snippet = highlightMentions ( rawSnippet , thread . threadId , context )
snippetTextView . typeface = if ( unreadCount > 0 ) Typeface . DEFAULT _BOLD else Typeface . DEFAULT
snippetTextView . text = snippet
snippetTextView . visibility = if ( isTyping ) View . GONE else View . VISIBLE
snippetTextView . typeface = if ( unreadCount > 0 ) Typeface . DEFAULT _BOLD else Typeface . DEFAULT
if ( isTyping ) {
snippetTextView . visibility = if ( isTyping ) View . GONE else View . VISIBLE
typingIndicatorView . startAnimation ( )
if ( isTyping ) {
} else {
typingIndicatorView . startAnimation ( )
typingIndicatorView . stopAnimation ( )
} else {
}
typingIndicatorView . stopAnimation ( )
typingIndicatorView . visibility = if ( isTyping ) View . VISIBLE else View . GONE
}
statusIndicatorImageView . visibility = View . VISIBLE
typingIndicatorView . visibility = if ( isTyping ) View . VISIBLE else View . GONE
when {
statusIndicatorImageView . visibility = View . VISIBLE
! thread . isOutgoing -> statusIndicatorImageView . visibility = View . GONE
when {
thread . isFailed -> {
! thread . isOutgoing -> statusIndicatorImageView . visibility = View . GONE
val drawable = ContextCompat . getDrawable ( context , R . drawable . ic _error ) ?. mutate ( )
thread . isFailed -> {
drawable ?. setTint ( ContextCompat . getColor ( context , R . color . destructive ) )
val drawable = ContextCompat . getDrawable ( context , R . drawable . ic _error ) ?. mutate ( )
statusIndicatorImageView . setImageDrawable ( drawable )
drawable ?. setTint ( ContextCompat . getColor ( context , R . color . destructive ) )
statusIndicatorImageView . setImageDrawable ( drawable )
}
thread . isPending -> statusIndicatorImageView . setImageResource ( R . drawable . ic _circle _dot _dot _dot )
thread . isRead -> statusIndicatorImageView . setImageResource ( R . drawable . ic _filled _circle _check )
else -> statusIndicatorImageView . setImageResource ( R . drawable . ic _circle _check )
}
GlobalScope . launch ( Dispatchers . IO ) {
populateUserPublicKeyCacheIfNeeded ( thread . threadId , context ) // FIXME: This is a bad place to do this
withContext ( Dispatchers . Main ) {
profilePictureView . update ( thread . recipient , thread . threadId )
}
}
}
thread . isPending -> statusIndicatorImageView . setImageResource ( R . drawable . ic _circle _dot _dot _dot )
thread . isRead -> statusIndicatorImageView . setImageResource ( R . drawable . ic _filled _circle _check )
else -> statusIndicatorImageView . setImageResource ( R . drawable . ic _circle _check )
}
post {
profilePictureView . glide = glide
profilePictureView . update ( thread . recipient , thread . threadId )
}
}
}
}