removed dependency to Hex
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / FileActivity.java
index 8a5449e..9cf695d 100644 (file)
@@ -37,9 +37,9 @@ import android.os.IBinder;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
+import android.support.v7.app.ActionBarActivity;
 import android.widget.Toast;
 
-import com.actionbarsherlock.app.SherlockFragmentActivity;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountUtils;
@@ -67,15 +67,18 @@ import com.owncloud.android.utils.ErrorMessageAdapter;
 
 
 /**
- * Activity with common behaviour for activities handling {@link OCFile}s in ownCloud {@link Account}s .
+ * Activity with common behaviour for activities handling {@link OCFile}s in ownCloud
+ * {@link Account}s .
  */
-public class FileActivity extends SherlockFragmentActivity
+public class FileActivity extends ActionBarActivity
         implements OnRemoteOperationListener, ComponentsGetter {
 
     public static final String EXTRA_FILE = "com.owncloud.android.ui.activity.FILE";
     public static final String EXTRA_ACCOUNT = "com.owncloud.android.ui.activity.ACCOUNT";
-    public static final String EXTRA_WAITING_TO_PREVIEW = "com.owncloud.android.ui.activity.WAITING_TO_PREVIEW";
-    public static final String EXTRA_FROM_NOTIFICATION = "com.owncloud.android.ui.activity.FROM_NOTIFICATION";
+    public static final String EXTRA_WAITING_TO_PREVIEW =
+            "com.owncloud.android.ui.activity.WAITING_TO_PREVIEW";
+    public static final String EXTRA_FROM_NOTIFICATION =
+            "com.owncloud.android.ui.activity.FROM_NOTIFICATION";
     
     public static final String TAG = FileActivity.class.getSimpleName();
     
@@ -87,13 +90,14 @@ public class FileActivity extends SherlockFragmentActivity
     protected static final long DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS = 200;
     
     
-    /** OwnCloud {@link Account} where the main {@link OCFile} handled by the activity is located. */
+    /** OwnCloud {@link Account} where the main {@link OCFile} handled by the activity is located.*/
     private Account mAccount;
     
     /** Main {@link OCFile} handled by the activity.*/
     private OCFile mFile;
     
-    /** Flag to signal that the activity will is finishing to enforce the creation of an ownCloud {@link Account} */
+    /** Flag to signal that the activity will is finishing to enforce the creation of an ownCloud
+     * {@link Account} */
     private boolean mRedirectingToSetupAccount = false;
     
     /** Flag to signal when the value of mAccount was set */ 
@@ -136,9 +140,8 @@ public class FileActivity extends SherlockFragmentActivity
         super.onCreate(savedInstanceState);
         mHandler = new Handler();
         mFileOperationsHelper = new FileOperationsHelper(this);
-        Account account;
+        Account account = null;
         if(savedInstanceState != null) {
-            account = savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT);
             mFile = savedInstanceState.getParcelable(FileActivity.EXTRA_FILE);
             mFromNotification = savedInstanceState.getBoolean(FileActivity.EXTRA_FROM_NOTIFICATION);
             mFileOperationsHelper.setOpIdWaitingFor(
@@ -148,26 +151,32 @@ public class FileActivity extends SherlockFragmentActivity
         } else {
             account = getIntent().getParcelableExtra(FileActivity.EXTRA_ACCOUNT);
             mFile = getIntent().getParcelableExtra(FileActivity.EXTRA_FILE);
-            mFromNotification = getIntent().getBooleanExtra(FileActivity.EXTRA_FROM_NOTIFICATION, false);
+            mFromNotification = getIntent().getBooleanExtra(FileActivity.EXTRA_FROM_NOTIFICATION,
+                    false);
         }
 
+        AccountUtils.updateAccountVersion(this); // best place, before any access to AccountManager
+                                                 // or database
+
         setAccount(account, savedInstanceState != null);
         
         mOperationsServiceConnection = new OperationsServiceConnection();
-        bindService(new Intent(this, OperationsService.class), mOperationsServiceConnection, Context.BIND_AUTO_CREATE);
+        bindService(new Intent(this, OperationsService.class), mOperationsServiceConnection,
+                Context.BIND_AUTO_CREATE);
         
         mDownloadServiceConnection = newTransferenceServiceConnection();
         if (mDownloadServiceConnection != null) {
-            bindService(new Intent(this, FileDownloader.class), mDownloadServiceConnection, Context.BIND_AUTO_CREATE);
+            bindService(new Intent(this, FileDownloader.class), mDownloadServiceConnection,
+                    Context.BIND_AUTO_CREATE);
         }
         mUploadServiceConnection = newTransferenceServiceConnection();
         if (mUploadServiceConnection != null) {
-            bindService(new Intent(this, FileUploader.class), mUploadServiceConnection, Context.BIND_AUTO_CREATE);
+            bindService(new Intent(this, FileUploader.class), mUploadServiceConnection,
+                    Context.BIND_AUTO_CREATE);
         }
 
     }
 
-
     @Override
     protected void onNewIntent (Intent intent) {
         Log_OC.v(TAG, "onNewIntent() start");
@@ -197,42 +206,34 @@ public class FileActivity extends SherlockFragmentActivity
     
     @Override 
     protected void onStart() {
-        Log_OC.v(TAG, "onStart() start");
         super.onStart();
 
         if (mAccountWasSet) {
             onAccountSet(mAccountWasRestored);
         }
-        Log_OC.v(TAG, "onStart() end");
     }
     
     @Override
     protected void onResume() {
-        Log_OC.v(TAG, "onResume() start");
         super.onResume();
         
         if (mOperationsServiceBinder != null) {
             doOnResumeAndBound();
         }
-        Log_OC.v(TAG, "onResume() end");
     }
     
     @Override
     protected void onPause()  {
-        Log_OC.v(TAG, "onPause() start");
-
         if (mOperationsServiceBinder != null) {
             mOperationsServiceBinder.removeOperationListener(this);
         }
         
         super.onPause();
-        Log_OC.v(TAG, "onPause() end");
     }
     
     
     @Override
     protected void onDestroy() {
-        Log_OC.v(TAG, "onDestroy() start");
         if (mOperationsServiceConnection != null) {
             unbindService(mOperationsServiceConnection);
             mOperationsServiceBinder = null;
@@ -247,7 +248,6 @@ public class FileActivity extends SherlockFragmentActivity
         }
 
         super.onDestroy();
-        Log_OC.v(TAG, "onDestroy() end");
     }
     
     
@@ -264,7 +264,8 @@ public class FileActivity extends SherlockFragmentActivity
     protected void setAccount(Account account, boolean savedAccount) {
         Account oldAccount = mAccount;
         boolean validAccount =
-                (account != null && AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), account.name));
+                (account != null && AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(),
+                        account.name));
         if (validAccount) {
             mAccount = account;
             mAccountWasSet = true;
@@ -324,7 +325,6 @@ public class FileActivity extends SherlockFragmentActivity
     protected void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
         outState.putParcelable(FileActivity.EXTRA_FILE, mFile);
-        outState.putParcelable(FileActivity.EXTRA_ACCOUNT, mAccount);
         outState.putBoolean(FileActivity.EXTRA_FROM_NOTIFICATION, mFromNotification);
         outState.putLong(KEY_WAITING_FOR_OP_ID, mFileOperationsHelper.getOpIdWaitingFor());
         outState.putBoolean(KEY_TRY_SHARE_AGAIN, mTryShareAgain);
@@ -352,9 +352,11 @@ public class FileActivity extends SherlockFragmentActivity
 
     
     /**
-     * Getter for the ownCloud {@link Account} where the main {@link OCFile} handled by the activity is located.
+     * Getter for the ownCloud {@link Account} where the main {@link OCFile} handled by the activity
+     * is located.
      * 
-     * @return  OwnCloud {@link Account} where the main {@link OCFile} handled by the activity is located.
+     * @return  OwnCloud {@link Account} where the main {@link OCFile} handled by the activity
+     *          is located.
      */
     public Account getAccount() {
         return mAccount;
@@ -474,7 +476,8 @@ public class FileActivity extends SherlockFragmentActivity
      */
     @Override
     public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
-        Log_OC.d(TAG, "Received result of operation in FileActivity - common behaviour for all the FileActivities ");
+        Log_OC.d(TAG, "Received result of operation in FileActivity - common behaviour for all the " +
+                "FileActivities ");
         
         mFileOperationsHelper.setOpIdWaitingFor(Long.MAX_VALUE);
         
@@ -552,15 +555,16 @@ public class FileActivity extends SherlockFragmentActivity
     }
     
     
-    private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, RemoteOperationResult result) {
+    private void onUnshareLinkOperationFinish(UnshareLinkOperation operation,
+                                              RemoteOperationResult result) {
         dismissLoadingDialog();
         
         if (result.isSuccess()){
             updateFileFromDB();
             
         } else {
-            Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), 
-                    Toast.LENGTH_LONG);
+            Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result,
+                            operation, getResources()), Toast.LENGTH_LONG);
             t.show();
         } 
     }
@@ -569,8 +573,8 @@ public class FileActivity extends SherlockFragmentActivity
             SynchronizeFolderOperation operation, RemoteOperationResult result
     ) {
         if (!result.isSuccess() && result.getCode() != ResultCode.CANCELLED){
-            Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
-                    Toast.LENGTH_LONG);
+            Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result,
+                            operation, getResources()), Toast.LENGTH_LONG);
             t.show();
         }
     }
@@ -612,7 +616,8 @@ public class FileActivity extends SherlockFragmentActivity
         mOperationsServiceBinder.addOperationListener(FileActivity.this, mHandler);
         long waitingForOpId = mFileOperationsHelper.getOpIdWaitingFor();
         if (waitingForOpId <= Integer.MAX_VALUE) {
-            boolean wait = mOperationsServiceBinder.dispatchResultIfFinished((int)waitingForOpId, this);
+            boolean wait = mOperationsServiceBinder.dispatchResultIfFinished((int)waitingForOpId,
+                    this);
             if (!wait ) {
                 dismissLoadingDialog();
             }