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..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 @@ -36,6 +37,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 @@ -79,6 +82,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 @@ -142,6 +147,7 @@ class ThreadActivity : SimpleActivity() { } setupThread() + setupScrollFab() } } else { finish() @@ -173,12 +179,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) @@ -394,12 +395,11 @@ class ThreadActivity : SimpleActivity() { runOnUiThread { refreshMenuItems() getOrCreateThreadAdapter().apply { - val scrollPosition = if (currentList.lastOrNull() != threadItems.lastOrNull()) { - threadItems.lastIndex - } else { - -1 - } - updateMessages(threadItems, scrollPosition) + val layoutManager = thread_messages_list.layoutManager as LinearLayoutManager + val lastPosition = itemCount - 1 + val lastVisiblePosition = layoutManager.findLastVisibleItemPosition() + val shouldScrollToBottom = currentList.lastOrNull() != threadItems.lastOrNull() && lastPosition - lastVisiblePosition == 1 + updateMessages(threadItems, if (shouldScrollToBottom) lastPosition else -1) } } @@ -438,6 +438,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) @@ -633,6 +649,11 @@ class ThreadActivity : SimpleActivity() { addAttachment(it) } } + scroll_to_bottom_fab.setOnClickListener { + scrollToBottom() + } + scroll_to_bottom_fab.backgroundTintList = ColorStateList.valueOf(getBottomBarColor()) + scroll_to_bottom_fab.applyColorFilter(textColor) setupScheduleSendUi() } @@ -1235,7 +1256,7 @@ class ThreadActivity : SimpleActivity() { val newItems = getThreadItems() runOnUiThread { - getOrCreateThreadAdapter().updateMessages(newItems) + getOrCreateThreadAdapter().updateMessages(newItems, newItems.lastIndex) if (!refreshedSinceSent) { refreshMessages() } @@ -1661,4 +1682,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/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/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt index f89d86f5..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 = 50 +const val MESSAGES_LIMIT = 75 // intent launch request codes const val PICK_PHOTO_INTENT = 42 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 @@ + + + diff --git a/app/src/main/res/layout/activity_thread.xml b/app/src/main/res/layout/activity_thread.xml index fcc3fb2d..7f4e1f8f 100644 --- a/app/src/main/res/layout/activity_thread.xml +++ b/app/src/main/res/layout/activity_thread.xml @@ -121,6 +121,18 @@ + +