Skip to content

Commit dac52e6

Browse files
committed
Added main ToS/PP, WIP
1 parent f221717 commit dac52e6

12 files changed

+151
-57
lines changed

auth/src/main/java/com/firebase/ui/auth/ui/email/CheckEmailFragment.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,21 @@
1313
import android.view.View;
1414
import android.view.ViewGroup;
1515
import android.widget.EditText;
16+
import android.widget.TextView;
1617

18+
import com.firebase.ui.auth.AuthUI;
1719
import com.firebase.ui.auth.R;
1820
import com.firebase.ui.auth.data.model.User;
1921
import com.firebase.ui.auth.ui.FragmentBase;
2022
import com.firebase.ui.auth.util.ExtraConstants;
2123
import com.firebase.ui.auth.util.ui.ImeHelper;
24+
import com.firebase.ui.auth.util.ui.PreambleHandler;
2225
import com.firebase.ui.auth.util.ui.fieldvalidators.EmailFieldValidator;
2326
import com.firebase.ui.auth.viewmodel.ResourceObserver;
2427
import com.google.firebase.auth.EmailAuthProvider;
2528

29+
import java.util.List;
30+
2631
/**
2732
* Fragment that shows a form with an email field and checks for existing accounts with that email.
2833
* <p>
@@ -96,6 +101,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
96101
}
97102

98103
view.findViewById(R.id.button_next).setOnClickListener(this);
104+
setUpTermsOfService(view);
99105
}
100106

101107
@Override
@@ -175,4 +181,14 @@ private void validateAndProceed() {
175181
mHandler.fetchProvider(email);
176182
}
177183
}
184+
185+
private void setUpTermsOfService(View view) {
186+
List<AuthUI.IdpConfig> providers = getFlowParams().providerInfo;
187+
if (providers.size() == 1) {
188+
PreambleHandler.setup(getContext(),
189+
getFlowParams(),
190+
R.string.fui_tos_and_pp,
191+
view.<TextView>findViewById(R.id.email_tos_and_pp_text));
192+
}
193+
}
178194
}

auth/src/main/java/com/firebase/ui/auth/ui/email/RegisterEmailFragment.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.support.annotation.NonNull;
77
import android.support.annotation.Nullable;
88
import android.support.annotation.RestrictTo;
9+
import android.support.annotation.StringRes;
910
import android.support.design.widget.TextInputLayout;
1011
import android.text.TextUtils;
1112
import android.view.LayoutInflater;
@@ -140,11 +141,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
140141
// Only show the name field if required
141142
nameInput.setVisibility(requireName ? View.VISIBLE : View.GONE);
142143

143-
PreambleHandler.setup(
144-
getContext(),
145-
getFlowParams(),
146-
R.string.fui_button_text_save,
147-
view.<TextView>findViewById(R.id.create_account_text));
148144
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && getFlowParams().enableCredentials) {
149145
mEmailEditText.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO);
150146
}
@@ -173,6 +169,18 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
173169
}
174170
}
175171

172+
private @StringRes int getTermsStringResource() {
173+
boolean hasTos = !TextUtils.isEmpty(getFlowParams().termsOfServiceUrl);
174+
boolean hasPp = !TextUtils.isEmpty(getFlowParams().privacyPolicyUrl);
175+
if(hasTos && hasPp) {
176+
return R.string.fui_create_account_preamble_tos_and_pp;
177+
} else if(hasTos) {
178+
return R.string.fui_create_account_preamble_tos_only;
179+
} else {
180+
return R.string.fui_create_account_preamble_pp_only;
181+
}
182+
}
183+
176184
private void safeRequestFocus(final View v) {
177185
v.post(new Runnable() {
178186
@Override

auth/src/main/java/com/firebase/ui/auth/ui/idp/AuthMethodPickerActivity.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.firebase.ui.auth.ui.idp;
1616

17+
import android.app.Activity;
1718
import android.arch.lifecycle.ViewModelProvider;
1819
import android.arch.lifecycle.ViewModelProviders;
1920
import android.content.Context;
@@ -28,6 +29,7 @@
2829
import android.view.View;
2930
import android.view.ViewGroup;
3031
import android.widget.ImageView;
32+
import android.widget.TextView;
3133
import android.widget.Toast;
3234

3335
import com.firebase.ui.auth.AuthUI;
@@ -42,6 +44,7 @@
4244
import com.firebase.ui.auth.data.remote.PhoneSignInHandler;
4345
import com.firebase.ui.auth.data.remote.TwitterSignInHandler;
4446
import com.firebase.ui.auth.ui.AppCompatBase;
47+
import com.firebase.ui.auth.util.ui.PreambleHandler;
4548
import com.firebase.ui.auth.viewmodel.ResourceObserver;
4649
import com.firebase.ui.auth.viewmodel.idp.ProviderSignInBase;
4750
import com.firebase.ui.auth.viewmodel.idp.SocialProviderResponseHandler;
@@ -106,6 +109,8 @@ protected void onFailure(@NonNull Exception e) {
106109
}
107110
}
108111
});
112+
113+
setUpTermsOfService();
109114
}
110115

111116
private void populateIdpList(List<IdpConfig> providerConfigs,
@@ -204,6 +209,14 @@ public void onClick(View view) {
204209
}
205210
}
206211

212+
private void setUpTermsOfService() {
213+
TextView view = (TextView) findViewById(R.id.main_tos_and_pp);
214+
PreambleHandler.setup(AuthMethodPickerActivity.this,
215+
getFlowParams(),
216+
R.string.fui_tos_and_pp,
217+
view);
218+
}
219+
207220
@Override
208221
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
209222
super.onActivityResult(requestCode, resultCode, data);

auth/src/main/java/com/firebase/ui/auth/ui/phone/SubmitConfirmationCodeFragment.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public class SubmitConfirmationCodeFragment extends FragmentBase {
5656
private Button mSubmitConfirmationButton;
5757
private CustomCountDownTimer mCountdownTimer;
5858
private PhoneActivity mVerifier;
59-
private TextView mAgreementText;
6059
private long mMillisUntilFinished;
6160

6261
public static SubmitConfirmationCodeFragment newInstance(FlowParameters flowParameters,
@@ -83,7 +82,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
8382
mResendCodeTextView = v.findViewById(R.id.resend_code);
8483
mConfirmationCodeEditText = v.findViewById(R.id.confirmation_code);
8584
mSubmitConfirmationButton = v.findViewById(R.id.submit_confirmation_code);
86-
mAgreementText = v.findViewById(R.id.create_account_tos);
8785

8886
final String phoneNumber = getArguments().getString(ExtraConstants.PHONE);
8987

@@ -93,7 +91,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
9391
setupCountDown(RESEND_WAIT_MILLIS);
9492
setupSubmitConfirmationCodeButton();
9593
setupResendConfirmationCodeTextView(phoneNumber);
96-
setUpTermsOfService();
9794
return v;
9895
}
9996

@@ -221,13 +218,6 @@ private void cancelTimer() {
221218
}
222219
}
223220

224-
private void setUpTermsOfService() {
225-
PreambleHandler.setup(getContext(),
226-
getFlowParams(),
227-
R.string.fui_continue_phone_login,
228-
mAgreementText);
229-
}
230-
231221
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
232222
CustomCountDownTimer getCountdownTimer() {
233223
return mCountdownTimer;

auth/src/main/java/com/firebase/ui/auth/ui/phone/VerifyPhoneNumberFragment.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.widget.EditText;
3434
import android.widget.TextView;
3535

36+
import com.firebase.ui.auth.AuthUI;
3637
import com.firebase.ui.auth.R;
3738
import com.firebase.ui.auth.data.model.CountryInfo;
3839
import com.firebase.ui.auth.data.model.FlowParameters;
@@ -42,11 +43,14 @@
4243
import com.firebase.ui.auth.util.GoogleApiUtils;
4344
import com.firebase.ui.auth.util.data.PhoneNumberUtils;
4445
import com.firebase.ui.auth.util.ui.ImeHelper;
46+
import com.firebase.ui.auth.util.ui.PreambleHandler;
4547
import com.firebase.ui.auth.viewmodel.RequestCodes;
4648
import com.google.android.gms.auth.api.credentials.Credential;
4749
import com.google.android.gms.auth.api.credentials.CredentialPickerConfig;
4850
import com.google.android.gms.auth.api.credentials.HintRequest;
51+
import com.google.firebase.auth.PhoneAuthProvider;
4952

53+
import java.util.List;
5054
import java.util.Locale;
5155

5256
/**
@@ -55,7 +59,6 @@
5559
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
5660
public class VerifyPhoneNumberFragment extends FragmentBase implements View.OnClickListener {
5761
public static final String TAG = "VerifyPhoneFragment";
58-
5962
private Context mAppContext;
6063

6164
private CountryListSpinner mCountryListSpinner;
@@ -107,15 +110,13 @@ public void onDonePressed() {
107110
parentActivity.setTitle(getString(R.string.fui_verify_phone_number_title));
108111
setupCountrySpinner();
109112
setupSendCodeButton();
110-
setupTerms();
111-
112113
return v;
113114
}
114115

115-
private void setupTerms() {
116-
final String verifyPhoneButtonText = getString(R.string.fui_verify_phone_number);
117-
final String terms = getString(R.string.fui_sms_terms_of_service, verifyPhoneButtonText);
118-
mSmsTermsText.setText(terms);
116+
@Override
117+
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
118+
super.onViewCreated(view, savedInstanceState);
119+
setUpTermsOfService(view);
119120
}
120121

121122
@Override
@@ -273,6 +274,21 @@ private void setCountryCode(PhoneNumber phoneNumber) {
273274
}
274275
}
275276

277+
private void setUpTermsOfService(View view) {
278+
List<AuthUI.IdpConfig> providers = getFlowParams().providerInfo;
279+
if(providers.size() > 1) {
280+
final String verifyPhoneButtonText = getString(R.string.fui_verify_phone_number);
281+
final String terms = getString(R.string.fui_sms_terms_of_service, verifyPhoneButtonText);
282+
mSmsTermsText.setText(terms);
283+
} else {
284+
PreambleHandler.setup(getContext(),
285+
getFlowParams(),
286+
R.string.fui_verify_phone_number,
287+
R.string.fui_sms_terms_of_service_extended,
288+
view.<TextView>findViewById(R.id.send_sms_tos));
289+
}
290+
}
291+
276292
void showError(String e) {
277293
mPhoneInputLayout.setError(e);
278294
}

auth/src/main/java/com/firebase/ui/auth/util/ui/PreambleHandler.java

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class PreambleHandler {
2525
private static final String BTN_TARGET = "%BTN%";
2626
private static final String TOS_TARGET = "%TOS%";
2727
private static final String PP_TARGET = "%PP%";
28+
private static final int NO_BUTTON = -1;
2829

2930
private final Context mContext;
3031
private final FlowParameters mFlowParameters;
@@ -41,12 +42,30 @@ private PreambleHandler(Context context, FlowParameters parameters, @StringRes i
4142
R.color.fui_linkColor));
4243
}
4344

45+
private PreambleHandler(Context context, FlowParameters parameters) {
46+
mContext = context;
47+
mFlowParameters = parameters;
48+
mButtonText = NO_BUTTON;
49+
mLinkSpan = new ForegroundColorSpan(ContextCompat.getColor(mContext,
50+
R.color.fui_linkColor));
51+
}
52+
4453
public static void setup(Context context,
4554
FlowParameters parameters,
4655
@StringRes int buttonText,
56+
@StringRes int textViewText,
4757
TextView textView) {
4858
PreambleHandler handler = new PreambleHandler(context, parameters, buttonText);
49-
handler.setupCreateAccountPreamble();
59+
handler.setupPreamble(textViewText);
60+
handler.setPreamble(textView);
61+
}
62+
63+
public static void setup(Context context,
64+
FlowParameters parameters,
65+
@StringRes int textViewText,
66+
TextView textView) {
67+
PreambleHandler handler = new PreambleHandler(context, parameters);
68+
handler.setupPreamble(textViewText);
5069
handler.setPreamble(textView);
5170
}
5271

@@ -55,8 +74,9 @@ private void setPreamble(TextView textView) {
5574
textView.setText(mBuilder);
5675
}
5776

58-
private void setupCreateAccountPreamble() {
59-
String withTargets = getPreambleStringWithTargets();
77+
private void setupPreamble(@StringRes int textViewText) {
78+
String withTargets = (mButtonText == NO_BUTTON) ? getPreambleStringWithTargetsNoButton(
79+
textViewText) : getPreambleStringWithTargets(textViewText);
6080
if (withTargets == null) {
6181
return;
6282
}
@@ -92,24 +112,40 @@ private void replaceUrlTarget(String target, @StringRes int replacementRes, Stri
92112
}
93113

94114
@Nullable
95-
private String getPreambleStringWithTargets() {
115+
private String getPreambleStringWithTargets(@StringRes int textViewText) {
96116
boolean hasTos = !TextUtils.isEmpty(mFlowParameters.termsOfServiceUrl);
97117
boolean hasPp = !TextUtils.isEmpty(mFlowParameters.privacyPolicyUrl);
118+
if (hasTos && hasPp) {
119+
return mContext.getString(textViewText,
120+
BTN_TARGET, TOS_TARGET, PP_TARGET);
121+
} else if (hasTos) {
122+
return mContext.getString(textViewText,
123+
BTN_TARGET, TOS_TARGET);
124+
} else if (hasPp) {
125+
return mContext.getString(textViewText,
126+
BTN_TARGET, PP_TARGET);
127+
}
128+
return null;
129+
}
98130

131+
@Nullable
132+
private String getPreambleStringWithTargetsNoButton(@StringRes int textViewText) {
133+
boolean hasTos = !TextUtils.isEmpty(mFlowParameters.termsOfServiceUrl);
134+
boolean hasPp = !TextUtils.isEmpty(mFlowParameters.privacyPolicyUrl);
99135
if (hasTos && hasPp) {
100-
return mContext.getString(R.string.fui_create_account_preamble_tos_and_pp,
101-
BTN_TARGET, TOS_TARGET, PP_TARGET);
136+
return mContext.getString(textViewText,
137+
TOS_TARGET, PP_TARGET);
102138
} else if (hasTos) {
103-
return mContext.getString(R.string.fui_create_account_preamble_tos_only,
104-
BTN_TARGET, TOS_TARGET);
139+
return mContext.getString(textViewText,
140+
TOS_TARGET);
105141
} else if (hasPp) {
106-
return mContext.getString(R.string.fui_create_account_preamble_pp_only,
107-
BTN_TARGET, PP_TARGET);
108-
} else {
109-
return null;
142+
return mContext.getString(textViewText,
143+
PP_TARGET);
110144
}
145+
return null;
111146
}
112147

148+
113149
private class CustomTabsSpan extends ClickableSpan {
114150
private final String mUrl;
115151
private final CustomTabsIntent mCustomTabsIntent;

auth/src/main/res/layout-land/fui_auth_method_picker_layout.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
android:id="@+id/btn_holder"
3333
style="@style/FirebaseUI.AuthMethodPicker.ButtonHolder" />
3434

35+
<TextView
36+
android:id="@+id/main_tos_and_pp"
37+
style="@style/FirebaseUI.Text.BodyText"
38+
android:layout_width="match_parent"
39+
android:layout_height="wrap_content"
40+
android:layout_marginTop="@dimen/fui_field_padding_vert"
41+
android:textColor="?android:textColorTertiary"
42+
android:textIsSelectable="false"
43+
app:layout_constraintTop_toBottomOf="@+id/btn_holder" />
44+
3545
</ScrollView>
3646

3747
</android.support.constraint.ConstraintLayout>

auth/src/main/res/layout/fui_auth_method_picker_layout.xml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
android:clipChildren="false"
1010
android:clipToPadding="false">
1111

12+
1213
<ImageView
1314
android:id="@+id/logo"
1415
style="@style/FirebaseUI.AuthMethodPicker.Logo"
@@ -26,12 +27,23 @@
2627
app:layout_constraintEnd_toEndOf="parent"
2728
app:layout_constraintTop_toTopOf="parent"
2829
app:layout_constraintBottom_toBottomOf="parent"
29-
app:layout_constraintVertical_bias="0.9">
30+
app:layout_constraintVertical_bias="0.7">
3031

3132
<LinearLayout
3233
android:id="@+id/btn_holder"
33-
style="@style/FirebaseUI.AuthMethodPicker.ButtonHolder" />
34-
34+
style="@style/FirebaseUI.AuthMethodPicker.ButtonHolder"/>
3535
</ScrollView>
36-
36+
<TextView
37+
android:id="@+id/main_tos_and_pp"
38+
style="@style/FirebaseUI.Text.BodyText"
39+
android:layout_width="wrap_content"
40+
android:layout_height="wrap_content"
41+
android:layout_marginTop="@dimen/fui_field_padding_vert"
42+
android:textColor="?android:textColorTertiary"
43+
android:textIsSelectable="false"
44+
android:gravity="center"
45+
app:layout_constraintTop_toBottomOf="@id/container"/>
3746
</android.support.constraint.ConstraintLayout>
47+
48+
49+

0 commit comments

Comments
 (0)