allow removing local file only
authorBartek Przybylski <bart.p.pl@gmail.com>
Sat, 28 Jul 2012 19:15:41 +0000 (21:15 +0200)
committerBartek Przybylski <bart.p.pl@gmail.com>
Sat, 28 Jul 2012 19:15:41 +0000 (21:15 +0200)
res/values/strings.xml
src/eu/alefzero/owncloud/ui/fragment/ConfirmationDialogFragment.java
src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java

index 7ade27c..fa3e924 100644 (file)
@@ -15,7 +15,7 @@
     <string name="main_tit_accsetup">Setup Account</string>
     <string name="main_wrn_accsetup">There are no ownCloud accounts on your device. In order to use this App, you need to create one.</string>
     
     <string name="main_tit_accsetup">Setup Account</string>
     <string name="main_wrn_accsetup">There are no ownCloud accounts on your device. In order to use this App, you need to create one.</string>
     
-    <string name="actionbar_sync">Sync account</string>
+    <string name="actionbar_sync">Refresh</string>
     <string name="actionbar_upload">Upload file</string>
     <string name="actionbar_mkdir">Create directory</string>
     <string name="actionbar_search">Search</string>
     <string name="actionbar_upload">Upload file</string>
     <string name="actionbar_mkdir">Create directory</string>
     <string name="actionbar_search">Search</string>
     <string name="common_rename">Rename</string>
     <string name="common_remove">Remove</string>
     
     <string name="common_rename">Rename</string>
     <string name="common_remove">Remove</string>
     
-       <string name="confirmation_remove_alert">"Do you really want to remove %1$s ?"</string>
+         <string name="confirmation_remove_alert">"Do you really want to remove %1$s ?"</string>
+         <string name="confirmation_remove_local">Local only</string>
+         <string name="confirmation_remove_remote">Remove form server</string>
+         <string name="confirmation_remove_remote_and_local">Both remote and local</string>
 
     <string name="remove_success_msg">"Successful removal"</string>
     <string name="remove_fail_msg">"Removal could not be completed"</string>
 
     <string name="remove_success_msg">"Successful removal"</string>
     <string name="remove_fail_msg">"Removal could not be completed"</string>
index c5394f8..110f337 100644 (file)
@@ -15,13 +15,20 @@ public class ConfirmationDialogFragment extends SherlockDialogFragment {
     public final static String ARG_CONF_RESOURCE_ID = "resource_id";
     public final static String ARG_CONF_ARGUMENTS = "string_array";
     
     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(int string_id, String[] arguments) {
+    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.putInt(ARG_CONF_RESOURCE_ID, string_id);
         args.putStringArray(ARG_CONF_ARGUMENTS, arguments);
         ConfirmationDialogFragment frag = new ConfirmationDialogFragment();
         Bundle args = new Bundle();
         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;
     }
         frag.setArguments(args);
         return frag;
     }
@@ -34,34 +41,51 @@ public class ConfirmationDialogFragment extends SherlockDialogFragment {
     public Dialog onCreateDialog(Bundle savedInstanceState) {
         Object[] confirmationTarget = getArguments().getStringArray(ARG_CONF_ARGUMENTS);
         int resourceId = getArguments().getInt(ARG_CONF_RESOURCE_ID, -1);
     public Dialog onCreateDialog(Bundle savedInstanceState) {
         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;
         }
 
         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(resourceId), confirmationTarget))
-                .setPositiveButton(R.string.common_ok,
+        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
+            .setIcon(android.R.drawable.ic_dialog_alert)
+            .setMessage(String.format(getString(resourceId), confirmationTarget))
+            .setIconAttribute(android.R.attr.alertDialogIcon)
+            .setTitle(android.R.string.dialog_alert_title);
+        
+        if (posBtn != -1)
+            builder.setPositiveButton(posBtn,
                     new DialogInterface.OnClickListener() {
                         public void onClick(DialogInterface dialog, int whichButton) {
                     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) {
                     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 interface ConfirmationDialogFragmentListener {
-        public void onConfirmation(boolean confirmation, String callerTag);
+        public void onConfirmation(String callerTag);
+        public void onNeutral(String callerTag);
+        public void onCancel(String callerTag);
     }
     
 }
     }
     
 }
index aa59a5c..d7fb886 100644 (file)
@@ -273,7 +273,12 @@ public class FileDetailFragment extends SherlockFragment implements
                 break;\r
             }   \r
             case R.id.fdRemoveBtn: {\r
                 break;\r
             }   \r
             case R.id.fdRemoveBtn: {\r
-                ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(R.string.confirmation_remove_alert, new String[]{mFile.getFileName()});\r
+                ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(\r
+                        R.string.confirmation_remove_alert,\r
+                        new String[]{mFile.getFileName()},\r
+                        mFile.isDown() ? R.string.confirmation_remove_remote_and_local : R.string.confirmation_remove_remote,\r
+                        mFile.isDown() ? R.string.confirmation_remove_local : -1,\r
+                        R.string.common_cancel);\r
                 confDialog.setOnConfirmationListener(this);\r
                 confDialog.show(getFragmentManager(), FTAG_CONFIRMATION);\r
                 break;\r
                 confDialog.setOnConfirmationListener(this);\r
                 confDialog.show(getFragmentManager(), FTAG_CONFIRMATION);\r
                 break;\r
@@ -331,14 +336,31 @@ public class FileDetailFragment extends SherlockFragment implements
     \r
     \r
     @Override\r
     \r
     \r
     @Override\r
-    public void onConfirmation(boolean confirmation, String callerTag) {\r
-        if (confirmation && callerTag.equals(FTAG_CONFIRMATION)) {\r
+    public void onConfirmation(String callerTag) {\r
+        if (callerTag.equals(FTAG_CONFIRMATION)) {\r
             Log.e("ASD","onConfirmation");\r
             FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver());\r
             if (fdsm.getFileById(mFile.getFileId()) != null) {\r
                 new Thread(new RemoveRunnable(mFile, mAccount, new Handler())).start();\r
             }\r
             Log.e("ASD","onConfirmation");\r
             FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver());\r
             if (fdsm.getFileById(mFile.getFileId()) != null) {\r
                 new Thread(new RemoveRunnable(mFile, mAccount, new Handler())).start();\r
             }\r
-        } else if (!confirmation) Log.d(TAG, "REMOVAL CANCELED");\r
+        }\r
+    }\r
+    \r
+    @Override\r
+    public void onNeutral(String callerTag) {\r
+        FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver());\r
+        File f = null;\r
+        if (mFile.isDown() && (f = new File(mFile.getStoragePath())).exists()) {\r
+            f.delete();\r
+            mFile.setStoragePath(null);\r
+            fdsm.saveFile(mFile);\r
+            updateFileDetails(mFile, mAccount);\r
+        }\r
+    }\r
+    \r
+    @Override\r
+    public void onCancel(String callerTag) {\r
+        Log.d(TAG, "REMOVAL CANCELED");\r
     }\r
     \r
     \r
     }\r
     \r
     \r