Bug 919230 - Implement empty screen state for bookmarks. r=sriram

This commit is contained in:
Chenxia Liu 2013-10-16 09:42:33 -07:00
parent 4fdacac4f7
commit c9c696a583
8 changed files with 34 additions and 0 deletions

View File

@ -635,6 +635,7 @@ RES_DRAWABLE_MDPI = \
res/drawable-mdpi/ic_url_bar_search.png \
res/drawable-mdpi/ic_url_bar_star.png \
res/drawable-mdpi/ic_url_bar_tab.png \
res/drawable-mdpi/icon_bookmarks_empty.png \
res/drawable-mdpi/icon_last_tabs.png \
res/drawable-mdpi/icon_last_tabs_empty.png \
res/drawable-mdpi/icon_most_recent.png \
@ -752,6 +753,7 @@ RES_DRAWABLE_HDPI = \
res/drawable-hdpi/ic_url_bar_search.png \
res/drawable-hdpi/ic_url_bar_star.png \
res/drawable-hdpi/ic_url_bar_tab.png \
res/drawable-hdpi/icon_bookmarks_empty.png \
res/drawable-hdpi/icon_last_tabs.png \
res/drawable-hdpi/icon_last_tabs_empty.png \
res/drawable-hdpi/icon_most_recent.png \
@ -855,6 +857,7 @@ RES_DRAWABLE_XHDPI = \
res/drawable-xhdpi/ic_url_bar_search.png \
res/drawable-xhdpi/ic_url_bar_star.png \
res/drawable-xhdpi/ic_url_bar_tab.png \
res/drawable-xhdpi/icon_bookmarks_empty.png \
res/drawable-xhdpi/icon_last_tabs.png \
res/drawable-xhdpi/icon_last_tabs_empty.png \
res/drawable-xhdpi/icon_most_recent.png \

View File

@ -20,7 +20,10 @@ import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewStub;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
/**
* A page in about:home that displays a ListView of bookmarks.
@ -40,6 +43,9 @@ public class BookmarksPage extends HomeFragment {
// Adapter for list of bookmarks.
private BookmarksListAdapter mListAdapter;
// Reference to the View to display when there are no results.
private View mEmptyView;
// Callback for cursor loaders.
private CursorLoaderCallbacks mLoaderCallbacks;
@ -102,6 +108,7 @@ public class BookmarksPage extends HomeFragment {
public void onDestroyView() {
mList = null;
mListAdapter = null;
mEmptyView = null;
super.onDestroyView();
}
@ -130,6 +137,22 @@ public class BookmarksPage extends HomeFragment {
getLoaderManager().initLoader(LOADER_ID_BOOKMARKS_LIST, null, mLoaderCallbacks);
}
private void updateUiFromCursor(Cursor c) {
if ((c == null || c.getCount() == 0) && mEmptyView == null) {
// Set empty page view. We delay this so that the empty view won't flash.
final ViewStub emptyViewStub = (ViewStub) getView().findViewById(R.id.home_empty_view_stub);
mEmptyView = emptyViewStub.inflate();
final ImageView emptyIcon = (ImageView) mEmptyView.findViewById(R.id.home_empty_image);
emptyIcon.setImageResource(R.drawable.icon_bookmarks_empty);
final TextView emptyText = (TextView) mEmptyView.findViewById(R.id.home_empty_text);
emptyText.setText(R.string.home_bookmarks_empty);
mList.setEmptyView(mEmptyView);
}
}
/**
* Loader for the list for bookmarks.
*/
@ -167,6 +190,7 @@ public class BookmarksPage extends HomeFragment {
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
mListAdapter.swapCursor(c);
updateUiFromCursor(c);
}
@Override

View File

@ -275,6 +275,7 @@ size. -->
<!ENTITY home_top_sites_add "Add a site">
<!ENTITY home_history_title "History">
<!ENTITY home_bookmarks_empty "Bookmarks you save show up here.">
<!ENTITY home_last_tabs_title "Tabs from last time">
<!ENTITY home_last_tabs_open "Open all tabs from last time">
<!ENTITY home_last_tabs_empty "Your recent tabs show up here.">

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 997 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -7,6 +7,11 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ViewStub android:id="@+id/home_empty_view_stub"
android:layout="@layout/home_empty_page"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<org.mozilla.gecko.home.BookmarksListView
android:id="@+id/bookmarks_list"
android:layout_width="fill_parent"

View File

@ -257,6 +257,7 @@
<string name="home_top_sites_title">&home_top_sites_title;</string>
<string name="home_top_sites_add">&home_top_sites_add;</string>
<string name="home_history_title">&home_history_title;</string>
<string name="home_bookmarks_empty">&home_bookmarks_empty;</string>
<string name="home_last_tabs_title">&home_last_tabs_title;</string>
<string name="home_last_tabs_open">&home_last_tabs_open;</string>
<string name="home_last_tabs_empty">&home_last_tabs_empty;</string>