OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.ntp.cards; | 5 package org.chromium.chrome.browser.ntp.cards; |
6 | 6 |
7 import android.support.annotation.StringRes; | 7 import android.support.annotation.StringRes; |
8 import android.view.LayoutInflater; | 8 import android.view.LayoutInflater; |
9 import android.view.View; | 9 import android.view.View; |
10 import android.view.View.OnClickListener; | 10 import android.view.View.OnClickListener; |
11 import android.view.ViewGroup; | 11 import android.view.ViewGroup; |
12 import android.widget.Button; | 12 import android.widget.Button; |
13 import android.widget.TextView; | 13 import android.widget.TextView; |
14 | 14 |
15 import org.chromium.chrome.R; | 15 import org.chromium.chrome.R; |
16 import org.chromium.chrome.browser.ntp.NewTabPageUma; | 16 import org.chromium.chrome.browser.ntp.NewTabPageUma; |
17 import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager; | |
18 | 17 |
19 import java.util.Calendar; | 18 import java.util.Calendar; |
20 | 19 |
21 /** | 20 /** |
22 * Displayed when all suggested content and their sections have been dismissed.
Provides a button | 21 * Displayed when all suggested content and their sections have been dismissed.
Provides a button |
23 * to restore the dismissed sections and load new suggestions from the server. | 22 * to restore the dismissed sections and load new suggestions from the server. |
24 */ | 23 */ |
25 public class AllDismissedItem extends OptionalLeaf { | 24 public class AllDismissedItem extends OptionalLeaf { |
26 /** | 25 /** |
27 * @param parent The item's parent node. | 26 * @param parent The item's parent node. |
(...skipping 13 matching lines...) Expand all Loading... |
41 assert holder instanceof ViewHolder; | 40 assert holder instanceof ViewHolder; |
42 ((ViewHolder) holder).onBindViewHolder(); | 41 ((ViewHolder) holder).onBindViewHolder(); |
43 } | 42 } |
44 | 43 |
45 /** | 44 /** |
46 * ViewHolder for an item of type {@link ItemViewType#ALL_DISMISSED}. | 45 * ViewHolder for an item of type {@link ItemViewType#ALL_DISMISSED}. |
47 */ | 46 */ |
48 public static class ViewHolder extends NewTabPageViewHolder { | 47 public static class ViewHolder extends NewTabPageViewHolder { |
49 private final TextView mBodyTextView; | 48 private final TextView mBodyTextView; |
50 | 49 |
51 public ViewHolder( | 50 public ViewHolder(ViewGroup root, final SectionList sections) { |
52 ViewGroup root, final NewTabPageManager manager, final NewTabPag
eAdapter adapter) { | |
53 super(LayoutInflater.from(root.getContext()) | 51 super(LayoutInflater.from(root.getContext()) |
54 .inflate(R.layout.new_tab_page_all_dismissed, root,
false)); | 52 .inflate(R.layout.new_tab_page_all_dismissed, root,
false)); |
55 mBodyTextView = (TextView) itemView.findViewById(R.id.body_text); | 53 mBodyTextView = (TextView) itemView.findViewById(R.id.body_text); |
56 | 54 |
57 ((Button) itemView.findViewById(R.id.action_button)) | 55 ((Button) itemView.findViewById(R.id.action_button)) |
58 .setOnClickListener(new OnClickListener() { | 56 .setOnClickListener(new OnClickListener() { |
59 @Override | 57 @Override |
60 public void onClick(View v) { | 58 public void onClick(View v) { |
61 NewTabPageUma.recordAction( | 59 NewTabPageUma.recordAction( |
62 NewTabPageUma.ACTION_CLICKED_ALL_DISMISSED_R
EFRESH); | 60 NewTabPageUma.ACTION_CLICKED_ALL_DISMISSED_R
EFRESH); |
63 manager.getSuggestionsSource().restoreDismissedCateg
ories(); | 61 sections.restoreDismissedSections(); |
64 adapter.resetSections(/*allowEmptySections=*/true); | |
65 manager.getSuggestionsSource().fetchRemoteSuggestion
s(); | |
66 } | 62 } |
67 }); | 63 }); |
68 } | 64 } |
69 | 65 |
70 public void onBindViewHolder() { | 66 public void onBindViewHolder() { |
71 int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); | 67 int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); |
72 @StringRes | 68 @StringRes |
73 int messageId; | 69 int messageId; |
74 if (hour >= 0 && hour < 12) { | 70 if (hour >= 0 && hour < 12) { |
75 messageId = R.string.ntp_all_dismissed_body_text_morning; | 71 messageId = R.string.ntp_all_dismissed_body_text_morning; |
76 } else if (hour >= 12 && hour < 17) { | 72 } else if (hour >= 12 && hour < 17) { |
77 messageId = R.string.ntp_all_dismissed_body_text_afternoon; | 73 messageId = R.string.ntp_all_dismissed_body_text_afternoon; |
78 } else { | 74 } else { |
79 messageId = R.string.ntp_all_dismissed_body_text_evening; | 75 messageId = R.string.ntp_all_dismissed_body_text_evening; |
80 } | 76 } |
81 mBodyTextView.setText(messageId); | 77 mBodyTextView.setText(messageId); |
82 } | 78 } |
83 } | 79 } |
84 } | 80 } |
OLD | NEW |