Bug 902507 - Follow-up: Move "setEmptyView" to after cursor is loaded for MostRecentPage. r=lucasr
authorChenxia Liu <liuche@mozilla.com>
Thu, 08 Aug 2013 17:34:46 -0700
changeset 143513 51eb7425cb01f6ef2475bbceacd4af03b0822c4a
parent 143512 8689289ad25e081e966365b9a48357d2796c0fde
child 143514 a9eb5d014736089cc5bfb28a7f77abcbf1b0021a
push id25130
push userlrocha@mozilla.com
push dateWed, 21 Aug 2013 09:41:27 +0000
treeherdermozilla-central@b2486721572e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs902507
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 902507 - Follow-up: Move "setEmptyView" to after cursor is loaded for MostRecentPage. r=lucasr
mobile/android/base/home/MostRecentPage.java
mobile/android/base/resources/layout/home_list_with_title.xml
--- a/mobile/android/base/home/MostRecentPage.java
+++ b/mobile/android/base/home/MostRecentPage.java
@@ -40,16 +40,22 @@ public class MostRecentPage extends Home
     private static final int LOADER_ID_HISTORY = 0;
 
     // Adapter for the list of search results
     private MostRecentAdapter mAdapter;
 
     // The view shown by the fragment.
     private ListView mList;
 
+    // The title for this HomeFragment page.
+    private TextView mTitle;
+
+    // Reference to the View to display when there are no results.
+    private View mEmptyView;
+
     // Callbacks used for the search and favicon cursor loaders
     private CursorLoaderCallbacks mCursorLoaderCallbacks;
 
     // On URL open listener
     private OnUrlOpenListener mUrlOpenListener;
 
     public static MostRecentPage newInstance() {
         return new MostRecentPage();
@@ -79,36 +85,30 @@ public class MostRecentPage extends Home
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
         return inflater.inflate(R.layout.home_most_recent_page, container, false);
     }
 
     @Override
     public void onViewCreated(View view, Bundle savedInstanceState) {
-        final TextView title = (TextView) view.findViewById(R.id.title);
-        title.setText(R.string.home_most_recent_title);
+        mTitle = (TextView) view.findViewById(R.id.title);
+        mTitle.setText(R.string.home_most_recent_title);
 
         mList = (ListView) view.findViewById(R.id.list);
         mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
             @Override
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                 position -= mAdapter.getMostRecentSectionsCountBefore(position);
                 final Cursor c = mAdapter.getCursor(position);
                 final String url = c.getString(c.getColumnIndexOrThrow(URLColumns.URL));
                 mUrlOpenListener.onUrlOpen(url);
             }
         });
 
-        // Set empty page view.
-        final View emptyView = view.findViewById(R.id.home_empty_view);
-        ((ImageView) emptyView.findViewById(R.id.home_empty_image)).setImageResource(R.drawable.icon_most_recent_empty);
-        ((TextView) emptyView.findViewById(R.id.home_empty_text)).setText(R.string.home_most_recent_empty);
-        mList.setEmptyView(emptyView);
-
         registerForContextMenu(mList);
     }
 
     @Override
     public void onDestroyView() {
         super.onDestroyView();
         mList = null;
     }
@@ -143,16 +143,38 @@ public class MostRecentPage extends Home
 
         @Override
         public Cursor loadCursor() {
             final ContentResolver cr = getContext().getContentResolver();
             return BrowserDB.getRecentHistory(cr, HISTORY_LIMIT);
         }
     }
 
+    private void updateUiFromCursor(Cursor c) {
+        if (c != null && c.getCount() > 0) {
+            mTitle.setVisibility(View.VISIBLE);
+            return;
+        }
+
+        // Cursor is empty, so hide the title and set the empty view if it hasn't been set already.
+        mTitle.setVisibility(View.GONE);
+        if (mEmptyView == null) {
+            // Set empty page view. We delay this so that the empty view won't flash.
+            mEmptyView = getActivity().findViewById(R.id.home_empty_view);
+
+            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);
+
+            mList.setEmptyView(mEmptyView);
+        }
+    }
+
     private static class MostRecentAdapter extends MultiTypeCursorAdapter {
         private static final int ROW_HEADER = 0;
         private static final int ROW_STANDARD = 1;
 
         private static final int[] VIEW_TYPES = new int[] { ROW_STANDARD, ROW_HEADER };
         private static final int[] LAYOUT_TYPES = new int[] { R.layout.home_item_row, R.layout.home_header_row };
 
         // For the time sections in history
@@ -334,16 +356,17 @@ public class MostRecentPage extends Home
                 return super.onCreateLoader(id, args);
             }
         }
 
         @Override
         public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
             if (loader.getId() == LOADER_ID_HISTORY) {
                 mAdapter.swapCursor(c);
+                updateUiFromCursor(c);
                 loadFavicons(c);
             } else {
                 super.onLoadFinished(loader, c);
             }
         }
 
         @Override
         public void onLoaderReset(Loader<Cursor> loader) {
--- a/mobile/android/base/resources/layout/home_list_with_title.xml
+++ b/mobile/android/base/resources/layout/home_list_with_title.xml
@@ -24,17 +24,18 @@
                   android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:gravity="center"
                   android:textAppearance="@style/TextAppearance.EmptyMessage"/>
 
     </LinearLayout>
 
     <TextView android:id="@+id/title"
-              style="@style/Widget.Home.PageTitle"/>
+              style="@style/Widget.Home.PageTitle"
+              android:visibility="gone"/>
 
     <org.mozilla.gecko.home.HomeListView
             android:id="@+id/list"
             android:layout_width="fill_parent"
             android:layout_height="0dp"
             android:layout_weight="1"/>
 
 </merge>