Commit f8a5a382 authored by Cathy Li's avatar Cathy Li Committed by Commit Bot

[Explore sites]: Add error and loading from network views to recycler view.

Bug: 867488
Change-Id: Ic2615ce1b19eaf9fb283890d1a25df124b26fce2
Reviewed-on: https://chromium-review.googlesource.com/c/1252849
Commit-Queue: Cathy Li <chili@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Reviewed-by: default avatarJustin DeWitt <dewittj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596429}
parent 831290e1
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/explore_sites_loading_error"
android:drawableTop="@drawable/sad_tab" />
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<org.chromium.chrome.browser.widget.LoadingView
android:id="@+id/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="@dimen/tile_view_width"
android:minWidth="@dimen/tile_view_width" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/explore_sites_loading_from_net" />
</LinearLayout>
...@@ -8,6 +8,7 @@ import android.support.annotation.IntDef; ...@@ -8,6 +8,7 @@ import android.support.annotation.IntDef;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.modelutil.ForwardingListObservable; import org.chromium.chrome.browser.modelutil.ForwardingListObservable;
import org.chromium.chrome.browser.modelutil.PropertyKey; import org.chromium.chrome.browser.modelutil.PropertyKey;
import org.chromium.chrome.browser.modelutil.PropertyModel; import org.chromium.chrome.browser.modelutil.PropertyModel;
...@@ -15,6 +16,7 @@ import org.chromium.chrome.browser.modelutil.PropertyObservable; ...@@ -15,6 +16,7 @@ import org.chromium.chrome.browser.modelutil.PropertyObservable;
import org.chromium.chrome.browser.modelutil.RecyclerViewAdapter; import org.chromium.chrome.browser.modelutil.RecyclerViewAdapter;
import org.chromium.chrome.browser.native_page.ContextMenuManager; import org.chromium.chrome.browser.native_page.ContextMenuManager;
import org.chromium.chrome.browser.native_page.NativePageNavigationDelegate; import org.chromium.chrome.browser.native_page.NativePageNavigationDelegate;
import org.chromium.chrome.browser.widget.LoadingView;
import org.chromium.chrome.browser.widget.RoundedIconGenerator; import org.chromium.chrome.browser.widget.RoundedIconGenerator;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
...@@ -71,15 +73,18 @@ class CategoryCardAdapter extends ForwardingListObservable<Void> ...@@ -71,15 +73,18 @@ class CategoryCardAdapter extends ForwardingListObservable<Void>
@ViewType @ViewType
public int getItemViewType(int position) { public int getItemViewType(int position) {
if (position == 0) return ViewType.HEADER; if (position == 0) return ViewType.HEADER;
if (mCategoryModel.get(ExploreSitesPage.STATUS_KEY) switch (mCategoryModel.get(ExploreSitesPage.STATUS_KEY)) {
== ExploreSitesPage.CatalogLoadingState.ERROR) { case ExploreSitesPage.CatalogLoadingState.ERROR:
return ViewType.ERROR; return ViewType.ERROR;
} case ExploreSitesPage.CatalogLoadingState.LOADING: // fall-through
if (mCategoryModel.get(ExploreSitesPage.STATUS_KEY) case ExploreSitesPage.CatalogLoadingState.LOADING_NET:
== ExploreSitesPage.CatalogLoadingState.LOADING) { return ViewType.LOADING;
return ViewType.LOADING; case ExploreSitesPage.CatalogLoadingState.SUCCESS:
return ViewType.CATEGORY;
default:
assert(false);
return ViewType.ERROR;
} }
return ViewType.CATEGORY;
} }
@Override @Override
...@@ -91,6 +96,10 @@ class CategoryCardAdapter extends ForwardingListObservable<Void> ...@@ -91,6 +96,10 @@ class CategoryCardAdapter extends ForwardingListObservable<Void>
view.setCategory( view.setCategory(
mCategoryModel.get(ExploreSitesPage.CATEGORY_LIST_KEY).get(position - 1), mCategoryModel.get(ExploreSitesPage.CATEGORY_LIST_KEY).get(position - 1),
mIconGenerator, mContextMenuManager, mNavDelegate); mIconGenerator, mContextMenuManager, mNavDelegate);
} else if (holder.getItemViewType() == ViewType.LOADING) {
// Start spinner.
LoadingView spinner = holder.itemView.findViewById(R.id.loading);
spinner.showLoadingUI();
} }
} }
...@@ -99,8 +108,7 @@ class CategoryCardAdapter extends ForwardingListObservable<Void> ...@@ -99,8 +108,7 @@ class CategoryCardAdapter extends ForwardingListObservable<Void>
PropertyObservable<PropertyKey> source, @Nullable PropertyKey key) { PropertyObservable<PropertyKey> source, @Nullable PropertyKey key) {
if (key == ExploreSitesPage.STATUS_KEY) { if (key == ExploreSitesPage.STATUS_KEY) {
int status = mCategoryModel.get(ExploreSitesPage.STATUS_KEY); int status = mCategoryModel.get(ExploreSitesPage.STATUS_KEY);
if (status == ExploreSitesPage.CatalogLoadingState.LOADING if (status != ExploreSitesPage.CatalogLoadingState.SUCCESS) {
|| status == ExploreSitesPage.CatalogLoadingState.ERROR) {
notifyItemChanged(1); notifyItemChanged(1);
} // Else the list observer takes care of updating. } // Else the list observer takes care of updating.
} }
......
...@@ -8,7 +8,6 @@ import android.support.v7.widget.RecyclerView; ...@@ -8,7 +8,6 @@ import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.modelutil.RecyclerViewAdapter; import org.chromium.chrome.browser.modelutil.RecyclerViewAdapter;
...@@ -38,9 +37,15 @@ class CategoryCardViewHolderFactory implements RecyclerViewAdapter.ViewHolderFac ...@@ -38,9 +37,15 @@ class CategoryCardViewHolderFactory implements RecyclerViewAdapter.ViewHolderFac
.inflate(R.layout.explore_sites_category_card_view, parent, .inflate(R.layout.explore_sites_category_card_view, parent,
/* attachToRoot = */ false); /* attachToRoot = */ false);
break; break;
case CategoryCardAdapter.ViewType.LOADING: // inflate loading spinny case CategoryCardAdapter.ViewType.LOADING:
view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.explore_sites_loading_from_net_view, parent,
/* attachToRoot = */ false);
break;
case CategoryCardAdapter.ViewType.ERROR: // inflate error case CategoryCardAdapter.ViewType.ERROR: // inflate error
view = new TextView(parent.getContext()); // dummy view. view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.explore_sites_loading_error_view, parent,
/* attachToRoot = */ false);
break; break;
default: default:
assert false; assert false;
......
...@@ -49,9 +49,10 @@ public class ExploreSitesPage extends BasicNativePage { ...@@ -49,9 +49,10 @@ public class ExploreSitesPage extends BasicNativePage {
@IntDef({CatalogLoadingState.LOADING, CatalogLoadingState.SUCCESS, CatalogLoadingState.ERROR}) @IntDef({CatalogLoadingState.LOADING, CatalogLoadingState.SUCCESS, CatalogLoadingState.ERROR})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface CatalogLoadingState { public @interface CatalogLoadingState {
int LOADING = 1; int LOADING = 1; // Loading catalog info from disk.
int SUCCESS = 2; int SUCCESS = 2;
int ERROR = 3; int ERROR = 3; // Error retrieving catalog resources from internet.
int LOADING_NET = 4; // Retrieving catalog resources from internet.
} }
private final TabModelSelector mTabModelSelector; private final TabModelSelector mTabModelSelector;
...@@ -124,6 +125,10 @@ public class ExploreSitesPage extends BasicNativePage { ...@@ -124,6 +125,10 @@ public class ExploreSitesPage extends BasicNativePage {
mModel.set(STATUS_KEY, CatalogLoadingState.ERROR); mModel.set(STATUS_KEY, CatalogLoadingState.ERROR);
return; return;
} }
if (categoryList.isEmpty()) {
mModel.set(STATUS_KEY, CatalogLoadingState.LOADING_NET);
return;
}
mModel.set(STATUS_KEY, CatalogLoadingState.SUCCESS); mModel.set(STATUS_KEY, CatalogLoadingState.SUCCESS);
ListModel<ExploreSitesCategory> categoryListModel = mModel.get(CATEGORY_LIST_KEY); ListModel<ExploreSitesCategory> categoryListModel = mModel.get(CATEGORY_LIST_KEY);
categoryListModel.set(categoryList); categoryListModel.set(categoryList);
......
...@@ -2849,6 +2849,12 @@ To obtain new licenses, connect to the internet and play your downloaded content ...@@ -2849,6 +2849,12 @@ To obtain new licenses, connect to the internet and play your downloaded content
<message name="IDS_EXPLORE_SITES_DEFAULT_CATEGORY_COOKING" desc="The caption for a button that when clicked opens a UI in this tab that shows a list of websites with content related to food and cooking. [CHAR-LIMIT=12]"> <message name="IDS_EXPLORE_SITES_DEFAULT_CATEGORY_COOKING" desc="The caption for a button that when clicked opens a UI in this tab that shows a list of websites with content related to food and cooking. [CHAR-LIMIT=12]">
Cooking Cooking
</message> </message>
<message name="IDS_EXPLORE_SITES_LOADING_FROM_NET" desc="Caption for an indeterminate loading spinner indicating that we are loading the data from the internet">
Finding the best from the web.
</message>
<message name="IDS_EXPLORE_SITES_LOADING_ERROR" desc="Caption text indicating that a set of site icons and links failed to load.">
Oops! Something went wrong. Please check your connection.
</message>
<!-- Contextual suggestions strings --> <!-- Contextual suggestions strings -->
<message name="IDS_CONTEXTUAL_SUGGESTIONS_IN_PRODUCT_HELP" desc="The string displayed in an in-product help bubble when contextual suggestions are displayed for the first time. The bubble points to a toolbar button that shows suggestions related to the webpage the user is currently viewing when pressed."> <message name="IDS_CONTEXTUAL_SUGGESTIONS_IN_PRODUCT_HELP" desc="The string displayed in an in-product help bubble when contextual suggestions are displayed for the first time. The bubble points to a toolbar button that shows suggestions related to the webpage the user is currently viewing when pressed.">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment