+ Log_OC.d(TAG, "onCreate() end");
+ }
+
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ if (mDownloadConnection != null)
+ unbindService(mDownloadConnection);
+ if (mUploadConnection != null)
+ unbindService(mUploadConnection);
+ }
+
+
+ /**
+ * Called when the ownCloud {@link Account} associated to the Activity was just updated.
+ */
+ @Override
+ protected void onAccountSet(boolean stateWasRecovered) {
+ if (getAccount() != null) {
+ mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver());
+
+ /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
+ OCFile file = getFile();
+ // get parent from path
+ String parentPath = "";
+ if (file != null) {
+ if (file.isDown() && file.getLastSyncDateForProperties() == 0) {
+ // upload in progress - right now, files are not inserted in the local cache until the upload is successful
+ // get parent from path
+ parentPath = file.getRemotePath().substring(0, file.getRemotePath().lastIndexOf(file.getFileName()));
+ if (mStorageManager.getFileByPath(parentPath) == null)
+ file = null; // not able to know the directory where the file is uploading
+ } else {
+ file = mStorageManager.getFileByPath(file.getRemotePath()); // currentDir = null if not in the current Account
+ }
+ }
+ if (file == null) {
+ // fall back to root folder
+ file = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR); // never returns null
+ }
+ setFile(file);
+ mDirectories.clear();
+ OCFile fileIt = file;
+ while(fileIt != null && fileIt.getFileName() != OCFile.PATH_SEPARATOR) {
+ if (fileIt.isDirectory()) {
+ mDirectories.add(fileIt.getFileName());
+ }
+ // get parent from path
+ parentPath = fileIt.getRemotePath().substring(0, fileIt.getRemotePath().lastIndexOf(fileIt.getFileName()));
+ fileIt = mStorageManager.getFileByPath(parentPath);
+ }
+ mDirectories.add(OCFile.PATH_SEPARATOR);
+ if (!stateWasRecovered) {
+ Log_OC.e(TAG, "Initializing Fragments in onAccountChanged..");
+ initFragmentsWithFile();
+
+ } else {
+ updateFragmentsVisibility(!file.isDirectory());
+ updateNavigationElementsInActionBar(file.isDirectory() ? null : file);
+ }