Skip to content

Commit

Permalink
show bookmark item as toggled when page is first entered
Browse files Browse the repository at this point in the history
  • Loading branch information
tahmid-23 committed Mar 12, 2022
1 parent 08360ae commit f33d652
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions app/src/main/java/com/quran/labs/androidquran/ui/PagerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -445,18 +445,7 @@ public void onPageSelected(int position) {
refreshActionBarSpinner();
}

if (bookmarksCache.indexOfKey(page) < 0) {
if (isDualPages && !isSplitScreen) {
if (bookmarksCache.indexOfKey(page - 1) < 0) {
checkIfPageIsBookmarked(page - 1, page);
}
} else {
// we don't have the key
checkIfPageIsBookmarked(page);
}
} else {
refreshBookmarksMenu();
}
refreshBookmarksCache(page);

// If we're more than 1 page away from ayah selection end ayah mode
final SuraAyah suraAyah = getSelectionStart();
Expand Down Expand Up @@ -1036,7 +1025,7 @@ public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
MenuItem item = bookmarksMenuItem;
if (item != null) {
refreshBookmarksMenu();
refreshBookmarksCache(getCurrentPage());
}

MenuItem quran = menu.findItem(R.id.goto_quran);
Expand Down Expand Up @@ -1439,6 +1428,18 @@ public void onError(@NonNull Throwable e) {
}));
}

private void refreshBookmarksCache(int page) {
if (bookmarksCache.indexOfKey(page) < 0) {
if (isDualPageVisible() && bookmarksCache.indexOfKey(page - 1) < 0) {
checkIfPageIsBookmarked(page - 1, page);
} else {
checkIfPageIsBookmarked(page);
}
} else {
refreshBookmarksMenu();
}
}

private void checkIfPageIsBookmarked(Integer... pages) {
compositeDisposable.add(bookmarkModel.getIsBookmarkedObservable(pages)
.observeOn(AndroidSchedulers.mainThread())
Expand Down

0 comments on commit f33d652

Please sign in to comment.