X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/eb2a7bcec2bf9c9f3e6d12b1b89c775d70baeed3..e8852fa725ccd1adb25c7af1fd1ddf2429f67a8f:/src/eu/alefzero/owncloud/ui/fragment/ConfirmationDialogFragment.java diff --git a/src/eu/alefzero/owncloud/ui/fragment/ConfirmationDialogFragment.java b/src/eu/alefzero/owncloud/ui/fragment/ConfirmationDialogFragment.java index d977474c..cc6a0f7f 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/ConfirmationDialogFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/ConfirmationDialogFragment.java @@ -4,6 +4,7 @@ import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; +import android.util.Log; import com.actionbarsherlock.app.SherlockDialogFragment; @@ -11,14 +12,23 @@ import eu.alefzero.owncloud.R; public class ConfirmationDialogFragment extends SherlockDialogFragment { - public final static String ARG_CONF_TARGET = "target"; + public final static String ARG_CONF_RESOURCE_ID = "resource_id"; + public final static String ARG_CONF_ARGUMENTS = "string_array"; - ConfirmationDialogFragmentListener mListener; + public final static String ARG_POSITIVE_BTN_RES = "positive_btn_res"; + public final static String ARG_NEUTRAL_BTN_RES = "neutral_btn_res"; + public final static String ARG_NEGATIVE_BTN_RES = "negative_btn_res"; - public static ConfirmationDialogFragment newInstance(String confirmationTarget) { + private ConfirmationDialogFragmentListener mListener; + + public static ConfirmationDialogFragment newInstance(int string_id, String[] arguments, int posBtn, int neuBtn, int negBtn) { ConfirmationDialogFragment frag = new ConfirmationDialogFragment(); Bundle args = new Bundle(); - args.putString(ARG_CONF_TARGET, confirmationTarget); + args.putInt(ARG_CONF_RESOURCE_ID, string_id); + args.putStringArray(ARG_CONF_ARGUMENTS, arguments); + args.putInt(ARG_POSITIVE_BTN_RES, posBtn); + args.putInt(ARG_NEUTRAL_BTN_RES, neuBtn); + args.putInt(ARG_NEGATIVE_BTN_RES, negBtn); frag.setArguments(args); return frag; } @@ -29,33 +39,55 @@ public class ConfirmationDialogFragment extends SherlockDialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - String confirmationTarget = getArguments().getString(ARG_CONF_TARGET); - if (confirmationTarget == null) - confirmationTarget = ""; - - return new AlertDialog.Builder(getActivity()) - .setIcon(android.R.drawable.ic_dialog_alert) - .setMessage(String.format(getString(R.string.confirmation_alert_prefix), confirmationTarget)) - .setPositiveButton(R.string.common_ok, + Object[] confirmationTarget = getArguments().getStringArray(ARG_CONF_ARGUMENTS); + int resourceId = getArguments().getInt(ARG_CONF_RESOURCE_ID, -1); + int posBtn = getArguments().getInt(ARG_POSITIVE_BTN_RES, -1); + int neuBtn = getArguments().getInt(ARG_NEUTRAL_BTN_RES, -1); + int negBtn = getArguments().getInt(ARG_NEGATIVE_BTN_RES, -1); + + if (confirmationTarget == null || resourceId == -1) { + Log.wtf(getTag(), "Calling confirmation dialog without resource or arguments"); + return null; + } + + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()) + .setIcon(android.R.drawable.ic_dialog_alert) + .setMessage(String.format(getString(resourceId), confirmationTarget)) + .setTitle(android.R.string.dialog_alert_title); + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { + builder.setIconAttribute(android.R.attr.alertDialogIcon); + } + + if (posBtn != -1) + builder.setPositiveButton(posBtn, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { - mListener.onConfirmation(true, getTag()); + mListener.onConfirmation(getTag()); } - } - ) - .setNegativeButton(R.string.common_cancel, + }); + if (neuBtn != -1) + builder.setNeutralButton(neuBtn, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { - mListener.onConfirmation(false, getTag()); + mListener.onNeutral(getTag()); + } + }); + if (negBtn != -1) + builder.setNegativeButton(negBtn, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + mListener.onCancel(getTag()); } - } - ) - .create(); + }); + return builder.create(); } public interface ConfirmationDialogFragmentListener { - public void onConfirmation(boolean confirmation, String callerTag); + public void onConfirmation(String callerTag); + public void onNeutral(String callerTag); + public void onCancel(String callerTag); } }