Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1198)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SignInPromo.java

Issue 2470913009: 📰 Refactor SuggestionsSection change detection (Closed)
Patch Set: address comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SignInPromo.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SignInPromo.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SignInPromo.java
index a8e01097767e866d4034c8e14f3b26e2c65ce8ee..5754f1835f91362bb324c7eb1460c41c62e2f9b0 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SignInPromo.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SignInPromo.java
@@ -24,18 +24,11 @@
import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver;
/**
- * Shows a card prompting the user to sign in. This item is also a {@link TreeNode}, and calling
- * {@link #hide()} or {@link #maybeShow()} will control its visibility.
+ * Shows a card prompting the user to sign in. This item is also an {@link OptionalLeaf}, and sign
+ * in state changes control its visibility.
*/
public class SignInPromo extends OptionalLeaf
implements StatusCardViewHolder.DataSource, ImpressionTracker.Listener {
- /**
- * Whether the promo should be visible, according to the parent object.
- *
- * The {@link NewTabPageAdapter} calls to {@link #maybeShow()} and {@link #hide()} modify this
- * when the sign in status changes.
- */
- private boolean mVisible;
/**
* Whether the user has seen the promo and dismissed it at some point. When this is set,
@@ -55,7 +48,7 @@ public SignInPromo(NodeParent parent, NewTabPageAdapter adapter) {
final SigninManager signinManager = SigninManager.get(ContextUtils.getApplicationContext());
mObserver = mDismissed ? null : new SigninObserver(signinManager, adapter);
- mVisible = signinManager.isSignInAllowed() && !signinManager.isSignedInOnNative();
+ setVisible(signinManager.isSignInAllowed() && !signinManager.isSignedInOnNative());
}
@Override
@@ -110,34 +103,15 @@ public void onImpression() {
}
@Override
- public boolean isShown() {
- return !mDismissed && mVisible;
- }
-
- /** Attempts to show the sign in promo. If the user dismissed it before, it will not be shown.*/
- private void maybeShow() {
- if (mVisible) return;
- mVisible = true;
-
- if (mDismissed) return;
-
- notifyItemInserted(0);
- }
-
- /** Hides the sign in promo. */
- private void hide() {
- if (!mVisible) return;
- mVisible = false;
-
- if (mDismissed) return;
-
- notifyItemRemoved(0);
+ public void setVisible(boolean visible) {
+ super.setVisible(!mDismissed && visible);
}
/** Hides the sign in promo and sets a preference to make sure it is not shown again. */
public void dismiss() {
- hide();
mDismissed = true;
+ setVisible(false);
+
ChromePreferenceManager.getInstance(ContextUtils.getApplicationContext())
.setNewTabPageSigninPromoDismissed(true);
mObserver.unregister();
@@ -177,22 +151,18 @@ public void onSignInAllowedChanged() {
// Listening to onSignInAllowedChanged is important for the FRE. Sign in is not allowed
// until it is completed, but the NTP is initialised before the FRE is even shown. By
// implementing this we can show the promo if the user did not sign in during the FRE.
- if (mSigninManager.isSignInAllowed()) {
- maybeShow();
- } else {
- hide();
- }
+ setVisible(mSigninManager.isSignInAllowed());
}
@Override
public void onSignedIn() {
- hide();
+ setVisible(false);
mAdapter.resetSections(/*alwaysAllowEmptySections=*/false);
}
@Override
public void onSignedOut() {
- maybeShow();
+ setVisible(true);
}
}

Powered by Google App Engine
This is Rietveld 408576698