Bug 1220928 - Handle back button when in client's child view. r=sebastian
☠☠ backed out by a30dd3829cd0 ☠ ☠
authorChenxia Liu <liuche@mozilla.com>
Mon, 28 Mar 2016 12:04:03 -0700
changeset 290835 916fb74ed491c4f492d97bb4bbc5b8f786cd223f
parent 290834 81b90ed9ff464c38667488a5d4892728a802bdb0
child 290836 ac7d8d5ec09e45261cc73392e65f996fed4df909
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1220928
milestone48.0a1
Bug 1220928 - Handle back button when in client's child view. r=sebastian MozReview-Commit-ID: BDiyR5JCHQD
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryRecyclerView.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
@@ -190,20 +190,24 @@ public class CombinedHistoryAdapter exte
         }
         // Handle "back" view.
         clientChildren.add(null);
         clientChildren.addAll(remoteClients.get(transformAdapterPositionForDataStructure(ItemType.CLIENT, parentPosition)).tabs);
         inChildView = true;
         notifyDataSetChanged();
     }
 
-    public void exitChildView() {
+    public boolean exitChildView() {
+        if (!inChildView) {
+            return false;
+        }
         inChildView = false;
         clientChildren.clear();
         notifyDataSetChanged();
+        return true;
     }
 
     private ItemType getItemTypeForPosition(int position) {
         return ItemType.viewTypeToItemType(getItemViewType(position));
     }
 
     /**
      * Transform an adapter position to the position for the data structure backing the item type.
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryRecyclerView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryRecyclerView.java
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.home;
 
 import android.content.Context;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.util.AttributeSet;
+import android.view.KeyEvent;
 import android.view.View;
 import org.mozilla.gecko.db.RemoteClient;
 import org.mozilla.gecko.home.CombinedHistoryPanel.OnPanelLevelChangeListener;
 import org.mozilla.gecko.home.CombinedHistoryPanel.OnPanelLevelChangeListener.PanelLevel;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.widget.RecyclerViewClickSupport;
 
@@ -45,16 +46,29 @@ public class CombinedHistoryRecyclerView
     private void init(Context context) {
         LinearLayoutManager layoutManager = new LinearLayoutManager(context);
         layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
         setLayoutManager(layoutManager);
 
         RecyclerViewClickSupport.addTo(this)
             .setOnItemClickListener(this)
             .setOnItemLongClickListener(this);
+
+        setOnKeyListener(new View.OnKeyListener() {
+            @Override
+            public boolean onKey(View v, int keyCode, KeyEvent event) {
+                final int action = event.getAction();
+
+                // If the user hit the BACK key, try to move to the parent folder.
+                if (action == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
+                    return ((CombinedHistoryAdapter) getAdapter()).exitChildView();
+                }
+                return false;
+            }
+        });
     }
 
     public void setOnHistoryClickedListener(HomePager.OnUrlOpenListener listener) {
         this.mOnUrlOpenListener = listener;
     }
 
     public void setOnPanelLevelChangeListener(OnPanelLevelChangeListener listener) {
         this.mOnPanelLevelChangeListener = listener;