+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onAccountChanged() {
+ if (getAccount() != null) {
+ mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver());
+
+ /// Check if the 'main' @OCFile handled by the Activity is a directory
+ OCFile currentDir = getFile();
+ if(currentDir != null && !currentDir.isDirectory()) {
+ mChosenFile = getFile();
+ currentDir = mStorageManager.getFileById(currentDir.getParentId());
+ }
+
+ /// Check if currentDir and mChosenFile are in the current account, and update them
+ if (currentDir != null) {
+ currentDir = mStorageManager.getFileByPath(currentDir.getRemotePath()); // currentDir = null if not in the current Account
+ }
+ if (mChosenFile != null) {
+ if (mChosenFile.fileExists()) {
+ mChosenFile = mStorageManager.getFileByPath(mChosenFile.getRemotePath()); // mChosenFile = null if not in the current Account
+ } // else : keep mChosenFile 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
+ }
+
+ /// Default to root if mCurrentDir was not found
+ if (currentDir == null) {
+ currentDir = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR); // never returns null
+ }
+
+ setFile(currentDir);
+
+ } else {
+ Log_OC.wtf(TAG, "onAccountChanged was called with NULL account associated!");
+ }
+ }
+