Skip to content

Commit

Permalink
Prevent extra click after long press on Android O and greater
Browse files Browse the repository at this point in the history
  • Loading branch information
bluemarvin committed Mar 11, 2020
1 parent f7dae11 commit 243217e
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.content.res.Configuration;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Build;
import android.preference.PreferenceManager;
import android.util.AttributeSet;
import android.util.Log;
Expand Down Expand Up @@ -103,6 +104,7 @@ public interface NavigationListener {
private int mBlockedCount;
private Executor mUIThreadExecutor;
private ArrayList<NavigationListener> mNavigationListeners;
private boolean mAfterLongClick = false;

public NavigationBarWidget(Context aContext) {
super(aContext);
Expand Down Expand Up @@ -183,6 +185,10 @@ private void updateUI() {
});

mBinding.navigationBarNavigation.reloadButton.setOnClickListener(v -> {
if (mAfterLongClick) {
mAfterLongClick = false;
return;
}
v.requestFocusFromTouch();
if (mViewModel.getIsLoading().getValue().get()) {
getSession().stop();
Expand All @@ -207,6 +213,9 @@ private void updateUI() {
mAudio.playSound(AudioEngine.Sound.CLICK);
}
mNavigationListeners.forEach(NavigationListener::onReload);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mAfterLongClick = true;
}
return true;
});

Expand Down

0 comments on commit 243217e

Please sign in to comment.