From 7b5d32e62418c28fa618536d77719a7775d94191 Mon Sep 17 00:00:00 2001 From: yparitcher Date: Wed, 10 May 2023 15:37:43 -0400 Subject: [PATCH 1/2] refresh sms history based on oldest sms loaded, ignoring mms all mms are always loaded, the number of messages only concerns sms, so only reference sms to determine the oldest loaded message this should load all sms messages when there are mms messages in between Fixes: #535 --- .../smsmessenger/activities/ThreadActivity.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt index 81aae2e3..3def4a72 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -514,7 +514,8 @@ class ThreadActivity : SimpleActivity() { return } - val dateOfFirstItem = messages.first().date + val firstItem = messages.first{ !it.isMMS } + val dateOfFirstItem = firstItem.date if (oldestMessageDate == dateOfFirstItem) { allMessagesFetched = true return @@ -524,7 +525,6 @@ class ThreadActivity : SimpleActivity() { loadingOlderMessages = true ensureBackgroundThread { - val firstItem = messages.first() val olderMessages = getMessages(threadId, true, oldestMessageDate) .filter { message -> !messages.contains(message) } From 707d7499e34a7691114f4111d56c8815831ed82d Mon Sep 17 00:00:00 2001 From: yparitcher Date: Wed, 10 May 2023 20:35:12 -0400 Subject: [PATCH 2/2] better method: limit the total of sms+mms to MESSAGES_LIMIT this causes the sms and mms to load together for a smoother flow --- .../smsmessenger/activities/ThreadActivity.kt | 4 ++-- .../com/simplemobiletools/smsmessenger/extensions/Context.kt | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt index 3def4a72..1ed13448 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -514,7 +514,7 @@ class ThreadActivity : SimpleActivity() { return } - val firstItem = messages.first{ !it.isMMS } + val firstItem = messages.first() val dateOfFirstItem = firstItem.date if (oldestMessageDate == dateOfFirstItem) { allMessagesFetched = true @@ -529,7 +529,7 @@ class ThreadActivity : SimpleActivity() { .filter { message -> !messages.contains(message) } messages.addAll(0, olderMessages) - allMessagesFetched = olderMessages.size < MESSAGES_LIMIT || olderMessages.isEmpty() + allMessagesFetched = olderMessages.isEmpty() threadItems = getThreadItems() runOnUiThread { diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt index 2aa8604b..0bfbcb2a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt @@ -135,6 +135,7 @@ fun Context.getMessages( .filter { it.participants.isNotEmpty() } .filterNot { it.isScheduled && it.millis() < System.currentTimeMillis() } .sortedWith(compareBy { it.date }.thenBy { it.id }) + .takeLast(limit) .toMutableList() as ArrayList return messages