import android.accounts.AccountManager;
import android.accounts.AuthenticatorException;
import android.annotation.TargetApi;
-import android.app.AlertDialog;
+import android.support.v7.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
+import android.support.v4.content.ContextCompat;
import android.support.v4.view.GravityCompat;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
-import android.view.Window;
+import android.widget.ProgressBar;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
import android.widget.Toast;
import com.owncloud.android.MainApp;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.operations.CopyFileOperation;
import com.owncloud.android.operations.CreateFolderOperation;
import com.owncloud.android.operations.CreateShareOperation;
import com.owncloud.android.operations.MoveFileOperation;
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;
import java.io.File;
-import java.io.File;
-import java.io.IOException;
-
-
/**
* Displays, what files the user has available in his ownCloud.
*/
implements FileFragment.ContainerActivity,
OnSslUntrustedCertListener, OnEnforceableRefreshListener {
+
+
private SyncBroadcastReceiver mSyncBroadcastReceiver;
private UploadFinishReceiver mUploadFinishReceiver;
private DownloadFinishReceiver mDownloadFinishReceiver;
private boolean mDualPane;
private View mLeftFragmentContainer;
private View mRightFragmentContainer;
+ private ProgressBar mProgressBar;
private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
private static final String KEY_SYNC_IN_PROGRESS = "SYNC_IN_PROGRESS";
@Override
protected void onCreate(Bundle savedInstanceState) {
Log_OC.v(TAG, "onCreate() start");
- requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState); // this calls onAccountChanged() when ownCloud Account
// is valid
mSyncInProgress = savedInstanceState.getBoolean(KEY_SYNC_IN_PROGRESS);
mWaitingToSend = (OCFile) savedInstanceState.getParcelable(
FileDisplayActivity.KEY_WAITING_TO_SEND);
-
} else {
mWaitingToPreview = null;
mSyncInProgress = false;
// Navigation Drawer
initDrawer();
+ mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
+ mProgressBar.setIndeterminateDrawable(
+ ContextCompat.getDrawable(this,
+ R.drawable.actionbar_progress_indeterminate_horizontal));
+
mDualPane = getResources().getBoolean(R.bool.large_land_layout);
mLeftFragmentContainer = findViewById(R.id.left_fragment_container);
mRightFragmentContainer = findViewById(R.id.right_fragment_container);
// according to the official
// documentation
- setSupportProgressBarIndeterminateVisibility(mSyncInProgress
- /*|| mRefreshSharesInProgress*/);
+ // enable ActionBar app icon to behave as action to toggle nav drawer
+ //getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ getSupportActionBar().setHomeButtonEnabled(true);
+
+ mProgressBar.setIndeterminate(mSyncInProgress);
// always AFTER setContentView(...) ; to work around bug in its implementation
-
+
setBackgroundText();
Log_OC.v(TAG, "onCreate() end");
protected void onStart() {
Log_OC.v(TAG, "onStart() start");
super.onStart();
- getSupportActionBar().setIcon(DisplayUtils.getSeasonalIconId());
Log_OC.v(TAG, "onStart() end");
}
}
setFile(file);
+ if (mAccountWasSet) {
+ RelativeLayout navigationDrawerLayout = (RelativeLayout) findViewById(R.id.left_drawer);
+ if (navigationDrawerLayout != null && getAccount() != null) {
+ TextView username = (TextView) navigationDrawerLayout.findViewById(R.id.drawer_username);
+ int lastAtPos = getAccount().name.lastIndexOf("@");
+ username.setText(getAccount().name.substring(0, lastAtPos));
+ }
+ }
+
if (!stateWasRecovered) {
Log_OC.d(TAG, "Initializing Fragments in onAccountChanged..");
initFragmentsWithFile();
}
}
-
private void createMinFragments() {
OCFileListFragment listOfFiles = new OCFileListFragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
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 >(");
}
setSecondFragment(secondFragment);
updateFragmentsVisibility(true);
updateActionBarTitleAndHomeButton(file);
-
+
} else {
cleanSecondFragment();
+ if (file.isDown() && PreviewTextFragment.canBePreviewed(file))
+ startTextPreview(file);
}
} else {
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;
}
if (PreviewMediaFragment.canBePreviewed(mWaitingToPreview)) {
startMediaPreview(mWaitingToPreview, 0, true);
detailsFragmentChanged = true;
+ } else if (PreviewTextFragment.canBePreviewed(mWaitingToPreview)) {
+ startTextPreview(mWaitingToPreview);
+ detailsFragmentChanged = true;
} else {
getFileOperationsHelper().openFile(mWaitingToPreview);
}
dialog.show(getSupportFragmentManager(), DIALOG_CREATE_FOLDER);
break;
}
+
case R.id.action_sync_account: {
startSynchronization();
break;
UploadSourceDialogFragment dialog =
UploadSourceDialogFragment.newInstance(getAccount());
dialog.show(getSupportFragmentManager(), DIALOG_UPLOAD_SOURCE);
-
break;
}
case android.R.id.home: {
resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {
requestMultipleUpload(data, resultCode);
-//<<<<<<< HEAD
} else if (requestCode == ACTION_MOVE_FILES && resultCode == RESULT_OK){
-/*=======
- } else if (requestCode == ACTION_MOVE_FILES && (resultCode == RESULT_OK ||
- resultCode == MoveActivity.RESULT_OK_AND_MOVE)) {
->>>>>>> Added 'ACTION_COPY_FILES'.
-*/
-
final Intent fData = data;
final int fResultCode = resultCode;
getHandler().postDelayed(
DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS
);
+ } else if (requestCode == ACTION_COPY_FILES && resultCode == RESULT_OK) {
+
+ final Intent fData = data;
+ final int fResultCode = resultCode;
+ getHandler().postDelayed(
+ new Runnable() {
+ @Override
+ public void run() {
+ requestCopyOperation(fData, fResultCode);
+ }
+ },
+ DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS
+ );
+
} else {
super.onActivityResult(requestCode, resultCode, data);
}
getFileOperationsHelper().moveFile(folderToMoveAt, targetFile);
}
+ /**
+ * Request the operation for copying the file/folder from one path to another
+ *
+ * @param data Intent received
+ * @param resultCode Result code received
+ */
+ private void requestCopyOperation(Intent data, int resultCode) {
+ OCFile folderToMoveAt = data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
+ OCFile targetFile = data.getParcelableExtra(FolderPickerActivity.EXTRA_FILE);
+ getFileOperationsHelper().copyFile(folderToMoveAt, targetFile);
+ }
+
@Override
public void onBackPressed() {
- OCFileListFragment listOfFiles = getListOfFilesFragment();
- if (mDualPane || getSecondFragment() == null) {
- OCFile currentDir = getCurrentDir();
- if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) {
- finish();
- return;
+ if (!isDrawerOpen()){
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
+ if (mDualPane || getSecondFragment() == null) {
+ OCFile currentDir = getCurrentDir();
+ if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) {
+ finish();
+ return;
+ }
+ if (listOfFiles != null) { // should never be null, indeed
+ listOfFiles.onBrowseUp();
+ }
}
if (listOfFiles != null) { // should never be null, indeed
- listOfFiles.onBrowseUp();
+ setFile(listOfFiles.getCurrentFile());
}
+ cleanSecondFragment();
+ } else {
+ super.onBackPressed();
}
- if (listOfFiles != null) { // should never be null, indeed
- setFile(listOfFiles.getCurrentFile());
- }
- cleanSecondFragment();
-
}
@Override
protected void onResume() {
Log_OC.v(TAG, "onResume() start");
super.onResume();
-
// refresh Navigation Drawer account list
mNavigationDrawerAdapter.updateAccountList();
-
// refresh list of files
refreshListOfFilesFragment();
registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
Log_OC.v(TAG, "onResume() end");
+
}
FileSyncAdapter.EXTRA_RESULT);
boolean sameAccount = (getAccount() != null &&
accountName.equals(getAccount().name) && getStorageManager() != null);
-
+
if (sameAccount) {
if (FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) {
synchFolderRemotePath),
Toast.LENGTH_LONG)
.show();
+
browseToRoot();
} else {
.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() ||
new OwnCloudAccount(getAccount(), context);
client = (OwnCloudClientManagerFactory.getDefaultSingleton().
removeClientFor(ocAccount));
-
if (client != null) {
OwnCloudCredentials cred = client.getCredentials();
if (cred != null) {
}
removeStickyBroadcast(intent);
Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
- setSupportProgressBarIndeterminateVisibility(mSyncInProgress
- /*|| mRefreshSharesInProgress*/);
+ mProgressBar.setIndeterminate(mSyncInProgress);
+ //mProgressBar.setVisibility((mSyncInProgress) ? View.VISIBLE : View.INVISIBLE);
+ //setSupportProgressBarIndeterminateVisibility(mSyncInProgress
+ /*|| mRefreshSharesInProgress*/ //);
setBackgroundText();
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);
} finally {
if (intent != null) {
removeStickyBroadcast(intent);
if (mWaitingToSend != null) {
mWaitingToSend =
getStorageManager().getFileByPath(mWaitingToSend.getRemotePath());
- if (mWaitingToSend.isDown()) {
+ if (mWaitingToSend.isDown()) {
sendDownloadedFile();
}
}
startSyncFolderOperation(root, false);
}
cleanSecondFragment();
-
}
}
-
@Override
protected ServiceConnection newTransferenceServiceConnection() {
return new ListServiceConnection();
}
// 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 ?
} else if (operation instanceof MoveFileOperation) {
onMoveFileOperationFinish((MoveFileOperation) operation, result);
+
+ } else if (operation instanceof CopyFileOperation) {
+ onCopyFileOperationFinish((CopyFileOperation) operation, result);
}
}
-
-
private void onCreateShareOperationFinish(CreateShareOperation operation,
RemoteOperationResult result) {
if (result.isSuccess()) {
}
}
-
private void onUnshareLinkOperationFinish(UnshareLinkOperation operation,
RemoteOperationResult result) {
if (result.isSuccess()) {
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);
}
Toast msg = Toast.makeText(this,
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
- Toast.LENGTH_LONG);
+ Toast.LENGTH_LONG);
msg.show();
if (result.isSuccess()) {
setFile(getStorageManager().getFileById(removedFile.getParentId()));
cleanSecondFragment();
}
- if (getStorageManager().getFileById(removedFile.getParentId()).equals(getCurrentDir())) {
+ if (getStorageManager().getFileById(removedFile.getParentId()).equals(getCurrentDir())){
refreshListOfFilesFragment();
}
invalidateOptionsMenu();
}
}
+ /**
+ * Updates the view associated to the activity after the finish of an operation trying to copy a
+ * file.
+ *
+ * @param operation Copy operation performed.
+ * @param result Result of the copy operation.
+ */
+ private void onCopyFileOperationFinish(CopyFileOperation operation, RemoteOperationResult result) {
+ if (result.isSuccess()) {
+ dismissLoadingDialog();
+ refreshListOfFilesFragment();
+ } else {
+ dismissLoadingDialog();
+ try {
+ Toast msg = Toast.makeText(FileDisplayActivity.this,
+ ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+ Toast.LENGTH_LONG);
+ msg.show();
+
+ } catch (NotFoundException e) {
+ Log_OC.e(TAG, "Error while trying to show fail message ", e);
+ }
+ }
+ }
/**
* Updates the view associated to the activity after the finish of an operation trying to rename
} 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);
+ }
}
}
} else {
Toast msg = Toast.makeText(this,
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
- Toast.LENGTH_LONG);
+ Toast.LENGTH_LONG);
msg.show();
if (result.isSslRecoverableException()) {
getApplicationContext()
);
synchFolderOp.execute(getAccount(), MainApp.getAppContext(), this, null, null);
-
- setSupportProgressBarIndeterminateVisibility(true);
+
+ mProgressBar.setIndeterminate(true);
setBackgroundText();
}
showDetailsIntent.putExtra(EXTRA_FILE, file);
showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
startActivity(showDetailsIntent);
-
}
/**
}
/**
+ * 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.
}
}
- private void sortByDate(boolean ascending){
+ private void sortByDate(boolean ascending) {
getListOfFilesFragment().sortByDate(ascending);
}
- private void sortBySize(boolean ascending){
+ private void sortBySize(boolean ascending) {
getListOfFilesFragment().sortBySize(ascending);
}
- private void sortByName(boolean ascending){
+ private void sortByName(boolean ascending) {
getListOfFilesFragment().sortByName(ascending);
}