Fixed local path NULL when making favourite a file not down ; fixed change of local...
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / FileDetailActivity.java
index ff39022..aade565 100644 (file)
@@ -28,6 +28,7 @@ import android.content.res.Configuration;
 import android.os.Bundle;\r
 import android.os.IBinder;\r
 import android.support.v4.app.FragmentTransaction;\r
+import android.util.Log;\r
 \r
 import com.actionbarsherlock.app.ActionBar;\r
 import com.actionbarsherlock.app.SherlockFragmentActivity;\r
@@ -35,6 +36,8 @@ import com.actionbarsherlock.view.MenuItem;
 import com.owncloud.android.datamodel.OCFile;\r
 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.ui.fragment.FileDetailFragment;\r
 \r
 import com.owncloud.android.R;\r
@@ -49,10 +52,14 @@ import com.owncloud.android.R;
 public class FileDetailActivity extends SherlockFragmentActivity implements FileDetailFragment.ContainerActivity {\r
     \r
     public static final int DIALOG_SHORT_WAIT = 0;\r
+\r
+    public static final String TAG = FileDetailActivity.class.getSimpleName();\r
     \r
     private boolean mConfigurationChangedToLandscape = false;\r
     private FileDownloaderBinder mDownloaderBinder = null;\r
-    private ServiceConnection mConnection = null;\r
+    private ServiceConnection mDownloadConnection, mUploadConnection = null;\r
+    private FileUploaderBinder mUploaderBinder = null;\r
+\r
 \r
     @Override\r
     protected void onCreate(Bundle savedInstanceState) {\r
@@ -65,8 +72,10 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File
                                            );\r
 \r
         if (!mConfigurationChangedToLandscape) {\r
-            mConnection = new DetailsServiceConnection();\r
-            bindService(new Intent(this, FileDownloader.class), mConnection, Context.BIND_AUTO_CREATE);\r
+            mDownloadConnection = new DetailsServiceConnection();\r
+            bindService(new Intent(this, FileDownloader.class), mDownloadConnection, Context.BIND_AUTO_CREATE);\r
+            mUploadConnection = new DetailsServiceConnection();\r
+            bindService(new Intent(this, FileUploader.class), mUploadConnection, Context.BIND_AUTO_CREATE);\r
             \r
             setContentView(R.layout.file_activity_details);\r
         \r
@@ -93,16 +102,30 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File
     private class DetailsServiceConnection implements ServiceConnection {\r
 \r
         @Override\r
-        public void onServiceConnected(ComponentName className, IBinder service) {\r
-            mDownloaderBinder = (FileDownloaderBinder) service;\r
+        public void onServiceConnected(ComponentName component, IBinder service) {\r
+            if (component.equals(new ComponentName(FileDetailActivity.this, FileDownloader.class))) {\r
+                Log.d(TAG, "Download service connected");\r
+                mDownloaderBinder = (FileDownloaderBinder) service;\r
+            } else if (component.equals(new ComponentName(FileDetailActivity.this, FileUploader.class))) {\r
+                Log.d(TAG, "Upload service connected");\r
+                mUploaderBinder = (FileUploaderBinder) service;\r
+            } else {\r
+                return;\r
+            }\r
             FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
             if (fragment != null)\r
                 fragment.updateFileDetails();   // let the fragment gets the mDownloadBinder through getDownloadBinder() (see FileDetailFragment#updateFileDetais())\r
         }\r
 \r
         @Override\r
-        public void onServiceDisconnected(ComponentName arg0) {\r
-            mDownloaderBinder = null;\r
+        public void onServiceDisconnected(ComponentName component) {\r
+            if (component.equals(new ComponentName(FileDetailActivity.this, FileDownloader.class))) {\r
+                Log.d(TAG, "Download service disconnected");\r
+                mDownloaderBinder = null;\r
+            } else if (component.equals(new ComponentName(FileDetailActivity.this, FileUploader.class))) {\r
+                Log.d(TAG, "Upload service disconnected");\r
+                mUploaderBinder = null;\r
+            }\r
         }\r
     };    \r
     \r
@@ -110,9 +133,13 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File
     @Override\r
     public void onDestroy() {\r
         super.onDestroy();\r
-        if (mConnection != null) {\r
-            unbindService(mConnection);\r
-            mConnection = null;\r
+        if (mDownloadConnection != null) {\r
+            unbindService(mDownloadConnection);\r
+            mDownloadConnection = null;\r
+        }\r
+        if (mUploadConnection != null) {\r
+            unbindService(mUploadConnection);\r
+            mUploadConnection = null;\r
         }\r
     }\r
     \r
@@ -189,5 +216,11 @@ public class FileDetailActivity extends SherlockFragmentActivity implements File
     public FileDownloaderBinder getFileDownloaderBinder() {\r
         return mDownloaderBinder;\r
     }\r
+\r
+\r
+    @Override\r
+    public FileUploaderBinder getFileUploaderBinder() {\r
+        return mUploaderBinder;\r
+    }\r
     \r
 }\r