Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
QuasselDroid-ng
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Janne Mareike Koschinski
QuasselDroid-ng
Commits
30cb7c12
Commit
30cb7c12
authored
7 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Finally reliably fix the scroll issue
parent
ec5f3df9
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/main/java/de/kuschku/quasseldroid/ui/chat/messages/MessageListFragment.kt
+19
-10
19 additions, 10 deletions
...chku/quasseldroid/ui/chat/messages/MessageListFragment.kt
with
19 additions
and
10 deletions
app/src/main/java/de/kuschku/quasseldroid/ui/chat/messages/MessageListFragment.kt
+
19
−
10
View file @
30cb7c12
...
@@ -83,6 +83,7 @@ class MessageListFragment : ServiceBoundFragment() {
...
@@ -83,6 +83,7 @@ class MessageListFragment : ServiceBoundFragment() {
messageList
.
itemAnimator
=
null
messageList
.
itemAnimator
=
null
messageList
.
setItemViewCacheSize
(
20
)
messageList
.
setItemViewCacheSize
(
20
)
var
isScrolling
=
false
messageList
.
addOnScrollListener
(
messageList
.
addOnScrollListener
(
object
:
RecyclerView
.
OnScrollListener
()
{
object
:
RecyclerView
.
OnScrollListener
()
{
override
fun
onScrolled
(
recyclerView
:
RecyclerView
,
dx
:
Int
,
dy
:
Int
)
{
override
fun
onScrolled
(
recyclerView
:
RecyclerView
,
dx
:
Int
,
dy
:
Int
)
{
...
@@ -93,7 +94,13 @@ class MessageListFragment : ServiceBoundFragment() {
...
@@ -93,7 +94,13 @@ class MessageListFragment : ServiceBoundFragment() {
scrollDown
.
toggle
(
canScrollDown
&&
isScrollingDown
)
scrollDown
.
toggle
(
canScrollDown
&&
isScrollingDown
)
}
}
override
fun
onScrollStateChanged
(
recyclerView
:
RecyclerView
?,
newState
:
Int
)
=
Unit
override
fun
onScrollStateChanged
(
recyclerView
:
RecyclerView
?,
newState
:
Int
)
{
isScrolling
=
when
(
newState
)
{
RecyclerView
.
SCROLL_STATE_SETTLING
,
RecyclerView
.
SCROLL_STATE_IDLE
->
false
RecyclerView
.
SCROLL_STATE_DRAGGING
->
true
else
->
isScrolling
}
}
})
})
val
data
=
viewModel
.
buffer_liveData
.
switchMapNotNull
{
buffer
->
val
data
=
viewModel
.
buffer_liveData
.
switchMapNotNull
{
buffer
->
...
@@ -124,15 +131,6 @@ class MessageListFragment : ServiceBoundFragment() {
...
@@ -124,15 +131,6 @@ class MessageListFragment : ServiceBoundFragment() {
if
(
message
!=
null
&&
bufferSyncer
!=
null
&&
previousMessageId
!=
message
.
messageId
)
{
if
(
message
!=
null
&&
bufferSyncer
!=
null
&&
previousMessageId
!=
message
.
messageId
)
{
markAsRead
(
bufferSyncer
,
message
.
bufferId
,
message
.
messageId
)
markAsRead
(
bufferSyncer
,
message
.
bufferId
,
message
.
messageId
)
previousMessageId
=
message
.
messageId
previousMessageId
=
message
.
messageId
if
(
firstVisibleItemPosition
<
2
)
{
activity
?.
runOnUiThread
{
messageList
.
scrollToPosition
(
0
)
}
runInBackgroundDelayed
(
16
)
{
activity
?.
runOnUiThread
{
messageList
.
scrollToPosition
(
0
)
}
}
}
}
}
}
}
})
})
...
@@ -144,6 +142,17 @@ class MessageListFragment : ServiceBoundFragment() {
...
@@ -144,6 +142,17 @@ class MessageListFragment : ServiceBoundFragment() {
}
}
})
})
fun
checkScroll
()
{
if
(
linearLayoutManager
.
findFirstVisibleItemPosition
()
<
2
&&
!
isScrolling
)
{
messageList
.
scrollToPosition
(
0
)
}
}
adapter
.
registerAdapterDataObserver
(
object
:
RecyclerView
.
AdapterDataObserver
()
{
override
fun
onChanged
()
=
checkScroll
()
override
fun
onItemRangeInserted
(
positionStart
:
Int
,
itemCount
:
Int
)
=
checkScroll
()
})
var
lastBuffer
=
-
1
var
lastBuffer
=
-
1
data
.
observe
(
this
,
Observer
{
list
->
data
.
observe
(
this
,
Observer
{
list
->
val
firstVisibleItemPosition
=
linearLayoutManager
.
findFirstVisibleItemPosition
()
val
firstVisibleItemPosition
=
linearLayoutManager
.
findFirstVisibleItemPosition
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment