improved read position

This commit is contained in:
Mariotaku Lee 2017-02-02 22:20:14 +08:00
parent ed7ebbcb1c
commit 8685437b85
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
2 changed files with 10 additions and 2 deletions

View File

@ -227,7 +227,7 @@ abstract class AbsActivitiesFragment protected constructor() :
val lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition()
wasAtTop = firstVisibleItemPosition == 0
val activityRange = rangeOfSize(adapter.activityStartIndex, Math.max(0, adapter.activityCount - 1))
val lastReadPosition = if (readFromBottom) {
val lastReadPosition = if (loadMore || readFromBottom) {
lastVisibleItemPosition
} else {
firstVisibleItemPosition
@ -255,6 +255,10 @@ abstract class AbsActivitiesFragment protected constructor() :
restorePosition = adapter.findPositionBySortTimestamp(lastReadId)
}
if (loadMore) {
restorePosition += 1
restorePosition.coerceInOr(0 until layoutManager.itemCount, -1)
}
if (restorePosition != -1 && adapter.isActivity(restorePosition) && (loadMore || !wasAtTop ||
readFromBottom
|| (rememberPosition && firstLoad))) {

View File

@ -280,7 +280,7 @@ abstract class AbsStatusesFragment protected constructor() :
val lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition()
wasAtTop = firstVisibleItemPosition == 0
val statusRange = rangeOfSize(adapter.statusStartIndex, adapter.statusCount - 1)
val lastReadPosition = if (readFromBottom) {
val lastReadPosition = if (loadMore || readFromBottom) {
lastVisibleItemPosition
} else {
firstVisibleItemPosition
@ -319,6 +319,10 @@ abstract class AbsStatusesFragment protected constructor() :
} else {
onHasMoreDataChanged(false)
}
if (loadMore) {
restorePosition += 1
restorePosition.coerceInOr(0 until layoutManager.itemCount, -1)
}
if (restorePosition != -1 && adapter.isStatus(restorePosition) && (loadMore || !wasAtTop
|| readFromBottom || (rememberPosition && firstLoad))) {
if (layoutManager.height == 0) {