+ * 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();
+ 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
+ if (mStorageManager.getFileById(file.getParentId()) == 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());
+ }
+ fileIt = mStorageManager.getFileById(fileIt.getParentId());
+ }
+ 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);
+ }
+
+
+ } else {
+ Log_OC.wtf(TAG, "onAccountChanged was called with NULL account associated!");
+ }
+ }
+
+
+ private void createMinFragments() {
+ OCFileListFragment listOfFiles = new OCFileListFragment();
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
+ transaction.add(R.id.left_fragment_container, listOfFiles, TAG_LIST_OF_FILES);
+ transaction.commit();
+ }
+
+ private void initFragmentsWithFile() {
+ if (getAccount() != null && getFile() != null) {
+ /// First fragment
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
+ if (listOfFiles != null) {
+ listOfFiles.listDirectory(getCurrentDir());
+ } else {
+ Log.e(TAG, "Still have a chance to lose the initializacion of list fragment >(");
+ }
+
+ /// Second fragment
+ OCFile file = getFile();
+ Fragment secondFragment = chooseInitialSecondFragment(file);
+ if (secondFragment != null) {
+ setSecondFragment(secondFragment);
+ updateFragmentsVisibility(true);
+ updateNavigationElementsInActionBar(file);
+
+ } else {
+ cleanSecondFragment();
+ }
+
+ } else {
+ Log.wtf(TAG, "initFragments() called with invalid NULLs!");
+ if (getAccount() == null) {
+ Log.wtf(TAG, "\t account is NULL");
+ }
+ if (getFile() == null) {
+ Log.wtf(TAG, "\t file is NULL");
+ }
+ }
+ }
+
+ private Fragment chooseInitialSecondFragment(OCFile file) {
+ Fragment secondFragment = null;
+ if (file != null && !file.isDirectory()) {
+ if (file.isDown() && PreviewMediaFragment.canBePreviewed(file)
+ && file.getLastSyncDateForProperties() > 0 // temporal fix
+ ) {
+ int startPlaybackPosition = getIntent().getIntExtra(PreviewVideoActivity.EXTRA_START_POSITION, 0);
+ boolean autoplay = getIntent().getBooleanExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, true);
+ secondFragment = new PreviewMediaFragment(file, getAccount(), startPlaybackPosition, autoplay);
+
+ } else {
+ secondFragment = new FileDetailFragment(file, getAccount());
+ }
+ }
+ return secondFragment;