+ * 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 should return null
+ }
+ setFile(file);
+
+ if (findViewById(android.R.id.content) != null && !stateWasRecovered) {
+ Log_OC.e(TAG, "Initializing Fragments in onAccountChanged..");
+ initFragmentsWithFile();
+ } else {
+ Log_OC.e(TAG, "Fragment initializacion ignored in onAccountChanged due to lack of CONTENT VIEW");
+ }
+
+ } 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) {
+ /// Second fragment
+ OCFile file = getFile();
+ Fragment secondFragment = chooseInitialSecondFragment(file);
+ if (secondFragment != null) {
+ setSecondFragment(secondFragment);
+ }
+
+ } 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;