Added a static list of downloads in progress to have a reliable way to check if a...
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / ui / fragment / FileDetailFragment.java
index 6a34c6d..7101dd0 100644 (file)
@@ -79,6 +79,7 @@ import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
 import eu.alefzero.owncloud.datamodel.FileDataStorageManager;\r
 import eu.alefzero.owncloud.datamodel.OCFile;\r
 import eu.alefzero.owncloud.files.services.FileDownloader;\r
 import eu.alefzero.owncloud.datamodel.FileDataStorageManager;\r
 import eu.alefzero.owncloud.datamodel.OCFile;\r
 import eu.alefzero.owncloud.files.services.FileDownloader;\r
+import eu.alefzero.owncloud.files.services.FileUploader;\r
 import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;\r
 import eu.alefzero.owncloud.utils.OwnCloudVersion;\r
 import eu.alefzero.webdav.WebdavClient;\r
 import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;\r
 import eu.alefzero.owncloud.utils.OwnCloudVersion;\r
 import eu.alefzero.webdav.WebdavClient;\r
@@ -240,7 +241,7 @@ 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("to remove " + mFile.getFileName());\r
+                ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(R.string.confirmation_remove_alert, new String[]{mFile.getFileName()});\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
@@ -361,7 +362,7 @@ public class FileDetailFragment extends SherlockFragment implements
             cb.setChecked(mFile.keepInSync());\r
 \r
             // configure UI for depending upon local state of the file\r
             cb.setChecked(mFile.keepInSync());\r
 \r
             // configure UI for depending upon local state of the file\r
-            if (mFile.isDownloading()) {\r
+            if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath())) {\r
                 setButtonsForDownloading();\r
                 \r
             } else if (mFile.isDown()) {\r
                 setButtonsForDownloading();\r
                 \r
             } else if (mFile.isDown()) {\r
@@ -553,7 +554,9 @@ public class FileDetailFragment extends SherlockFragment implements
     private class DownloadFinishReceiver extends BroadcastReceiver {\r
         @Override\r
         public void onReceive(Context context, Intent intent) {\r
     private class DownloadFinishReceiver extends BroadcastReceiver {\r
         @Override\r
         public void onReceive(Context context, Intent intent) {\r
-            if (mFile != null) {\r
+            String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);\r
+\r
+            if (accountName.equals(mAccount.name) && mFile != null) {\r
                 boolean downloadWasFine = intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false);\r
                 String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);\r
                 if (mFile.getRemotePath().equals(downloadedRemotePath)) {\r
                 boolean downloadWasFine = intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false);\r
                 String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);\r
                 if (mFile.getRemotePath().equals(downloadedRemotePath)) {\r
@@ -688,7 +691,7 @@ public class FileDetailFragment extends SherlockFragment implements
                 if (!newFilename.equals(mFile.getFileName())) {\r
                     FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver());\r
                     if (fdsm.getFileById(mFile.getFileId()) != null) {\r
                 if (!newFilename.equals(mFile.getFileName())) {\r
                     FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getContentResolver());\r
                     if (fdsm.getFileById(mFile.getFileId()) != null) {\r
-                        OCFile newFile = new OCFile(fdsm.getFileById(mFile.getParentId()).getRemotePath() + OCFile.PATH_SEPARATOR + newFilename);\r
+                        OCFile newFile = new OCFile(fdsm.getFileById(mFile.getParentId()).getRemotePath() + newFilename);\r
                         newFile.setCreationTimestamp(mFile.getCreationTimestamp());\r
                         newFile.setFileId(mFile.getFileId());\r
                         newFile.setFileLength(mFile.getFileLength());\r
                         newFile.setCreationTimestamp(mFile.getCreationTimestamp());\r
                         newFile.setFileId(mFile.getFileId());\r
                         newFile.setFileLength(mFile.getFileLength());\r
@@ -700,9 +703,9 @@ public class FileDetailFragment extends SherlockFragment implements
                         if (mFile.isDown()) {\r
                             File f = new File(mFile.getStoragePath());\r
                             Log.e(TAG, f.getAbsolutePath());\r
                         if (mFile.isDown()) {\r
                             File f = new File(mFile.getStoragePath());\r
                             Log.e(TAG, f.getAbsolutePath());\r
-                            f.renameTo(new File(f.getParent()+"/"+newFilename));\r
-                            Log.e(TAG, f.getAbsolutePath());\r
-                            newFile.setStoragePath(f.getAbsolutePath());\r
+                            f.renameTo(new File(f.getParent() + File.separator + newFilename)); // TODO check if fails\r
+                            Log.e(TAG, f.getParent() + File.separator + newFilename);\r
+                            newFile.setStoragePath(f.getParent() + File.separator + newFilename);\r
                         }\r
                         \r
                         new Thread(new RenameRunnable(mFile, newFile, mAccount, new Handler())).start();\r
                         }\r
                         \r
                         new Thread(new RenameRunnable(mFile, newFile, mAccount, new Handler())).start();\r