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
dca90fd1
Verified
Commit
dca90fd1
authored
7 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Always keep scroll state
parent
11840d2d
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
+42
-28
42 additions, 28 deletions
...chku/quasseldroid/ui/chat/messages/MessageListFragment.kt
with
42 additions
and
28 deletions
app/src/main/java/de/kuschku/quasseldroid/ui/chat/messages/MessageListFragment.kt
+
42
−
28
View file @
dca90fd1
...
@@ -48,6 +48,7 @@ import de.kuschku.libquassel.quassel.syncables.BufferSyncer
...
@@ -48,6 +48,7 @@ import de.kuschku.libquassel.quassel.syncables.BufferSyncer
import
de.kuschku.libquassel.session.SessionManager
import
de.kuschku.libquassel.session.SessionManager
import
de.kuschku.libquassel.util.flag.hasFlag
import
de.kuschku.libquassel.util.flag.hasFlag
import
de.kuschku.libquassel.util.helpers.mapSwitchMap
import
de.kuschku.libquassel.util.helpers.mapSwitchMap
import
de.kuschku.libquassel.util.helpers.nullIf
import
de.kuschku.libquassel.util.helpers.value
import
de.kuschku.libquassel.util.helpers.value
import
de.kuschku.libquassel.util.irc.HostmaskHelper
import
de.kuschku.libquassel.util.irc.HostmaskHelper
import
de.kuschku.quasseldroid.GlideApp
import
de.kuschku.quasseldroid.GlideApp
...
@@ -110,6 +111,7 @@ class MessageListFragment : ServiceBoundFragment() {
...
@@ -110,6 +111,7 @@ class MessageListFragment : ServiceBoundFragment() {
private
var
lastBuffer
:
BufferId
?
=
null
private
var
lastBuffer
:
BufferId
?
=
null
private
var
previousMessageId
:
MsgId
?
=
null
private
var
previousMessageId
:
MsgId
?
=
null
private
var
previousLoadKey
:
Int
?
=
null
private
var
actionMode
:
ActionMode
?
=
null
private
var
actionMode
:
ActionMode
?
=
null
...
@@ -318,7 +320,6 @@ class MessageListFragment : ServiceBoundFragment() {
...
@@ -318,7 +320,6 @@ class MessageListFragment : ServiceBoundFragment() {
}
}
}
}
var
previousLoadKey
:
Int
?
=
null
val
data
=
combineLatest
(
viewModel
.
buffer
,
val
data
=
combineLatest
(
viewModel
.
buffer
,
viewModel
.
selectedMessages
,
viewModel
.
selectedMessages
,
viewModel
.
expandedMessages
,
viewModel
.
expandedMessages
,
...
@@ -387,10 +388,18 @@ class MessageListFragment : ServiceBoundFragment() {
...
@@ -387,10 +388,18 @@ class MessageListFragment : ServiceBoundFragment() {
}
}
})
})
var
hasLoaded
=
false
fun
checkScroll
()
{
fun
checkScroll
()
{
if
(
hasLoaded
)
{
if
(
linearLayoutManager
.
findFirstVisibleItemPosition
()
<
2
&&
!
isScrolling
)
{
if
(
linearLayoutManager
.
findFirstVisibleItemPosition
()
<
2
&&
!
isScrolling
)
{
messageList
.
scrollToPosition
(
0
)
messageList
.
scrollToPosition
(
0
)
}
}
}
else
{
savedInstanceState
?.
apply
{
messageList
.
layoutManager
.
onRestoreInstanceState
(
getParcelable
(
KEY_STATE_LIST
))
}
hasLoaded
=
true
}
}
}
adapter
.
registerAdapterDataObserver
(
object
:
RecyclerView
.
AdapterDataObserver
()
{
adapter
.
registerAdapterDataObserver
(
object
:
RecyclerView
.
AdapterDataObserver
()
{
...
@@ -398,27 +407,6 @@ class MessageListFragment : ServiceBoundFragment() {
...
@@ -398,27 +407,6 @@ class MessageListFragment : ServiceBoundFragment() {
override
fun
onItemRangeInserted
(
positionStart
:
Int
,
itemCount
:
Int
)
=
checkScroll
()
override
fun
onItemRangeInserted
(
positionStart
:
Int
,
itemCount
:
Int
)
=
checkScroll
()
})
})
var
lastBuffer
=
-
1
data
.
observe
(
this
,
Observer
{
list
->
previousLoadKey
=
list
?.
lastKey
as
?
Int
val
firstVisibleItemPosition
=
linearLayoutManager
.
findFirstVisibleItemPosition
()
val
firstVisibleMessageId
=
adapter
[
firstVisibleItemPosition
]
?.
content
?.
messageId
runInBackground
{
activity
?.
runOnUiThread
{
list
?.
let
(
adapter
::
submitList
)
}
val
buffer
=
viewModel
.
buffer
.
value
?:
-
1
if
(
buffer
!=
lastBuffer
)
{
adapter
.
clearCache
()
viewModel
.
session
.
value
?.
orNull
()
?.
bufferSyncer
?.
let
{
bufferSyncer
->
onBufferChange
(
lastBuffer
,
buffer
,
firstVisibleMessageId
,
bufferSyncer
)
}
lastBuffer
=
buffer
}
}
})
scrollDown
.
hide
(
object
:
FloatingActionButton
.
OnVisibilityChangedListener
()
{
scrollDown
.
hide
(
object
:
FloatingActionButton
.
OnVisibilityChangedListener
()
{
override
fun
onHidden
(
fab
:
FloatingActionButton
)
{
override
fun
onHidden
(
fab
:
FloatingActionButton
)
{
fab
.
visibility
=
View
.
VISIBLE
fab
.
visibility
=
View
.
VISIBLE
...
@@ -426,10 +414,6 @@ class MessageListFragment : ServiceBoundFragment() {
...
@@ -426,10 +414,6 @@ class MessageListFragment : ServiceBoundFragment() {
})
})
scrollDown
.
setOnClickListener
{
messageList
.
scrollToPosition
(
0
)
}
scrollDown
.
setOnClickListener
{
messageList
.
scrollToPosition
(
0
)
}
savedInstanceState
?.
run
{
messageList
.
layoutManager
.
onRestoreInstanceState
(
getParcelable
(
KEY_STATE_LIST
))
}
val
avatarSize
=
TypedValue
.
applyDimension
(
val
avatarSize
=
TypedValue
.
applyDimension
(
TypedValue
.
COMPLEX_UNIT_SP
,
TypedValue
.
COMPLEX_UNIT_SP
,
messageSettings
.
textSize
*
2.5f
,
messageSettings
.
textSize
*
2.5f
,
...
@@ -454,12 +438,40 @@ class MessageListFragment : ServiceBoundFragment() {
...
@@ -454,12 +438,40 @@ class MessageListFragment : ServiceBoundFragment() {
adapter
,
requireContext
(),
R
.
dimen
.
markerline_height
,
R
.
attr
.
colorMarkerLine
adapter
,
requireContext
(),
R
.
dimen
.
markerline_height
,
R
.
attr
.
colorMarkerLine
))
))
savedInstanceState
?.
run
{
messageList
.
layoutManager
.
onRestoreInstanceState
(
getParcelable
(
KEY_STATE_LIST
))
previousLoadKey
=
getInt
(
KEY_STATE_PAGING
).
nullIf
{
it
==
-
1
}
lastBuffer
=
getInt
(
KEY_STATE_BUFFER
).
nullIf
{
it
==
-
1
}
}
data
.
observe
(
this
,
Observer
{
list
->
previousLoadKey
=
list
?.
lastKey
as
?
Int
val
firstVisibleItemPosition
=
linearLayoutManager
.
findFirstVisibleItemPosition
()
val
firstVisibleMessageId
=
adapter
[
firstVisibleItemPosition
]
?.
content
?.
messageId
runInBackground
{
activity
?.
runOnUiThread
{
list
?.
let
(
adapter
::
submitList
)
}
val
buffer
=
viewModel
.
buffer
.
value
?:
-
1
if
(
buffer
!=
lastBuffer
)
{
adapter
.
clearCache
()
viewModel
.
session
.
value
?.
orNull
()
?.
bufferSyncer
?.
let
{
bufferSyncer
->
onBufferChange
(
lastBuffer
,
buffer
,
firstVisibleMessageId
,
bufferSyncer
)
}
lastBuffer
=
buffer
}
}
})
return
view
return
view
}
}
override
fun
onSaveInstanceState
(
outState
:
Bundle
)
{
override
fun
onSaveInstanceState
(
outState
:
Bundle
)
{
super
.
onSaveInstanceState
(
outState
)
super
.
onSaveInstanceState
(
outState
)
outState
.
putParcelable
(
KEY_STATE_LIST
,
messageList
.
layoutManager
.
onSaveInstanceState
())
outState
.
putParcelable
(
KEY_STATE_LIST
,
messageList
.
layoutManager
.
onSaveInstanceState
())
outState
.
putInt
(
KEY_STATE_PAGING
,
previousLoadKey
?:
-
1
)
outState
.
putInt
(
KEY_STATE_BUFFER
,
lastBuffer
?:
-
1
)
}
}
private
fun
markAsRead
(
bufferSyncer
:
BufferSyncer
,
buffer
:
BufferId
,
lastMessageId
:
MsgId
?)
{
private
fun
markAsRead
(
bufferSyncer
:
BufferSyncer
,
buffer
:
BufferId
,
lastMessageId
:
MsgId
?)
{
...
@@ -528,5 +540,7 @@ class MessageListFragment : ServiceBoundFragment() {
...
@@ -528,5 +540,7 @@ class MessageListFragment : ServiceBoundFragment() {
companion
object
{
companion
object
{
private
const
val
KEY_STATE_LIST
=
"KEY_STATE_LIST"
private
const
val
KEY_STATE_LIST
=
"KEY_STATE_LIST"
private
const
val
KEY_STATE_PAGING
=
"KEY_STATE_PAGING"
private
const
val
KEY_STATE_BUFFER
=
"KEY_STATE_BUFFER"
}
}
}
}
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