mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Remove dead code from dialog util (#2612)
This commit is contained in:
parent
0bbfd54465
commit
1d225c545e
1 changed files with 9 additions and 92 deletions
|
|
@ -2,14 +2,8 @@ package fr.free.nrw.commons.utils;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.AlertDialog.Builder;
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
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 android.view.View;
|
||||||
|
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
|
|
@ -17,37 +11,12 @@ import timber.log.Timber;
|
||||||
|
|
||||||
public class DialogUtil {
|
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.
|
* Shows a dialog safely.
|
||||||
* @param activity the activity
|
* @param activity the activity
|
||||||
* @param dialog the dialog to be shown
|
* @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) {
|
if (activity == null || dialog == null) {
|
||||||
Timber.d("Show called with null activity / dialog. Ignoring.");
|
Timber.d("Show called with null activity / dialog. Ignoring.");
|
||||||
return;
|
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,
|
public static void showAlertDialog(Activity activity,
|
||||||
String title,
|
String title,
|
||||||
String message,
|
String message,
|
||||||
|
|
@ -182,7 +105,7 @@ public class DialogUtil {
|
||||||
/*
|
/*
|
||||||
Shows alert dialog with custom view
|
Shows alert dialog with custom view
|
||||||
*/
|
*/
|
||||||
public static void showAlertDialog(Activity activity,
|
private static void showAlertDialog(Activity activity,
|
||||||
String title,
|
String title,
|
||||||
String message,
|
String message,
|
||||||
String positiveButtonText,
|
String positiveButtonText,
|
||||||
|
|
@ -215,10 +138,4 @@ public class DialogUtil {
|
||||||
showSafely(activity, dialog);
|
showSafely(activity, dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Callback {
|
|
||||||
|
|
||||||
void onPositiveButtonClicked();
|
|
||||||
|
|
||||||
void onNegativeButtonClicked();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue