X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/dbe0ff54aedb6eab3e9c596f48fc816ef7ee43e8..ba2db14b736728aea4fdb2c4b75881892fa2ec06:/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 7cfb123f..30c4610c 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; @@ -313,12 +315,26 @@ public class FileActivity extends AppCompatActivity super.onBackPressed(); } + /** + * checks if the drawer exists and is opened. + * + * @return true if the drawer is open, else false + */ public boolean isDrawerOpen() { - return mDrawerLayout.isDrawerOpen(GravityCompat.START); + if(mDrawerLayout != null) { + return mDrawerLayout.isDrawerOpen(GravityCompat.START); + } else { + return false; + } } + /** + * closes the navigation drawer. + */ public void closeNavDrawer() { - mDrawerLayout.closeDrawer(GravityCompat.START); + if(mDrawerLayout != null) { + mDrawerLayout.closeDrawer(GravityCompat.START); + } } protected void initDrawer(){ @@ -346,6 +362,14 @@ public class FileActivity extends AppCompatActivity // 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); @@ -364,18 +388,17 @@ public class FileActivity extends AppCompatActivity mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0], mDrawerContentDescriptions[0], R.drawable.ic_folder_open)); - // TODO Enable when "On Device" is recovered // On Device - //mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2], - // mDrawerContentDescriptions[2])); + mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[1], mDrawerContentDescriptions[1], + R.drawable.ic_action_download_grey)); // Settings - mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[1], mDrawerContentDescriptions[1], + mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2], mDrawerContentDescriptions[2], R.drawable.ic_settings)); // Logs if (BuildConfig.DEBUG) { - mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2], - mDrawerContentDescriptions[2],R.drawable.ic_log)); + mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[3], + mDrawerContentDescriptions[3],R.drawable.ic_log)); } // setting the nav drawer list adapter @@ -407,7 +430,7 @@ public class FileActivity extends AppCompatActivity // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); - + mDrawerToggle.setDrawerIndicatorEnabled(false); } /** @@ -486,7 +509,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(); @@ -527,7 +550,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()); + } } @@ -574,7 +601,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; @@ -724,6 +751,7 @@ public class FileActivity extends AppCompatActivity } + private void onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) { dismissLoadingDialog(); @@ -792,14 +820,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(); } } @@ -828,7 +857,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; @@ -900,6 +929,12 @@ public class FileActivity extends AppCompatActivity startActivity(i); } + public void refresh(){ + Intent i = new Intent(this, FileDisplayActivity.class); + i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(i); + } + // TODO re-enable when "Accounts" is available in Navigation Drawer // public void closeDrawer() { // mDrawerLayout.closeDrawers(); @@ -909,6 +944,10 @@ public class FileActivity extends AppCompatActivity 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) { @@ -925,24 +964,25 @@ public class FileActivity extends AppCompatActivity // break; case 0: // All Files - allFilesOption(); + MainApp.showOnlyFilesOnDevice(false); + refreshDirectory(); mDrawerLayout.closeDrawers(); break; - // TODO Enable when "On Device" is recovered ? -// case 2: -// MainApp.showOnlyFilesOnDevice(true); -// mDrawerLayout.closeDrawers(); -// break; + case 1: // On Device + MainApp.showOnlyFilesOnDevice(true); + refreshDirectory(); + mDrawerLayout.closeDrawers(); + break; - case 1: // Settings + case 2: // Settings Intent settingsIntent = new Intent(getApplicationContext(), Preferences.class); startActivity(settingsIntent); mDrawerLayout.closeDrawers(); break; - case 2: // Logs + case 3: // Logs Intent loggerIntent = new Intent(getApplicationContext(), LogHistoryActivity.class); startActivity(loggerIntent);