| 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.Intent; | |
| 9 import android.content.SharedPreferences; | 8 import android.content.SharedPreferences; |
| 10 import android.preference.PreferenceManager; | 9 import android.preference.PreferenceManager; |
| 11 import android.support.v7.widget.RecyclerView; | 10 import android.support.v7.widget.RecyclerView; |
| 12 import android.support.v7.widget.RecyclerView.ViewHolder; | 11 import android.support.v7.widget.RecyclerView.ViewHolder; |
| 13 import android.view.LayoutInflater; | |
| 14 import android.view.View; | 12 import android.view.View; |
| 15 import android.view.View.OnClickListener; | |
| 16 import android.view.ViewGroup; | 13 import android.view.ViewGroup; |
| 17 | 14 |
| 18 import org.chromium.base.metrics.RecordUserAction; | 15 import org.chromium.base.metrics.RecordUserAction; |
| 19 import org.chromium.chrome.R; | 16 import org.chromium.chrome.browser.signin.SigninAccessPoint; |
| 17 import org.chromium.chrome.browser.signin.SigninAndSyncView; |
| 20 import org.chromium.chrome.browser.signin.SigninManager; | 18 import org.chromium.chrome.browser.signin.SigninManager; |
| 21 import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver; | 19 import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver; |
| 22 import org.chromium.sync.AndroidSyncSettings; | 20 import org.chromium.sync.AndroidSyncSettings; |
| 23 import org.chromium.sync.AndroidSyncSettings.AndroidSyncSettingsObserver; | 21 import org.chromium.sync.AndroidSyncSettings.AndroidSyncSettingsObserver; |
| 24 | 22 |
| 25 /** | 23 /** |
| 26 * Class that manages all the logic and UI behind the signin promo header in the
bookmark | 24 * Class that manages all the logic and UI behind the signin promo header in the
bookmark |
| 27 * content UI. The header is shown only on certain situations, (e.g., not signed
in). | 25 * content UI. The header is shown only on certain situations, (e.g., not signed
in). |
| 28 */ | 26 */ |
| 29 class BookmarkPromoHeader implements AndroidSyncSettingsObserver, | 27 class BookmarkPromoHeader implements AndroidSyncSettingsObserver, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 */ | 89 */ |
| 92 boolean shouldShow() { | 90 boolean shouldShow() { |
| 93 return mShouldShow; | 91 return mShouldShow; |
| 94 } | 92 } |
| 95 | 93 |
| 96 /** | 94 /** |
| 97 * @return Signin promo header {@link ViewHolder} instance that can be used
with | 95 * @return Signin promo header {@link ViewHolder} instance that can be used
with |
| 98 * {@link RecyclerView}. | 96 * {@link RecyclerView}. |
| 99 */ | 97 */ |
| 100 ViewHolder createHolder(ViewGroup parent) { | 98 ViewHolder createHolder(ViewGroup parent) { |
| 101 ViewGroup promoHeader = (ViewGroup) LayoutInflater.from(mContext) | 99 SigninAndSyncView.Listener listener = new SigninAndSyncView.Listener() { |
| 102 .inflate(R.layout.bookmark_promo_header, parent, false); | |
| 103 | |
| 104 promoHeader.findViewById(R.id.no_thanks).setOnClickListener(new OnClickL
istener() { | |
| 105 @Override | 100 @Override |
| 106 public void onClick(View view) { | 101 public void onViewDismissed() { |
| 107 RecordUserAction.record("Stars_SignInPromoHeader_Dismissed"); | 102 RecordUserAction.record("Stars_SignInPromoHeader_Dismissed"); |
| 108 setSigninPromoDeclined(); | 103 setSigninPromoDeclined(); |
| 109 updateShouldShow(true); | 104 updateShouldShow(true); |
| 110 } | 105 } |
| 111 }); | 106 }; |
| 112 | 107 |
| 113 promoHeader.findViewById(R.id.sign_in).setOnClickListener(new OnClickLis
tener() { | 108 View view = new SigninAndSyncView(mContext, listener, SigninAccessPoint.
BOOKMARK_MANAGER); |
| 114 @Override | 109 return new ViewHolder(view) {}; |
| 115 public void onClick(View view) { | |
| 116 mContext.startActivity(new Intent(mContext, BookmarkSigninActivi
ty.class)); | |
| 117 } | |
| 118 }); | |
| 119 | |
| 120 return new ViewHolder(promoHeader) {}; | |
| 121 } | 110 } |
| 122 | 111 |
| 123 /** | 112 /** |
| 124 * @return Whether user tapped "No" button on the signin promo header. | 113 * @return Whether user tapped "No" button on the signin promo header. |
| 125 */ | 114 */ |
| 126 private boolean wasSigninPromoDeclined() { | 115 private boolean wasSigninPromoDeclined() { |
| 127 return PreferenceManager.getDefaultSharedPreferences(mContext).getBoolea
n( | 116 return PreferenceManager.getDefaultSharedPreferences(mContext).getBoolea
n( |
| 128 PREF_SIGNIN_PROMO_DECLINED, false); | 117 PREF_SIGNIN_PROMO_DECLINED, false); |
| 129 } | 118 } |
| 130 | 119 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 @Override | 151 @Override |
| 163 public void onSignedIn() { | 152 public void onSignedIn() { |
| 164 updateShouldShow(true); | 153 updateShouldShow(true); |
| 165 } | 154 } |
| 166 | 155 |
| 167 @Override | 156 @Override |
| 168 public void onSignedOut() { | 157 public void onSignedOut() { |
| 169 updateShouldShow(true); | 158 updateShouldShow(true); |
| 170 } | 159 } |
| 171 } | 160 } |
| OLD | NEW |