From 5cfe709281bce78d1927796a273ab088d8a7599a Mon Sep 17 00:00:00 2001 From: Vivek Maskara Date: Sun, 22 Jul 2018 21:21:41 +0530 Subject: [PATCH] Fix view util methods to always execute on UI thread (#1728) --- .../java/fr/free/nrw/commons/utils/ViewUtil.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/utils/ViewUtil.java b/app/src/main/java/fr/free/nrw/commons/utils/ViewUtil.java index 0c22a40a2..af71e826d 100644 --- a/app/src/main/java/fr/free/nrw/commons/utils/ViewUtil.java +++ b/app/src/main/java/fr/free/nrw/commons/utils/ViewUtil.java @@ -15,12 +15,19 @@ public class ViewUtil { public static final String SHOWCASE_VIEW_ID_3 = "SHOWCASE_VIEW_ID_3"; public static void showSnackbar(View view, int messageResourceId) { - Snackbar.make(view, messageResourceId, Snackbar.LENGTH_SHORT).show(); + if(view.getContext() == null) { + return; + } + + ExecutorUtils.uiExecutor().execute(() -> Snackbar.make(view, messageResourceId, Snackbar.LENGTH_SHORT).show()); } public static void showLongToast(Context context, String text) { - Toast.makeText(context, text, - Toast.LENGTH_LONG).show(); + if (context == null) { + return; + } + + ExecutorUtils.uiExecutor().execute(() -> Toast.makeText(context, text, Toast.LENGTH_LONG).show()); } public static boolean isPortrait(Context context) {