Skip to content

Commit

Permalink
Fix a crash when the translation view is scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedre committed May 26, 2017
1 parent eff9f20 commit 62a4e3d
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public TranslationView(Context context, AttributeSet attrs, int defStyleAttr) {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);

// do not modify the RecyclerView from this method or any method called from
// the onScrolled listener, since most modification methods cannot be called
// while the RecyclerView is computing layout or scrolling
if (selectedAyah != null) {
updateAyahToolBarPosition();
}
Expand Down Expand Up @@ -153,12 +157,18 @@ public void onClick(View v) {
}
}

/**
* This method updates the toolbar position when an ayah is selected
* This method is called from the onScroll listener, and as thus must make sure not to ask
* the RecyclerView to change anything (otherwise, it will result in a crash, as methods to
* update the RecyclerView cannot be called amidst scrolling or computing of a layout).
*/
private void updateAyahToolBarPosition() {
int[] versePopupPosition = translationAdapter.getSelectedVersePopupPosition();
if (versePopupPosition != null) {
AyahToolBar.AyahToolBarPosition position = new AyahToolBar.AyahToolBarPosition();
if (versePopupPosition[1] > getHeight() || versePopupPosition[1] < 0) {
unhighlightAyat();
ayahToolBar.hideMenu();
} else {
position.x = versePopupPosition[0];
position.y = versePopupPosition[1];
Expand Down

0 comments on commit 62a4e3d

Please sign in to comment.