Bug 1261527 - Empty state for history only. r=sebastian, a=lizzard
authorChenxia Liu <liuche@mozilla.com>
Wed, 27 Apr 2016 11:53:59 -0700
changeset 332733 7cd6e6a653dd6e28967d7183011f6358fdaec3a0
parent 332732 69886489143eaac2e9e9a5503b5f31fd313f761a
child 332734 e702eabb5ec7cb0aae38e951702dac5d5dceee34
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian, lizzard
bugs1261527
milestone48.0a2
Bug 1261527 - Empty state for history only. r=sebastian, a=lizzard MozReview-Commit-ID: AUFwPl2Yllz
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
@@ -185,32 +185,29 @@ public class CombinedHistoryPanel extend
                     Log.e(LOGTAG, "Unknown loader id!");
                     return null;
             }
         }
 
         @Override
         public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
             final int loaderId = loader.getId();
-            boolean showEmptyView = false;
             switch (loaderId) {
                 case LOADER_ID_HISTORY:
                     mHistoryAdapter.setHistory(c);
-                    showEmptyView = mHistoryAdapter.getItemCount() == NUM_SMART_FOLDERS;
                     break;
 
                 case LOADER_ID_REMOTE:
                     final List<RemoteClient> clients = mDB.getTabsAccessor().getClientsFromCursor(c);
                     mHistoryAdapter.getDeviceUpdateHandler().onDeviceCountUpdated(clients.size());
                     mClientsAdapter.setClients(clients);
-                    showEmptyView = mClientsAdapter.getItemCount() == 1;
                     break;
             }
 
-            updateEmptyView(showEmptyView, mPanelLevel);
+            updateEmptyView();
             updateButtonFromLevel();
         }
 
         @Override
         public void onLoaderReset(Loader<Cursor> loader) {
             mClientsAdapter.setClients(Collections.<RemoteClient>emptyList());
             mHistoryAdapter.setHistory(null);
         }
@@ -227,16 +224,18 @@ public class CombinedHistoryPanel extend
             switch (level) {
                 case PARENT:
                     mRecyclerView.swapAdapter(mHistoryAdapter, false);
                     break;
                 case CHILD:
                     mRecyclerView.swapAdapter(mClientsAdapter, false);
                     break;
             }
+
+            updateEmptyView();
             updateButtonFromLevel();
             return true;
         }
     }
 
     private void updateButtonFromLevel() {
         switch (mPanelLevel) {
             case PARENT:
@@ -283,50 +282,60 @@ public class CombinedHistoryPanel extend
                     Telemetry.sendUIEvent(TelemetryContract.Event.SANITIZE, TelemetryContract.Method.BUTTON, "history");
                 }
             });
 
             dialogBuilder.show();
         }
     }
 
-    private void updateEmptyView(boolean showEmptyState, OnPanelLevelChangeListener.PanelLevel level) {
-        // TODO: Add Sync empty state.
-        if (showEmptyState) {
-            if (mEmptyView == null) {
-                // Set empty panel view if it needs to be shown and hasn't been inflated.
-                final ViewStub emptyViewStub = (ViewStub) getView().findViewById(R.id.home_empty_view_stub);
-                mEmptyView = emptyViewStub.inflate();
+    private void updateEmptyView() {
+        switch (mPanelLevel) {
+            case PARENT:
+                final boolean showEmptyHistoryView = mHistoryAdapter.getItemCount() == NUM_SMART_FOLDERS && mClientsAdapter.getItemCount() == 1;
+                if (showEmptyHistoryView) {
+                    if (mEmptyView == null) {
+                        // Set empty panel view if it needs to be shown and hasn't been inflated.
+                        final ViewStub emptyViewStub = (ViewStub) getView().findViewById(R.id.home_empty_view_stub);
+                        mEmptyView = emptyViewStub.inflate();
 
-                final boolean isParentLevel = level == OnPanelLevelChangeListener.PanelLevel.PARENT;
-                final ImageView emptyIcon = (ImageView) mEmptyView.findViewById(R.id.home_empty_image);
-                emptyIcon.setImageResource(isParentLevel ? R.drawable.icon_most_recent_empty : R.drawable.icon_remote_tabs_empty);
+                        final ImageView emptyIcon = (ImageView) mEmptyView.findViewById(R.id.home_empty_image);
+                        emptyIcon.setImageResource(R.drawable.icon_most_recent_empty);
+
+                        final TextView emptyText = (TextView) mEmptyView.findViewById(R.id.home_empty_text);
+                        emptyText.setText(R.string.home_most_recent_empty);
 
-                final TextView emptyText = (TextView) mEmptyView.findViewById(R.id.home_empty_text);
-                emptyText.setText(R.string.home_most_recent_empty);
-
-                final TextView emptyHint = (TextView) mEmptyView.findViewById(R.id.home_empty_hint);
+                        final TextView emptyHint = (TextView) mEmptyView.findViewById(R.id.home_empty_hint);
 
-                if (!Restrictions.isAllowed(getActivity(), Restrictable.PRIVATE_BROWSING) || !isParentLevel) {
-                    emptyHint.setVisibility(View.GONE);
+                        if (!Restrictions.isAllowed(getActivity(), Restrictable.PRIVATE_BROWSING)) {
+                            emptyHint.setVisibility(View.GONE);
+                        } else {
+                            final String hintText = getResources().getString(R.string.home_most_recent_emptyhint);
+                            final SpannableStringBuilder hintBuilder = formatHintText(hintText);
+                            if (hintBuilder != null) {
+                                emptyHint.setText(hintBuilder);
+                                emptyHint.setMovementMethod(LinkMovementMethod.getInstance());
+                                emptyHint.setVisibility(View.VISIBLE);
+                            }
+                        }
+                    }
+                    mEmptyView.setVisibility(View.VISIBLE);
                 } else {
-                    final String hintText = getResources().getString(R.string.home_most_recent_emptyhint);
-                    final SpannableStringBuilder hintBuilder = formatHintText(hintText);
-                    if (hintBuilder != null) {
-                        emptyHint.setText(hintBuilder);
-                        emptyHint.setMovementMethod(LinkMovementMethod.getInstance());
-                        emptyHint.setVisibility(View.VISIBLE);
+                    if (mEmptyView != null) {
+                        mEmptyView.setVisibility(View.GONE);
                     }
                 }
-            }
-            mEmptyView.setVisibility(View.VISIBLE);
-        } else {
-            if (mEmptyView != null) {
-                mEmptyView.setVisibility(View.GONE);
-            }
+                break;
+
+            case CHILD:
+                // TODO: Bug 1262285
+                if (mEmptyView != null) {
+                    mEmptyView.setVisibility(View.GONE);
+                }
+                break;
         }
     }
     /**
      * Make Span that is clickable, and underlined
      * between the string markers <code>FORMAT_S1</code> and
      * <code>FORMAT_S2</code>.
      *
      * @param text String to format