Bug 902507 - Follow-up: Move "setEmptyView" to after cursor is loaded for MostRecentPage. r=lucasr

This commit is contained in:
Chenxia Liu 2013-08-08 17:34:46 -07:00
parent a673c4a071
commit 8f9ef39936
2 changed files with 33 additions and 9 deletions

View File

@ -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<Cursor> loader, Cursor c) {
if (loader.getId() == LOADER_ID_HISTORY) {
mAdapter.swapCursor(c);
updateUiFromCursor(c);
loadFavicons(c);
} else {
super.onLoadFinished(loader, c);

View File

@ -29,7 +29,8 @@
</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"