import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
-import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
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.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.UnshareLinkOperation;
+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";
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 DIALOG_SHARE_PASSWORD = "DIALOG_SHARE_PASSWORD";
private static final String KEY_TRY_SHARE_AGAIN = "TRY_SHARE_AGAIN";
private static final String KEY_ACTION_BAR_TITLE = "ACTION_BAR_TITLE";
- protected static final long DELAY_TO_REQUEST_OPERATION_ON_ACTIVITY_RESULTS = 200;
+ protected static final long DELAY_TO_REQUEST_OPERATIONS_LATER = 200;
/** 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);
- getSupportActionBar().setTitle(savedInstanceState.getString(KEY_ACTION_BAR_TITLE));
+ if (getSupportActionBar() != null) {
+ getSupportActionBar().setTitle(savedInstanceState.getString(KEY_ACTION_BAR_TITLE));
+ }
} else {
account = getIntent().getParcelableExtra(FileActivity.EXTRA_ACCOUNT);
mFile = getIntent().getParcelableExtra(FileActivity.EXTRA_FILE);
@Override
protected void onResume() {
super.onResume();
-
+ mResumed = true;
if (mOperationsServiceBinder != null) {
doOnResumeAndBound();
}
if (mOperationsServiceBinder != null) {
mOperationsServiceBinder.removeOperationListener(this);
}
-
+ mResumed = false;
super.onPause();
}
// }
// Display username in drawer
- Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
- if (account != null) {
- TextView username = (TextView) navigationDrawerLayout.findViewById(R.id.drawer_username);
- int lastAtPos = account.name.lastIndexOf("@");
- username.setText(account.name.substring(0, lastAtPos));
- }
+ setUsernameInDrawer(navigationDrawerLayout, AccountUtils.getCurrentOwnCloudAccount(getApplicationContext()));
// load slide menu items
mDrawerTitles = getResources().getStringArray(R.array.drawer_items);
// Settings
mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2], mDrawerContentDescriptions[2],
- R.drawable.ic_settings));
+ R.drawable.ic_action_settings));
// Logs
if (BuildConfig.DEBUG) {
mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[3],
}
/**
+ * sets the given account name in the drawer in case the drawer is available. The account name
+ * is shortened beginning from the @-sign in the username.
+ *
+ * @param navigationDrawerLayout the drawer layout to be used
+ * @param account the account to be set in the drawer
+ */
+ protected void setUsernameInDrawer(RelativeLayout navigationDrawerLayout, Account account) {
+ if (navigationDrawerLayout != null && getAccount() != null) {
+ TextView username = (TextView) navigationDrawerLayout.findViewById(R.id.drawer_username);
+ int lastAtPos = account.name.lastIndexOf("@");
+ username.setText(account.name.substring(0, lastAtPos));
+ }
+ }
+
+ /**
* Updates title bar and home buttons (state and icon).
*
* Assumes that navigation drawer is NOT visible.
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().getTitle() != null) {
+ 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
outState.putString(KEY_ACTION_BAR_TITLE, getSupportActionBar().getTitle().toString());
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!");
mFileOperationsHelper.setOpIdWaitingFor(Long.MAX_VALUE);
+ dismissLoadingDialog();
+
if (!result.isSuccess() && (
result.getCode() == ResultCode.UNAUTHORIZED ||
result.isIdPRedirection() ||
Toast.LENGTH_LONG);
t.show();
}
- mTryShareAgain = false;
- } else if (operation instanceof CreateShareOperation) {
- onCreateShareOperationFinish((CreateShareOperation) operation, result);
+ } else if (operation == null ||
+ operation instanceof CreateShareWithShareeOperation ||
+ operation instanceof UnshareOperation ||
+ operation instanceof SynchronizeFolderOperation ||
+ operation instanceof UpdateShareViaLinkOperation
+ ) {
+ if (result.isSuccess()) {
+ updateFileFromDB();
- } else if (operation instanceof UnshareLinkOperation) {
- onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result);
+ } else if (result.getCode() != ResultCode.CANCELLED) {
+ Toast t = Toast.makeText(this,
+ ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+ Toast.LENGTH_LONG);
+ t.show();
+ }
+
+ } else if (operation instanceof CreateShareViaLinkOperation) {
+ onCreateShareViaLinkOperationFinish((CreateShareViaLinkOperation) operation, result);
- } else if (operation instanceof SynchronizeFolderOperation) {
- onSynchronizeFolderOperationFinish((SynchronizeFolderOperation)operation, result);
+ } else if (operation instanceof SynchronizeFileOperation) {
+ onSynchronizeFileOperationFinish((SynchronizeFileOperation) operation, result);
- }else if (operation instanceof SynchronizeFileOperation) {
- onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result);
+ } else if (operation instanceof GetSharesForFileOperation) {
+ if (result.isSuccess() || result.getCode() == ResultCode.SHARE_NOT_FOUND) {
+ updateFileFromDB();
+ } else {
+ Toast t = Toast.makeText(this,
+ ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+ Toast.LENGTH_LONG);
+ t.show();
+ }
}
}
- private void onCreateShareOperationFinish(CreateShareOperation operation,
- RemoteOperationResult result) {
- dismissLoadingDialog();
+ private void onCreateShareViaLinkOperationFinish(CreateShareViaLinkOperation operation,
+ RemoteOperationResult result) {
if (result.isSuccess()) {
- mTryShareAgain = false;
updateFileFromDB();
- Intent sendIntent = operation.getSendIntent();
- startActivity(sendIntent);
+ Intent sendIntent = operation.getSendIntentWithSubject(this);
+ 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,
}
}
-
- private void onUnshareLinkOperationFinish(UnshareLinkOperation operation,
- RemoteOperationResult result) {
- dismissLoadingDialog();
-
- if (result.isSuccess()){
- updateFileFromDB();
-
- } else {
- Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result,
- operation, getResources()), Toast.LENGTH_LONG);
- 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();
- }
- }
-
private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation,
RemoteOperationResult result) {
- dismissLoadingDialog();
OCFile syncedFile = operation.getLocalFile();
if (!result.isSuccess()) {
if (result.getCode() == ResultCode.SYNC_CONFLICT) {
/**
* Show loading dialog
*/
- public void showLoadingDialog() {
+ public void showLoadingDialog(String message) {
// Construct dialog
- LoadingDialog loading = new LoadingDialog(getResources().getString(R.string.wait_a_moment));
+ LoadingDialog loading = new LoadingDialog(message);
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
loading.show(ft, DIALOG_WAIT_TAG);
public void dismissLoadingDialog() {
Fragment frag = getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG);
if (frag != null) {
+ Log_OC.d(TAG, "dismiss loading dialog");
LoadingDialog loading = (LoadingDialog) frag;
loading.dismiss();
}
/*if (!mOperationsServiceBinder.isPerformingBlockingOperation()) {
dismissLoadingDialog();
}*/
- doOnResumeAndBound();
+ if (mResumed) {
+ doOnResumeAndBound();
+ }
} else {
return;
restart();
}
+ public void refreshDirectory(){
+ // overridden by FileDisplayActivity
+ }
+
private class DrawerItemClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
case 0: // All Files
MainApp.showOnlyFilesOnDevice(false);
- allFilesOption();
+ refreshDirectory();
mDrawerLayout.closeDrawers();
break;
case 1: // On Device
- // TODO Tobi: refresh
MainApp.showOnlyFilesOnDevice(true);
- allFilesOption();
-
+ refreshDirectory();
mDrawerLayout.closeDrawers();
break;