X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/3ecabe3ea7a657c3b5f23bf28d260f25d4f617dd..12bffce50ce12ab8b1ee90be53584c3a770a5de9:/src/com/owncloud/android/ui/activity/FileDisplayActivity.java diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index ae8c9207..508b7bec 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -208,7 +208,14 @@ public class FileDisplayActivity extends FileActivity implements /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account OCFile file = getFile(); if (file != null) { - file = mStorageManager.getFileByPath(file.getRemotePath()); // currentDir = null if not in the current Account + 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 @@ -216,18 +223,24 @@ public class FileDisplayActivity extends FileActivity implements } setFile(file); mDirectories.clear(); - while(file != null && file.getFileName() != OCFile.PATH_SEPARATOR) { - if (file.isDirectory()) { - mDirectories.add(file.getFileName()); + OCFile fileIt = file; + while(fileIt != null && fileIt.getFileName() != OCFile.PATH_SEPARATOR) { + if (fileIt.isDirectory()) { + mDirectories.add(fileIt.getFileName()); } - file = mStorageManager.getFileById(file.getParentId()); + 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!"); } @@ -243,6 +256,14 @@ public class FileDisplayActivity extends FileActivity implements 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); @@ -269,7 +290,9 @@ public class FileDisplayActivity extends FileActivity implements private Fragment chooseInitialSecondFragment(OCFile file) { Fragment secondFragment = null; if (file != null && !file.isDirectory()) { - if (file.isDown() && PreviewMediaFragment.canBePreviewed(file)) { + 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); @@ -608,12 +631,6 @@ public class FileDisplayActivity extends FileActivity implements mDownloadFinishReceiver = new DownloadFinishReceiver(); registerReceiver(mDownloadFinishReceiver, downloadIntentFilter); - // List current directory - OCFileListFragment listOfFiles = getListOfFilesFragment(); - if (listOfFiles != null) { - listOfFiles.listDirectory(getCurrentDir()); // TODO we should find the way to avoid the need of this (maybe it's not necessary yet; to check) - } - Log_OC.d(TAG, "onResume() end"); } @@ -828,8 +845,9 @@ public class FileDisplayActivity extends FileActivity implements if (fileListFragment != null) { fileListFragment.listDirectory(currentDir); } + if (getSecondFragment() == null) + setFile(currentDir); } - setFile(currentDir); setSupportProgressBarIndeterminateVisibility(inProgress); removeStickyBroadcast(intent); @@ -988,9 +1006,9 @@ public class FileDisplayActivity extends FileActivity implements /** * TODO */ - private void updateNavigationElementsInActionBar(OCFile currentFile) { + private void updateNavigationElementsInActionBar(OCFile chosenFile) { ActionBar actionBar = getSupportActionBar(); - if (currentFile == null || mDualPane) { + if (chosenFile == null || mDualPane) { // only list of files - set for browsing through folders OCFile currentDir = getCurrentDir(); actionBar.setDisplayHomeAsUpEnabled(currentDir != null && currentDir.getParentId() != 0); @@ -1001,7 +1019,7 @@ public class FileDisplayActivity extends FileActivity implements } else { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowTitleEnabled(true); - actionBar.setTitle(currentFile.getFileName()); + actionBar.setTitle(chosenFile.getFileName()); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); } } @@ -1011,17 +1029,9 @@ public class FileDisplayActivity extends FileActivity implements * {@inheritDoc} */ @Override - public OCFile getInitialDirectory() { - return getCurrentDir(); - } - - - /** - * {@inheritDoc} - */ - @Override public void onFileStateChanged() { refeshListOfFilesFragment(); + updateNavigationElementsInActionBar(getSecondFragment().getFile()); } @@ -1317,12 +1327,11 @@ public class FileDisplayActivity extends FileActivity implements if (file != null) { if (file.isDirectory()) { return file; - } else { + } else if (mStorageManager != null) { return mStorageManager.getFileById(file.getParentId()); } - } else { - return null; } + return null; } }