[Touchless] Update news feed more button to match specs
Using dialog_list_item layout to match the more button to specs.
Bug: 937450
Change-Id: I3f5966a5a9f8fb47e9d674361b02a9913c89561c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1559236
Commit-Queue: Brandon Wylie <wylieb@chromium.org>
Reviewed-by: Matthew Jones <mdjones@chromium.org>
Reviewed-by: Theresa <twellington@chromium.org>
Reviewed-by: Sky Malice <skym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652587}
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/ActionItem.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/ActionItem.java
index 37da76b..a8f64c89 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/ActionItem.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/ActionItem.java
@@ -8,7 +8,6 @@
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;
-import android.widget.Button;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R;
@@ -157,17 +156,26 @@
/** ViewHolder associated to {@link ItemViewType#ACTION}. */
public static class ViewHolder extends CardViewHolder implements ContextMenuManager.Delegate {
private ActionItem mActionListItem;
+ protected View mButton;
+
private final ProgressIndicatorView mProgressIndicator;
- private final Button mButton;
private final SuggestionsUiDelegate mUiDelegate;
public ViewHolder(SuggestionsRecyclerView recyclerView,
ContextMenuManager contextMenuManager, final SuggestionsUiDelegate uiDelegate,
UiConfig uiConfig) {
- super(getLayout(), recyclerView, uiConfig, contextMenuManager);
+ this(getLayout(), recyclerView, contextMenuManager, uiDelegate, uiConfig);
+ }
+
+ public ViewHolder(int layoutId, SuggestionsRecyclerView recyclerView,
+ ContextMenuManager contextMenuManager, final SuggestionsUiDelegate uiDelegate,
+ UiConfig uiConfig) {
+ super(layoutId, recyclerView, uiConfig, contextMenuManager);
mProgressIndicator = itemView.findViewById(R.id.progress_indicator);
mButton = itemView.findViewById(R.id.action_button);
+ // If we fail to find it under the action_button id, fallback to the top-level view.
+ if (mButton == null) mButton = itemView;
mUiDelegate = uiDelegate;
mButton.setOnClickListener(v -> mActionListItem.performAction(uiDelegate,
this::showFetchFailureSnackbar, this::showNoNewSuggestionsSnackbar));
@@ -204,7 +212,7 @@
return R.layout.content_suggestions_action_card_modern;
}
- private void setState(@State int state) {
+ protected void setState(@State int state) {
assert state != State.HIDDEN;
// When hiding children, we keep them invisible rather than GONE to make sure the
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java
index f67524f..706a6a9 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageAdapter.java
@@ -40,13 +40,13 @@
*/
public class NewTabPageAdapter extends Adapter<NewTabPageViewHolder>
implements ListObservable.ListObserver<PartialBindCallback> {
- private final SuggestionsUiDelegate mUiDelegate;
- private final ContextMenuManager mContextMenuManager;
+ protected final SuggestionsUiDelegate mUiDelegate;
+ protected final ContextMenuManager mContextMenuManager;
private final OfflinePageBridge mOfflinePageBridge;
private final @Nullable View mAboveTheFoldView;
- private final UiConfig mUiConfig;
- private SuggestionsRecyclerView mRecyclerView;
+ protected final UiConfig mUiConfig;
+ protected SuggestionsRecyclerView mRecyclerView;
private final InnerNode<NewTabPageViewHolder, PartialBindCallback> mRoot;
diff --git a/chrome/android/touchless/java/res/drawable/ic_note_add.xml b/chrome/android/touchless/java/res/drawable/ic_note_add.xml
new file mode 100644
index 0000000..7cdfba3
--- /dev/null
+++ b/chrome/android/touchless/java/res/drawable/ic_note_add.xml
@@ -0,0 +1,14 @@
+<!-- Copyright 2019 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. -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0"
+ tools:targetApi="21">
+ <path
+ android:fillColor="@color/default_icon_color"
+ android:pathData="M13,10h-2v3L8,13v2h3v3h2v-3h3v-2h-3zM14,2L6,2c-1.1,0 -2,0.9 -2,2v16c0,1.1 0.89,2 1.99,2L18,22c1.1,0 2,-0.9 2,-2L20,8l-6,-6zM18,20L6,20L6,4h7v5h5v11z"/>
+</vector>
diff --git a/chrome/android/touchless/java/res/layout/dialog_list_item.xml b/chrome/android/touchless/java/res/layout/dialog_list_item.xml
index 91f25a5..aa2268f 100644
--- a/chrome/android/touchless/java/res/layout/dialog_list_item.xml
+++ b/chrome/android/touchless/java/res/layout/dialog_list_item.xml
@@ -11,7 +11,8 @@
android:paddingTop="9dp"
android:paddingBottom="9dp"
android:orientation="horizontal"
- android:background="@color/modern_primary_color">
+ android:background="@color/modern_primary_color"
+ android:theme="@style/Theme.AppCompat.Light">
<org.chromium.ui.widget.ChromeImageView
android:id="@+id/dialog_item_icon"
diff --git a/chrome/android/touchless/java/src/org/chromium/chrome/browser/touchless/TouchlessActionItemViewHolder.java b/chrome/android/touchless/java/src/org/chromium/chrome/browser/touchless/TouchlessActionItemViewHolder.java
new file mode 100644
index 0000000..d83c16a
--- /dev/null
+++ b/chrome/android/touchless/java/src/org/chromium/chrome/browser/touchless/TouchlessActionItemViewHolder.java
@@ -0,0 +1,58 @@
+// Copyright 2019 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.
+
+package org.chromium.chrome.browser.touchless;
+
+import android.view.View;
+import android.widget.TextView;
+
+import org.chromium.base.ApiCompatibilityUtils;
+import org.chromium.chrome.browser.native_page.ContextMenuManager;
+import org.chromium.chrome.browser.ntp.cards.ActionItem;
+import org.chromium.chrome.browser.suggestions.SuggestionsRecyclerView;
+import org.chromium.chrome.browser.suggestions.SuggestionsUiDelegate;
+import org.chromium.chrome.browser.widget.displaystyle.UiConfig;
+import org.chromium.chrome.touchless.R;
+import org.chromium.ui.widget.ChromeImageView;
+
+/** ViewHolder associated to {@link ItemViewType#ACTION} for touchless devices. */
+class TouchlessActionItemViewHolder extends ActionItem.ViewHolder {
+ private TextView mTextView;
+ private ChromeImageView mImageView;
+
+ TouchlessActionItemViewHolder(SuggestionsRecyclerView recyclerView,
+ ContextMenuManager contextMenuManager, final SuggestionsUiDelegate uiDelegate,
+ UiConfig uiConfig) {
+ super(R.layout.dialog_list_item, recyclerView, contextMenuManager, uiDelegate, uiConfig);
+ mTextView = itemView.findViewById(R.id.dialog_item_text);
+ mImageView = itemView.findViewById(R.id.dialog_item_icon);
+ }
+
+ @Override
+ public void onBindViewHolder(ActionItem item) {
+ super.onBindViewHolder(item);
+
+ itemView.setBackground(ApiCompatibilityUtils.getDrawable(
+ itemView.getResources(), R.drawable.hairline_border_card_background));
+ mTextView.setText(itemView.getResources().getString(R.string.more_articles));
+ mImageView.setImageDrawable(
+ ApiCompatibilityUtils.getDrawable(itemView.getResources(), R.drawable.ic_note_add));
+ }
+
+ @Override
+ protected void setState(@ActionItem.State int state) {
+ assert state != ActionItem.State.HIDDEN;
+
+ // Similar to the method in ActionItem.ViewHolder, but removing the animted progress
+ // indicator that's not supported for touchless devices.
+ if (state == ActionItem.State.BUTTON) {
+ mButton.setVisibility(View.VISIBLE);
+ } else if (state == ActionItem.State.LOADING) {
+ mButton.setVisibility(View.INVISIBLE);
+ } else {
+ // Not even HIDDEN is supported as the item should not be able to receive updates.
+ assert false : "ActionViewHolder got notified of an unsupported state: " + state;
+ }
+ }
+}
\ No newline at end of file
diff --git a/chrome/android/touchless/java/src/org/chromium/chrome/browser/touchless/TouchlessNewTabPageAdapter.java b/chrome/android/touchless/java/src/org/chromium/chrome/browser/touchless/TouchlessNewTabPageAdapter.java
index 657f5bdc..af6d4067 100644
--- a/chrome/android/touchless/java/src/org/chromium/chrome/browser/touchless/TouchlessNewTabPageAdapter.java
+++ b/chrome/android/touchless/java/src/org/chromium/chrome/browser/touchless/TouchlessNewTabPageAdapter.java
@@ -6,6 +6,7 @@
import android.support.annotation.Nullable;
import android.view.View;
+import android.view.ViewGroup;
import org.chromium.base.Callback;
import org.chromium.chrome.browser.native_page.ContextMenuManager;
@@ -48,6 +49,17 @@
}
@Override
+ public NewTabPageViewHolder onCreateViewHolder(ViewGroup parent, @ItemViewType int viewType) {
+ switch (viewType) {
+ case ItemViewType.ACTION:
+ return new TouchlessActionItemViewHolder(
+ mRecyclerView, mContextMenuManager, mUiDelegate, mUiConfig);
+ default:
+ return super.onCreateViewHolder(parent, viewType);
+ }
+ }
+
+ @Override
public void onBindViewHolder(NewTabPageViewHolder holder, int position, List<Object> payloads) {
super.onBindViewHolder(holder, position, payloads);
diff --git a/chrome/android/touchless/java/strings/touchless_strings.grd b/chrome/android/touchless/java/strings/touchless_strings.grd
index 66e5a33..75f08ae 100644
--- a/chrome/android/touchless/java/strings/touchless_strings.grd
+++ b/chrome/android/touchless/java/strings/touchless_strings.grd
@@ -125,6 +125,9 @@
<message name="IDS_NTP_ALL_APPS" desc="Text to accompany icon that will navigate to a page showing a categorized view of different applications or sites">
All apps
</message>
+ <message name="IDS_MORE_ARTICLES" desc="Message at the bottom of a list of news items prompting the user to load more.">
+ More articles
+ </message>
</messages>
</release>
</grit>
diff --git a/chrome/android/touchless/touchless_java_sources.gni b/chrome/android/touchless/touchless_java_sources.gni
index 8c28f26..c952aa7 100644
--- a/chrome/android/touchless/touchless_java_sources.gni
+++ b/chrome/android/touchless/touchless_java_sources.gni
@@ -20,6 +20,7 @@
"touchless/java/src/org/chromium/chrome/browser/touchless/SiteSuggestionsMediator.java",
"touchless/java/src/org/chromium/chrome/browser/touchless/SiteSuggestionsTileView.java",
"touchless/java/src/org/chromium/chrome/browser/touchless/SiteSuggestionsViewHolderFactory.java",
+ "touchless/java/src/org/chromium/chrome/browser/touchless/TouchlessActionItemViewHolder.java",
"touchless/java/src/org/chromium/chrome/browser/touchless/TouchlessDelegate.java",
"touchless/java/src/org/chromium/chrome/browser/touchless/TouchlessNewTabPage.java",
"touchless/java/src/org/chromium/chrome/browser/touchless/TouchlessNewTabPageAdapter.java",