-
-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix inaccurate scroll bar due to lazy loading #1232
Signed-off-by: Christine Coenen <[email protected]>
- Loading branch information
Showing
3 changed files
with
38 additions
and
8 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...-Android-App/src/main/java/de/luhmer/owncloudnewsreader/LazyLoadingLinearLayoutManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package de.luhmer.owncloudnewsreader | ||
|
||
import android.content.Context | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import androidx.recyclerview.widget.RecyclerView | ||
import kotlin.math.roundToInt | ||
|
||
class LazyLoadingLinearLayoutManager( | ||
context: Context?, | ||
@RecyclerView.Orientation orientation: Int, | ||
reverseLayout: Boolean | ||
) : LinearLayoutManager(context, orientation, reverseLayout) { | ||
|
||
var totalItemCount: Int = 0 | ||
|
||
override fun computeVerticalScrollRange(state: RecyclerView.State): Int { | ||
if (state.itemCount == 0) { | ||
return 0 | ||
} | ||
|
||
return (super.computeVerticalScrollRange(state) / state.itemCount.toFloat() * totalItemCount).roundToInt() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters