Bug 1261527 - Empty state for history only. r=sebastian
authorChenxia Liu <liuche@mozilla.com>
Wed, 27 Apr 2016 11:53:59 -0700
changeset 362658 af4e12a26b8231acc482d4ca32dffb63b04d7cda
parent 362657 5b048886e0c9ad7938cd2a6da6dd4b95bb4a9bec
child 362659 bf0d533070d85858b44e522d93a08b7da26fb7fc
push id17008
push userbgrinstead@mozilla.com
push dateMon, 02 May 2016 21:59:43 +0000
reviewerssebastian
bugs1261527
milestone49.0a1
Bug 1261527 - Empty state for history only. r=sebastian 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