Cancellation of current download in details view - UI changes
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / fragment / FileDetailFragment.java
index 4772ddf..5b76c01 100644 (file)
@@ -35,7 +35,6 @@ import org.apache.http.protocol.HTTP;
 import org.apache.jackrabbit.webdav.client.methods.DavMethodBase;\r
 import org.apache.jackrabbit.webdav.client.methods.DeleteMethod;\r
 import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;\r
-import org.json.JSONException;\r
 import org.json.JSONObject;\r
 \r
 import android.accounts.Account;\r
@@ -79,7 +78,6 @@ import com.owncloud.android.authenticator.AccountAuthenticator;
 import com.owncloud.android.datamodel.FileDataStorageManager;\r
 import com.owncloud.android.datamodel.OCFile;\r
 import com.owncloud.android.files.services.FileDownloader;\r
-import com.owncloud.android.files.services.FileObserverService;\r
 import com.owncloud.android.files.services.FileUploader;\r
 import com.owncloud.android.network.OwnCloudClientUtils;\r
 import com.owncloud.android.ui.activity.FileDetailActivity;\r
@@ -244,17 +242,29 @@ public class FileDetailFragment extends SherlockFragment implements
     public void onClick(View v) {\r
         switch (v.getId()) {\r
             case R.id.fdDownloadBtn: {\r
-                Intent i = new Intent(getActivity(), FileDownloader.class);\r
-                i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);\r
-                i.putExtra(FileDownloader.EXTRA_REMOTE_PATH, mFile.getRemotePath());\r
-                i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getRemotePath());\r
-                i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength());\r
+                if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath())) {\r
+                    \r
+                    // TODO cancelar descarga\r
+                    \r
+                    if (mFile.isDown()) {\r
+                        setButtonsForDown();\r
+                    } else {\r
+                        setButtonsForRemote();\r
+                    }\r
+                    \r
+                } else {\r
+                    Intent i = new Intent(getActivity(), FileDownloader.class);\r
+                    i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);\r
+                    i.putExtra(FileDownloader.EXTRA_REMOTE_PATH, mFile.getRemotePath());\r
+                    i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getRemotePath());\r
+                    i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength());\r
                 \r
-                // update ui \r
-                setButtonsForTransferring();\r
+                    // update ui \r
+                    setButtonsForTransferring();\r
                 \r
-                getActivity().startService(i);\r
-                mContainerActivity.onFileStateChanged();    // this is not working; it is performed before the fileDownloadService registers it as 'in progress'\r
+                    getActivity().startService(i);\r
+                    mContainerActivity.onFileStateChanged();    // this is not working; it is performed before the fileDownloadService registers it as 'in progress'\r
+                }\r
                 break;\r
             }\r
             case R.id.fdKeepInSync: {\r
@@ -510,8 +520,8 @@ public class FileDetailFragment extends SherlockFragment implements
     private void setButtonsForTransferring() {\r
         if (!isEmpty()) {\r
             Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);\r
-            //downloadButton.setText(R.string.filedetails_download_in_progress);    // ugly\r
-            downloadButton.setEnabled(false);   // TODO replace it with a 'cancel download' button\r
+            downloadButton.setText(R.string.common_cancel);\r
+            //downloadButton.setEnabled(false);\r
         \r
             // let's protect the user from himself ;)\r
             ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(false);\r
@@ -526,8 +536,8 @@ public class FileDetailFragment extends SherlockFragment implements
     private void setButtonsForDown() {\r
         if (!isEmpty()) {\r
             Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);\r
-            //downloadButton.setText(R.string.filedetails_redownload);      // ugly\r
-            downloadButton.setEnabled(true);\r
+            downloadButton.setText(R.string.filedetails_redownload);\r
+            //downloadButton.setEnabled(true);\r
         \r
             ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(true);\r
             ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true);\r
@@ -541,8 +551,7 @@ public class FileDetailFragment extends SherlockFragment implements
     private void setButtonsForRemote() {\r
         if (!isEmpty()) {\r
             Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);\r
-            //downloadButton.setText(R.string.filedetails_download);    // unnecessary\r
-            downloadButton.setEnabled(true);\r
+            downloadButton.setText(R.string.filedetails_download);\r
             \r
             ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(false);\r
             ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true);\r
@@ -649,6 +658,7 @@ public class FileDetailFragment extends SherlockFragment implements
     \r
 \r
     // this is a temporary class for sharing purposes, it need to be replaced in transfer service\r
+    @SuppressWarnings("unused")\r
     private class ShareRunnable implements Runnable {\r
         private String mPath;\r
 \r
@@ -741,17 +751,7 @@ public class FileDetailFragment extends SherlockFragment implements
                     String uri = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + SHARED_PATH + token; \r
                     Log.d("Actions:shareFile ok", "url: " + uri);   \r
                     \r
-                } catch (HttpException e) {\r
-                    // TODO Auto-generated catch block\r
-                    e.printStackTrace();\r
-                } catch (IOException e) {\r
-                    // TODO Auto-generated catch block\r
-                    e.printStackTrace();\r
-                } catch (JSONException e) {\r
-                    // TODO Auto-generated catch block\r
-                    e.printStackTrace();\r
                 } catch (Exception e) {\r
-                    // TODO Auto-generated catch block\r
                     e.printStackTrace();\r
                 }\r
                 \r