Delete remote file - confirmation dialog added
authorDavid A. Velasco <dvelasco@solidgear.es>
Wed, 11 Jul 2012 16:46:47 +0000 (18:46 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Thu, 12 Jul 2012 07:48:55 +0000 (09:48 +0200)
res/layout/file_details_fragment.xml
res/values/strings.xml
src/eu/alefzero/owncloud/ui/fragment/ConfirmationDialogFragment.java [new file with mode: 0644]
src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java

index 4f9e944..8d0dc7d 100644 (file)
                     android:gravity="center_horizontal" >
 
                     <Button
-                        android:id="@+id/Button01"
+                        android:id="@+id/fdRemoveBtn"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_marginTop="12dp"
index a9ce150..e4a2483 100644 (file)
     <string name="common_share">Share</string>
     <string name="common_rename">Rename</string>
     <string name="common_remove">Remove</string>
+    
+    <string name="confirmation_alert_prefix">Do you really want </string>
+    <string name="confirmation_alert_suffix">"?"</string>
 </resources>
diff --git a/src/eu/alefzero/owncloud/ui/fragment/ConfirmationDialogFragment.java b/src/eu/alefzero/owncloud/ui/fragment/ConfirmationDialogFragment.java
new file mode 100644 (file)
index 0000000..c323a69
--- /dev/null
@@ -0,0 +1,60 @@
+package eu.alefzero.owncloud.ui.fragment;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+
+import com.actionbarsherlock.app.SherlockDialogFragment;
+
+import eu.alefzero.owncloud.R;
+
+public class ConfirmationDialogFragment extends SherlockDialogFragment {
+
+    public final static String ARG_CONF_TARGET = "target";
+    
+    ConfirmationDialogFragmentListener mListener;
+    
+    public static ConfirmationDialogFragment newInstance(String confirmationTarget) {
+        ConfirmationDialogFragment frag = new ConfirmationDialogFragment();
+        Bundle args = new Bundle();
+        args.putString(ARG_CONF_TARGET, confirmationTarget);
+        frag.setArguments(args);
+        return frag;
+    }
+    
+    public void setOnConfirmationListener(ConfirmationDialogFragmentListener listener) {
+        mListener = listener;
+    }
+
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        int confirmationTarget = getArguments().getInt(ARG_CONF_TARGET);
+
+        return new AlertDialog.Builder(getActivity())
+                .setIcon(android.R.drawable.ic_dialog_alert)
+                .setMessage(R.string.confirmation_alert_prefix + confirmationTarget + R.string.confirmation_alert_suffix )
+                .setPositiveButton(R.string.common_ok,
+                    new DialogInterface.OnClickListener() {
+                        public void onClick(DialogInterface dialog, int whichButton) {
+                            mListener.onConfirmation(true, getTag()); 
+                        }
+                    }
+                )
+                .setNegativeButton(R.string.common_cancel,
+                    new DialogInterface.OnClickListener() {
+                        public void onClick(DialogInterface dialog, int whichButton) {
+                            mListener.onConfirmation(false, getTag()); 
+                        }
+                    }
+                )
+                .create();
+    }
+    
+    
+    public interface ConfirmationDialogFragmentListener {
+        public void onConfirmation(boolean confirmation, String callerTag);
+    }
+    
+}
+
index 9b41093..96ed209 100644 (file)
@@ -42,6 +42,8 @@ import org.json.JSONObject;
 \r
 import android.accounts.Account;\r
 import android.accounts.AccountManager;\r
+import android.app.AlertDialog;\r
+import android.app.Dialog;\r
 import android.content.ActivityNotFoundException;\r
 import android.content.BroadcastReceiver;\r
 import android.content.Context;\r
@@ -94,7 +96,7 @@ import eu.alefzero.webdav.WebdavClient;
  * \r
  */\r
 public class FileDetailFragment extends SherlockFragment implements\r
-        OnClickListener {\r
+        OnClickListener, ConfirmationDialogFragment.ConfirmationDialogFragmentListener {\r
 \r
     public static final String EXTRA_FILE = "FILE";\r
     public static final String EXTRA_ACCOUNT = "ACCOUNT";\r
@@ -222,6 +224,12 @@ public class FileDetailFragment extends SherlockFragment implements
                 dialog.show(getFragmentManager(), "nameeditdialog");\r
                 dialog.setOnDismissListener(this);\r
                 break;\r
+            }   \r
+            case R.id.fdRemoveBtn: {\r
+                ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance("remove " + mFile.getFileName());\r
+                confDialog.setOnConfirmationListener(this);\r
+                confDialog.show(getFragmentManager(), "REMOVE_CONFIRMATION_FRAGMENT");\r
+                break;\r
             }\r
             default:\r
                 Log.e(TAG, "Incorrect view clicked!");\r
@@ -232,8 +240,16 @@ public class FileDetailFragment extends SherlockFragment implements
             t.start();\r
         }*/\r
     }\r
-\r
-\r
+    \r
+    \r
+    @Override\r
+    public void onConfirmation(boolean confirmation, String callerTag) {\r
+        if (confirmation && callerTag.equals("REMOVE_CONFIRMATION_FRAGMENT")) {\r
+            // TODO remove in a separated thread\r
+        }\r
+    }\r
+    \r
+    \r
     /**\r
      * Check if the fragment was created with an empty layout. An empty fragment can't show file details, must be replaced.\r
      * \r
@@ -502,7 +518,7 @@ public class FileDetailFragment extends SherlockFragment implements
         \r
     }\r
     \r
-    // this is a temporary class for sharing purposes, it need to be replacead in transfer service\r
+    // this is a temporary class for sharing purposes, it need to be replaced in transfer service\r
     private class ShareRunnable implements Runnable {\r
         private String mPath;\r
 \r
@@ -772,4 +788,5 @@ public class FileDetailFragment extends SherlockFragment implements
         }\r
         \r
     }\r
+\r
 }\r