Jelajahi Sumber

make confirmation dialog more universal

Bartek Przybylski 12 tahun lalu
induk
melakukan
7f75f13f0c

+ 1 - 1
res/values/strings.xml

@@ -131,7 +131,7 @@
     <string name="common_rename">Rename</string>
     <string name="common_remove">Remove</string>
     
-	<string name="confirmation_alert">"Do you really want %1$s ?"</string>
+	<string name="confirmation_remove_alert">"Do you really want to remove %1$s ?"</string>
 
     <string name="remove_success_msg">"Successful removal"</string>
     <string name="remove_fail_msg">"Removal could not be completed"</string>

+ 13 - 7
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,16 @@ 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 static ConfirmationDialogFragment newInstance(String confirmationTarget) {
+    public static ConfirmationDialogFragment newInstance(int string_id, String[] arguments) {
         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);
         frag.setArguments(args);
         return frag;
     }
@@ -29,13 +32,16 @@ public class ConfirmationDialogFragment extends SherlockDialogFragment {
 
     @Override
     public Dialog onCreateDialog(Bundle savedInstanceState) {
-        String confirmationTarget = getArguments().getString(ARG_CONF_TARGET);
-        if (confirmationTarget == null)
-            confirmationTarget = "";
+        Object[] confirmationTarget = getArguments().getStringArray(ARG_CONF_ARGUMENTS);
+        int resourceId = getArguments().getInt(ARG_CONF_RESOURCE_ID, -1);
+        if (confirmationTarget == null || resourceId == -1) {
+            Log.wtf(getTag(), "Calling confirmation dialog without resource or arguments");
+            return null;
+        }
 
         return new AlertDialog.Builder(getActivity())
                 .setIcon(android.R.drawable.ic_dialog_alert)
-                .setMessage(String.format(getString(R.string.confirmation_alert), confirmationTarget))
+                .setMessage(String.format(getString(resourceId), confirmationTarget))
                 .setPositiveButton(R.string.common_ok,
                     new DialogInterface.OnClickListener() {
                         public void onClick(DialogInterface dialog, int whichButton) {

+ 1 - 1
src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java

@@ -241,7 +241,7 @@ public class FileDetailFragment extends SherlockFragment implements
                 break;
             }   
             case R.id.fdRemoveBtn: {
-                ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance("to remove " + mFile.getFileName());
+                ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(R.string.confirmation_remove_alert, new String[]{mFile.getFileName()});
                 confDialog.setOnConfirmationListener(this);
                 confDialog.show(getFragmentManager(), FTAG_CONFIRMATION);
                 break;