From e98351c14648ee43904f76a6ea7c08c779d330de Mon Sep 17 00:00:00 2001 From: Naveen Date: Sun, 15 Jan 2023 08:41:07 +0530 Subject: [PATCH 1/7] Increase first load limit to 100 --- .../com/simplemobiletools/smsmessenger/helpers/Constants.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt index f89d86f5..a004b8ce 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt @@ -70,7 +70,7 @@ const val FILE_SIZE_600_KB = 614_400L const val FILE_SIZE_1_MB = 1_048_576L const val FILE_SIZE_2_MB = 2_097_152L -const val MESSAGES_LIMIT = 50 +const val MESSAGES_LIMIT = 100 // intent launch request codes const val PICK_PHOTO_INTENT = 42 From 2d6ff0bc301be2f667c2d458d8dbffa552000c60 Mon Sep 17 00:00:00 2001 From: Naveen Date: Sun, 15 Jan 2023 08:42:15 +0530 Subject: [PATCH 2/7] Fix scroll-up glitch when new message arrives --- .../smsmessenger/activities/ThreadActivity.kt | 10 +++++++--- .../smsmessenger/adapters/ThreadAdapter.kt | 2 +- app/src/main/res/drawable/ic_arrow_down_vector.xml | 3 +++ 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/drawable/ic_arrow_down_vector.xml 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 dfc044ee..8bfd93bc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -36,6 +36,8 @@ import androidx.annotation.StringRes import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.res.ResourcesCompat import androidx.core.view.* +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import com.google.gson.Gson import com.google.gson.reflect.TypeToken import com.simplemobiletools.commons.dialogs.ConfirmationDialog @@ -394,8 +396,10 @@ class ThreadActivity : SimpleActivity() { runOnUiThread { refreshMenuItems() getOrCreateThreadAdapter().apply { - val scrollPosition = if (currentList.lastOrNull() != threadItems.lastOrNull()) { - threadItems.lastIndex + val lastPosition = itemCount - 1 + val lastVisiblePosition = (thread_messages_list.layoutManager as LinearLayoutManager).findLastVisibleItemPosition() + val scrollPosition = if (currentList.lastOrNull() != threadItems.lastOrNull() && lastPosition - lastVisiblePosition <= 2) { + lastPosition } else { -1 } @@ -1235,7 +1239,7 @@ class ThreadActivity : SimpleActivity() { val newItems = getThreadItems() runOnUiThread { - getOrCreateThreadAdapter().updateMessages(newItems) + getOrCreateThreadAdapter().updateMessages(newItems, newItems.lastIndex) if (!refreshedSinceSent) { refreshMessages() } diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt index 4d2ccf76..8e942bfb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt @@ -227,7 +227,7 @@ class ThreadAdapter( private fun isThreadDateTime(position: Int) = currentList.getOrNull(position) is ThreadDateTime - fun updateMessages(newMessages: ArrayList, scrollPosition: Int = newMessages.lastIndex) { + fun updateMessages(newMessages: ArrayList, scrollPosition: Int = -1) { val latestMessages = newMessages.toMutableList() submitList(latestMessages) { if (scrollPosition != -1) { diff --git a/app/src/main/res/drawable/ic_arrow_down_vector.xml b/app/src/main/res/drawable/ic_arrow_down_vector.xml new file mode 100644 index 00000000..eefe3292 --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_down_vector.xml @@ -0,0 +1,3 @@ + + + From 37944e8b4094ddab1c4f70a58a7a24fccdd8392f Mon Sep 17 00:00:00 2001 From: Naveen Date: Sun, 15 Jan 2023 08:43:19 +0530 Subject: [PATCH 3/7] Add helper fab for quick scroll to bottom --- .../smsmessenger/activities/ThreadActivity.kt | 25 +++++++++++++++++++ app/src/main/res/layout/activity_thread.xml | 11 ++++++++ 2 files changed, 36 insertions(+) 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 8bfd93bc..55d6d80d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -81,6 +81,8 @@ class ThreadActivity : SimpleActivity() { private val TYPE_SEND = 15 private val TYPE_DELETE = 16 + private val SCROLL_TO_BOTTOM_FAB_LIMIT = 20 + private var threadId = 0L private var currentSIMCardIndex = 0 private var isActivityVisible = false @@ -144,6 +146,7 @@ class ThreadActivity : SimpleActivity() { } setupThread() + setupScrollFab() } } else { finish() @@ -442,6 +445,22 @@ class ThreadActivity : SimpleActivity() { } } + private fun setupScrollFab() { + thread_messages_list.addOnScrollListener(object : RecyclerView.OnScrollListener() { + override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { + super.onScrolled(recyclerView, dx, dy) + val layoutManager = thread_messages_list.layoutManager as LinearLayoutManager + val lastVisibleItemPosition = layoutManager.findLastCompletelyVisibleItemPosition() + val isCloseToBottom = lastVisibleItemPosition >= getOrCreateThreadAdapter().itemCount - SCROLL_TO_BOTTOM_FAB_LIMIT + if (isCloseToBottom) { + scroll_to_bottom_fab.hide() + } else { + scroll_to_bottom_fab.show() + } + } + }) + } + private fun handleItemClick(any: Any) { when { any is Message && any.isScheduled -> showScheduledMessageInfo(any) @@ -534,6 +553,7 @@ class ThreadActivity : SimpleActivity() { private fun setupButtons() { updateTextColors(thread_holder) val textColor = getProperTextColor() + val backgroundColor = getProperBackgroundColor() thread_send_message.apply { setTextColor(textColor) compoundDrawables.forEach { @@ -637,6 +657,11 @@ class ThreadActivity : SimpleActivity() { addAttachment(it) } } + scroll_to_bottom_fab.setOnClickListener { + scrollToBottom() + } + scroll_to_bottom_fab.hide() + scroll_to_bottom_fab.setColors(textColor, backgroundColor, backgroundColor) setupScheduleSendUi() } diff --git a/app/src/main/res/layout/activity_thread.xml b/app/src/main/res/layout/activity_thread.xml index fcc3fb2d..b8b957f6 100644 --- a/app/src/main/res/layout/activity_thread.xml +++ b/app/src/main/res/layout/activity_thread.xml @@ -121,6 +121,17 @@ + + Date: Sun, 15 Jan 2023 09:12:07 +0530 Subject: [PATCH 4/7] Lower limit to 75 for quick loading --- .../com/simplemobiletools/smsmessenger/helpers/Constants.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt index a004b8ce..7e19217e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt @@ -70,7 +70,7 @@ const val FILE_SIZE_600_KB = 614_400L const val FILE_SIZE_1_MB = 1_048_576L const val FILE_SIZE_2_MB = 2_097_152L -const val MESSAGES_LIMIT = 100 +const val MESSAGES_LIMIT = 75 // intent launch request codes const val PICK_PHOTO_INTENT = 42 From bdafa4b84785b04e5d858d5def237c901c3f0574 Mon Sep 17 00:00:00 2001 From: Naveen Date: Sun, 15 Jan 2023 09:12:30 +0530 Subject: [PATCH 5/7] Change fab bg color --- .../smsmessenger/activities/ThreadActivity.kt | 18 +++++++++--------- app/src/main/res/layout/activity_thread.xml | 1 + 2 files changed, 10 insertions(+), 9 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 55d6d80d..bf412185 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -178,12 +178,7 @@ class ThreadActivity : SimpleActivity() { } } - val bottomBarColor = if (baseConfig.isUsingSystemTheme) { - resources.getColor(R.color.you_bottom_bar_color) - } else { - getBottomNavigationBackgroundColor() - } - + val bottomBarColor = getBottomBarColor() thread_send_message_holder.setBackgroundColor(bottomBarColor) reply_disabled_info_holder.setBackgroundColor(bottomBarColor) updateNavigationBarColor(bottomBarColor) @@ -553,7 +548,6 @@ class ThreadActivity : SimpleActivity() { private fun setupButtons() { updateTextColors(thread_holder) val textColor = getProperTextColor() - val backgroundColor = getProperBackgroundColor() thread_send_message.apply { setTextColor(textColor) compoundDrawables.forEach { @@ -660,8 +654,8 @@ class ThreadActivity : SimpleActivity() { scroll_to_bottom_fab.setOnClickListener { scrollToBottom() } - scroll_to_bottom_fab.hide() - scroll_to_bottom_fab.setColors(textColor, backgroundColor, backgroundColor) + val fabColor = getBottomBarColor() + scroll_to_bottom_fab.setColors(textColor, fabColor, fabColor) setupScheduleSendUi() } @@ -1690,4 +1684,10 @@ class ThreadActivity : SimpleActivity() { showAttachmentPicker() } } + + private fun getBottomBarColor() = if (baseConfig.isUsingSystemTheme) { + resources.getColor(R.color.you_bottom_bar_color) + } else { + getBottomNavigationBackgroundColor() + } } diff --git a/app/src/main/res/layout/activity_thread.xml b/app/src/main/res/layout/activity_thread.xml index b8b957f6..7f4e1f8f 100644 --- a/app/src/main/res/layout/activity_thread.xml +++ b/app/src/main/res/layout/activity_thread.xml @@ -127,6 +127,7 @@ android:layout_height="wrap_content" android:layout_margin="@dimen/activity_margin" android:src="@drawable/ic_arrow_down_vector" + android:visibility="invisible" app:fabSize="mini" app:layout_constraintBottom_toBottomOf="@id/thread_messages_fastscroller" app:layout_constraintEnd_toEndOf="@id/thread_messages_fastscroller" From fce31b7bcf4fe06fcccd356b19bd39e5a0fe2fe9 Mon Sep 17 00:00:00 2001 From: Naveen Date: Sun, 15 Jan 2023 09:24:19 +0530 Subject: [PATCH 6/7] Reduce minimum scroll distance to 1 --- .../smsmessenger/activities/ThreadActivity.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 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 bf412185..4a49d337 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -394,14 +394,11 @@ class ThreadActivity : SimpleActivity() { runOnUiThread { refreshMenuItems() getOrCreateThreadAdapter().apply { + val layoutManager = thread_messages_list.layoutManager as LinearLayoutManager val lastPosition = itemCount - 1 - val lastVisiblePosition = (thread_messages_list.layoutManager as LinearLayoutManager).findLastVisibleItemPosition() - val scrollPosition = if (currentList.lastOrNull() != threadItems.lastOrNull() && lastPosition - lastVisiblePosition <= 2) { - lastPosition - } else { - -1 - } - updateMessages(threadItems, scrollPosition) + val lastVisiblePosition = layoutManager.findLastVisibleItemPosition() + val shouldScrollToBottom = currentList.lastOrNull() != threadItems.lastOrNull() && lastPosition - lastVisiblePosition == 1 + updateMessages(threadItems, if (shouldScrollToBottom) lastPosition else -1) } } From b68c672be6cdec55ae68b1dbb4cd333dd7863cce Mon Sep 17 00:00:00 2001 From: Naveen Date: Mon, 16 Jan 2023 18:09:58 +0530 Subject: [PATCH 7/7] Use text color as fab icon color --- .../smsmessenger/activities/ThreadActivity.kt | 5 +++-- 1 file 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 4a49d337..764075e9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.app.Activity import android.content.ActivityNotFoundException import android.content.Intent +import android.content.res.ColorStateList import android.graphics.BitmapFactory import android.graphics.drawable.LayerDrawable import android.media.MediaMetadataRetriever @@ -651,8 +652,8 @@ class ThreadActivity : SimpleActivity() { scroll_to_bottom_fab.setOnClickListener { scrollToBottom() } - val fabColor = getBottomBarColor() - scroll_to_bottom_fab.setColors(textColor, fabColor, fabColor) + scroll_to_bottom_fab.backgroundTintList = ColorStateList.valueOf(getBottomBarColor()) + scroll_to_bottom_fab.applyColorFilter(textColor) setupScheduleSendUi() }