X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/a8fade7369bc8d1752dc4ba5fe07935cac84e96f..966daf3b9ec4e978b35408252a88ef5accbe59b1:/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 5eba7dc0..d65ec6c8 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -60,7 +60,6 @@ import com.actionbarsherlock.view.Window; import com.owncloud.android.Log_OC; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountAuthenticator; -import com.owncloud.android.datamodel.DataStorageManager; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader; @@ -103,7 +102,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa private ArrayAdapter mDirectories; /** Access point to the cached database for the current ownCloud {@link Account} */ - private DataStorageManager mStorageManager = null; + private FileDataStorageManager mStorageManager = null; private SyncBroadcastReceiver mSyncBroadcastReceiver; private UploadFinishReceiver mUploadFinishReceiver; @@ -229,25 +228,17 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa } if (file == null) { // fall back to root folder - file = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR); // never returns null + file = mStorageManager.getFileByPath(OCFile.ROOT_PATH); // 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); + setNavigationListWithFolder(file); if (!stateWasRecovered) { Log_OC.e(TAG, "Initializing Fragments in onAccountChanged.."); initFragmentsWithFile(); } else { - updateFragmentsVisibility(!file.isDirectory()); - updateNavigationElementsInActionBar(file.isDirectory() ? null : file); + updateFragmentsVisibility(!file.isFolder()); + updateNavigationElementsInActionBar(file.isFolder() ? null : file); } @@ -257,6 +248,19 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa } + private void setNavigationListWithFolder(OCFile file) { + mDirectories.clear(); + OCFile fileIt = file; + while(fileIt != null && fileIt.getFileName() != OCFile.ROOT_PATH) { + if (fileIt.isFolder()) { + mDirectories.add(fileIt.getFileName()); + } + fileIt = mStorageManager.getFileById(fileIt.getParentId()); + } + mDirectories.add(OCFile.PATH_SEPARATOR); + } + + private void createMinFragments() { OCFileListFragment listOfFiles = new OCFileListFragment(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); @@ -299,7 +303,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa private Fragment chooseInitialSecondFragment(OCFile file) { Fragment secondFragment = null; - if (file != null && !file.isDirectory()) { + if (file != null && !file.isFolder()) { if (file.isDown() && PreviewMediaFragment.canBePreviewed(file) && file.getLastSyncDateForProperties() > 0 // temporal fix ) { @@ -488,15 +492,22 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa @Override public boolean onNavigationItemSelected(int itemPosition, long itemId) { - int i = itemPosition; - while (i-- != 0) { - onBackPressed(); - } - // the next operation triggers a new call to this method, but it's necessary to - // ensure that the name exposed in the action bar is the current directory when the - // user selected it in the navigation list - if (itemPosition != 0) + if (itemPosition != 0) { + String targetPath = ""; + for (int i=itemPosition; i < mDirectories.getCount() - 1; i++) { + targetPath = mDirectories.getItem(i) + OCFile.PATH_SEPARATOR + targetPath; + } + targetPath = OCFile.PATH_SEPARATOR + targetPath; + OCFile targetFolder = mStorageManager.getFileByPath(targetPath); + if (targetFolder != null) { + browseTo(targetFolder); + } + + // the next operation triggers a new call to this method, but it's necessary to + // ensure that the name exposed in the action bar is the current directory when the + // user selected it in the navigation list getSupportActionBar().setSelectedNavigationItem(0); + } return true; } @@ -594,23 +605,24 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa @Override public void onBackPressed() { - if (!mSyncInProgress) { - OCFileListFragment listOfFiles = getListOfFilesFragment(); - if (mDualPane || getSecondFragment() == null) { - if (listOfFiles != null) { // should never be null, indeed - if (mDirectories.getCount() <= 1) { - finish(); - return; - } + OCFileListFragment listOfFiles = getListOfFilesFragment(); + if (mDualPane || getSecondFragment() == null) { + if (listOfFiles != null) { // should never be null, indeed + if (mDirectories.getCount() <= 1) { + finish(); + return; + } + int levelsUp = listOfFiles.onBrowseUp(); + for (int i=0; i < levelsUp && mDirectories.getCount() > 1 ; i++) { popDirname(); - listOfFiles.onBrowseUp(); } } - if (listOfFiles != null) { // should never be null, indeed - setFile(listOfFiles.getCurrentFile()); - } - cleanSecondFragment(); } + if (listOfFiles != null) { // should never be null, indeed + setFile(listOfFiles.getCurrentFile()); + } + cleanSecondFragment(); + } @Override @@ -652,19 +664,6 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa @Override - protected void onStart() { - super.onStart(); - Log_OC.e(TAG, "onStart() start"); - - // Update the sync operation - if (mSyncInProgress){ - } - - Log_OC.e(TAG, "onStart() end"); - } - - - @Override protected void onPause() { super.onPause(); Log_OC.e(TAG, "onPause() start"); @@ -821,10 +820,10 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa /** * Pushes a directory to the drop down list * @param directory to push - * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false. + * @throws IllegalArgumentException If the {@link OCFile#isFolder()} returns false. */ public void pushDirname(OCFile directory) { - if(!directory.isDirectory()){ + if(!directory.isFolder()){ throw new IllegalArgumentException("Only directories may be pushed!"); } mDirectories.insert(directory.getFileName(), 0); @@ -876,42 +875,44 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa public void onReceive(Context context, Intent intent) { boolean inProgress = intent.getBooleanExtra(FileSyncService.IN_PROGRESS, false); String accountName = intent.getStringExtra(FileSyncService.ACCOUNT_NAME); - - Log_OC.d(TAG, "sync of account " + accountName + " is in_progress: " + inProgress); - RemoteOperationResult synchResult = (RemoteOperationResult)intent.getSerializableExtra(FileSyncService.SYNC_RESULT); - + if (getAccount() != null && accountName.equals(getAccount().name)) { String synchFolderRemotePath = intent.getStringExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH); - boolean fillBlankRoot = false; - OCFile currentDir = getCurrentDir(); - if (currentDir == null) { - currentDir = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR); - fillBlankRoot = (currentDir != null); - } + OCFile currentFile = (getFile() == null) ? null : mStorageManager.getFileByPath(getFile().getRemotePath()); + OCFile currentDir = (getCurrentDir() == null) ? null : mStorageManager.getFileByPath(getCurrentDir().getRemotePath()); - if ((synchFolderRemotePath != null && currentDir != null && (currentDir.getRemotePath().equals(synchFolderRemotePath))) - || fillBlankRoot ) { - if (!fillBlankRoot) - currentDir = getStorageManager().getFileByPath(synchFolderRemotePath); - OCFileListFragment fileListFragment = getListOfFilesFragment(); - if (fileListFragment != null) { - fileListFragment.listDirectory(currentDir); - + if (currentDir == null) { + // current folder was removed from the server + Toast.makeText( FileDisplayActivity.this, + String.format(getString(R.string.sync_current_folder_was_removed), mDirectories.getItem(0)), + Toast.LENGTH_LONG) + .show(); + browseToRoot(); + + } else { + if (currentFile == null && !getFile().isFolder()) { + // currently selected file was removed in the server, and now we know it + cleanSecondFragment(); + currentFile = currentDir; + } + + if (synchFolderRemotePath != null && currentDir.getRemotePath().equals(synchFolderRemotePath)) { + OCFileListFragment fileListFragment = getListOfFilesFragment(); + if (fileListFragment != null) { + fileListFragment.listDirectory(currentDir); + } } - if (getSecondFragment() == null) - setFile(currentDir); + setFile(currentFile); } setSupportProgressBarIndeterminateVisibility(inProgress); removeStickyBroadcast(intent); - mSyncInProgress = inProgress; } - if (synchResult != null) { if (synchResult.getCode().equals(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED)) { @@ -981,11 +982,43 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa * {@inheritDoc} */ @Override - public DataStorageManager getStorageManager() { + public FileDataStorageManager getStorageManager() { return mStorageManager; } + public void browseToRoot() { + OCFileListFragment listOfFiles = getListOfFilesFragment(); + if (listOfFiles != null) { // should never be null, indeed + while (mDirectories.getCount() > 1) { + popDirname(); + } + OCFile root = mStorageManager.getFileByPath(OCFile.ROOT_PATH); + listOfFiles.listDirectory(root); + setFile(listOfFiles.getCurrentFile()); + startSyncFolderOperation(root); + } + cleanSecondFragment(); + } + + + public void browseTo(OCFile folder) { + if (folder == null || !folder.isFolder()) { + throw new IllegalArgumentException("Trying to browse to invalid folder " + folder); + } + OCFileListFragment listOfFiles = getListOfFilesFragment(); + if (listOfFiles != null) { + setNavigationListWithFolder(folder); + listOfFiles.listDirectory(folder); + setFile(listOfFiles.getCurrentFile()); + startSyncFolderOperation(folder); + } else { + Log_OC.e(TAG, "Unexpected null when accessing list fragment"); + } + cleanSecondFragment(); + } + + /** * {@inheritDoc} * @@ -997,7 +1030,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa cleanSecondFragment(); // Sync Folder - startSyncFolderOperation(directory.getRemotePath(), directory.getFileId()); + startSyncFolderOperation(directory); } @@ -1073,7 +1106,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa if (chosenFile == null || mDualPane) { // only list of files - set for browsing through folders OCFile currentDir = getCurrentDir(); - actionBar.setDisplayHomeAsUpEnabled(currentDir != null && currentDir.getParentId() != 0 && !mSyncInProgress); + actionBar.setDisplayHomeAsUpEnabled(currentDir != null && currentDir.getParentId() != 0); actionBar.setDisplayShowTitleEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); actionBar.setListNavigationCallbacks(mDirectories, this); // assuming mDirectories is updated @@ -1371,7 +1404,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa // Create directory path += newDirectoryName + OCFile.PATH_SEPARATOR; - RemoteOperation operation = new CreateFolderOperation(path, getCurrentDir().getFileId(), mStorageManager); + RemoteOperation operation = new CreateFolderOperation(path, false, mStorageManager); operation.execute( getAccount(), FileDisplayActivity.this, FileDisplayActivity.this, @@ -1398,7 +1431,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa private OCFile getCurrentDir() { OCFile file = getFile(); if (file != null) { - if (file.isDirectory()) { + if (file.isFolder()) { return file; } else if (mStorageManager != null) { return mStorageManager.getFileById(file.getParentId()); @@ -1407,21 +1440,20 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa return null; } - public void startSyncFolderOperation(String remotePath, long parentId) { + public void startSyncFolderOperation(OCFile folder) { long currentSyncTime = System.currentTimeMillis(); mSyncInProgress = true; // perform folder synchronization - RemoteOperation synchFolderOp = new SynchronizeFolderOperation( remotePath, - currentSyncTime, - parentId, - false, - false, - getStorageManager(), - getAccount(), - getApplicationContext() - ); + RemoteOperation synchFolderOp = new SynchronizeFolderOperation( folder, + currentSyncTime, + false, + false, + getStorageManager(), + getAccount(), + getApplicationContext() + ); synchFolderOp.execute(getAccount(), this, null, null, this); setSupportProgressBarIndeterminateVisibility(true);