| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.bookmarks; | 5 package org.chromium.chrome.browser.bookmarks; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.SharedPreferences; | 8 import android.content.SharedPreferences; |
| 9 import android.preference.PreferenceManager; | |
| 10 import android.support.v7.widget.RecyclerView; | 9 import android.support.v7.widget.RecyclerView; |
| 11 import android.support.v7.widget.RecyclerView.ViewHolder; | 10 import android.support.v7.widget.RecyclerView.ViewHolder; |
| 12 import android.view.ViewGroup; | 11 import android.view.ViewGroup; |
| 13 | 12 |
| 13 import org.chromium.base.ContextUtils; |
| 14 import org.chromium.base.metrics.RecordUserAction; | 14 import org.chromium.base.metrics.RecordUserAction; |
| 15 import org.chromium.chrome.browser.signin.SigninAccessPoint; | 15 import org.chromium.chrome.browser.signin.SigninAccessPoint; |
| 16 import org.chromium.chrome.browser.signin.SigninAndSyncView; | 16 import org.chromium.chrome.browser.signin.SigninAndSyncView; |
| 17 import org.chromium.chrome.browser.signin.SigninManager; | 17 import org.chromium.chrome.browser.signin.SigninManager; |
| 18 import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver; | 18 import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver; |
| 19 import org.chromium.sync.AndroidSyncSettings; | 19 import org.chromium.sync.AndroidSyncSettings; |
| 20 import org.chromium.sync.AndroidSyncSettings.AndroidSyncSettingsObserver; | 20 import org.chromium.sync.AndroidSyncSettings.AndroidSyncSettingsObserver; |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * Class that manages all the logic and UI behind the signin promo header in the
bookmark | 23 * Class that manages all the logic and UI behind the signin promo header in the
bookmark |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 mContext = context; | 57 mContext = context; |
| 58 mShowingChangeListener = showingChangeListener; | 58 mShowingChangeListener = showingChangeListener; |
| 59 | 59 |
| 60 AndroidSyncSettings.registerObserver(mContext, this); | 60 AndroidSyncSettings.registerObserver(mContext, this); |
| 61 | 61 |
| 62 mSignInManager = SigninManager.get(mContext); | 62 mSignInManager = SigninManager.get(mContext); |
| 63 mSignInManager.addSignInStateObserver(this); | 63 mSignInManager.addSignInStateObserver(this); |
| 64 | 64 |
| 65 updateShouldShow(false); | 65 updateShouldShow(false); |
| 66 if (shouldShow()) { | 66 if (shouldShow()) { |
| 67 int promoShowCount = PreferenceManager.getDefaultSharedPreferences(m
Context) | 67 int promoShowCount = ContextUtils.getAppSharedPreferences() |
| 68 .getInt(PREF_SIGNIN_PROMO_SHOW_COUNT, 0) + 1; | 68 .getInt(PREF_SIGNIN_PROMO_SHOW_COUNT, 0) + 1; |
| 69 PreferenceManager.getDefaultSharedPreferences(mContext).edit() | 69 ContextUtils.getAppSharedPreferences().edit() |
| 70 .putInt(PREF_SIGNIN_PROMO_SHOW_COUNT, promoShowCount).apply(
); | 70 .putInt(PREF_SIGNIN_PROMO_SHOW_COUNT, promoShowCount).apply(
); |
| 71 RecordUserAction.record("Stars_SignInPromoHeader_Displayed"); | 71 RecordUserAction.record("Stars_SignInPromoHeader_Displayed"); |
| 72 RecordUserAction.record("Signin_Impression_FromBookmarkManager"); | 72 RecordUserAction.record("Signin_Impression_FromBookmarkManager"); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 /** | 76 /** |
| 77 * Clean ups the class. Must be called once done using this class. | 77 * Clean ups the class. Must be called once done using this class. |
| 78 */ | 78 */ |
| 79 void destroy() { | 79 void destroy() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 return new ViewHolder( | 107 return new ViewHolder( |
| 108 SigninAndSyncView.create(parent, listener, SigninAccessPoint.BOO
KMARK_MANAGER)) {}; | 108 SigninAndSyncView.create(parent, listener, SigninAccessPoint.BOO
KMARK_MANAGER)) {}; |
| 109 } | 109 } |
| 110 | 110 |
| 111 /** | 111 /** |
| 112 * @return Whether user tapped "No" button on the signin promo header. | 112 * @return Whether user tapped "No" button on the signin promo header. |
| 113 */ | 113 */ |
| 114 private boolean wasSigninPromoDeclined() { | 114 private boolean wasSigninPromoDeclined() { |
| 115 return PreferenceManager.getDefaultSharedPreferences(mContext).getBoolea
n( | 115 return ContextUtils.getAppSharedPreferences().getBoolean( |
| 116 PREF_SIGNIN_PROMO_DECLINED, false); | 116 PREF_SIGNIN_PROMO_DECLINED, false); |
| 117 } | 117 } |
| 118 | 118 |
| 119 /** | 119 /** |
| 120 * Save that user tapped "No" button on the signin promo header. | 120 * Save that user tapped "No" button on the signin promo header. |
| 121 */ | 121 */ |
| 122 private void setSigninPromoDeclined() { | 122 private void setSigninPromoDeclined() { |
| 123 SharedPreferences.Editor sharedPreferencesEditor = | 123 SharedPreferences.Editor sharedPreferencesEditor = |
| 124 PreferenceManager.getDefaultSharedPreferences(mContext).edit(); | 124 ContextUtils.getAppSharedPreferences().edit(); |
| 125 sharedPreferencesEditor.putBoolean(PREF_SIGNIN_PROMO_DECLINED, true); | 125 sharedPreferencesEditor.putBoolean(PREF_SIGNIN_PROMO_DECLINED, true); |
| 126 sharedPreferencesEditor.apply(); | 126 sharedPreferencesEditor.apply(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 private void updateShouldShow(boolean notifyUI) { | 129 private void updateShouldShow(boolean notifyUI) { |
| 130 boolean oldIsShowing = mShouldShow; | 130 boolean oldIsShowing = mShouldShow; |
| 131 mShouldShow = AndroidSyncSettings.isMasterSyncEnabled(mContext) | 131 mShouldShow = AndroidSyncSettings.isMasterSyncEnabled(mContext) |
| 132 && mSignInManager.isSignInAllowed() | 132 && mSignInManager.isSignInAllowed() |
| 133 && !wasSigninPromoDeclined() | 133 && !wasSigninPromoDeclined() |
| 134 && PreferenceManager.getDefaultSharedPreferences(mContext).getIn
t( | 134 && ContextUtils.getAppSharedPreferences().getInt( |
| 135 PREF_SIGNIN_PROMO_SHOW_COUNT, 0) < MAX_SIGNIN_PROMO_SHOW
_COUNT; | 135 PREF_SIGNIN_PROMO_SHOW_COUNT, 0) < MAX_SIGNIN_PROMO_SHOW
_COUNT; |
| 136 if (oldIsShowing != mShouldShow && notifyUI) { | 136 if (oldIsShowing != mShouldShow && notifyUI) { |
| 137 mShowingChangeListener.onPromoHeaderShowingChanged(mShouldShow); | 137 mShowingChangeListener.onPromoHeaderShowingChanged(mShouldShow); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 // AndroidSyncSettingsObserver implementation | 141 // AndroidSyncSettingsObserver implementation |
| 142 | 142 |
| 143 @Override | 143 @Override |
| 144 public void androidSyncSettingsChanged() { | 144 public void androidSyncSettingsChanged() { |
| 145 updateShouldShow(true); | 145 updateShouldShow(true); |
| 146 } | 146 } |
| 147 | 147 |
| 148 // SignInStateObserver implementations | 148 // SignInStateObserver implementations |
| 149 | 149 |
| 150 @Override | 150 @Override |
| 151 public void onSignedIn() { | 151 public void onSignedIn() { |
| 152 updateShouldShow(true); | 152 updateShouldShow(true); |
| 153 } | 153 } |
| 154 | 154 |
| 155 @Override | 155 @Override |
| 156 public void onSignedOut() { | 156 public void onSignedOut() { |
| 157 updateShouldShow(true); | 157 updateShouldShow(true); |
| 158 } | 158 } |
| 159 } | 159 } |
| OLD | NEW |