mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-06-05 21:49:22 +02:00
Fix scroll-up glitch when new message arrives
This commit is contained in:
@ -36,6 +36,8 @@ import androidx.annotation.StringRes
|
|||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.core.view.*
|
import androidx.core.view.*
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||||
@ -394,8 +396,10 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
refreshMenuItems()
|
refreshMenuItems()
|
||||||
getOrCreateThreadAdapter().apply {
|
getOrCreateThreadAdapter().apply {
|
||||||
val scrollPosition = if (currentList.lastOrNull() != threadItems.lastOrNull()) {
|
val lastPosition = itemCount - 1
|
||||||
threadItems.lastIndex
|
val lastVisiblePosition = (thread_messages_list.layoutManager as LinearLayoutManager).findLastVisibleItemPosition()
|
||||||
|
val scrollPosition = if (currentList.lastOrNull() != threadItems.lastOrNull() && lastPosition - lastVisiblePosition <= 2) {
|
||||||
|
lastPosition
|
||||||
} else {
|
} else {
|
||||||
-1
|
-1
|
||||||
}
|
}
|
||||||
@ -1235,7 +1239,7 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
|
|
||||||
val newItems = getThreadItems()
|
val newItems = getThreadItems()
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
getOrCreateThreadAdapter().updateMessages(newItems)
|
getOrCreateThreadAdapter().updateMessages(newItems, newItems.lastIndex)
|
||||||
if (!refreshedSinceSent) {
|
if (!refreshedSinceSent) {
|
||||||
refreshMessages()
|
refreshMessages()
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ class ThreadAdapter(
|
|||||||
|
|
||||||
private fun isThreadDateTime(position: Int) = currentList.getOrNull(position) is ThreadDateTime
|
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()
|
val latestMessages = newMessages.toMutableList()
|
||||||
submitList(latestMessages) {
|
submitList(latestMessages) {
|
||||||
if (scrollPosition != -1) {
|
if (scrollPosition != -1) {
|
||||||
|
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>
|
Reference in New Issue
Block a user