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.lib.resources.status.OCCapability;
import com.owncloud.android.operations.CreateShareViaLinkOperation;
import com.owncloud.android.operations.CreateShareWithShareeOperation;
import com.owncloud.android.operations.GetSharesForFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.operations.SynchronizeFolderOperation;
import com.owncloud.android.operations.UnshareOperation;
+import com.owncloud.android.operations.UpdateShareViaLinkOperation;
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
import com.owncloud.android.ui.NavigationDrawerItem;
public static final String EXTRA_FILE = "com.owncloud.android.ui.activity.FILE";
public static final String EXTRA_ACCOUNT = "com.owncloud.android.ui.activity.ACCOUNT";
- public static final String EXTRA_WAITING_TO_PREVIEW =
- "com.owncloud.android.ui.activity.WAITING_TO_PREVIEW";
public static final String EXTRA_FROM_NOTIFICATION =
"com.owncloud.android.ui.activity.FROM_NOTIFICATION";
/** OwnCloud {@link Account} where the main {@link OCFile} handled by the activity is located.*/
private Account mAccount;
- /** Main {@link OCFile} handled by the activity.*/
+ /** Capabilites of the server where {@link #mAccount} lives */
+ private OCCapability mCapabilities;
+
+ /** Main {@link OCFile} handled by the activity.*/
private OCFile mFile;
+
/** Flag to signal that the activity will is finishing to enforce the creation of an ownCloud
* {@link Account} */
private boolean mRedirectingToSetupAccount = false;
private OperationsServiceBinder mOperationsServiceBinder = null;
+ private boolean mResumed = false;
+
protected FileDownloaderBinder mDownloaderBinder = null;
protected FileUploaderBinder mUploaderBinder = null;
private ServiceConnection mDownloadServiceConnection, mUploadServiceConnection = null;
- private boolean mTryShareAgain = false;
-
// Navigation Drawer
protected DrawerLayout mDrawerLayout;
protected ActionBarDrawerToggle mDrawerToggle;
protected NavigationDrawerListAdapter mNavigationDrawerAdapter = null;
+
// TODO re-enable when "Accounts" is available in Navigation Drawer
// protected boolean mShowAccounts = false;
mFileOperationsHelper.setOpIdWaitingFor(
savedInstanceState.getLong(KEY_WAITING_FOR_OP_ID, Long.MAX_VALUE)
);
- mTryShareAgain = savedInstanceState.getBoolean(KEY_TRY_SHARE_AGAIN);
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(savedInstanceState.getString(KEY_ACTION_BAR_TITLE));
}
@Override
protected void onResume() {
super.onResume();
-
+ mResumed = true;
if (mOperationsServiceBinder != null) {
doOnResumeAndBound();
}
if (mOperationsServiceBinder != null) {
mOperationsServiceBinder.removeOperationListener(this);
}
-
+ mResumed = false;
super.onPause();
}
outState.putParcelable(FileActivity.EXTRA_FILE, mFile);
outState.putBoolean(FileActivity.EXTRA_FROM_NOTIFICATION, mFromNotification);
outState.putLong(KEY_WAITING_FOR_OP_ID, mFileOperationsHelper.getOpIdWaitingFor());
- outState.putBoolean(KEY_TRY_SHARE_AGAIN, mTryShareAgain);
if(getSupportActionBar() != null && getSupportActionBar().getTitle() != null) {
// Null check in case the actionbar is used in ActionBar.NAVIGATION_MODE_LIST
// since it doesn't have a title then
mAccount = account;
}
+
+ /**
+ * Getter for the capabilities of the server where the current OC account lives.
+ *
+ * @return Capabilities of the server where the current OC account lives. Null if the account is not
+ * set yet.
+ */
+ public OCCapability getCapabilities() {
+ return mCapabilities;
+ }
+
+
/**
* @return Value of mFromNotification: True if the Activity is launched by a notification
*/
return mRedirectingToSetupAccount;
}
- public boolean isTryShareAgain(){
- return mTryShareAgain;
- }
-
- public void setTryShareAgain(boolean tryShareAgain) {
- mTryShareAgain = tryShareAgain;
- }
-
public OperationsServiceBinder getOperationsServiceBinder() {
return mOperationsServiceBinder;
}
protected void onAccountSet(boolean stateWasRecovered) {
if (getAccount() != null) {
mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver());
+ mCapabilities = mStorageManager.getCapability(mAccount.name);
} else {
Log_OC.wtf(TAG, "onAccountChanged was called with NULL account associated!");
Toast.LENGTH_LONG);
t.show();
}
- mTryShareAgain = false;
} else if (operation == null ||
operation instanceof CreateShareWithShareeOperation ||
operation instanceof UnshareOperation ||
- operation instanceof SynchronizeFolderOperation
+ operation instanceof SynchronizeFolderOperation ||
+ operation instanceof UpdateShareViaLinkOperation
) {
if (result.isSuccess()) {
updateFileFromDB();
onSynchronizeFileOperationFinish((SynchronizeFileOperation) operation, result);
} else if (operation instanceof GetSharesForFileOperation) {
- if (result.isSuccess()) {
+ if (result.isSuccess() || result.getCode() == ResultCode.SHARE_NOT_FOUND) {
updateFileFromDB();
- } else if (result.getCode() != ResultCode.SHARE_NOT_FOUND) {
+ } else {
Toast t = Toast.makeText(this,
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
Toast.LENGTH_LONG);
private void onCreateShareViaLinkOperationFinish(CreateShareViaLinkOperation operation,
RemoteOperationResult result) {
if (result.isSuccess()) {
- mTryShareAgain = false;
updateFileFromDB();
Intent sendIntent = operation.getSendIntentWithSubject(this);
- startActivity(sendIntent);
+ if (sendIntent != null) {
+ startActivity(sendIntent);
+ }
+
} else {
// Detect Failure (403) --> needs Password
if (result.getCode() == ResultCode.SHARE_FORBIDDEN) {
- if (!isTryShareAgain()) {
+ String password = operation.getPassword();
+ if ((password == null || password.length() == 0) &&
+ getCapabilities().getFilesSharingPublicEnabled().isUnknown())
+ {
+ // Was tried without password, but not sure that it's optional. Try with password.
+ // Try with password before giving up.
+ // See also ShareFileFragment#OnShareViaLinkListener
SharePasswordDialogFragment dialog =
- SharePasswordDialogFragment.newInstance(new OCFile(operation.getPath()),
- operation.getSendIntent());
+ SharePasswordDialogFragment.newInstance(new OCFile(operation.getPath()), true);
dialog.show(getSupportFragmentManager(), DIALOG_SHARE_PASSWORD);
} else {
Toast t = Toast.makeText(this,
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
Toast.LENGTH_LONG);
t.show();
- mTryShareAgain = false;
}
} else {
Toast t = Toast.makeText(this,
/*if (!mOperationsServiceBinder.isPerformingBlockingOperation()) {
dismissLoadingDialog();
}*/
- doOnResumeAndBound();
+ if (mResumed) {
+ doOnResumeAndBound();
+ }
} else {
return;