Skip to content

Commit 12018b3

Browse files
committed
- Library screen / endless : Memorize scroll position when going back to the screen after LibraryActivity has been destroyed and recreated (#452)
- Cleanup
1 parent fff5b11 commit 12018b3

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

app/src/main/java/me/devsaki/hentoid/fragments/library/LibraryFragment.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
647647

648648
Timber.i(">> memorize position %s", topItemPosition);
649649
outState.putInt(KEY_LAST_LIST_POSITION, topItemPosition);
650+
topItemPosition = -1;
650651
}
651652

652653
@Override
@@ -1038,7 +1039,7 @@ private void updateTitle(long totalSelectedCount, long totalCount) {
10381039
private boolean onBookClick(ContentItem item, int position) {
10391040
if (0 == selectExtension.getSelectedItems().size()) {
10401041
if (!invalidateNextBookClick) {
1041-
topItemPosition = position; // TODO - still useful ?
1042+
topItemPosition = position;
10421043
ContentHelper.openHentoidViewer(requireContext(), item.getContent(), viewModel.getSearchManagerBundle());
10431044
} else invalidateNextBookClick = false;
10441045

@@ -1130,20 +1131,15 @@ private void viewQueue() {
11301131
}
11311132

11321133
private void differEndCallback() {
1133-
Timber.i(">> differEnd::topItem = %s", topItemPosition);
11341134
if (topItemPosition > -1) {
11351135
int currentPosition = getTopItemPosition();
1136-
Timber.i(">> differEnd::current vs. memorized %s / %s", currentPosition, topItemPosition);
1137-
if (currentPosition != topItemPosition) {
1138-
Timber.i(">> differEnd::scrolling to last memorized position : %s", topItemPosition);
1139-
// llm.scrollToPositionWithOffset(topItemPosition, 0); // TODO - enable or delete the whole method
1140-
topItemPosition = -1;
1141-
}
1136+
if (currentPosition != topItemPosition)
1137+
llm.scrollToPositionWithOffset(topItemPosition, 0); // Used to restore position after activity has been stopped and recreated
1138+
topItemPosition = -1;
11421139
}
11431140
}
11441141

11451142
private int getTopItemPosition() {
1146-
Timber.i(">> [gettopitem %s %s]", llm.findFirstVisibleItemPosition(), llm.findFirstCompletelyVisibleItemPosition());
11471143
return Math.max(llm.findFirstVisibleItemPosition(), llm.findFirstCompletelyVisibleItemPosition());
11481144
}
11491145
}

0 commit comments

Comments
 (0)