X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/d474239b21f01465975ff43944ea4c2981802ff0..13a73dd56872b6fcbc12ab8c62806cbfd48dc93b:/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 516daa15..3edd40c9 100644 --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/com/owncloud/android/ui/activity/FileActivity.java @@ -43,10 +43,12 @@ import android.support.v4.widget.DrawerLayout; 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 android.widget.RelativeLayout; +import android.widget.TextView; import android.widget.Toast; import com.owncloud.android.BuildConfig; @@ -289,7 +291,7 @@ public class FileActivity extends AppCompatActivity // 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); } @@ -304,6 +306,37 @@ public class FileActivity extends AppCompatActivity } } + @Override + public void onBackPressed() { + if (isDrawerOpen()) { + closeNavDrawer(); + return; + } + super.onBackPressed(); + } + + /** + * checks if the drawer exists and is opened. + * + * @return true if the drawer is open, else false + */ + 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); @@ -329,6 +362,9 @@ public class FileActivity extends AppCompatActivity // username.setText(account.name.substring(0, lastAtPos)); // } + // Display username in drawer + setUsernameInDrawer(navigationDrawerLayout, AccountUtils.getCurrentOwnCloudAccount(getApplicationContext())); + // load slide menu items mDrawerTitles = getResources().getStringArray(R.array.drawer_items); @@ -369,13 +405,6 @@ public class FileActivity extends AppCompatActivity mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,R.string.drawer_open,R.string.drawer_close) { - //new ActionBarDrawerToggle( - //this, - // mDrawerLayout, - // R.drawable.ic_drawer, - // R.string.app_name, - // R.string.drawer_close) { - /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); @@ -391,14 +420,28 @@ public class FileActivity extends AppCompatActivity 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); + } + /** + * 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)); + } } /** @@ -477,7 +520,7 @@ public class FileActivity extends AppCompatActivity */ 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(); @@ -518,7 +561,11 @@ public class FileActivity extends AppCompatActivity 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().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()); + } } @@ -565,7 +612,7 @@ public class FileActivity extends AppCompatActivity } /** - * @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; @@ -715,6 +762,7 @@ public class FileActivity extends AppCompatActivity } + private void onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) { dismissLoadingDialog(); @@ -783,14 +831,15 @@ public class FileActivity extends AppCompatActivity 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(); } } @@ -819,7 +868,7 @@ public class FileActivity extends AppCompatActivity /** * Dismiss loading dialog */ - public void dismissLoadingDialog(){ + public void dismissLoadingDialog() { Fragment frag = getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG); if (frag != null) { LoadingDialog loading = (LoadingDialog) frag;