X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/fe5b6aa4a81d1878f4b5ad610cb9141e86630b1a..1b4db02b4e5fc29f5344fd35f16b88024bb5ec13:/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 63f700c3..8dda1f8e 100644 --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/com/owncloud/android/ui/activity/FileActivity.java @@ -35,18 +35,20 @@ import android.content.res.Configuration; 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.util.Log; 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; @@ -85,7 +87,7 @@ 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"; @@ -289,7 +291,7 @@ public class FileActivity extends ActionBarActivity // 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 ActionBarActivity } } + @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); @@ -311,7 +344,7 @@ public class FileActivity extends ActionBarActivity 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 @@ -329,6 +362,14 @@ public class FileActivity extends ActionBarActivity // 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); @@ -344,19 +385,20 @@ public class FileActivity extends ActionBarActivity // 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 - //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_action_settings)); // Logs if (BuildConfig.DEBUG) { - mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2], - mDrawerContentDescriptions[2])); + mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[3], + mDrawerContentDescriptions[3],R.drawable.ic_log)); } // setting the nav drawer list adapter @@ -364,12 +406,8 @@ public class FileActivity extends ActionBarActivity 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) { @@ -386,13 +424,13 @@ public class FileActivity extends ActionBarActivity 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); } /** @@ -512,7 +550,11 @@ public class FileActivity extends ActionBarActivity 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()); + } } @@ -709,6 +751,7 @@ public class FileActivity extends ActionBarActivity } + private void onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) { dismissLoadingDialog(); @@ -886,6 +929,12 @@ public class FileActivity extends ActionBarActivity 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(); @@ -895,6 +944,10 @@ public class FileActivity extends ActionBarActivity 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) { @@ -911,24 +964,25 @@ public class FileActivity extends ActionBarActivity // 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);