From db987952bba4b277bf8fde27bcda64189575ec1e Mon Sep 17 00:00:00 2001 From: Sergey Eremin Date: Fri, 18 May 2018 15:48:55 +0300 Subject: [PATCH] Making sure dialogs are shown on the ui thread --- .../yalpstore/view/DialogWrapper.java | 30 ++++++++++++++++--- .../yalpstore/view/DialogWrapper.java | 30 ++++++++++++++++--- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/app/src/contemporary/java/com/github/yeriomin/yalpstore/view/DialogWrapper.java b/app/src/contemporary/java/com/github/yeriomin/yalpstore/view/DialogWrapper.java index 8d2a474c..6b279172 100644 --- a/app/src/contemporary/java/com/github/yeriomin/yalpstore/view/DialogWrapper.java +++ b/app/src/contemporary/java/com/github/yeriomin/yalpstore/view/DialogWrapper.java @@ -26,6 +26,8 @@ import android.view.View; import android.widget.ListAdapter; +import com.github.yeriomin.yalpstore.ContextUtil; + public class DialogWrapper extends DialogWrapperAbstract { protected AlertDialog.Builder builder; @@ -120,7 +122,12 @@ public DialogWrapperAbstract setCancelable(boolean cancelable) { @Override public DialogWrapperAbstract create() { - dialog = builder.create(); + ContextUtil.runOnUiThread(new Runnable() { + @Override + public void run() { + dialog = builder.create(); + } + }); return this; } @@ -129,21 +136,36 @@ public DialogWrapperAbstract show() { if (null == dialog) { create(); } - dialog.show(); + ContextUtil.runOnUiThread(new Runnable() { + @Override + public void run() { + dialog.show(); + } + }); return this; } @Override public void cancel() { if (null != dialog) { - dialog.cancel(); + ContextUtil.runOnUiThread(new Runnable() { + @Override + public void run() { + dialog.cancel(); + } + }); } } @Override public void dismiss() { if (null != dialog) { - dialog.dismiss(); + ContextUtil.runOnUiThread(new Runnable() { + @Override + public void run() { + dialog.dismiss(); + } + }); } } } diff --git a/app/src/legacy/java/com/github/yeriomin/yalpstore/view/DialogWrapper.java b/app/src/legacy/java/com/github/yeriomin/yalpstore/view/DialogWrapper.java index 94a65dba..3bfd7123 100644 --- a/app/src/legacy/java/com/github/yeriomin/yalpstore/view/DialogWrapper.java +++ b/app/src/legacy/java/com/github/yeriomin/yalpstore/view/DialogWrapper.java @@ -26,6 +26,8 @@ import android.view.View; import android.widget.ListAdapter; +import com.github.yeriomin.yalpstore.ContextUtil; + public class DialogWrapper extends DialogWrapperAbstract { protected AlertDialog.Builder builder; @@ -120,7 +122,12 @@ public DialogWrapperAbstract setCancelable(boolean cancelable) { @Override public DialogWrapperAbstract create() { - dialog = builder.create(); + ContextUtil.runOnUiThread(new Runnable() { + @Override + public void run() { + dialog = builder.create(); + } + }); return this; } @@ -129,21 +136,36 @@ public DialogWrapperAbstract show() { if (null == dialog) { create(); } - dialog.show(); + ContextUtil.runOnUiThread(new Runnable() { + @Override + public void run() { + dialog.show(); + } + }); return this; } @Override public void cancel() { if (null != dialog) { - dialog.cancel(); + ContextUtil.runOnUiThread(new Runnable() { + @Override + public void run() { + dialog.cancel(); + } + }); } } @Override public void dismiss() { if (null != dialog) { - dialog.dismiss(); + ContextUtil.runOnUiThread(new Runnable() { + @Override + public void run() { + dialog.dismiss(); + } + }); } } }