X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/aa354e5d73d2e1777b93e957220990d145f3b6ba..6f1fe5ad6d8b6f49275a8e44c9631cc65b1bafc8:/src/com/owncloud/android/ui/activity/FileActivity.java diff --git a/src/com/owncloud/android/ui/activity/FileActivity.java b/src/com/owncloud/android/ui/activity/FileActivity.java index 136bdb55..8eb20e4d 100644 --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/com/owncloud/android/ui/activity/FileActivity.java @@ -1,6 +1,9 @@ -/* ownCloud Android client application +/** + * ownCloud Android client application + * + * @author David A. Velasco * Copyright (C) 2011 Bartek Przybylski - * Copyright (C) 2012-2014 ownCloud Inc. + * Copyright (C) 2015 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -54,21 +57,21 @@ 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.CreateShareOperation; +import com.owncloud.android.operations.SynchronizeFolderOperation; import com.owncloud.android.operations.UnshareLinkOperation; - import com.owncloud.android.services.OperationsService; import com.owncloud.android.services.OperationsService.OperationsServiceBinder; +import com.owncloud.android.ui.dialog.CreateFolderDialogFragment; import com.owncloud.android.ui.dialog.LoadingDialog; +import com.owncloud.android.ui.dialog.SharePasswordDialogFragment; import com.owncloud.android.utils.ErrorMessageAdapter; /** * Activity with common behaviour for activities handling {@link OCFile}s in ownCloud {@link Account}s . - * - * @author David A. Velasco */ -public class FileActivity extends SherlockFragmentActivity -implements OnRemoteOperationListener, ComponentsGetter { +public class FileActivity extends SherlockFragmentActivity + implements OnRemoteOperationListener, ComponentsGetter { public static final String EXTRA_FILE = "com.owncloud.android.ui.activity.FILE"; public static final String EXTRA_ACCOUNT = "com.owncloud.android.ui.activity.ACCOUNT"; @@ -78,7 +81,8 @@ implements OnRemoteOperationListener, ComponentsGetter { public static final String TAG = FileActivity.class.getSimpleName(); private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT"; - private static final String KEY_WAITING_FOR_OP_ID = "WAITING_FOR_OP_ID";; + private static final String KEY_WAITING_FOR_OP_ID = "WAITING_FOR_OP_ID"; + private static final String DIALOG_SHARE_PASSWORD = "DIALOG_SHARE_PASSWORD"; protected static final long DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS = 200; @@ -157,7 +161,7 @@ implements OnRemoteOperationListener, ComponentsGetter { if (mUploadServiceConnection != null) { bindService(new Intent(this, FileUploader.class), mUploadServiceConnection, Context.BIND_AUTO_CREATE); } - + } @@ -220,6 +224,7 @@ implements OnRemoteOperationListener, ComponentsGetter { unbindService(mUploadServiceConnection); mUploadServiceConnection = null; } + super.onDestroy(); } @@ -255,8 +260,6 @@ implements OnRemoteOperationListener, ComponentsGetter { * to create a new ownCloud {@link Account}. * * POSTCONDITION: updates {@link #mAccountWasSet} and {@link #mAccountWasRestored}. - * - * @return 'True' if the checked {@link Account} was valid. */ private void swapToDefaultAccount() { // default to the most recently used account @@ -355,15 +358,12 @@ implements OnRemoteOperationListener, ComponentsGetter { protected ServiceConnection newTransferenceServiceConnection() { return null; } - /** * Helper class handling a callback from the {@link AccountManager} after the creation of * a new ownCloud {@link Account} finished, successfully or not. * * At this moment, only called after the creation of the first account. - * - * @author David A. Velasco */ public class AccountCreationCallback implements AccountManagerCallback { @@ -453,7 +453,8 @@ implements OnRemoteOperationListener, ComponentsGetter { if (result.getCode() == ResultCode.UNAUTHORIZED) { dismissLoadingDialog(); - Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), + Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, + operation, getResources()), Toast.LENGTH_LONG); t.show(); } @@ -464,7 +465,10 @@ implements OnRemoteOperationListener, ComponentsGetter { } else if (operation instanceof UnshareLinkOperation) { onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result); - } + } else if (operation instanceof SynchronizeFolderOperation) { + onSynchronizeFolderOperationFinish((SynchronizeFolderOperation)operation, result); + + } } protected void requestCredentialsUpdate() { @@ -478,7 +482,8 @@ implements OnRemoteOperationListener, ComponentsGetter { } - private void onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) { + private void onCreateShareOperationFinish(CreateShareOperation operation, + RemoteOperationResult result) { dismissLoadingDialog(); if (result.isSuccess()) { updateFileFromDB(); @@ -486,10 +491,19 @@ implements OnRemoteOperationListener, ComponentsGetter { Intent sendIntent = operation.getSendIntent(); startActivity(sendIntent); - } else { - Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), - Toast.LENGTH_LONG); - t.show(); + } else { + // Detect Failure (403) --> needs Password + if (result.getCode() == ResultCode.SHARE_FORBIDDEN) { + SharePasswordDialogFragment dialog = + SharePasswordDialogFragment.newInstance( new OCFile(operation.getPath()), + operation.getSendIntent()); + dialog.show(getSupportFragmentManager(), DIALOG_SHARE_PASSWORD); + } else { + Toast t = Toast.makeText(this, + ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), + Toast.LENGTH_LONG); + t.show(); + } } } @@ -506,7 +520,14 @@ implements OnRemoteOperationListener, ComponentsGetter { t.show(); } } - + + private void onSynchronizeFolderOperationFinish(SynchronizeFolderOperation operation, RemoteOperationResult result) { + if (!result.isSuccess() && result.getCode() != ResultCode.CANCELLED){ + Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), + Toast.LENGTH_LONG); + t.show(); + } + } protected void updateFileFromDB(){ OCFile file = getFile(); @@ -594,7 +615,7 @@ implements OnRemoteOperationListener, ComponentsGetter { @Override public FileUploaderBinder getFileUploaderBinder() { return mUploaderBinder; - }; + } }