Commit 58bdb9de authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Unity][Android] Add ConsentBumpFragment

This CL implements ConsentBumpFragment - a SigninFragmentBase subclass
that provides an easy option to enable all features gated by unified
consent. This CL also modifies SigninActivity to use it as a container
for this fragment.

Bug: 869426
Change-Id: Ibbe64a674aad4ac2a05afca83424449f52f9a683
Reviewed-on: https://chromium-review.googlesource.com/1159068Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580131}
parent 402dbf5a
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.signin;
import android.os.Bundle;
import android.support.annotation.StringRes;
import org.chromium.chrome.R;
/**
* This fragment implements the consent bump screen. This is a variation of the sign-in screen that
* provides an easy option to enable all features gated by unified consent. This screen is shown to
* users who are already signed in and have Sync enabled, so there's no need to sign in users.
*/
public class ConsentBumpFragment extends SigninFragmentBase {
public static Bundle createArguments() {
return createArgumentsForConsentBumpFlow();
}
// Every fragment must have a public default constructor.
public ConsentBumpFragment() {}
@Override
protected Bundle getSigninArguments() {
return getArguments();
}
@Override
protected void onSigninRefused() {
// TODO(https://crbug.com/869426): Show ConsentBumpMoreOptionsFragment.
}
@Override
protected void onSigninAccepted(String accountName, boolean isDefaultAccount,
boolean settingsClicked, Runnable callback) {
// TODO(https://crbug.com/869426): Save the consent state.
getActivity().finish();
}
@Override
@StringRes
protected int getNegativeButtonTextId() {
return R.string.consent_bump_more_options;
}
}
...@@ -19,6 +19,8 @@ import org.chromium.chrome.browser.SynchronousInitializationActivity; ...@@ -19,6 +19,8 @@ import org.chromium.chrome.browser.SynchronousInitializationActivity;
// TODO(https://crbug.com/820491): extend AsyncInitializationActivity. // TODO(https://crbug.com/820491): extend AsyncInitializationActivity.
public class SigninActivity extends SynchronousInitializationActivity { public class SigninActivity extends SynchronousInitializationActivity {
private static final String TAG = "SigninActivity"; private static final String TAG = "SigninActivity";
private static final String ARGUMENT_FRAGMENT_NAME = "SigninActivity.FragmentName";
private static final String ARGUMENT_FRAGMENT_ARGS = "SigninActivity.FragmentArgs";
/** /**
* Creates an {@link Intent} which can be used to start sign-in flow. * Creates an {@link Intent} which can be used to start sign-in flow.
...@@ -26,7 +28,8 @@ public class SigninActivity extends SynchronousInitializationActivity { ...@@ -26,7 +28,8 @@ public class SigninActivity extends SynchronousInitializationActivity {
*/ */
public static Intent createIntent( public static Intent createIntent(
Context context, @AccountSigninActivity.AccessPoint int accessPoint) { Context context, @AccountSigninActivity.AccessPoint int accessPoint) {
return createIntentInternal(context, SigninFragment.createArguments(accessPoint)); return createIntentInternal(
context, SigninFragment.class, SigninFragment.createArguments(accessPoint));
} }
/** /**
...@@ -36,7 +39,7 @@ public class SigninActivity extends SynchronousInitializationActivity { ...@@ -36,7 +39,7 @@ public class SigninActivity extends SynchronousInitializationActivity {
*/ */
public static Intent createIntentForPromoDefaultFlow( public static Intent createIntentForPromoDefaultFlow(
Context context, @SigninAccessPoint int accessPoint, String accountName) { Context context, @SigninAccessPoint int accessPoint, String accountName) {
return createIntentInternal(context, return createIntentInternal(context, SigninFragment.class,
SigninFragment.createArgumentsForPromoDefaultFlow(accessPoint, accountName)); SigninFragment.createArgumentsForPromoDefaultFlow(accessPoint, accountName));
} }
...@@ -48,7 +51,7 @@ public class SigninActivity extends SynchronousInitializationActivity { ...@@ -48,7 +51,7 @@ public class SigninActivity extends SynchronousInitializationActivity {
*/ */
public static Intent createIntentForPromoChooseAccountFlow( public static Intent createIntentForPromoChooseAccountFlow(
Context context, @SigninAccessPoint int accessPoint, String accountName) { Context context, @SigninAccessPoint int accessPoint, String accountName) {
return createIntentInternal(context, return createIntentInternal(context, SigninFragment.class,
SigninFragment.createArgumentsForPromoChooseAccountFlow(accessPoint, accountName)); SigninFragment.createArgumentsForPromoChooseAccountFlow(accessPoint, accountName));
} }
...@@ -59,13 +62,24 @@ public class SigninActivity extends SynchronousInitializationActivity { ...@@ -59,13 +62,24 @@ public class SigninActivity extends SynchronousInitializationActivity {
*/ */
public static Intent createIntentForPromoAddAccountFlow( public static Intent createIntentForPromoAddAccountFlow(
Context context, @SigninAccessPoint int accessPoint) { Context context, @SigninAccessPoint int accessPoint) {
return createIntentInternal(context, SigninFragment.class,
SigninFragment.createArgumentsForPromoAddAccountFlow(accessPoint));
}
/**
* Creates an {@link Intent} which can be used to start consent bump flow.
*/
public static Intent createIntentForConsentBump(Context context) {
return createIntentInternal( return createIntentInternal(
context, SigninFragment.createArgumentsForPromoAddAccountFlow(accessPoint)); context, ConsentBumpFragment.class, ConsentBumpFragment.createArguments());
} }
private static Intent createIntentInternal(Context context, Bundle fragmentArguments) { private static Intent createIntentInternal(
Context context, Class<? extends Fragment> fragmentName, Bundle fragmentArgs) {
Intent intent = new Intent(context, SigninActivity.class); Intent intent = new Intent(context, SigninActivity.class);
intent.putExtras(fragmentArguments); intent.putExtra(ARGUMENT_FRAGMENT_NAME, fragmentName.getName());
intent.putExtra(ARGUMENT_FRAGMENT_ARGS, fragmentArgs);
intent.putExtras(fragmentArgs);
return intent; return intent;
} }
...@@ -77,8 +91,9 @@ public class SigninActivity extends SynchronousInitializationActivity { ...@@ -77,8 +91,9 @@ public class SigninActivity extends SynchronousInitializationActivity {
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentManager fragmentManager = getSupportFragmentManager();
Fragment fragment = fragmentManager.findFragmentById(R.id.fragment_container); Fragment fragment = fragmentManager.findFragmentById(R.id.fragment_container);
if (fragment == null) { if (fragment == null) {
fragment = new SigninFragment(); String fragmentName = getIntent().getStringExtra(ARGUMENT_FRAGMENT_NAME);
fragment.setArguments(getIntent().getExtras()); Bundle fragmentArgs = getIntent().getBundleExtra(ARGUMENT_FRAGMENT_ARGS);
fragment = Fragment.instantiate(this, fragmentName, fragmentArgs);
fragmentManager.beginTransaction().add(R.id.fragment_container, fragment).commit(); fragmentManager.beginTransaction().add(R.id.fragment_container, fragment).commit();
} }
} }
......
...@@ -74,13 +74,14 @@ public abstract class SigninFragmentBase ...@@ -74,13 +74,14 @@ public abstract class SigninFragmentBase
private static final int ADD_ACCOUNT_REQUEST_CODE = 1; private static final int ADD_ACCOUNT_REQUEST_CODE = 1;
@IntDef({SigninFlowType.DEFAULT, SigninFlowType.FORCED, SigninFlowType.CHOOSE_ACCOUNT, @IntDef({SigninFlowType.DEFAULT, SigninFlowType.FORCED, SigninFlowType.CHOOSE_ACCOUNT,
SigninFlowType.ADD_ACCOUNT}) SigninFlowType.ADD_ACCOUNT, SigninFlowType.CONSENT_BUMP})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@interface SigninFlowType { @interface SigninFlowType {
int DEFAULT = 0; int DEFAULT = 0;
int FORCED = 1; int FORCED = 1;
int CHOOSE_ACCOUNT = 2; int CHOOSE_ACCOUNT = 2;
int ADD_ACCOUNT = 3; int ADD_ACCOUNT = 3;
int CONSENT_BUMP = 4;
} }
private @SigninFlowType int mSigninFlowType; private @SigninFlowType int mSigninFlowType;
...@@ -156,6 +157,13 @@ public abstract class SigninFragmentBase ...@@ -156,6 +157,13 @@ public abstract class SigninFragmentBase
return result; return result;
} }
/** Creates an argument bundle for the consent bump screen. */
protected static Bundle createArgumentsForConsentBumpFlow() {
Bundle result = new Bundle();
result.putInt(ARGUMENT_SIGNIN_FLOW_TYPE, SigninFlowType.CONSENT_BUMP);
return result;
}
protected SigninFragmentBase() { protected SigninFragmentBase() {
mAccountsChangedObserver = this::triggerUpdateAccounts; mAccountsChangedObserver = this::triggerUpdateAccounts;
mProfileDataCacheObserver = (String accountId) -> updateProfileData(); mProfileDataCacheObserver = (String accountId) -> updateProfileData();
...@@ -262,10 +270,12 @@ public abstract class SigninFragmentBase ...@@ -262,10 +270,12 @@ public abstract class SigninFragmentBase
mView.getDetailsDescriptionView().setMovementMethod(LinkMovementMethod.getInstance()); mView.getDetailsDescriptionView().setMovementMethod(LinkMovementMethod.getInstance());
final Drawable endImageViewDrawable; final Drawable endImageViewDrawable;
if (isForcedSignin()) { if (mSigninFlowType == SigninFlowType.FORCED) {
endImageViewDrawable = SigninView.getCheckmarkDrawable(getContext()); endImageViewDrawable = SigninView.getCheckmarkDrawable(getContext());
mView.getRefuseButton().setVisibility(View.GONE); mView.getRefuseButton().setVisibility(View.GONE);
mView.getAcceptButtonEndPadding().setVisibility(View.INVISIBLE); mView.getAcceptButtonEndPadding().setVisibility(View.INVISIBLE);
} else if (mSigninFlowType == SigninFlowType.CONSENT_BUMP) {
endImageViewDrawable = SigninView.getCheckmarkDrawable(getContext());
} else { } else {
endImageViewDrawable = SigninView.getExpandArrowDrawable(getContext()); endImageViewDrawable = SigninView.getExpandArrowDrawable(getContext());
} }
......
...@@ -2588,6 +2588,9 @@ To obtain new licenses, connect to the internet and play your downloaded content ...@@ -2588,6 +2588,9 @@ To obtain new licenses, connect to the internet and play your downloaded content
Choose an account Choose an account
</message> </message>
<!-- Consent bump screen strings --> <!-- Consent bump screen strings -->
<message name="IDS_CONSENT_BUMP_MORE_OPTIONS" desc="Text for the button in the basic consent bump screen that opens the advanced consent bump screen. The advanced consent bump screen lets the user select from several options to enable or customize personalized and non-personalized services. [CHAR-LIMIT=20]">
More options
</message>
<message name="IDS_CONSENT_BUMP_TITLE" desc="Text for the title of the consent bump screen with advanced options. This screen lets user select from several options to enable or customize personalized and non-personalized services."> <message name="IDS_CONSENT_BUMP_TITLE" desc="Text for the title of the consent bump screen with advanced options. This screen lets user select from several options to enable or customize personalized and non-personalized services.">
Control sync, personalization, and more Control sync, personalization, and more
</message> </message>
......
...@@ -1260,6 +1260,7 @@ chrome_java_sources = [ ...@@ -1260,6 +1260,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/signin/ConfirmManagedSyncDataDialog.java", "java/src/org/chromium/chrome/browser/signin/ConfirmManagedSyncDataDialog.java",
"java/src/org/chromium/chrome/browser/signin/ConfirmSyncDataStateMachine.java", "java/src/org/chromium/chrome/browser/signin/ConfirmSyncDataStateMachine.java",
"java/src/org/chromium/chrome/browser/signin/ConfirmSyncDataStateMachineDelegate.java", "java/src/org/chromium/chrome/browser/signin/ConfirmSyncDataStateMachineDelegate.java",
"java/src/org/chromium/chrome/browser/signin/ConsentBumpFragment.java",
"java/src/org/chromium/chrome/browser/signin/ConsentBumpMoreOptionsFragment.java", "java/src/org/chromium/chrome/browser/signin/ConsentBumpMoreOptionsFragment.java",
"java/src/org/chromium/chrome/browser/signin/ConsentTextTracker.java", "java/src/org/chromium/chrome/browser/signin/ConsentTextTracker.java",
"java/src/org/chromium/chrome/browser/signin/DisplayableProfileData.java", "java/src/org/chromium/chrome/browser/signin/DisplayableProfileData.java",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment