Remove show toast method call from cancel timer to ensure that toast show is called only once. #118

This commit is contained in:
EddyVerbruggen
2018-08-22 09:37:36 +02:00
parent e4e18f143a
commit 8869b81749
4 changed files with 11 additions and 4 deletions
+8 -2
View File
@@ -36,6 +36,7 @@ public class Toast extends CordovaPlugin {
private ViewGroup viewGroup;
private static final boolean IS_AT_LEAST_LOLLIPOP = Build.VERSION.SDK_INT >= 21;
private static final boolean IS_AT_LEAST_PIE = Build.VERSION.SDK_INT >= 28;
// note that webView.isPaused() is not Xwalk compatible, so tracking it poor-man style
private boolean isPaused;
@@ -192,7 +193,12 @@ public class Toast extends CordovaPlugin {
}
// trigger show every 2500 ms for as long as the requested duration
_timer = new CountDownTimer(hideAfterMs, 2500) {
public void onTick(long millisUntilFinished) { }
public void onTick(long millisUntilFinished) {
// see https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin/issues/116
if (!IS_AT_LEAST_PIE) {
toast.show();
}
}
public void onFinish() {
returnTapEvent("hide", msg, data, callbackContext);
toast.cancel();
@@ -257,4 +263,4 @@ public class Toast extends CordovaPlugin {
public void onResume(boolean multitasking) {
this.isPaused = false;
}
}
}