mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
Merge pull request #690 from hjubb/startup_performance
Startup Performance Improvements
This commit is contained in:
commit
11928ce072
@ -142,7 +142,7 @@ dependencies {
|
||||
testImplementation 'org.robolectric:shadows-multidex:4.2'
|
||||
}
|
||||
|
||||
def canonicalVersionCode = 211
|
||||
def canonicalVersionCode = 215
|
||||
def canonicalVersionName = "1.11.7"
|
||||
|
||||
def postFixSize = 10
|
||||
|
@ -53,17 +53,15 @@ class ProfilePictureView : RelativeLayout {
|
||||
return recipient.isOpenGroupRecipient && recipient.groupAvatarId != null
|
||||
}
|
||||
if (recipient.isGroupRecipient && !isOpenGroupWithProfilePicture(recipient)) {
|
||||
val users = MentionsManager.userPublicKeyCache[threadID]?.toMutableList() ?: mutableListOf()
|
||||
users.remove(TextSecurePreferences.getLocalNumber(context))
|
||||
val randomUsers = users.sorted().toMutableList() // Sort to provide a level of stability
|
||||
if (users.count() == 1) {
|
||||
val userPublicKey = TextSecurePreferences.getLocalNumber(context)!!
|
||||
randomUsers.add(0, userPublicKey) // Ensure the current user is at the back visually
|
||||
}
|
||||
val pk = randomUsers.getOrNull(0) ?: ""
|
||||
val members = DatabaseFactory.getGroupDatabase(context)
|
||||
.getGroupMemberAddresses(recipient.address.toGroupString(), true)
|
||||
.sorted()
|
||||
.take(2)
|
||||
.toMutableList()
|
||||
val pk = members.getOrNull(0)?.serialize() ?: ""
|
||||
publicKey = pk
|
||||
displayName = getUserDisplayName(pk)
|
||||
val apk = randomUsers.getOrNull(1) ?: ""
|
||||
val apk = members.getOrNull(1)?.serialize() ?: ""
|
||||
additionalPublicKey = apk
|
||||
additionalDisplayName = getUserDisplayName(apk)
|
||||
} else {
|
||||
|
@ -9,15 +9,17 @@ import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||
object MentionManagerUtilities {
|
||||
|
||||
fun populateUserPublicKeyCacheIfNeeded(threadID: Long, context: Context) {
|
||||
// exit early if we need to
|
||||
if (MentionsManager.userPublicKeyCache[threadID] != null) return
|
||||
|
||||
val result = mutableSetOf<String>()
|
||||
val recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadID)
|
||||
if (recipient != null && recipient.address.isClosedGroup) {
|
||||
val recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadID) ?: return
|
||||
if (recipient.address.isClosedGroup) {
|
||||
val members = DatabaseFactory.getGroupDatabase(context).getGroupMembers(recipient.address.toGroupString(), false).map { it.address.serialize() }
|
||||
result.addAll(members)
|
||||
} else {
|
||||
if (MentionsManager.userPublicKeyCache[threadID] != null) { return }
|
||||
val messageDatabase = DatabaseFactory.getMmsSmsDatabase(context)
|
||||
val reader = messageDatabase.readerFor(messageDatabase.getConversation(threadID))
|
||||
val reader = messageDatabase.readerFor(messageDatabase.getConversation(threadID, 0, 200))
|
||||
var record: MessageRecord? = reader.next
|
||||
while (record != null) {
|
||||
result.add(record.individualRecipient.address.serialize())
|
||||
|
@ -14,6 +14,7 @@ import com.annimon.stream.Stream;
|
||||
|
||||
import net.sqlcipher.database.SQLiteDatabase;
|
||||
|
||||
import org.session.libsession.utilities.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||
|
||||
@ -155,6 +156,20 @@ public class GroupDatabase extends Database implements LokiOpenGroupDatabaseProt
|
||||
return recipients;
|
||||
}
|
||||
|
||||
public @NonNull List<Address> getGroupMemberAddresses(String groupId, boolean includeSelf) {
|
||||
List<Address> members = getCurrentMembers(groupId, false);
|
||||
if (!includeSelf) {
|
||||
String ownNumber = TextSecurePreferences.getLocalNumber(context);
|
||||
if (ownNumber == null) return members;
|
||||
Address ownAddress = Address.fromSerialized(ownNumber);
|
||||
int indexOfSelf = members.indexOf(ownAddress);
|
||||
if (indexOfSelf >= 0) {
|
||||
members.remove(indexOfSelf);
|
||||
}
|
||||
}
|
||||
return members;
|
||||
}
|
||||
|
||||
public @NonNull List<Recipient> getGroupZombieMembers(String groupId) {
|
||||
List<Address> members = getCurrentZombieMembers(groupId);
|
||||
List<Recipient> recipients = new LinkedList<>();
|
||||
|
@ -651,7 +651,7 @@ public class ThreadDatabase extends Database {
|
||||
groupRecord = Optional.absent();
|
||||
}
|
||||
|
||||
Recipient recipient = Recipient.from(context, address, settings, groupRecord, false);
|
||||
Recipient recipient = Recipient.from(context, address, settings, groupRecord, true);
|
||||
String body = cursor.getString(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET));
|
||||
long date = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.DATE));
|
||||
long count = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.MESSAGE_COUNT));
|
||||
|
@ -14,7 +14,6 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlinx.android.synthetic.main.view_conversation.view.*
|
||||
import network.loki.messenger.R
|
||||
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.database.RecipientDatabase
|
||||
import org.thoughtcrime.securesms.database.model.ThreadRecord
|
||||
@ -40,7 +39,7 @@ class ConversationView : LinearLayout {
|
||||
// region Updating
|
||||
fun bind(thread: ThreadRecord, isTyping: Boolean, glide: GlideRequests) {
|
||||
this.thread = thread
|
||||
populateUserPublicKeyCacheIfNeeded(thread.threadId, context) // FIXME: This is a bad place to do this
|
||||
profilePictureView.glide = glide
|
||||
val unreadCount = thread.unreadCount
|
||||
if (thread.recipient.isBlocked) {
|
||||
accentView.setBackgroundResource(R.color.destructive)
|
||||
@ -55,9 +54,8 @@ class ConversationView : LinearLayout {
|
||||
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.update(thread.recipient, thread.threadId)
|
||||
val senderDisplayName = getUserDisplayName(thread.recipient) ?: thread.recipient.address.toString()
|
||||
val senderDisplayName = getUserDisplayName(thread.recipient)
|
||||
?: thread.recipient.address.toString()
|
||||
conversationViewDisplayNameTextView.text = senderDisplayName
|
||||
timestampTextView.text = DateUtils.getDisplayFormattedTimeSpanString(context, Locale.getDefault(), thread.date)
|
||||
val recipient = thread.recipient
|
||||
@ -84,13 +82,16 @@ class ConversationView : LinearLayout {
|
||||
!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))
|
||||
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)
|
||||
}
|
||||
post {
|
||||
profilePictureView.update(thread.recipient, thread.threadId)
|
||||
}
|
||||
}
|
||||
|
||||
fun recycle() {
|
||||
|
@ -80,8 +80,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), ConversationClickLis
|
||||
// Set up seed reminder view
|
||||
val hasViewedSeed = TextSecurePreferences.getHasViewedSeed(this)
|
||||
if (!hasViewedSeed) {
|
||||
seedReminderStub.isVisible = true
|
||||
seedReminderStub.apply {
|
||||
seedReminderStub.inflate().apply {
|
||||
val seedReminderView = this.seedReminderView
|
||||
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)
|
||||
|
@ -153,6 +153,7 @@ public class Recipient implements RecipientModifiedListener {
|
||||
this.profileSharing = stale.profileSharing;
|
||||
this.unidentifiedAccessMode = stale.unidentifiedAccessMode;
|
||||
this.forceSmsSelection = stale.forceSmsSelection;
|
||||
this.notifyType = stale.notifyType;
|
||||
|
||||
this.participants.clear();
|
||||
this.participants.addAll(stale.participants);
|
||||
@ -180,6 +181,7 @@ public class Recipient implements RecipientModifiedListener {
|
||||
this.profileSharing = details.get().profileSharing;
|
||||
this.unidentifiedAccessMode = details.get().unidentifiedAccessMode;
|
||||
this.forceSmsSelection = details.get().forceSmsSelection;
|
||||
this.notifyType = details.get().notifyType;
|
||||
|
||||
this.participants.clear();
|
||||
this.participants.addAll(details.get().participants);
|
||||
|
Loading…
Reference in New Issue
Block a user