import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
-import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
-import android.support.v7.app.ActionBarActivity;
+import android.support.v7.app.ActionBarDrawerToggle;
+import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
-import android.widget.LinearLayout;
import android.widget.ListView;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
import android.widget.Toast;
import com.owncloud.android.BuildConfig;
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;
import com.owncloud.android.ui.adapter.NavigationDrawerListAdapter;
import com.owncloud.android.ui.dialog.LoadingDialog;
import com.owncloud.android.ui.dialog.SharePasswordDialogFragment;
-import com.owncloud.android.ui.fragment.FileDetailFragment;
-import com.owncloud.android.ui.fragment.FileFragment;
import com.owncloud.android.utils.ErrorMessageAdapter;
import java.util.ArrayList;
* Activity with common behaviour for activities handling {@link OCFile}s in ownCloud
* {@link Account}s .
*/
-public class FileActivity extends ActionBarActivity
+public class FileActivity extends AppCompatActivity
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";
- 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();
}
// Sync the toggle state after onRestoreInstanceState has occurred.
if (mDrawerToggle != null) {
mDrawerToggle.syncState();
- if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
+ if (isDrawerOpen()) {
getSupportActionBar().setTitle(R.string.app_name);
mDrawerToggle.setDrawerIndicatorEnabled(true);
}
}
}
+ @Override
+ public void onBackPressed() {
+ if (isDrawerOpen()) {
+ closeNavDrawer();
+ return;
+ }
+ super.onBackPressed();
+ }
+
+ /**
+ * checks if the drawer exists and is opened.
+ *
+ * @return <code>true</code> if the drawer is open, else <code>false</code>
+ */
+ public boolean isDrawerOpen() {
+ if(mDrawerLayout != null) {
+ return mDrawerLayout.isDrawerOpen(GravityCompat.START);
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * closes the navigation drawer.
+ */
+ public void closeNavDrawer() {
+ if(mDrawerLayout != null) {
+ mDrawerLayout.closeDrawer(GravityCompat.START);
+ }
+ }
+
protected void initDrawer(){
// constant settings for action bar when navigation drawer is inited
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
// Notification Drawer
- LinearLayout navigationDrawerLayout = (LinearLayout) findViewById(R.id.left_drawer);
+ RelativeLayout navigationDrawerLayout = (RelativeLayout) findViewById(R.id.left_drawer);
mDrawerList = (ListView) navigationDrawerLayout.findViewById(R.id.drawer_list);
// TODO re-enable when "Accounts" is available in Navigation Drawer
// username.setText(account.name.substring(0, lastAtPos));
// }
+ // 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));
+ }
+
// load slide menu items
mDrawerTitles = getResources().getStringArray(R.array.drawer_items);
// mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0],
// mDrawerContentDescriptions[0]));
// All Files
- mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0], mDrawerContentDescriptions[0]));
+ mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0], mDrawerContentDescriptions[0],
+ R.drawable.ic_folder_open));
// TODO Enable when "On Device" is recovered
// On Device
// mDrawerContentDescriptions[2]));
// Settings
- mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[1], mDrawerContentDescriptions[1]));
+ mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[1], mDrawerContentDescriptions[1],
+ R.drawable.ic_settings));
// Logs
if (BuildConfig.DEBUG) {
mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2],
- mDrawerContentDescriptions[2]));
+ mDrawerContentDescriptions[2],R.drawable.ic_log));
}
// setting the nav drawer list adapter
mDrawerItems);
mDrawerList.setAdapter(mNavigationDrawerAdapter);
- mDrawerToggle = new ActionBarDrawerToggle(
- this,
- mDrawerLayout,
- R.drawable.ic_drawer,
- R.string.app_name,
- R.string.drawer_close) {
+
+ mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,R.string.drawer_open,R.string.drawer_close) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
invalidateOptionsMenu();
}
};
-
- //mDrawerToggle.setDrawerIndicatorEnabled(true);
+
// Set the list's click listener
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
+ mDrawerToggle.setDrawerIndicatorEnabled(false);
}
/**
*/
private void swapToDefaultAccount() {
// default to the most recently used account
- Account newAccount = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
+ Account newAccount = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
if (newAccount == null) {
/// no account available: force account creation
createFirstAccount();
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);
- outState.putString(KEY_ACTION_BAR_TITLE, getSupportActionBar().getTitle().toString());
+ 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 'True' when the Activity is finishing to enforce the setup of a new account.
+ * @return 'True' when the Activity is finishing to enforce the setup of a new account.
*/
protected boolean isRedirectingToSetupAccount() {
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) {
i.putExtra(ConflictsResolveActivity.EXTRA_FILE, syncedFile);
i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, getAccount());
startActivity(i);
-
}
+
} else {
if (!operation.transferWasRequested()) {
Toast msg = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result,
operation, getResources()), Toast.LENGTH_LONG);
msg.show();
}
+ invalidateOptionsMenu();
}
}
/**
* 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);
/**
* Dismiss loading dialog
*/
- public void dismissLoadingDialog(){
+ public void dismissLoadingDialog() {
Fragment frag = getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG);
if (frag != null) {
LoadingDialog loading = (LoadingDialog) frag;
/*if (!mOperationsServiceBinder.isPerformingBlockingOperation()) {
dismissLoadingDialog();
}*/
- doOnResumeAndBound();
+ if (mResumed) {
+ doOnResumeAndBound();
+ }
} else {
return;