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'
|
testImplementation 'org.robolectric:shadows-multidex:4.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
def canonicalVersionCode = 211
|
def canonicalVersionCode = 215
|
||||||
def canonicalVersionName = "1.11.7"
|
def canonicalVersionName = "1.11.7"
|
||||||
|
|
||||||
def postFixSize = 10
|
def postFixSize = 10
|
||||||
|
@ -53,17 +53,15 @@ class ProfilePictureView : RelativeLayout {
|
|||||||
return recipient.isOpenGroupRecipient && recipient.groupAvatarId != null
|
return recipient.isOpenGroupRecipient && recipient.groupAvatarId != null
|
||||||
}
|
}
|
||||||
if (recipient.isGroupRecipient && !isOpenGroupWithProfilePicture(recipient)) {
|
if (recipient.isGroupRecipient && !isOpenGroupWithProfilePicture(recipient)) {
|
||||||
val users = MentionsManager.userPublicKeyCache[threadID]?.toMutableList() ?: mutableListOf()
|
val members = DatabaseFactory.getGroupDatabase(context)
|
||||||
users.remove(TextSecurePreferences.getLocalNumber(context))
|
.getGroupMemberAddresses(recipient.address.toGroupString(), true)
|
||||||
val randomUsers = users.sorted().toMutableList() // Sort to provide a level of stability
|
.sorted()
|
||||||
if (users.count() == 1) {
|
.take(2)
|
||||||
val userPublicKey = TextSecurePreferences.getLocalNumber(context)!!
|
.toMutableList()
|
||||||
randomUsers.add(0, userPublicKey) // Ensure the current user is at the back visually
|
val pk = members.getOrNull(0)?.serialize() ?: ""
|
||||||
}
|
|
||||||
val pk = randomUsers.getOrNull(0) ?: ""
|
|
||||||
publicKey = pk
|
publicKey = pk
|
||||||
displayName = getUserDisplayName(pk)
|
displayName = getUserDisplayName(pk)
|
||||||
val apk = randomUsers.getOrNull(1) ?: ""
|
val apk = members.getOrNull(1)?.serialize() ?: ""
|
||||||
additionalPublicKey = apk
|
additionalPublicKey = apk
|
||||||
additionalDisplayName = getUserDisplayName(apk)
|
additionalDisplayName = getUserDisplayName(apk)
|
||||||
} else {
|
} else {
|
||||||
|
@ -9,15 +9,17 @@ 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) ?: return
|
||||||
if (recipient != null && recipient.address.isClosedGroup) {
|
if (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, 0, 200))
|
||||||
var record: MessageRecord? = reader.next
|
var record: MessageRecord? = reader.next
|
||||||
while (record != null) {
|
while (record != null) {
|
||||||
result.add(record.individualRecipient.address.serialize())
|
result.add(record.individualRecipient.address.serialize())
|
||||||
|
@ -14,6 +14,7 @@ import com.annimon.stream.Stream;
|
|||||||
|
|
||||||
import net.sqlcipher.database.SQLiteDatabase;
|
import net.sqlcipher.database.SQLiteDatabase;
|
||||||
|
|
||||||
|
import org.session.libsession.utilities.TextSecurePreferences;
|
||||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||||
|
|
||||||
@ -155,6 +156,20 @@ public class GroupDatabase extends Database implements LokiOpenGroupDatabaseProt
|
|||||||
return recipients;
|
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) {
|
public @NonNull List<Recipient> getGroupZombieMembers(String groupId) {
|
||||||
List<Address> members = getCurrentZombieMembers(groupId);
|
List<Address> members = getCurrentZombieMembers(groupId);
|
||||||
List<Recipient> recipients = new LinkedList<>();
|
List<Recipient> recipients = new LinkedList<>();
|
||||||
|
@ -651,7 +651,7 @@ public class ThreadDatabase extends Database {
|
|||||||
groupRecord = Optional.absent();
|
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));
|
String body = cursor.getString(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET));
|
||||||
long date = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.DATE));
|
long date = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.DATE));
|
||||||
long count = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.MESSAGE_COUNT));
|
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 kotlinx.android.synthetic.main.view_conversation.view.*
|
||||||
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
|
||||||
@ -40,7 +39,7 @@ 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
|
profilePictureView.glide = glide
|
||||||
val unreadCount = thread.unreadCount
|
val unreadCount = thread.unreadCount
|
||||||
if (thread.recipient.isBlocked) {
|
if (thread.recipient.isBlocked) {
|
||||||
accentView.setBackgroundResource(R.color.destructive)
|
accentView.setBackgroundResource(R.color.destructive)
|
||||||
@ -55,9 +54,8 @@ class ConversationView : LinearLayout {
|
|||||||
unreadCountTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize)
|
unreadCountTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize)
|
||||||
unreadCountTextView.setTypeface(Typeface.DEFAULT, if (unreadCount < 100) Typeface.BOLD else Typeface.NORMAL)
|
unreadCountTextView.setTypeface(Typeface.DEFAULT, if (unreadCount < 100) Typeface.BOLD else Typeface.NORMAL)
|
||||||
unreadCountIndicator.isVisible = (unreadCount != 0)
|
unreadCountIndicator.isVisible = (unreadCount != 0)
|
||||||
profilePictureView.glide = glide
|
val senderDisplayName = getUserDisplayName(thread.recipient)
|
||||||
profilePictureView.update(thread.recipient, thread.threadId)
|
?: thread.recipient.address.toString()
|
||||||
val senderDisplayName = getUserDisplayName(thread.recipient) ?: thread.recipient.address.toString()
|
|
||||||
conversationViewDisplayNameTextView.text = senderDisplayName
|
conversationViewDisplayNameTextView.text = senderDisplayName
|
||||||
timestampTextView.text = DateUtils.getDisplayFormattedTimeSpanString(context, Locale.getDefault(), thread.date)
|
timestampTextView.text = DateUtils.getDisplayFormattedTimeSpanString(context, Locale.getDefault(), thread.date)
|
||||||
val recipient = thread.recipient
|
val recipient = thread.recipient
|
||||||
@ -84,13 +82,16 @@ class ConversationView : LinearLayout {
|
|||||||
!thread.isOutgoing -> statusIndicatorImageView.visibility = View.GONE
|
!thread.isOutgoing -> statusIndicatorImageView.visibility = View.GONE
|
||||||
thread.isFailed -> {
|
thread.isFailed -> {
|
||||||
val drawable = ContextCompat.getDrawable(context, R.drawable.ic_error)?.mutate()
|
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)
|
statusIndicatorImageView.setImageDrawable(drawable)
|
||||||
}
|
}
|
||||||
thread.isPending -> statusIndicatorImageView.setImageResource(R.drawable.ic_circle_dot_dot_dot)
|
thread.isPending -> statusIndicatorImageView.setImageResource(R.drawable.ic_circle_dot_dot_dot)
|
||||||
thread.isRead -> statusIndicatorImageView.setImageResource(R.drawable.ic_filled_circle_check)
|
thread.isRead -> statusIndicatorImageView.setImageResource(R.drawable.ic_filled_circle_check)
|
||||||
else -> statusIndicatorImageView.setImageResource(R.drawable.ic_circle_check)
|
else -> statusIndicatorImageView.setImageResource(R.drawable.ic_circle_check)
|
||||||
}
|
}
|
||||||
|
post {
|
||||||
|
profilePictureView.update(thread.recipient, thread.threadId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun recycle() {
|
fun recycle() {
|
||||||
|
@ -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)
|
||||||
|
@ -153,6 +153,7 @@ public class Recipient implements RecipientModifiedListener {
|
|||||||
this.profileSharing = stale.profileSharing;
|
this.profileSharing = stale.profileSharing;
|
||||||
this.unidentifiedAccessMode = stale.unidentifiedAccessMode;
|
this.unidentifiedAccessMode = stale.unidentifiedAccessMode;
|
||||||
this.forceSmsSelection = stale.forceSmsSelection;
|
this.forceSmsSelection = stale.forceSmsSelection;
|
||||||
|
this.notifyType = stale.notifyType;
|
||||||
|
|
||||||
this.participants.clear();
|
this.participants.clear();
|
||||||
this.participants.addAll(stale.participants);
|
this.participants.addAll(stale.participants);
|
||||||
@ -180,6 +181,7 @@ public class Recipient implements RecipientModifiedListener {
|
|||||||
this.profileSharing = details.get().profileSharing;
|
this.profileSharing = details.get().profileSharing;
|
||||||
this.unidentifiedAccessMode = details.get().unidentifiedAccessMode;
|
this.unidentifiedAccessMode = details.get().unidentifiedAccessMode;
|
||||||
this.forceSmsSelection = details.get().forceSmsSelection;
|
this.forceSmsSelection = details.get().forceSmsSelection;
|
||||||
|
this.notifyType = details.get().notifyType;
|
||||||
|
|
||||||
this.participants.clear();
|
this.participants.clear();
|
||||||
this.participants.addAll(details.get().participants);
|
this.participants.addAll(details.get().participants);
|
||||||
|
Loading…
Reference in New Issue
Block a user