mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-16 10:56:50 -04:00
Add new Dialogs to ConfirmationDialogFragment.java, Add new method to AlertDialogShower
This commit is contained in:
parent
1684d2e7cf
commit
c0c58eb9fd
@ -19,12 +19,13 @@
|
||||
package org.kiwix.kiwixmobile.core.main;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import org.kiwix.kiwixmobile.core.R;
|
||||
import javax.inject.Inject;
|
||||
import kotlin.Unit;
|
||||
import org.kiwix.kiwixmobile.core.utils.AlertDialogShower;
|
||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog;
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil;
|
||||
|
||||
/**
|
||||
@ -48,6 +49,8 @@ public class ConfirmationAlertDialogFragment extends DialogFragment {
|
||||
private SharedPreferenceUtil sharedPreferenceUtil;
|
||||
private int stringResourceId;
|
||||
private String parentDialogFragmentTAG;
|
||||
@Inject
|
||||
protected AlertDialogShower alertDialogShower;
|
||||
|
||||
public ConfirmationAlertDialogFragment(SharedPreferenceUtil sharedPreferenceUtil,
|
||||
String parentDialogFragmentTAG, int stringResourceId) {
|
||||
@ -59,27 +62,20 @@ public class ConfirmationAlertDialogFragment extends DialogFragment {
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
Fragment parentDialogFragment = getFragmentManager().findFragmentByTag(parentDialogFragmentTAG);
|
||||
|
||||
return new AlertDialog.Builder(getActivity()).setMessage(stringResourceId)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
if (parentDialogFragment != null) {
|
||||
((UserClickListener) parentDialogFragment).onPositiveClick();
|
||||
}
|
||||
return alertDialogShower.create(new KiwixDialog.ConfirmationAlertDialogFragment(stringResourceId),
|
||||
() -> {
|
||||
if (parentDialogFragment != null) {
|
||||
((UserClickListener) parentDialogFragment).onPositiveClick();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
if (parentDialogFragment != null) {
|
||||
((UserClickListener) parentDialogFragment).onNegativeClick();
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
},
|
||||
() -> {
|
||||
if (parentDialogFragment != null) {
|
||||
((UserClickListener) parentDialogFragment).onNegativeClick();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,12 +19,17 @@
|
||||
package org.kiwix.kiwixmobile.core.utils
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import javax.inject.Inject
|
||||
|
||||
class AlertDialogShower @Inject constructor(private val activity: Activity) : DialogShower {
|
||||
override fun show(dialog: KiwixDialog, vararg clickListeners: () -> Unit) {
|
||||
AlertDialog.Builder(activity)
|
||||
create(dialog, *clickListeners)
|
||||
}
|
||||
|
||||
override fun create(dialog: KiwixDialog, vararg clickListeners: () -> Unit): Dialog {
|
||||
return AlertDialog.Builder(activity)
|
||||
.apply {
|
||||
dialog.title?.let(this::setTitle)
|
||||
dialog.icon?.let(this::setIcon)
|
||||
@ -55,7 +60,7 @@ class AlertDialogShower @Inject constructor(private val activity: Activity) : Di
|
||||
dialog.getView?.let { setView(it()) }
|
||||
setCancelable(dialog.cancelable)
|
||||
}
|
||||
.show()
|
||||
.create()
|
||||
}
|
||||
|
||||
private fun bodyArguments(dialog: KiwixDialog) =
|
||||
|
@ -17,9 +17,16 @@
|
||||
*/
|
||||
package org.kiwix.kiwixmobile.core.utils
|
||||
|
||||
import android.app.Dialog
|
||||
|
||||
interface DialogShower {
|
||||
fun show(
|
||||
dialog: KiwixDialog,
|
||||
vararg clickListeners: (() -> Unit)
|
||||
)
|
||||
|
||||
fun create(
|
||||
dialog: KiwixDialog,
|
||||
vararg clickListeners: (() -> Unit)
|
||||
): Dialog
|
||||
}
|
||||
|
@ -161,6 +161,13 @@ sealed class KiwixDialog(
|
||||
getView = customGetView
|
||||
)
|
||||
|
||||
data class ConfirmationAlertDialogFragment(val CustomMessage: Int) : KiwixDialog(
|
||||
null,
|
||||
CustomMessage,
|
||||
R.string.yes,
|
||||
android.R.string.cancel
|
||||
)
|
||||
|
||||
open class YesNoDialog(
|
||||
title: Int,
|
||||
message: Int
|
||||
|
Loading…
x
Reference in New Issue
Block a user