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