Some fixes about downloads and how the detals view and list view is updated when...
authorDavid A. Velasco <dvelasco@solidgear.es>
Fri, 20 Jul 2012 08:13:50 +0000 (10:13 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Fri, 20 Jul 2012 08:13:50 +0000 (10:13 +0200)
12 files changed:
AndroidManifest.xml
res/layout/file_details_fragment.xml
res/layout/list_layout.xml
res/values/strings.xml
src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java
src/eu/alefzero/owncloud/datamodel/OCFile.java
src/eu/alefzero/owncloud/files/services/FileDownloader.java
src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java
src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java
src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java
src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java
src/eu/alefzero/webdav/WebdavClient.java

index dc9338d..94d1d37 100644 (file)
@@ -18,7 +18,7 @@
  -->\r
 <manifest package="eu.alefzero.owncloud"\r
     android:versionCode="1"\r
-    android:versionName="0.1.167B" xmlns:android="http://schemas.android.com/apk/res/android">\r
+    android:versionName="0.1.168B" xmlns:android="http://schemas.android.com/apk/res/android">\r
 \r
     <uses-permission android:name="android.permission.GET_ACCOUNTS" />\r
     <uses-permission android:name="android.permission.USE_CREDENTIALS" />\r
index 8d0dc7d..6199e4a 100644 (file)
                         android:text="@string/common_remove" />
 
                     <Button
+                        android:id="@+id/fdOpenBtn"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:layout_marginTop="12dp"
+                        android:text="@string/filedetails_open" />
+
+                    <Button
                         android:id="@+id/fdDownloadBtn"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
index bf6dade..39a3edd 100644 (file)
             android:src="@drawable/local_file_indicator"/>
 
         <ImageView
+            android:id="@+id/imageView4"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:src="@drawable/downloading_file_indicator"/>
+
+        <ImageView
             android:id="@+id/imageView1"
             android:layout_width="20dp"
             android:layout_height="20dp"
index c5789ff..f5cece1 100644 (file)
@@ -60,6 +60,8 @@
     <string name="filedetails_created">Created:</string>
     <string name="filedetails_modified">Modified:</string>
     <string name="filedetails_download">Download</string>
+       <string name="filedetails_redownload">Redownload</string>
+       <string name="filedetails_download_in_progress">Downloading</string>
     <string name="filedetails_open">Open</string>
     <string name="common_yes">Yes</string>
     <string name="common_no">No</string>
     <string name="common_save_exit">Save &amp; Exit</string>
     <string name="common_error">Error</string>
     <string name="uploader_info_dirname">Directory name</string>
-    <string name="uploader_upload_succeed">Uploading completed successfully</string>
+    <string name="uploader_upload_succeed">Upload was successful</string>
     <string name="uploader_upload_failed">Upload failed: </string>
     <string name="uploader_files_uploaded_suffix"> files uploaded</string>
+    <string name="downloader_download_succeed">Download was successful</string>
     <string name="downloader_download_failed">Download could not be completed</string>
     <string name="common_choose_account">Choose account</string>
     <string name="sync_string_contacts">Contacts</string>
     <string name="auth_connection_established">Connection established</string>
     <string name="auth_testing_connection">Testing connection…</string>
     <string name="auth_not_configured_title">Malformed ownCloud configuration</string>
-    <string name="auth_not_configured_message">It seems that your ownCloud intance is not correctly configured. Contact your administrator for more details.</string>
+    <string name="auth_not_configured_message">It seems that your ownCloud instance is not correctly configured. Contact your administrator for more details.</string>
     <string name="auth_unknown_error_title">Unknown error occurred</string>
     <string name="auth_unknown_error_message">Unknown error occurred. Please contact authors and include logs from your device.</string>
     <string name="auth_unknow_host_title">Can\'t establish connection</string>
     <string name="auth_unknow_host_message">Coundn\'t establish connection to host. Please check hostname and server availability and try again.</string>
-    <string name="auth_incorrect_path_title">ownCloud intance not found</string>
+    <string name="auth_incorrect_path_title">ownCloud instance not found</string>
     <string name="auth_incorrect_path_message">Application couldn\'t find ownClound instance at given path. Please check your path and try again.</string>
     <string name="auth_secure_connection">Secure connection established</string>
     <string name="auth_unknow_error">Unknown error occured!</string>
index c732f59..43af746 100644 (file)
@@ -412,7 +412,7 @@ public class FileDataStorageManager implements DataStorageManager {
                                         ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
                                         new String[]{mAccount.name});
         }
-        if (file.getStoragePath() != null) {
+        if (file.isDown()) {
             new File(file.getStoragePath()).delete();
         }
     }
index 5cd54f6..32d36de 100644 (file)
@@ -144,10 +144,31 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     /**
      * Use this to check if this file is available locally
      * 
+     * TODO use a better condition not dependent upon mLenght being synchronized; to change when downloads are done through a temporal file
+     * 
      * @return true if it is
      */
-    public boolean isDownloaded() {
-        return mLocalPath != null && !mLocalPath.equals("");
+    public boolean isDown() {
+        if (mLocalPath != null && mLocalPath.length() > 0) {
+            File file = new File(mLocalPath);
+            return (file.exists() && file.length() == mLength);
+        }
+        return false;
+    }
+    
+    /**
+     * Use this to check if this file is downloading
+     * 
+     * TODO use a better condition not dependent upon mLenght being synchronized; to change when downloads are done through a temporal file
+     * 
+     * @return true if it is in a download in progress
+     */
+    public boolean isDownloading() {
+        if (mLocalPath != null && mLocalPath.length() > 0) {
+            File file = new File(mLocalPath);
+            return (file.exists() && file.length() < mLength);  
+        }
+        return false;
     }
 
     /**
@@ -368,7 +389,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     @Override
     public String toString() {
         String asString = "[id=%s, name=%s, mime=%s, downloaded=%s, local=%s, remote=%s]";
-        asString = String.format(asString, new Long(mId), getFileName(), mMimeType, isDownloaded(), mLocalPath, mRemotePath);
+        asString = String.format(asString, new Long(mId), getFileName(), mMimeType, isDown(), mLocalPath, mRemotePath);
         return asString;
     }
 
index 9c9b3ef..cc66e38 100644 (file)
@@ -20,6 +20,7 @@ import android.os.Message;
 import android.os.Process;\r
 import android.util.Log;\r
 import android.widget.RemoteViews;\r
+import android.widget.Toast;\r
 import eu.alefzero.owncloud.R;\r
 import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
 import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;\r
@@ -146,9 +147,17 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
         \r
         mNotificationMngr.cancel(1);\r
         Intent end = new Intent(DOWNLOAD_FINISH_MESSAGE);\r
+        end.putExtra(EXTRA_REMOTE_PATH, mRemotePath);\r
         end.putExtra(EXTRA_FILE_PATH, file.getAbsolutePath());\r
         end.putExtra(EXTRA_DOWNLOAD_RESULT, download_result);\r
         sendBroadcast(end);\r
+\r
+        if (download_result) {\r
+            Toast.makeText(this, R.string.downloader_download_succeed , Toast.LENGTH_SHORT).show();\r
+        } else {\r
+            Toast.makeText(this, R.string.downloader_download_failed , Toast.LENGTH_SHORT).show();\r
+        }\r
+        \r
     }\r
 \r
     @Override\r
@@ -163,5 +172,6 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
         \r
         mLastPercent = percent;\r
     }\r
-\r
+    \r
+    \r
 }\r
index 9dfa8f6..d14151a 100644 (file)
@@ -185,6 +185,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
                 }\r
                 if (getStorageManager().getFileByPath(file.getRemotePath()) != null)\r
                     file.setKeepInSync(getStorageManager().getFileByPath(file.getRemotePath()).keepInSync());\r
+                \r
                 //getStorageManager().saveFile(file);\r
                 updatedFiles.add(file);\r
                 if (parentId == 0)\r
index 7493c70..c8e3297 100644 (file)
@@ -89,6 +89,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
     private DataStorageManager mStorageManager;\r
     private SyncBroadcastReceiver mSyncBroadcastReceiver;\r
     private UploadFinishReceiver mUploadFinishReceiver;\r
+    private DownloadFinishReceiver mDownloadFinishReceiver;\r
     \r
     private View mLayoutView = null;\r
     private FileListFragment mFileList;\r
@@ -329,6 +330,11 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
             IntentFilter uploadIntentFilter = new IntentFilter(FileUploader.UPLOAD_FINISH_MESSAGE);\r
             mUploadFinishReceiver = new UploadFinishReceiver();\r
             registerReceiver(mUploadFinishReceiver, uploadIntentFilter);\r
+            \r
+            // Listen for download messages\r
+            IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.DOWNLOAD_FINISH_MESSAGE);\r
+            mDownloadFinishReceiver = new DownloadFinishReceiver();\r
+            registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);\r
         \r
             // Storage manager initialization\r
             mStorageManager = new FileDataStorageManager(\r
@@ -410,6 +416,11 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
             unregisterReceiver(mUploadFinishReceiver);\r
             mUploadFinishReceiver = null;\r
         }\r
+        if (mDownloadFinishReceiver != null) {\r
+            unregisterReceiver(mDownloadFinishReceiver);\r
+            mDownloadFinishReceiver = null;\r
+        }\r
+        \r
         getIntent().putExtra(FileDetailFragment.EXTRA_FILE, mCurrentDir);\r
         Log.i(getClass().toString(), "onPause() end");\r
     }\r
@@ -685,6 +696,24 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
         }\r
         \r
     }\r
+    \r
+    \r
+    /**\r
+     * Once the file download has finished -> update view\r
+     */\r
+    private class DownloadFinishReceiver extends BroadcastReceiver {\r
+        @Override\r
+        public void onReceive(Context context, Intent intent) {\r
+            boolean downloadWasFine = intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false);\r
+            String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);\r
+            if (downloadWasFine && mCurrentDir != null && mCurrentDir.getFileId() == mStorageManager.getFileByPath(downloadedRemotePath).getParentId()) {\r
+                FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
+                if (fileListFragment != null) { \r
+                    fileListFragment.listDirectory();\r
+                }\r
+            }\r
+        }\r
+    }\r
 \r
     \r
     @Override\r
index 646a1ca..32cbb16 100644 (file)
@@ -109,12 +109,19 @@ public class FileListListAdapter implements ListAdapter {
             } else {\r
                 fileIcon.setImageResource(R.drawable.ic_menu_archive);\r
             }\r
-            ImageView down = (ImageView) view.findViewById(R.id.imageView2);\r
-            if (file.getStoragePath() != null)\r
-                down.setVisibility(View.VISIBLE);\r
-            else\r
-                down.setVisibility(View.INVISIBLE);\r
-\r
+            ImageView downloaded = (ImageView) view.findViewById(R.id.imageView2);\r
+            ImageView downloading = (ImageView) view.findViewById(R.id.imageView4);\r
+            if (file.isDown()) {\r
+                 downloaded.setVisibility(View.VISIBLE);\r
+                 downloading.setVisibility(View.INVISIBLE);\r
+            } else if (file.isDownloading()) {\r
+                downloaded.setVisibility(View.INVISIBLE);\r
+                downloading.setVisibility(View.VISIBLE);\r
+            } else {\r
+                downloaded.setVisibility(View.INVISIBLE);\r
+                downloading.setVisibility(View.INVISIBLE);\r
+            }\r
+                \r
             if (!file.isDirectory()) {\r
                 view.findViewById(R.id.file_size).setVisibility(View.VISIBLE);\r
                 view.findViewById(R.id.last_mod).setVisibility(View.VISIBLE);\r
index 34a82cb..6a34c6d 100644 (file)
@@ -22,14 +22,11 @@ import java.io.IOException;
 import java.util.ArrayList;\r
 import java.util.List;\r
 \r
-import org.apache.commons.httpclient.HostConfiguration;\r
 import org.apache.commons.httpclient.HttpException;\r
-import org.apache.commons.httpclient.cookie.CookiePolicy;\r
 import org.apache.commons.httpclient.methods.GetMethod;\r
 import org.apache.commons.httpclient.methods.PostMethod;\r
 import org.apache.commons.httpclient.methods.StringRequestEntity;\r
 import org.apache.commons.httpclient.params.HttpConnectionManagerParams;\r
-import org.apache.commons.httpclient.params.HttpMethodParams;\r
 import org.apache.http.HttpStatus;\r
 import org.apache.http.NameValuePair;\r
 import org.apache.http.client.utils.URLEncodedUtils;\r
@@ -37,20 +34,15 @@ import org.apache.http.message.BasicNameValuePair;
 import org.apache.http.protocol.HTTP;\r
 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.MoveMethod;\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
 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
-import android.content.DialogInterface;\r
-import android.content.DialogInterface.OnDismissListener;\r
 import android.content.Intent;\r
 import android.content.IntentFilter;\r
 import android.content.res.Resources.NotFoundException;\r
@@ -58,14 +50,10 @@ import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;\r
 import android.graphics.BitmapFactory.Options;\r
 import android.graphics.Point;\r
-import android.graphics.drawable.BitmapDrawable;\r
-import android.graphics.drawable.Drawable;\r
 import android.net.Uri;\r
 import android.os.AsyncTask;\r
 import android.os.Bundle;\r
-import android.os.Environment;\r
 import android.os.Handler;\r
-import android.preference.PreferenceActivity.Header;\r
 import android.support.v4.app.FragmentTransaction;\r
 import android.util.Log;\r
 import android.view.Display;\r
@@ -77,7 +65,6 @@ import android.view.WindowManager.LayoutParams;
 import android.webkit.MimeTypeMap;\r
 import android.widget.Button;\r
 import android.widget.CheckBox;\r
-import android.widget.EditText;\r
 import android.widget.ImageView;\r
 import android.widget.TextView;\r
 import android.widget.Toast;\r
@@ -169,9 +156,11 @@ public class FileDetailFragment extends SherlockFragment implements
         \r
         if (mLayout == R.layout.file_details_fragment) {\r
             mView.findViewById(R.id.fdKeepInSync).setOnClickListener(this);\r
-            //mView.findViewById(R.id.fdShareBtn).setOnClickListener(this);\r
             mView.findViewById(R.id.fdRenameBtn).setOnClickListener(this);\r
+            mView.findViewById(R.id.fdDownloadBtn).setOnClickListener(this);\r
+            mView.findViewById(R.id.fdOpenBtn).setOnClickListener(this);\r
             mView.findViewById(R.id.fdRemoveBtn).setOnClickListener(this);\r
+            //mView.findViewById(R.id.fdShareBtn).setOnClickListener(this);\r
             mPreview = (ImageView)mView.findViewById(R.id.fdPreview);\r
         }\r
         \r
@@ -221,13 +210,16 @@ public class FileDetailFragment extends SherlockFragment implements
     public void onClick(View v) {\r
         switch (v.getId()) {\r
             case R.id.fdDownloadBtn: {\r
-                //Toast.makeText(getActivity(), "Downloading", Toast.LENGTH_LONG).show();\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
-                v.setEnabled(false);\r
+                \r
+                // update ui \r
+                Toast.makeText(getActivity(), "Downloading", Toast.LENGTH_LONG).show();\r
+                setButtonsForDownloading();\r
+                \r
                 getActivity().startService(i);\r
                 break;\r
             }\r
@@ -253,6 +245,47 @@ public class FileDetailFragment extends SherlockFragment implements
                 confDialog.show(getFragmentManager(), FTAG_CONFIRMATION);\r
                 break;\r
             }\r
+            case R.id.fdOpenBtn: {\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
+                break;\r
+            }\r
             default:\r
                 Log.e(TAG, "Incorrect view clicked!");\r
         }\r
@@ -313,7 +346,6 @@ public class FileDetailFragment extends SherlockFragment implements
 \r
         if (mFile != null && mAccount != null && mLayout == R.layout.file_details_fragment) {\r
             \r
-            Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);\r
             // set file details\r
             setFilename(mFile.getFileName());\r
             setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mFile\r
@@ -327,16 +359,22 @@ public class FileDetailFragment extends SherlockFragment implements
             \r
             CheckBox cb = (CheckBox)getView().findViewById(R.id.fdKeepInSync);\r
             cb.setChecked(mFile.keepInSync());\r
-            \r
-            if (mFile.getStoragePath() != null) {\r
+\r
+            // configure UI for depending upon local state of the file\r
+            if (mFile.isDownloading()) {\r
+                setButtonsForDownloading();\r
+                \r
+            } else if (mFile.isDown()) {\r
                 // Update preview\r
                 if (mFile.getMimetype().startsWith("image/")) {\r
                     BitmapLoader bl = new BitmapLoader();\r
                     bl.execute(new String[]{mFile.getStoragePath()});\r
                 }\r
                 \r
+                setButtonsForDown();\r
+                \r
                 // Change download button to open button\r
-                downloadButton.setText(R.string.filedetails_open);\r
+                /*downloadButton.setText(R.string.filedetails_open);\r
                 downloadButton.setOnClickListener(new OnClickListener() {\r
                     @Override\r
                     public void onClick(View v) {\r
@@ -379,10 +417,9 @@ public class FileDetailFragment extends SherlockFragment implements
                             \r
                         }\r
                     }\r
-                });\r
+                });*/\r
             } else {\r
-                // Make download button effective\r
-                downloadButton.setOnClickListener(this);\r
+                setButtonsForRemote();\r
             }\r
         }\r
     }\r
@@ -444,6 +481,53 @@ public class FileDetailFragment extends SherlockFragment implements
     }\r
     \r
     /**\r
+     * Enables or disables buttons for a file being downloaded\r
+     */\r
+    private void setButtonsForDownloading() {\r
+        if (!isEmpty()) {\r
+            Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);\r
+            downloadButton.setText(R.string.filedetails_download_in_progress);\r
+            downloadButton.setEnabled(false);   // TODO replace it with a 'cancel download' button\r
+        \r
+            // let's protect the user from himself ;)\r
+            ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(false);\r
+            ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(false);\r
+            ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(false);\r
+        }\r
+    }\r
+    \r
+    /**\r
+     * Enables or disables buttons for a file locally available \r
+     */\r
+    private void setButtonsForDown() {\r
+        if (!isEmpty()) {\r
+            Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);\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
+            ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(true);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Enables or disables buttons for a file not locally available \r
+     */\r
+    private void setButtonsForRemote() {\r
+        if (!isEmpty()) {\r
+            Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);\r
+            downloadButton.setText(R.string.filedetails_download);\r
+            downloadButton.setEnabled(true);\r
+            \r
+            ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(false);\r
+            ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true);\r
+            ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(true);\r
+        }\r
+    }\r
+    \r
+\r
+    /**\r
      * In ownCloud 3.X.X and 4.X.X there is a bug that SabreDAV does not return\r
      * the time that the file was created. There is a chance that this will\r
      * be fixed in future versions. Use this method to check if this version of\r
@@ -469,17 +553,17 @@ public class FileDetailFragment extends SherlockFragment implements
     private class DownloadFinishReceiver extends BroadcastReceiver {\r
         @Override\r
         public void onReceive(Context context, Intent intent) {\r
-            if (getView()!=null && getView().findViewById(R.id.fdDownloadBtn) != null) \r
-                getView().findViewById(R.id.fdDownloadBtn).setEnabled(true);\r
-            \r
-            if (intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false)) {\r
-                mFile.setStoragePath(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH));\r
-                updateFileDetails();\r
-            } else if (intent.getAction().equals(FileDownloader.DOWNLOAD_FINISH_MESSAGE)) {\r
-                Toast.makeText(context, R.string.downloader_download_failed , Toast.LENGTH_SHORT).show();\r
+            if (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
+                    if (downloadWasFine) {\r
+                        mFile.setStoragePath(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH));\r
+                    }\r
+                    updateFileDetails();    // it updates the buttons; must be called although !downloadWasFine\r
+                }\r
             }\r
         }\r
-        \r
     }\r
     \r
     // this is a temporary class for sharing purposes, it need to be replaced in transfer service\r
@@ -613,11 +697,11 @@ public class FileDetailFragment extends SherlockFragment implements
                         newFile.setMimetype(mFile.getMimetype());\r
                         newFile.setModificationTimestamp(mFile.getModificationTimestamp());\r
                         newFile.setParentId(mFile.getParentId());\r
-                        if (mFile.isDownloaded()) {\r
+                        if (mFile.isDown()) {\r
                             File f = new File(mFile.getStoragePath());\r
-                            Log.e(TAG, f.getAbsolutePath()+"");\r
+                            Log.e(TAG, f.getAbsolutePath());\r
                             f.renameTo(new File(f.getParent()+"/"+newFilename));\r
-                            Log.e(TAG, f.getAbsolutePath()+"");\r
+                            Log.e(TAG, f.getAbsolutePath());\r
                             newFile.setStoragePath(f.getAbsolutePath());\r
                         }\r
                         \r
@@ -627,7 +711,7 @@ public class FileDetailFragment extends SherlockFragment implements
                 }\r
             }\r
         } else {\r
-            Log.e(TAG, "Unknown dialog intance passed to onDismissDalog: " + dialog.getClass().getCanonicalName());\r
+            Log.e(TAG, "Unknown dialog instance passed to onDismissDalog: " + dialog.getClass().getCanonicalName());\r
         }\r
         \r
     }\r
index 449cfff..a539800 100644 (file)
@@ -144,9 +144,9 @@ public class WebdavClient extends HttpClient {
                         mDataTransferListener.transferProgress(readResult);\r
                     fos.write(bytes, 0, readResult);\r
                 }\r
-                \r
+                ret = true;\r
             }\r
-            ret = true;\r
+            \r
         } catch (Throwable e) {\r
             e.printStackTrace();\r
             targetPath.delete();\r