Skip to content

Commit 1d225c5

Browse files
maskaravivekdomdomegg
authored andcommitted
Remove dead code from dialog util (commons-app#2612)
1 parent 0bbfd54 commit 1d225c5

File tree

1 file changed

+9
-92
lines changed

1 file changed

+9
-92
lines changed

app/src/main/java/fr/free/nrw/commons/utils/DialogUtil.java

+9-92
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,21 @@
22

33
import android.app.Activity;
44
import android.app.AlertDialog;
5-
import android.app.AlertDialog.Builder;
65
import android.app.Dialog;
7-
import android.content.Context;
86
import android.content.DialogInterface;
9-
import android.os.Build;
10-
import androidx.annotation.Nullable;
11-
import androidx.fragment.app.DialogFragment;
12-
import androidx.fragment.app.FragmentActivity;
137
import android.view.View;
148

159
import fr.free.nrw.commons.R;
1610
import timber.log.Timber;
1711

1812
public class DialogUtil {
1913

20-
/**
21-
* Dismisses a dialog safely.
22-
* @param activity the activity
23-
* @param dialog the dialog to be dismissed
24-
*/
25-
public static void dismissSafely(@Nullable Activity activity, @Nullable DialogFragment dialog) {
26-
boolean isActivityDestroyed = false;
27-
28-
if (activity == null || dialog == null) {
29-
Timber.d("dismiss called with null activity / dialog. Ignoring.");
30-
return;
31-
}
32-
33-
isActivityDestroyed = activity.isDestroyed();
34-
if (activity.isFinishing() || isActivityDestroyed) {
35-
return;
36-
}
37-
try {
38-
dialog.dismiss();
39-
40-
} catch (IllegalStateException e) {
41-
Timber.e(e, "Could not dismiss dialog.");
42-
}
43-
}
44-
4514
/**
4615
* Shows a dialog safely.
4716
* @param activity the activity
4817
* @param dialog the dialog to be shown
4918
*/
50-
public static void showSafely(Activity activity, Dialog dialog) {
19+
private static void showSafely(Activity activity, Dialog dialog) {
5120
if (activity == null || dialog == null) {
5221
Timber.d("Show called with null activity / dialog. Ignoring.");
5322
return;
@@ -65,52 +34,6 @@ public static void showSafely(Activity activity, Dialog dialog) {
6534
}
6635
}
6736

68-
/**
69-
* Shows a dialog safely.
70-
* @param activity the activity
71-
* @param dialog the dialog to be shown
72-
*/
73-
public static void showSafely(FragmentActivity activity, DialogFragment dialog) {
74-
boolean isActivityDestroyed = false;
75-
76-
if (activity == null || dialog == null) {
77-
Timber.d("show called with null activity / dialog. Ignoring.");
78-
return;
79-
}
80-
81-
isActivityDestroyed = activity.isDestroyed();
82-
if (activity.isFinishing() || isActivityDestroyed) {
83-
return;
84-
}
85-
86-
try {
87-
if (dialog.getDialog() == null || !dialog.getDialog().isShowing()) {
88-
dialog.show(activity.getSupportFragmentManager(), dialog.getClass().getSimpleName());
89-
}
90-
} catch (IllegalStateException e) {
91-
Timber.e(e, "Could not show dialog.");
92-
}
93-
}
94-
95-
public static AlertDialog getAlertDialogWithPositiveAndNegativeCallbacks(
96-
Context context, String title, String message, int iconResourceId, Callback callback) {
97-
98-
AlertDialog alertDialog = new Builder(context)
99-
.setTitle(title)
100-
.setMessage(message)
101-
.setPositiveButton(context.getString(R.string.ok), (dialog, which) -> {
102-
callback.onPositiveButtonClicked();
103-
dialog.dismiss();
104-
})
105-
.setNegativeButton(context.getString(R.string.cancel), (dialog, which) -> {
106-
callback.onNegativeButtonClicked();
107-
dialog.dismiss();
108-
})
109-
.setIcon(iconResourceId).create();
110-
111-
return alertDialog;
112-
}
113-
11437
public static void showAlertDialog(Activity activity,
11538
String title,
11639
String message,
@@ -182,14 +105,14 @@ public static void showAlertDialog(Activity activity,
182105
/*
183106
Shows alert dialog with custom view
184107
*/
185-
public static void showAlertDialog(Activity activity,
186-
String title,
187-
String message,
188-
String positiveButtonText,
189-
String negativeButtonText,
190-
final Runnable onPositiveBtnClick,
191-
final Runnable onNegativeBtnClick,
192-
View customView,
108+
private static void showAlertDialog(Activity activity,
109+
String title,
110+
String message,
111+
String positiveButtonText,
112+
String negativeButtonText,
113+
final Runnable onPositiveBtnClick,
114+
final Runnable onNegativeBtnClick,
115+
View customView,
193116
boolean cancelable) {
194117
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
195118
builder.setTitle(title);
@@ -215,10 +138,4 @@ public static void showAlertDialog(Activity activity,
215138
showSafely(activity, dialog);
216139
}
217140

218-
public interface Callback {
219-
220-
void onPositiveButtonClicked();
221-
222-
void onNegativeButtonClicked();
223-
}
224141
}

0 commit comments

Comments
 (0)