From 1b0aa6984730a91fc0f69d939336e788642bf37c Mon Sep 17 00:00:00 2001 From: Jahir Fiquitiva Date: Tue, 1 Aug 2023 02:16:08 +0800 Subject: [PATCH] FastScrollRecyclerView: Prevent division by zero --- .../symphonica/ui/component/FastScrollRecyclerView.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/akanework/symphonica/ui/component/FastScrollRecyclerView.java b/app/src/main/java/org/akanework/symphonica/ui/component/FastScrollRecyclerView.java index b8ec6d5..b0128dd 100644 --- a/app/src/main/java/org/akanework/symphonica/ui/component/FastScrollRecyclerView.java +++ b/app/src/main/java/org/akanework/symphonica/ui/component/FastScrollRecyclerView.java @@ -297,8 +297,9 @@ public String scrollToPositionAtProgress(float touchFraction) { //The offset used here is kind of hard to explain. //If the position we wish to scroll to is, say, position 10.5, we scroll to position 10, //and then offset by 0.5 * rowHeight. This is how we achieve smooth scrolling. - scrollPosition = spanCount * exactItemPos / mScrollPosState.rowHeight; - scrollOffset = -(exactItemPos % mScrollPosState.rowHeight); + int rowHeight = mScrollPosState.rowHeight > 0 ? mScrollPosState.rowHeight : 1; + scrollPosition = spanCount * exactItemPos / rowHeight; + scrollOffset = -(exactItemPos % rowHeight); } LinearLayoutManager layoutManager = ((LinearLayoutManager) getLayoutManager());