Browse Source

Fixed update of id.home action bar button on navigation through FileDisplayActivity

David A. Velasco 10 years ago
parent
commit
0117006313

+ 0 - 1
res/values/strings.xml

@@ -27,7 +27,6 @@
     <string name="drawer_item_on_device">On device</string>-->
     <string name="drawer_item_settings">Settings</string>
     <string name="drawer_item_logs">Logs</string>
-    <string name="drawer_open">ownCloud</string>
 	<string name="drawer_close">Close</string>
     <string name="prefs_category_general">General</string>
     <string name="prefs_category_more">More</string>

+ 9 - 4
src/com/owncloud/android/ui/activity/FileActivity.java

@@ -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;
@@ -286,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);
+            }
         }
     }
 
@@ -357,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();
@@ -372,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();
@@ -387,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));

+ 12 - 16
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -195,9 +195,6 @@ public class FileDisplayActivity extends HookActivity
         getSupportActionBar().setHomeButtonEnabled(true);       // mandatory since Android ICS,
                                                                 // according to the official
                                                                 // documentation
-        if (getFile() != null) {
-            updateActionBarTitle();
-        }
 
         setSupportProgressBarIndeterminateVisibility(mSyncInProgress
         /*|| mRefreshSharesInProgress*/);
@@ -263,7 +260,7 @@ public class FileDisplayActivity extends HookActivity
                 
             } else {
                 updateFragmentsVisibility(!file.isFolder());
-                updateNavigationElementsInActionBar(file.isFolder() ? null : file);
+                updateActionBarTitleAndHomeButton(file.isFolder() ? null : file);
             }
         }
     }
@@ -294,7 +291,7 @@ public class FileDisplayActivity extends HookActivity
             if (secondFragment != null) {
                 setSecondFragment(secondFragment);
                 updateFragmentsVisibility(true);
-                updateNavigationElementsInActionBar(file);
+                updateActionBarTitleAndHomeButton(file);
                 
             } else {
                 cleanSecondFragment();
@@ -402,7 +399,7 @@ public class FileDisplayActivity extends HookActivity
             tr.commit();
         }
         updateFragmentsVisibility(false);
-        updateNavigationElementsInActionBar(null);
+        updateActionBarTitleAndHomeButton(null);
     }
 
     protected void refreshListOfFilesFragment() {
@@ -747,7 +744,6 @@ public class FileDisplayActivity extends HookActivity
         if (listOfFiles != null) {  // should never be null, indeed
             setFile(listOfFiles.getCurrentFile());
         }
-        updateActionBarTitle();
         cleanSecondFragment();
 
     }
@@ -1126,7 +1122,6 @@ public class FileDisplayActivity extends HookActivity
             // listOfFiles.listDirectory(root, MainApp.getOnlyOnDevice());
             setFile(listOfFiles.getCurrentFile());
             startSyncFolderOperation(root, false);
-            updateActionBarTitle();
         }
         cleanSecondFragment();
 
@@ -1140,9 +1135,8 @@ public class FileDisplayActivity extends HookActivity
      */
     @Override
     public void onBrowsedDownTo(OCFile directory) {
-        cleanSecondFragment();
         setFile(directory);
-        updateActionBarTitle();
+        cleanSecondFragment();
         // Sync Folder
         startSyncFolderOperation(directory, false);
         
@@ -1159,7 +1153,7 @@ public class FileDisplayActivity extends HookActivity
         Fragment detailFragment = new FileDetailFragment(file, getAccount());
         setSecondFragment(detailFragment);
         updateFragmentsVisibility(true);
-        updateNavigationElementsInActionBar(file);
+        updateActionBarTitleAndHomeButton(file);
         setFile(file);
     }
 
@@ -1167,7 +1161,7 @@ public class FileDisplayActivity extends HookActivity
     /**
      * TODO
      */
-    private void updateNavigationElementsInActionBar(OCFile chosenFile) {
+    private void updateActionBarTitleAndHomeButton(OCFile chosenFile) {
         ActionBar actionBar = getSupportActionBar();
 
         // For adding content description tag to a title field in the action bar
@@ -1177,10 +1171,11 @@ public class FileDisplayActivity extends HookActivity
             // only list of files - set for browsing through folders
             OCFile currentDir = getCurrentDir();
             boolean noRoot = (currentDir != null && currentDir.getParentId() != 0);
-//            actionBar.setDisplayHomeAsUpEnabled(noRoot);
-//            actionBar.setDisplayShowTitleEnabled(!noRoot);
+            //actionBar.setDisplayHomeAsUpEnabled(noRoot);
+            //actionBar.setDisplayShowTitleEnabled(!noRoot);
             actionBar.setDisplayHomeAsUpEnabled(true);
             actionBar.setDisplayShowTitleEnabled(true);
+            mDrawerToggle.setDrawerIndicatorEnabled(!noRoot);
             if (!noRoot) {
                 actionBar.setTitle(getString(R.string.default_display_name_for_root_folder));
                 View actionBarTitleView = getWindow().getDecorView().findViewById(actionBarTitleId);
@@ -1194,6 +1189,7 @@ public class FileDisplayActivity extends HookActivity
         } else {
             actionBar.setDisplayHomeAsUpEnabled(true);
             actionBar.setDisplayShowTitleEnabled(true);
+            mDrawerToggle.setDrawerIndicatorEnabled(false);
             actionBar.setTitle(chosenFile.getFileName());
             actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
             View actionBarTitleView = getWindow().getDecorView().findViewById(actionBarTitleId);
@@ -1665,7 +1661,7 @@ public class FileDisplayActivity extends HookActivity
                 autoplay);
         setSecondFragment(mediaFragment);
         updateFragmentsVisibility(true);
-        updateNavigationElementsInActionBar(file);
+        updateActionBarTitleAndHomeButton(file);
         setFile(file);
     }
 
@@ -1682,7 +1678,7 @@ public class FileDisplayActivity extends HookActivity
         mWaitingToPreview = file;
         requestForDownload();
         updateFragmentsVisibility(true);
-        updateNavigationElementsInActionBar(file);
+        updateActionBarTitleAndHomeButton(file);
         setFile(file);
     }