Fix, the correct navigation not shown in the action bar
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / FileActivity.java
index f63c9ee..382019f 100644 (file)
@@ -39,6 +39,7 @@ 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;
@@ -99,6 +100,7 @@ public class FileActivity extends ActionBarActivity
     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;
     
@@ -176,6 +178,7 @@ public class FileActivity extends ActionBarActivity
                     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));
         } else {
             account = getIntent().getParcelableExtra(FileActivity.EXTRA_ACCOUNT);
             mFile = getIntent().getParcelableExtra(FileActivity.EXTRA_FILE);
@@ -284,6 +287,10 @@ public class FileActivity extends ActionBarActivity
         // Sync the toggle state after onRestoreInstanceState has occurred.
         if (mDrawerToggle != null) {
             mDrawerToggle.syncState();
+            if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
+                getSupportActionBar().setTitle(R.string.app_name);
+                mDrawerToggle.setDrawerIndicatorEnabled(true);
+            }
         }
     }
 
@@ -355,13 +362,13 @@ public class FileActivity extends ActionBarActivity
                 this,
                 mDrawerLayout,
                 R.drawable.ic_drawer,
-                R.string.drawer_open,
+                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);
-                updateActionBarTitle();
+                updateActionBarTitleAndHomeButton();
                 getSupportActionBar().setDisplayShowTitleEnabled(true);
                 getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
                 invalidateOptionsMenu();
@@ -370,7 +377,7 @@ public class FileActivity extends ActionBarActivity
             /** Called when a drawer has settled in a completely open state. */
             public void onDrawerOpened(View drawerView) {
                 super.onDrawerOpened(drawerView);
-                getSupportActionBar().setTitle(R.string.drawer_open);
+                getSupportActionBar().setTitle(R.string.app_name);
                 getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
                 mDrawerToggle.setDrawerIndicatorEnabled(true);
                 invalidateOptionsMenu();
@@ -385,7 +392,7 @@ public class FileActivity extends ActionBarActivity
         mDrawerLayout.setDrawerListener(mDrawerToggle);
     }
 
-    protected void updateActionBarTitle(){
+    protected void updateActionBarTitleAndHomeButton(){
         if (mFile.getParentId() == 0) {
             getSupportActionBar().setTitle(getString(
                     R.string.default_display_name_for_root_folder));
@@ -472,6 +479,7 @@ 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());
     }
     
     
@@ -858,12 +866,14 @@ public class FileActivity extends ActionBarActivity
                     Intent settingsIntent = new Intent(getApplicationContext(),
                             Preferences.class);
                     startActivity(settingsIntent);
+                    mDrawerLayout.closeDrawers();
                     break;
 
-                case 3: // Logs
+                case 2: // Logs
                     Intent loggerIntent = new Intent(getApplicationContext(),
                             LogHistoryActivity.class);
                     startActivity(loggerIntent);
+                    mDrawerLayout.closeDrawers();
                     break;
             }
         }