Moved recursive fetch to notify end-of-syncrhonization of a folder BEFORE its childre...
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / FileDisplayActivity.java
index 3d8f22c..77612e3 100644 (file)
@@ -69,6 +69,7 @@ import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.files.services.FileDownloader;\r
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;\r
 import com.owncloud.android.files.services.FileUploader;\r
+import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;\r
 import com.owncloud.android.network.OwnCloudClientUtils;\r
 import com.owncloud.android.syncadapter.FileSyncService;\r
 import com.owncloud.android.ui.fragment.FileDetailFragment;\r
@@ -96,6 +97,8 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
     private UploadFinishReceiver mUploadFinishReceiver;\r
     private DownloadFinishReceiver mDownloadFinishReceiver;\r
     private FileDownloaderBinder mDownloaderBinder = null;\r
+    private FileUploaderBinder mUploaderBinder = null;\r
+    private ServiceConnection mDownloadConnection = null, mUploadConnection = null;\r
     \r
     private OCFileListFragment mFileList;\r
     \r
@@ -140,7 +143,10 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
             \r
         }\r
         \r
-        bindService(new Intent(this, FileDownloader.class), mConnection, Context.BIND_AUTO_CREATE);\r
+        mUploadConnection = new ListServiceConnection(); \r
+        mDownloadConnection = new ListServiceConnection();\r
+        bindService(new Intent(this, FileUploader.class), mUploadConnection, Context.BIND_AUTO_CREATE);\r
+        bindService(new Intent(this, FileDownloader.class), mDownloadConnection, Context.BIND_AUTO_CREATE);\r
 \r
         // PIN CODE request ;  best location is to decide, let's try this first\r
         if (getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_MAIN) && savedInstanceState == null) {\r
@@ -216,7 +222,9 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
             mCurrentDir = mStorageManager.getFileByPath(mCurrentDir.getRemotePath());   // mCurrentDir == null if it is not in the current account\r
         }\r
         if (mCurrentFile != null) {\r
-            mCurrentFile = mStorageManager.getFileByPath(mCurrentFile.getRemotePath());   // mCurrentFile == null if it is not in the current account\r
+            if (mCurrentFile.fileExists()) {\r
+                mCurrentFile = mStorageManager.getFileByPath(mCurrentFile.getRemotePath());   // mCurrentFile == null if it is not in the current account\r
+            }   // else : keep mCurrentFile with the received value; this is currently the case of an upload in progress, when the user presses the status notification in a landscape tablet\r
         }\r
         \r
         /// Default to root if mCurrentDir was not found\r
@@ -243,7 +251,10 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
     @Override\r
     public void onDestroy() {\r
         super.onDestroy();\r
-        unbindService(mConnection);\r
+        if (mDownloadConnection != null)\r
+            unbindService(mDownloadConnection);\r
+        if (mUploadConnection != null)\r
+            unbindService(mUploadConnection);\r
     }\r
 \r
     \r
@@ -433,9 +444,11 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
         outState.putParcelable(FileDetailFragment.EXTRA_FILE, mCurrentDir);\r
         if (mDualPane) {\r
             FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
-            OCFile file = fragment.getDisplayedFile();\r
-            if (file != null) {\r
-                outState.putParcelable(FileDetailFragment.EXTRA_FILE, file);\r
+            if (fragment != null) {\r
+                OCFile file = fragment.getDisplayedFile();\r
+                if (file != null) {\r
+                    outState.putParcelable(FileDetailFragment.EXTRA_FILE, file);\r
+                }\r
             }\r
         }\r
         Log.d(getClass().toString(), "onSaveInstanceState() end");\r
@@ -932,15 +945,32 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
     public FileDownloaderBinder getFileDownloaderBinder() {\r
         return mDownloaderBinder;\r
     }\r
+\r
+    \r
+    /**\r
+     * {@inheritDoc}\r
+     */\r
+    @Override\r
+    public FileUploaderBinder getFileUploaderBinder() {\r
+        return mUploaderBinder;\r
+    }\r
     \r
     \r
     /** Defines callbacks for service binding, passed to bindService() */\r
-    private ServiceConnection mConnection = new ServiceConnection() {\r
+    private class ListServiceConnection implements ServiceConnection {\r
 \r
         @Override\r
-        public void onServiceConnected(ComponentName className, IBinder service) {\r
-            mDownloaderBinder = (FileDownloaderBinder) service;\r
-            // a new chance to get the mDownloadBinder through getDownloadBinder() - THIS IS A MESS\r
+        public void onServiceConnected(ComponentName component, IBinder service) {\r
+            if (component.equals(new ComponentName(FileDisplayActivity.this, FileDownloader.class))) {\r
+                Log.d(TAG, "Download service connected");\r
+                mDownloaderBinder = (FileDownloaderBinder) service;\r
+            } else if (component.equals(new ComponentName(FileDisplayActivity.this, FileUploader.class))) {\r
+                Log.d(TAG, "Upload service connected");\r
+                mUploaderBinder = (FileUploaderBinder) service;\r
+            } else {\r
+                return;\r
+            }\r
+            // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS\r
             if (mFileList != null)\r
                 mFileList.listDirectory();\r
             if (mDualPane) {\r
@@ -951,8 +981,14 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
         }\r
 \r
         @Override\r
-        public void onServiceDisconnected(ComponentName arg0) {\r
-            mDownloaderBinder = null;\r
+        public void onServiceDisconnected(ComponentName component) {\r
+            if (component.equals(new ComponentName(FileDisplayActivity.this, FileDownloader.class))) {\r
+                Log.d(TAG, "Download service disconnected");\r
+                mDownloaderBinder = null;\r
+            } else if (component.equals(new ComponentName(FileDisplayActivity.this, FileUploader.class))) {\r
+                Log.d(TAG, "Upload service disconnected");\r
+                mUploaderBinder = null;\r
+            }\r
         }\r
     };    \r
 \r