X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/f787213cd1cae854c169d263d3636e1de4dffa94..1fbc44b5743380523af7999c072299aad79fb65b:/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 6c09cbfd..9348f367 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -99,6 +99,7 @@ import com.owncloud.android.ui.fragment.OCFileListFragment; import com.owncloud.android.ui.preview.PreviewImageActivity; import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.ui.preview.PreviewMediaFragment; +import com.owncloud.android.ui.preview.PreviewTextFragment; import com.owncloud.android.ui.preview.PreviewVideoActivity; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.ErrorMessageAdapter; @@ -107,7 +108,6 @@ import com.owncloud.android.utils.UriUtils; import java.io.File; - /** * Displays, what files the user has available in his ownCloud. */ @@ -174,7 +174,6 @@ public class FileDisplayActivity extends HookActivity mSyncInProgress = savedInstanceState.getBoolean(KEY_SYNC_IN_PROGRESS); mWaitingToSend = (OCFile) savedInstanceState.getParcelable( FileDisplayActivity.KEY_WAITING_TO_SEND); - } else { mWaitingToPreview = null; mSyncInProgress = false; @@ -212,7 +211,7 @@ public class FileDisplayActivity extends HookActivity mProgressBar.setIndeterminate(mSyncInProgress); // always AFTER setContentView(...) ; to work around bug in its implementation - + setBackgroundText(); Log_OC.v(TAG, "onCreate() end"); @@ -286,7 +285,6 @@ public class FileDisplayActivity extends HookActivity } } - private void createMinFragments() { OCFileListFragment listOfFiles = new OCFileListFragment(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); @@ -302,6 +300,7 @@ public class FileDisplayActivity extends HookActivity listOfFiles.listDirectory(getCurrentDir()); // TODO Enable when "On Device" is recovered // listOfFiles.listDirectory(getCurrentDir(), MainApp.getOnlyOnDevice()); + } else { Log_OC.e(TAG, "Still have a chance to lose the initializacion of list fragment >("); } @@ -313,9 +312,11 @@ public class FileDisplayActivity extends HookActivity setSecondFragment(secondFragment); updateFragmentsVisibility(true); updateActionBarTitleAndHomeButton(file); - + } else { cleanSecondFragment(); + if (file.isDown() && PreviewTextFragment.canBePreviewed(file)) + startTextPreview(file); } } else { @@ -342,9 +343,11 @@ public class FileDisplayActivity extends HookActivity secondFragment = new PreviewMediaFragment(file, getAccount(), startPlaybackPosition, autoplay); + } else if (file.isDown() && PreviewTextFragment.canBePreviewed(file)) { + secondFragment = null; } else { - secondFragment = FileDetailFragment.newInstance(file, getAccount()); - } + secondFragment = FileDetailFragment.newInstance(file, getAccount()); + } } return secondFragment; } @@ -461,6 +464,9 @@ public class FileDisplayActivity extends HookActivity if (PreviewMediaFragment.canBePreviewed(mWaitingToPreview)) { startMediaPreview(mWaitingToPreview, 0, true); detailsFragmentChanged = true; + } else if (PreviewTextFragment.canBePreviewed(mWaitingToPreview)) { + startTextPreview(mWaitingToPreview); + detailsFragmentChanged = true; } else { getFileOperationsHelper().openFile(mWaitingToPreview); } @@ -503,6 +509,7 @@ public class FileDisplayActivity extends HookActivity dialog.show(getSupportFragmentManager(), DIALOG_CREATE_FOLDER); break; } + case R.id.action_sync_account: { startSynchronization(); break; @@ -511,7 +518,6 @@ public class FileDisplayActivity extends HookActivity UploadSourceDialogFragment dialog = UploadSourceDialogFragment.newInstance(getAccount()); dialog.show(getSupportFragmentManager(), DIALOG_UPLOAD_SOURCE); - break; } case android.R.id.home: { @@ -815,11 +821,9 @@ public class FileDisplayActivity extends HookActivity protected void onResume() { Log_OC.v(TAG, "onResume() start"); super.onResume(); - // refresh Navigation Drawer account list mNavigationDrawerAdapter.updateAccountList(); - // refresh list of files refreshListOfFilesFragment(); @@ -847,6 +851,7 @@ public class FileDisplayActivity extends HookActivity registerReceiver(mDownloadFinishReceiver, downloadIntentFilter); Log_OC.v(TAG, "onResume() end"); + } @@ -890,7 +895,7 @@ public class FileDisplayActivity extends HookActivity FileSyncAdapter.EXTRA_RESULT); boolean sameAccount = (getAccount() != null && accountName.equals(getAccount().name) && getStorageManager() != null); - + if (sameAccount) { if (FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) { @@ -911,6 +916,7 @@ public class FileDisplayActivity extends HookActivity synchFolderRemotePath), Toast.LENGTH_LONG) .show(); + browseToRoot(); } else { @@ -939,8 +945,8 @@ public class FileDisplayActivity extends HookActivity .equals(event)); if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED. - equals(event) && - /// TODO refactor and make common + equals(event) &&/// TODO refactor and make common + synchResult != null && !synchResult.isSuccess() && (synchResult.getCode() == ResultCode.UNAUTHORIZED || synchResult.isIdPRedirection() || @@ -954,7 +960,6 @@ public class FileDisplayActivity extends HookActivity new OwnCloudAccount(getAccount(), context); client = (OwnCloudClientManagerFactory.getDefaultSingleton(). removeClientFor(ocAccount)); - if (client != null) { OwnCloudCredentials cred = client.getCredentials(); if (cred != null) { @@ -1041,7 +1046,11 @@ public class FileDisplayActivity extends HookActivity (uploadedRemotePath.startsWith(currentDir.getRemotePath())); if (sameAccount && isDescendant) { - refreshListOfFilesFragment(); + String linkedToRemotePath = + intent.getStringExtra(FileDownloader.EXTRA_LINKED_TO_PATH); + if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) { + refreshListOfFilesFragment(); + } } boolean uploadWasFine = intent.getBooleanExtra(FileUploader.EXTRA_UPLOAD_RESULT, @@ -1074,10 +1083,15 @@ public class FileDisplayActivity extends HookActivity cleanSecondFragment(); } - // Force the preview if the file is an image - if (uploadWasFine && PreviewImageFragment.canBePreviewed(getFile())) { - startImagePreview(getFile()); - } // TODO what about other kind of previews? + // Force the preview if the file is an image or text file + if (uploadWasFine) { + OCFile ocFile = getFile(); + if (PreviewImageFragment.canBePreviewed(ocFile)) + startImagePreview(getFile()); + else if (PreviewTextFragment.canBePreviewed(ocFile)) + startTextPreview(ocFile); + // TODO what about other kind of previews? + } } mProgressBar.setIndeterminate(false); @@ -1089,6 +1103,16 @@ public class FileDisplayActivity extends HookActivity } + // TODO refactor this receiver, and maybe DownloadFinishReceiver; this method is duplicated :S + private boolean isAscendant(String linkedToRemotePath) { + OCFile currentDir = getCurrentDir(); + return ( + currentDir != null && + currentDir.getRemotePath().startsWith(linkedToRemotePath) + ); + } + + } @@ -1100,11 +1124,10 @@ public class FileDisplayActivity extends HookActivity */ private class DownloadFinishReceiver extends BroadcastReceiver { - //int refreshCounter = 0; @Override public void onReceive(Context context, Intent intent) { try { - boolean sameAccount = isSameAccount(context, intent); + boolean sameAccount = isSameAccount(intent); String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); boolean isDescendant = isDescendant(downloadedRemotePath); @@ -1113,7 +1136,6 @@ public class FileDisplayActivity extends HookActivity String linkedToRemotePath = intent.getStringExtra(FileDownloader.EXTRA_LINKED_TO_PATH); if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) { - //Log_OC.v(TAG, "refresh #" + ++refreshCounter); refreshListOfFilesFragment(); } refreshSecondFragment( @@ -1126,7 +1148,7 @@ public class FileDisplayActivity extends HookActivity if (mWaitingToSend != null) { mWaitingToSend = getStorageManager().getFileByPath(mWaitingToSend.getRemotePath()); - if (mWaitingToSend.isDown()) { + if (mWaitingToSend.isDown()) { sendDownloadedFile(); } } @@ -1155,7 +1177,7 @@ public class FileDisplayActivity extends HookActivity ); } - private boolean isSameAccount(Context context, Intent intent) { + private boolean isSameAccount(Intent intent) { String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME); return (accountName != null && getAccount() != null && accountName.equals(getAccount().name)); @@ -1174,7 +1196,6 @@ public class FileDisplayActivity extends HookActivity startSyncFolderOperation(root, false); } cleanSecondFragment(); - } @@ -1206,6 +1227,20 @@ public class FileDisplayActivity extends HookActivity setFile(file); } + /** + * Shows the share view for sharing {@link OCFile} received as a + * parameter in the second fragment. + * + * @param file {@link OCFile} File to share with + */ + @Override + public void showShareFile(OCFile file) { + Intent intent = new Intent(this, ShareActivity.class); + intent.putExtra(EXTRA_FILE, file); + intent.putExtra(EXTRA_ACCOUNT, getAccount()); + startActivity(intent); + } + @Override protected void updateActionBarTitleAndHomeButton(OCFile chosenFile) { if (mDualPane) { @@ -1253,7 +1288,7 @@ public class FileDisplayActivity extends HookActivity } // a new chance to get the mDownloadBinder through // getFileDownloadBinder() - THIS IS A MESS - OCFileListFragment listOfFiles = getListOfFilesFragment(); + OCFileListFragment listOfFiles = getListOfFilesFragment(); if (listOfFiles != null) { listOfFiles.listDirectory(); // TODO Enable when "On Device" is recovered ? @@ -1337,8 +1372,6 @@ public class FileDisplayActivity extends HookActivity } } - - private void onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) { if (result.isSuccess()) { @@ -1347,7 +1380,6 @@ public class FileDisplayActivity extends HookActivity } } - private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, RemoteOperationResult result) { if (result.isSuccess()) { @@ -1369,6 +1401,9 @@ public class FileDisplayActivity extends HookActivity if (details instanceof PreviewMediaFragment) { // Refresh OCFile of the fragment ((PreviewMediaFragment) details).updateFile(file); + } else if (details instanceof PreviewTextFragment) { + // Refresh OCFile of the fragment + ((PreviewTextFragment) details).updateFile(file); } else { showDetails(file); } @@ -1390,7 +1425,7 @@ public class FileDisplayActivity extends HookActivity Toast msg = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), - Toast.LENGTH_LONG); + Toast.LENGTH_LONG); msg.show(); if (result.isSuccess()) { @@ -1403,7 +1438,7 @@ public class FileDisplayActivity extends HookActivity setFile(getStorageManager().getFileById(removedFile.getParentId())); cleanSecondFragment(); } - if (getStorageManager().getFileById(removedFile.getParentId()).equals(getCurrentDir())) { + if (getStorageManager().getFileById(removedFile.getParentId()).equals(getCurrentDir())){ refreshListOfFilesFragment(); } invalidateOptionsMenu(); @@ -1495,6 +1530,14 @@ public class FileDisplayActivity extends HookActivity } else { getFileOperationsHelper().openFile(renamedFile); } + } else if (details instanceof PreviewTextFragment && + renamedFile.equals(details.getFile())) { + ((PreviewTextFragment) details).updateFile(renamedFile); + if (PreviewTextFragment.canBePreviewed(renamedFile)) { + startTextPreview(renamedFile); + } else { + getFileOperationsHelper().openFile(renamedFile); + } } } @@ -1505,7 +1548,7 @@ public class FileDisplayActivity extends HookActivity } else { Toast msg = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), - Toast.LENGTH_LONG); + Toast.LENGTH_LONG); msg.show(); if (result.isSslRecoverableException()) { @@ -1522,6 +1565,7 @@ public class FileDisplayActivity extends HookActivity OCFile syncedFile = operation.getLocalFile(); onTransferStateChanged(syncedFile, true, true); invalidateOptionsMenu(); + refreshShowDetails(); } } } @@ -1618,6 +1662,7 @@ public class FileDisplayActivity extends HookActivity getApplicationContext() ); synchFolderOp.execute(getAccount(), MainApp.getAppContext(), this, null, null); + mProgressBar.setIndeterminate(true); setBackgroundText(); @@ -1675,7 +1720,6 @@ public class FileDisplayActivity extends HookActivity showDetailsIntent.putExtra(EXTRA_FILE, file); showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount()); startActivity(showDetailsIntent); - } /** @@ -1697,6 +1741,23 @@ public class FileDisplayActivity extends HookActivity } /** + * Stars the preview of a text file {@link OCFile}. + * + * @param file Text {@link OCFile} to preview. + */ + public void startTextPreview(OCFile file) { + Bundle args = new Bundle(); + args.putParcelable(EXTRA_FILE, file); + args.putParcelable(EXTRA_ACCOUNT, getAccount()); + Fragment textPreviewFragment = Fragment.instantiate(getApplicationContext(), + PreviewTextFragment.class.getName(), args); + setSecondFragment(textPreviewFragment); + updateFragmentsVisibility(true); + //updateNavigationElementsInActionBar(file); + setFile(file); + } + + /** * Requests the download of the received {@link OCFile} , updates the UI * to monitor the download progress and prepares the activity to preview * or open the file when the download finishes.