allow removing local file only
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / ui / fragment / FileDetailFragment.java
index ce1ede9..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
@@ -406,51 +428,6 @@ public class FileDetailFragment extends SherlockFragment implements
                 \r
                 setButtonsForDown();\r
                 \r
                 \r
                 setButtonsForDown();\r
                 \r
-                // Change download button to open button\r
-                /*downloadButton.setText(R.string.filedetails_open);\r
-                downloadButton.setOnClickListener(new OnClickListener() {\r
-                    @Override\r
-                    public void onClick(View v) {\r
-                        String storagePath = mFile.getStoragePath();\r
-                        String encodedStoragePath = WebdavUtils.encodePath(storagePath);\r
-                        try {\r
-                            Intent i = new Intent(Intent.ACTION_VIEW);\r
-                            i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mFile.getMimetype());\r
-                            i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);\r
-                            startActivity(i);\r
-                            \r
-                        } catch (Throwable t) {\r
-                            Log.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.getMimetype());\r
-                            boolean toastIt = true; \r
-                            String mimeType = "";\r
-                            try {\r
-                                Intent i = new Intent(Intent.ACTION_VIEW);\r
-                                mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));\r
-                                if (mimeType != null && !mimeType.equals(mFile.getMimetype())) {\r
-                                    i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mimeType);\r
-                                    i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);\r
-                                    startActivity(i);\r
-                                    toastIt = false;\r
-                                }\r
-                                \r
-                            } catch (IndexOutOfBoundsException e) {\r
-                                Log.e(TAG, "Trying to find out MIME type of a file without extension: " + storagePath);\r
-                                \r
-                            } catch (ActivityNotFoundException e) {\r
-                                Log.e(TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType + " obtained from extension");\r
-                                \r
-                            } catch (Throwable th) {\r
-                                Log.e(TAG, "Unexpected problem when opening: " + storagePath, th);\r
-                                \r
-                            } finally {\r
-                                if (toastIt) {\r
-                                    Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT).show();\r
-                                }\r
-                            }\r
-                            \r
-                        }\r
-                    }\r
-                });*/\r
             } else {\r
                 setButtonsForRemote();\r
             }\r
             } else {\r
                 setButtonsForRemote();\r
             }\r