From 1d225c545e781651236cfef773268851db625176 Mon Sep 17 00:00:00 2001 From: Vivek Maskara Date: Sat, 16 Mar 2019 18:25:44 +0530 Subject: [PATCH] Remove dead code from dialog util (#2612) --- .../fr/free/nrw/commons/utils/DialogUtil.java | 101 ++---------------- 1 file changed, 9 insertions(+), 92 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/utils/DialogUtil.java b/app/src/main/java/fr/free/nrw/commons/utils/DialogUtil.java index 15e32b080..8ca900b21 100644 --- a/app/src/main/java/fr/free/nrw/commons/utils/DialogUtil.java +++ b/app/src/main/java/fr/free/nrw/commons/utils/DialogUtil.java @@ -2,14 +2,8 @@ package fr.free.nrw.commons.utils; import android.app.Activity; import android.app.AlertDialog; -import android.app.AlertDialog.Builder; import android.app.Dialog; -import android.content.Context; import android.content.DialogInterface; -import android.os.Build; -import androidx.annotation.Nullable; -import androidx.fragment.app.DialogFragment; -import androidx.fragment.app.FragmentActivity; import android.view.View; import fr.free.nrw.commons.R; @@ -17,37 +11,12 @@ import timber.log.Timber; public class DialogUtil { - /** - * Dismisses a dialog safely. - * @param activity the activity - * @param dialog the dialog to be dismissed - */ - public static void dismissSafely(@Nullable Activity activity, @Nullable DialogFragment dialog) { - boolean isActivityDestroyed = false; - - if (activity == null || dialog == null) { - Timber.d("dismiss called with null activity / dialog. Ignoring."); - return; - } - - isActivityDestroyed = activity.isDestroyed(); - if (activity.isFinishing() || isActivityDestroyed) { - return; - } - try { - dialog.dismiss(); - - } catch (IllegalStateException e) { - Timber.e(e, "Could not dismiss dialog."); - } - } - /** * Shows a dialog safely. * @param activity the activity * @param dialog the dialog to be shown */ - public static void showSafely(Activity activity, Dialog dialog) { + private static void showSafely(Activity activity, Dialog dialog) { if (activity == null || dialog == null) { Timber.d("Show called with null activity / dialog. Ignoring."); return; @@ -65,52 +34,6 @@ public class DialogUtil { } } - /** - * Shows a dialog safely. - * @param activity the activity - * @param dialog the dialog to be shown - */ - public static void showSafely(FragmentActivity activity, DialogFragment dialog) { - boolean isActivityDestroyed = false; - - if (activity == null || dialog == null) { - Timber.d("show called with null activity / dialog. Ignoring."); - return; - } - - isActivityDestroyed = activity.isDestroyed(); - if (activity.isFinishing() || isActivityDestroyed) { - return; - } - - try { - if (dialog.getDialog() == null || !dialog.getDialog().isShowing()) { - dialog.show(activity.getSupportFragmentManager(), dialog.getClass().getSimpleName()); - } - } catch (IllegalStateException e) { - Timber.e(e, "Could not show dialog."); - } - } - - public static AlertDialog getAlertDialogWithPositiveAndNegativeCallbacks( - Context context, String title, String message, int iconResourceId, Callback callback) { - - AlertDialog alertDialog = new Builder(context) - .setTitle(title) - .setMessage(message) - .setPositiveButton(context.getString(R.string.ok), (dialog, which) -> { - callback.onPositiveButtonClicked(); - dialog.dismiss(); - }) - .setNegativeButton(context.getString(R.string.cancel), (dialog, which) -> { - callback.onNegativeButtonClicked(); - dialog.dismiss(); - }) - .setIcon(iconResourceId).create(); - - return alertDialog; - } - public static void showAlertDialog(Activity activity, String title, String message, @@ -182,14 +105,14 @@ public class DialogUtil { /* Shows alert dialog with custom view */ - public static void showAlertDialog(Activity activity, - String title, - String message, - String positiveButtonText, - String negativeButtonText, - final Runnable onPositiveBtnClick, - final Runnable onNegativeBtnClick, - View customView, + private static void showAlertDialog(Activity activity, + String title, + String message, + String positiveButtonText, + String negativeButtonText, + final Runnable onPositiveBtnClick, + final Runnable onNegativeBtnClick, + View customView, boolean cancelable) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(title); @@ -215,10 +138,4 @@ public class DialogUtil { showSafely(activity, dialog); } - public interface Callback { - - void onPositiveButtonClicked(); - - void onNegativeButtonClicked(); - } }