HotFix to add Send File option, after PR#311
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / FileActivity.java
index 2775388..dc3ad0d 100644 (file)
@@ -154,6 +154,9 @@ public class FileActivity extends SherlockFragmentActivity implements OnRemoteOp
         if (mAccountWasSet) {
             onAccountSet(mAccountWasRestored);
         }
+        if (mOperationsServiceBinder != null) {
+            mOperationsServiceBinder.addOperationListener(FileActivity.this, mHandler);
+        }
     }
     
     
@@ -162,7 +165,6 @@ public class FileActivity extends SherlockFragmentActivity implements OnRemoteOp
         super.onStop();
         if (mOperationsServiceBinder != null) {
             mOperationsServiceBinder.removeOperationListener(this);
-            mOperationsServiceBinder = null;
         }
     }
     
@@ -170,8 +172,10 @@ public class FileActivity extends SherlockFragmentActivity implements OnRemoteOp
     @Override
     protected void onDestroy() {
         super.onDestroy();
-        if (mOperationsServiceConnection != null)
+        if (mOperationsServiceConnection != null) {
             unbindService(mOperationsServiceConnection);
+            mOperationsServiceBinder = null;
+        }
     }
     
     
@@ -393,6 +397,8 @@ public class FileActivity extends SherlockFragmentActivity implements OnRemoteOp
     private void onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) {
         dismissLoadingDialog();
         if (result.isSuccess()) {
+            updateFileFromDB();
+            
             Intent sendIntent = operation.getSendIntent();
             startActivity(sendIntent);
             
@@ -410,10 +416,13 @@ public class FileActivity extends SherlockFragmentActivity implements OnRemoteOp
     private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, RemoteOperationResult result) {
         dismissLoadingDialog();
         
-        if (result.getCode() == ResultCode.SHARE_NOT_FOUND)  {        // Error --> SHARE_NOT_FOUND
+        if (result.isSuccess()){
+            updateFileFromDB();
+            
+        } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND)  {        // Error --> SHARE_NOT_FOUND
             Toast t = Toast.makeText(this, getString(R.string.unshare_link_file_no_exist), Toast.LENGTH_LONG);
             t.show();
-        } else if (!result.isSuccess()){    // Generic error
+        } else {    // Generic error
             // Show a Message, operation finished without success
             Toast t = Toast.makeText(this, getString(R.string.unshare_link_file_error), Toast.LENGTH_LONG);
             t.show();
@@ -421,6 +430,14 @@ public class FileActivity extends SherlockFragmentActivity implements OnRemoteOp
         
     }
     
+    
+    private void updateFileFromDB(){
+      OCFile file = getStorageManager().getFileByPath(getFile().getRemotePath());
+      if (file != null) {
+          setFile(file);
+      }
+    }
+    
     /**
      * Show loading dialog 
      */
@@ -456,7 +473,7 @@ public class FileActivity extends SherlockFragmentActivity implements OnRemoteOp
             if (component.equals(new ComponentName(FileActivity.this, OperationsService.class))) {
                 Log_OC.d(TAG, "Operations service connected");
                 mOperationsServiceBinder = (OperationsServiceBinder) service;
-                mOperationsServiceBinder.addOperationListener(FileActivity.this);
+                mOperationsServiceBinder.addOperationListener(FileActivity.this, mHandler);
                 if (!mOperationsServiceBinder.isPerformingBlockingOperation()) {
                     dismissLoadingDialog();
                 }