mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-02-16 11:40:51 +01:00
Merge pull request #562 from Naveen3Singh/scrolling_improvements
Scrolling improvements
This commit is contained in:
commit
9ac2b71172
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ class ThreadAdapter(
|
||||
|
||||
private fun isThreadDateTime(position: Int) = currentList.getOrNull(position) is ThreadDateTime
|
||||
|
||||
fun updateMessages(newMessages: ArrayList<ThreadItem>, scrollPosition: Int = newMessages.lastIndex) {
|
||||
fun updateMessages(newMessages: ArrayList<ThreadItem>, scrollPosition: Int = -1) {
|
||||
val latestMessages = newMessages.toMutableList()
|
||||
submitList(latestMessages) {
|
||||
if (scrollPosition != -1) {
|
||||
|
@ -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
|
||||
|
3
app/src/main/res/drawable/ic_arrow_down_vector.xml
Normal file
3
app/src/main/res/drawable/ic_arrow_down_vector.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M11 5v11.17l-4.88-4.88c-0.39-0.39-1.03-0.39-1.42 0-0.39 0.39-0.39 1.02 0 1.41l6.59 6.59c0.39 0.39 1.02 0.39 1.41 0l6.59-6.59c0.39-0.39 0.39-1.02 0-1.41-0.39-0.39-1.02-0.39-1.41 0L13 16.17V5c0-0.55-0.45-1-1-1s-1 0.45-1 1z"/>
|
||||
</vector>
|
@ -121,6 +121,18 @@
|
||||
|
||||
</com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyFloatingActionButton
|
||||
android:id="@+id/scroll_to_bottom_fab"
|
||||
android:layout_width="wrap_content"
|
||||
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"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<include
|
||||
layout="@layout/layout_invalid_short_code_info"
|
||||
android:layout_width="match_parent"
|
||||
|
Loading…
x
Reference in New Issue
Block a user