fix: startup performance fixes

This commit is contained in:
jubb 2021-08-02 16:59:55 +10:00
parent 4d5296bb1c
commit dd01b2968f
4 changed files with 62 additions and 52 deletions

View File

@ -142,7 +142,7 @@ dependencies {
testImplementation 'org.robolectric:shadows-multidex:4.2' testImplementation 'org.robolectric:shadows-multidex:4.2'
} }
def canonicalVersionCode = 211 def canonicalVersionCode = 214
def canonicalVersionName = "1.11.7" def canonicalVersionName = "1.11.7"
def postFixSize = 10 def postFixSize = 10

View File

@ -9,13 +9,15 @@ import org.thoughtcrime.securesms.database.model.MessageRecord
object MentionManagerUtilities { object MentionManagerUtilities {
fun populateUserPublicKeyCacheIfNeeded(threadID: Long, context: Context) { fun populateUserPublicKeyCacheIfNeeded(threadID: Long, context: Context) {
// exit early if we need to
if (MentionsManager.userPublicKeyCache[threadID] != null) return
val result = mutableSetOf<String>() val result = mutableSetOf<String>()
val recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadID) val recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadID)
if (recipient != null && recipient.address.isClosedGroup) { if (recipient != null && recipient.address.isClosedGroup) {
val members = DatabaseFactory.getGroupDatabase(context).getGroupMembers(recipient.address.toGroupString(), false).map { it.address.serialize() } val members = DatabaseFactory.getGroupDatabase(context).getGroupMembers(recipient.address.toGroupString(), false).map { it.address.serialize() }
result.addAll(members) result.addAll(members)
} else { } else {
if (MentionsManager.userPublicKeyCache[threadID] != null) { return }
val messageDatabase = DatabaseFactory.getMmsSmsDatabase(context) val messageDatabase = DatabaseFactory.getMmsSmsDatabase(context)
val reader = messageDatabase.readerFor(messageDatabase.getConversation(threadID)) val reader = messageDatabase.readerFor(messageDatabase.getConversation(threadID))
var record: MessageRecord? = reader.next var record: MessageRecord? = reader.next

View File

@ -12,6 +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.MentionManagerUtilities.populateUserPublicKeyCacheIfNeeded
@ -40,56 +42,63 @@ 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
populateUserPublicKeyCacheIfNeeded(thread.threadId, context) // FIXME: This is a bad place to do this
val unreadCount = thread.unreadCount
if (thread.recipient.isBlocked) {
accentView.setBackgroundResource(R.color.destructive)
accentView.visibility = View.VISIBLE
} else {
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 textSize = if (unreadCount < 100) 12.0f else 9.0f
unreadCountTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize)
unreadCountTextView.setTypeface(Typeface.DEFAULT, if (unreadCount < 100) Typeface.BOLD else Typeface.NORMAL)
unreadCountIndicator.isVisible = (unreadCount != 0)
profilePictureView.glide = glide profilePictureView.glide = glide
profilePictureView.update(thread.recipient, thread.threadId) post {
val senderDisplayName = getUserDisplayName(thread.recipient) ?: thread.recipient.address.toString() val unreadCount = thread.unreadCount
conversationViewDisplayNameTextView.text = senderDisplayName if (thread.recipient.isBlocked) {
timestampTextView.text = DateUtils.getDisplayFormattedTimeSpanString(context, Locale.getDefault(), thread.date) accentView.setBackgroundResource(R.color.destructive)
val recipient = thread.recipient accentView.visibility = View.VISIBLE
muteIndicatorImageView.isVisible = recipient.isMuted || recipient.notifyType != RecipientDatabase.NOTIFY_TYPE_ALL } else {
val drawableRes = if (recipient.isMuted || recipient.notifyType == RecipientDatabase.NOTIFY_TYPE_NONE) { accentView.setBackgroundResource(R.color.accent)
R.drawable.ic_outline_notifications_off_24 accentView.visibility = if (unreadCount > 0) View.VISIBLE else View.INVISIBLE
} else { }
R.drawable.ic_notifications_mentions val formattedUnreadCount = if (unreadCount < 100) unreadCount.toString() else "99+"
} unreadCountTextView.text = formattedUnreadCount
muteIndicatorImageView.setImageResource(drawableRes) val textSize = if (unreadCount < 100) 12.0f else 9.0f
val rawSnippet = thread.getDisplayBody(context) unreadCountTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize)
val snippet = highlightMentions(rawSnippet, thread.threadId, context) unreadCountTextView.setTypeface(Typeface.DEFAULT, if (unreadCount < 100) Typeface.BOLD else Typeface.NORMAL)
snippetTextView.text = snippet unreadCountIndicator.isVisible = (unreadCount != 0)
snippetTextView.typeface = if (unreadCount > 0) Typeface.DEFAULT_BOLD else Typeface.DEFAULT val senderDisplayName = getUserDisplayName(thread.recipient)
snippetTextView.visibility = if (isTyping) View.GONE else View.VISIBLE ?: thread.recipient.address.toString()
if (isTyping) { conversationViewDisplayNameTextView.text = senderDisplayName
typingIndicatorView.startAnimation() timestampTextView.text = DateUtils.getDisplayFormattedTimeSpanString(context, Locale.getDefault(), thread.date)
} else { val recipient = thread.recipient
typingIndicatorView.stopAnimation() muteIndicatorImageView.isVisible = recipient.isMuted || recipient.notifyType != RecipientDatabase.NOTIFY_TYPE_ALL
} val drawableRes = if (recipient.isMuted || recipient.notifyType == RecipientDatabase.NOTIFY_TYPE_NONE) {
typingIndicatorView.visibility = if (isTyping) View.VISIBLE else View.GONE R.drawable.ic_outline_notifications_off_24
statusIndicatorImageView.visibility = View.VISIBLE } else {
when { R.drawable.ic_notifications_mentions
!thread.isOutgoing -> statusIndicatorImageView.visibility = View.GONE }
thread.isFailed -> { muteIndicatorImageView.setImageResource(drawableRes)
val drawable = ContextCompat.getDrawable(context, R.drawable.ic_error)?.mutate() val rawSnippet = thread.getDisplayBody(context)
drawable?.setTint(ContextCompat.getColor(context,R.color.destructive)) val snippet = highlightMentions(rawSnippet, thread.threadId, context)
statusIndicatorImageView.setImageDrawable(drawable) snippetTextView.text = snippet
snippetTextView.typeface = if (unreadCount > 0) Typeface.DEFAULT_BOLD else Typeface.DEFAULT
snippetTextView.visibility = if (isTyping) View.GONE else View.VISIBLE
if (isTyping) {
typingIndicatorView.startAnimation()
} else {
typingIndicatorView.stopAnimation()
}
typingIndicatorView.visibility = if (isTyping) View.VISIBLE else View.GONE
statusIndicatorImageView.visibility = View.VISIBLE
when {
!thread.isOutgoing -> statusIndicatorImageView.visibility = View.GONE
thread.isFailed -> {
val drawable = ContextCompat.getDrawable(context, R.drawable.ic_error)?.mutate()
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)
} }
} }

View File

@ -80,8 +80,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), ConversationClickLis
// Set up seed reminder view // Set up seed reminder view
val hasViewedSeed = TextSecurePreferences.getHasViewedSeed(this) val hasViewedSeed = TextSecurePreferences.getHasViewedSeed(this)
if (!hasViewedSeed) { if (!hasViewedSeed) {
seedReminderStub.isVisible = true seedReminderStub.inflate().apply {
seedReminderStub.apply {
val seedReminderView = this.seedReminderView val seedReminderView = this.seedReminderView
val seedReminderViewTitle = SpannableString("You're almost finished! 80%") // Intentionally not yet translated val seedReminderViewTitle = SpannableString("You're almost finished! 80%") // Intentionally not yet translated
seedReminderViewTitle.setSpan(ForegroundColorSpan(resources.getColorWithID(R.color.accent, theme)), 24, 27, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) seedReminderViewTitle.setSpan(ForegroundColorSpan(resources.getColorWithID(R.color.accent, theme)), 24, 27, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)