From 3b3e957bcf59f39eebd16756efd732076eccdc94 Mon Sep 17 00:00:00 2001 From: Chenxia Liu Date: Thu, 8 Aug 2013 15:40:34 -0700 Subject: [PATCH] Bug 902507 - Follow-up: Move "setEmptyView" to after cursor is loaded for MostRecentPage. r=lucasr --- mobile/android/base/home/MostRecentPage.java | 39 +++++++++++++++---- .../resources/layout/home_list_with_title.xml | 3 +- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/mobile/android/base/home/MostRecentPage.java b/mobile/android/base/home/MostRecentPage.java index e85980e1da5..611c75bb6ce 100644 --- a/mobile/android/base/home/MostRecentPage.java +++ b/mobile/android/base/home/MostRecentPage.java @@ -45,6 +45,12 @@ public class MostRecentPage extends HomeFragment { // 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; @@ -84,8 +90,8 @@ public class MostRecentPage extends HomeFragment { @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() { @@ -98,12 +104,6 @@ public class MostRecentPage extends HomeFragment { } }); - // 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); } @@ -148,6 +148,28 @@ public class MostRecentPage extends HomeFragment { } } + 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; @@ -339,6 +361,7 @@ public class MostRecentPage extends HomeFragment { public void onLoadFinished(Loader loader, Cursor c) { if (loader.getId() == LOADER_ID_HISTORY) { mAdapter.swapCursor(c); + updateUiFromCursor(c); loadFavicons(c); } else { super.onLoadFinished(loader, c); diff --git a/mobile/android/base/resources/layout/home_list_with_title.xml b/mobile/android/base/resources/layout/home_list_with_title.xml index c1ded2e6490..f8e818879e9 100644 --- a/mobile/android/base/resources/layout/home_list_with_title.xml +++ b/mobile/android/base/resources/layout/home_list_with_title.xml @@ -29,7 +29,8 @@ + style="@style/Widget.Home.PageTitle" + android:visibility="gone"/>