Skip to content

Commit

Permalink
Making sure dialogs are shown on the ui thread
Browse files Browse the repository at this point in the history
  • Loading branch information
yeriomin committed May 18, 2018
1 parent d898574 commit db98795
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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();
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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();
}
});
}
}
}

0 comments on commit db98795

Please sign in to comment.