| 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.content.Context; | 7 import android.content.Context; |
| 8 import android.support.annotation.DrawableRes; | 8 import android.support.annotation.DrawableRes; |
| 9 import android.support.annotation.Nullable; | 9 import android.support.annotation.Nullable; |
| 10 import android.support.annotation.StringRes; | 10 import android.support.annotation.StringRes; |
| 11 | 11 |
| 12 import org.chromium.base.Callback; | 12 import org.chromium.base.Callback; |
| 13 import org.chromium.base.ContextUtils; | 13 import org.chromium.base.ContextUtils; |
| 14 import org.chromium.base.VisibleForTesting; | 14 import org.chromium.base.VisibleForTesting; |
| 15 import org.chromium.base.metrics.RecordUserAction; | 15 import org.chromium.base.metrics.RecordUserAction; |
| 16 import org.chromium.chrome.R; | 16 import org.chromium.chrome.R; |
| 17 import org.chromium.chrome.browser.ntp.ContextMenuManager; |
| 17 import org.chromium.chrome.browser.ntp.NewTabPage.DestructionObserver; | 18 import org.chromium.chrome.browser.ntp.NewTabPage.DestructionObserver; |
| 18 import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager; | |
| 19 import org.chromium.chrome.browser.ntp.UiConfig; | 19 import org.chromium.chrome.browser.ntp.UiConfig; |
| 20 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; | 20 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; |
| 21 import org.chromium.chrome.browser.signin.AccountSigninActivity; | 21 import org.chromium.chrome.browser.signin.AccountSigninActivity; |
| 22 import org.chromium.chrome.browser.signin.SigninAccessPoint; | 22 import org.chromium.chrome.browser.signin.SigninAccessPoint; |
| 23 import org.chromium.chrome.browser.signin.SigninManager; | 23 import org.chromium.chrome.browser.signin.SigninManager; |
| 24 import org.chromium.chrome.browser.signin.SigninManager.SignInAllowedObserver; | 24 import org.chromium.chrome.browser.signin.SigninManager.SignInAllowedObserver; |
| 25 import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver; | 25 import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver; |
| 26 import org.chromium.chrome.browser.suggestions.SuggestionsUiDelegate; |
| 26 | 27 |
| 27 /** | 28 /** |
| 28 * Shows a card prompting the user to sign in. This item is also an {@link Optio
nalLeaf}, and sign | 29 * Shows a card prompting the user to sign in. This item is also an {@link Optio
nalLeaf}, and sign |
| 29 * in state changes control its visibility. | 30 * in state changes control its visibility. |
| 30 */ | 31 */ |
| 31 public class SignInPromo extends OptionalLeaf | 32 public class SignInPromo extends OptionalLeaf |
| 32 implements StatusCardViewHolder.DataSource, ImpressionTracker.Listener { | 33 implements StatusCardViewHolder.DataSource, ImpressionTracker.Listener { |
| 33 | 34 |
| 34 /** | 35 /** |
| 35 * Whether the user has seen the promo and dismissed it at some point. When
this is set, | 36 * Whether the user has seen the promo and dismissed it at some point. When
this is set, |
| 36 * the promo will never be shown. | 37 * the promo will never be shown. |
| 37 */ | 38 */ |
| 38 private boolean mDismissed; | 39 private boolean mDismissed; |
| 39 | 40 |
| 40 private final ImpressionTracker mImpressionTracker = new ImpressionTracker(n
ull, this); | 41 private final ImpressionTracker mImpressionTracker = new ImpressionTracker(n
ull, this); |
| 41 | 42 |
| 42 @Nullable | 43 @Nullable |
| 43 private final SigninObserver mObserver; | 44 private final SigninObserver mObserver; |
| 44 | 45 |
| 45 public SignInPromo(NewTabPageManager newTabPageManager) { | 46 public SignInPromo(SuggestionsUiDelegate uiDelegate) { |
| 46 mDismissed = ChromePreferenceManager.getInstance(ContextUtils.getApplica
tionContext()) | 47 mDismissed = ChromePreferenceManager.getInstance(ContextUtils.getApplica
tionContext()) |
| 47 .getNewTabPageSigninPromoDismissed(); | 48 .getNewTabPageSigninPromoDismissed(); |
| 48 | 49 |
| 49 SigninManager signinManager = SigninManager.get(ContextUtils.getApplicat
ionContext()); | 50 SigninManager signinManager = SigninManager.get(ContextUtils.getApplicat
ionContext()); |
| 50 if (mDismissed) { | 51 if (mDismissed) { |
| 51 mObserver = null; | 52 mObserver = null; |
| 52 } else { | 53 } else { |
| 53 mObserver = new SigninObserver(signinManager); | 54 mObserver = new SigninObserver(signinManager); |
| 54 newTabPageManager.addDestructionObserver(mObserver); | 55 uiDelegate.addDestructionObserver(mObserver); |
| 55 } | 56 } |
| 56 | 57 |
| 57 setVisible(signinManager.isSignInAllowed() && !signinManager.isSignedInO
nNative()); | 58 setVisible(signinManager.isSignInAllowed() && !signinManager.isSignedInO
nNative()); |
| 58 } | 59 } |
| 59 | 60 |
| 60 @Override | 61 @Override |
| 61 @ItemViewType | 62 @ItemViewType |
| 62 public int getItemViewType() { | 63 public int getItemViewType() { |
| 63 return ItemViewType.PROMO; | 64 return ItemViewType.PROMO; |
| 64 } | 65 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 @Override | 169 @Override |
| 169 public void onSignedOut() { | 170 public void onSignedOut() { |
| 170 setVisible(true); | 171 setVisible(true); |
| 171 } | 172 } |
| 172 } | 173 } |
| 173 | 174 |
| 174 /** | 175 /** |
| 175 * View Holder for {@link SignInPromo}. | 176 * View Holder for {@link SignInPromo}. |
| 176 */ | 177 */ |
| 177 public static class ViewHolder extends StatusCardViewHolder { | 178 public static class ViewHolder extends StatusCardViewHolder { |
| 178 | 179 public ViewHolder(NewTabPageRecyclerView parent, ContextMenuManager cont
extMenuManager, |
| 179 public ViewHolder(NewTabPageRecyclerView parent, NewTabPageManager newTa
bPageManager, | |
| 180 UiConfig config) { | 180 UiConfig config) { |
| 181 super(parent, newTabPageManager, config); | 181 super(parent, contextMenuManager, config); |
| 182 getParams().topMargin = parent.getResources().getDimensionPixelSize( | 182 getParams().topMargin = parent.getResources().getDimensionPixelSize( |
| 183 R.dimen.ntp_sign_in_promo_margin_top); | 183 R.dimen.ntp_sign_in_promo_margin_top); |
| 184 } | 184 } |
| 185 | 185 |
| 186 @DrawableRes | 186 @DrawableRes |
| 187 @Override | 187 @Override |
| 188 protected int selectBackground(boolean hasCardAbove, boolean hasCardBelo
w) { | 188 protected int selectBackground(boolean hasCardAbove, boolean hasCardBelo
w) { |
| 189 return R.drawable.ntp_signin_promo_card_single; | 189 return R.drawable.ntp_signin_promo_card_single; |
| 190 } | 190 } |
| 191 | 191 |
| 192 @Override | 192 @Override |
| 193 public boolean isDismissable() { | 193 public boolean isDismissable() { |
| 194 return true; | 194 return true; |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 } | 197 } |
| OLD | NEW |