-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Added main ToS/PP #1300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added main ToS/PP #1300
Changes from 1 commit
dac52e6
f5b0b75
420da68
5793bd8
670b363
21df8b3
3cedd37
302c94c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,16 +13,21 @@ | |
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.EditText; | ||
import android.widget.TextView; | ||
|
||
import com.firebase.ui.auth.AuthUI; | ||
import com.firebase.ui.auth.R; | ||
import com.firebase.ui.auth.data.model.User; | ||
import com.firebase.ui.auth.ui.FragmentBase; | ||
import com.firebase.ui.auth.util.ExtraConstants; | ||
import com.firebase.ui.auth.util.ui.ImeHelper; | ||
import com.firebase.ui.auth.util.ui.PreambleHandler; | ||
import com.firebase.ui.auth.util.ui.fieldvalidators.EmailFieldValidator; | ||
import com.firebase.ui.auth.viewmodel.ResourceObserver; | ||
import com.google.firebase.auth.EmailAuthProvider; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Fragment that shows a form with an email field and checks for existing accounts with that email. | ||
* <p> | ||
|
@@ -96,6 +101,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat | |
} | ||
|
||
view.findViewById(R.id.button_next).setOnClickListener(this); | ||
setUpTermsOfService(view); | ||
} | ||
|
||
@Override | ||
|
@@ -175,4 +181,14 @@ private void validateAndProceed() { | |
mHandler.fetchProvider(email); | ||
} | ||
} | ||
|
||
private void setUpTermsOfService(View view) { | ||
List<AuthUI.IdpConfig> providers = getFlowParams().providerInfo; | ||
if (providers.size() == 1) { | ||
|
||
PreambleHandler.setup(getContext(), | ||
getFlowParams(), | ||
R.string.fui_tos_and_pp, | ||
view.<TextView>findViewById(R.id.email_tos_and_pp_text)); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.support.annotation.RestrictTo; | ||
import android.support.annotation.StringRes; | ||
import android.support.design.widget.TextInputLayout; | ||
import android.text.TextUtils; | ||
import android.view.LayoutInflater; | ||
|
@@ -140,11 +141,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat | |
// Only show the name field if required | ||
nameInput.setVisibility(requireName ? View.VISIBLE : View.GONE); | ||
|
||
PreambleHandler.setup( | ||
getContext(), | ||
getFlowParams(), | ||
R.string.fui_button_text_save, | ||
view.<TextView>findViewById(R.id.create_account_text)); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && getFlowParams().enableCredentials) { | ||
mEmailEditText.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO); | ||
} | ||
|
@@ -173,6 +169,18 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat | |
} | ||
} | ||
|
||
private @StringRes int getTermsStringResource() { | ||
|
||
boolean hasTos = !TextUtils.isEmpty(getFlowParams().termsOfServiceUrl); | ||
boolean hasPp = !TextUtils.isEmpty(getFlowParams().privacyPolicyUrl); | ||
if(hasTos && hasPp) { | ||
return R.string.fui_create_account_preamble_tos_and_pp; | ||
} else if(hasTos) { | ||
return R.string.fui_create_account_preamble_tos_only; | ||
} else { | ||
return R.string.fui_create_account_preamble_pp_only; | ||
} | ||
} | ||
|
||
private void safeRequestFocus(final View v) { | ||
v.post(new Runnable() { | ||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ public class PreambleHandler { | |
private static final String BTN_TARGET = "%BTN%"; | ||
private static final String TOS_TARGET = "%TOS%"; | ||
private static final String PP_TARGET = "%PP%"; | ||
private static final int NO_BUTTON = -1; | ||
|
||
private final Context mContext; | ||
private final FlowParameters mFlowParameters; | ||
|
@@ -41,12 +42,30 @@ private PreambleHandler(Context context, FlowParameters parameters, @StringRes i | |
R.color.fui_linkColor)); | ||
} | ||
|
||
private PreambleHandler(Context context, FlowParameters parameters) { | ||
mContext = context; | ||
mFlowParameters = parameters; | ||
mButtonText = NO_BUTTON; | ||
mLinkSpan = new ForegroundColorSpan(ContextCompat.getColor(mContext, | ||
R.color.fui_linkColor)); | ||
} | ||
|
||
public static void setup(Context context, | ||
FlowParameters parameters, | ||
@StringRes int buttonText, | ||
@StringRes int textViewText, | ||
TextView textView) { | ||
PreambleHandler handler = new PreambleHandler(context, parameters, buttonText); | ||
handler.setupCreateAccountPreamble(); | ||
handler.setupPreamble(textViewText); | ||
handler.setPreamble(textView); | ||
} | ||
|
||
public static void setup(Context context, | ||
FlowParameters parameters, | ||
@StringRes int textViewText, | ||
TextView textView) { | ||
PreambleHandler handler = new PreambleHandler(context, parameters); | ||
handler.setupPreamble(textViewText); | ||
handler.setPreamble(textView); | ||
} | ||
|
||
|
@@ -55,8 +74,9 @@ private void setPreamble(TextView textView) { | |
textView.setText(mBuilder); | ||
} | ||
|
||
private void setupCreateAccountPreamble() { | ||
String withTargets = getPreambleStringWithTargets(); | ||
private void setupPreamble(@StringRes int textViewText) { | ||
|
||
String withTargets = (mButtonText == NO_BUTTON) ? getPreambleStringWithTargetsNoButton( | ||
textViewText) : getPreambleStringWithTargets(textViewText); | ||
if (withTargets == null) { | ||
return; | ||
} | ||
|
@@ -92,24 +112,40 @@ private void replaceUrlTarget(String target, @StringRes int replacementRes, Stri | |
} | ||
|
||
@Nullable | ||
private String getPreambleStringWithTargets() { | ||
private String getPreambleStringWithTargets(@StringRes int textViewText) { | ||
boolean hasTos = !TextUtils.isEmpty(mFlowParameters.termsOfServiceUrl); | ||
boolean hasPp = !TextUtils.isEmpty(mFlowParameters.privacyPolicyUrl); | ||
if (hasTos && hasPp) { | ||
return mContext.getString(textViewText, | ||
BTN_TARGET, TOS_TARGET, PP_TARGET); | ||
} else if (hasTos) { | ||
return mContext.getString(textViewText, | ||
BTN_TARGET, TOS_TARGET); | ||
} else if (hasPp) { | ||
return mContext.getString(textViewText, | ||
BTN_TARGET, PP_TARGET); | ||
} | ||
return null; | ||
} | ||
|
||
@Nullable | ||
private String getPreambleStringWithTargetsNoButton(@StringRes int textViewText) { | ||
boolean hasTos = !TextUtils.isEmpty(mFlowParameters.termsOfServiceUrl); | ||
boolean hasPp = !TextUtils.isEmpty(mFlowParameters.privacyPolicyUrl); | ||
if (hasTos && hasPp) { | ||
return mContext.getString(R.string.fui_create_account_preamble_tos_and_pp, | ||
BTN_TARGET, TOS_TARGET, PP_TARGET); | ||
return mContext.getString(textViewText, | ||
TOS_TARGET, PP_TARGET); | ||
} else if (hasTos) { | ||
return mContext.getString(R.string.fui_create_account_preamble_tos_only, | ||
BTN_TARGET, TOS_TARGET); | ||
return mContext.getString(textViewText, | ||
TOS_TARGET); | ||
} else if (hasPp) { | ||
return mContext.getString(R.string.fui_create_account_preamble_pp_only, | ||
BTN_TARGET, PP_TARGET); | ||
} else { | ||
return null; | ||
return mContext.getString(textViewText, | ||
PP_TARGET); | ||
} | ||
return null; | ||
} | ||
|
||
|
||
private class CustomTabsSpan extends ClickableSpan { | ||
private final String mUrl; | ||
private final CustomTabsIntent mCustomTabsIntent; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,16 @@ | |
android:id="@+id/btn_holder" | ||
style="@style/FirebaseUI.AuthMethodPicker.ButtonHolder" /> | ||
|
||
<TextView | ||
|
||
android:id="@+id/main_tos_and_pp" | ||
style="@style/FirebaseUI.Text.BodyText" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="@dimen/fui_field_padding_vert" | ||
android:textColor="?android:textColorTertiary" | ||
android:textIsSelectable="false" | ||
app:layout_constraintTop_toBottomOf="@+id/btn_holder" /> | ||
|
||
</ScrollView> | ||
|
||
</android.support.constraint.ConstraintLayout> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
android:clipChildren="false" | ||
android:clipToPadding="false"> | ||
|
||
|
||
<ImageView | ||
android:id="@+id/logo" | ||
style="@style/FirebaseUI.AuthMethodPicker.Logo" | ||
|
@@ -26,12 +27,23 @@ | |
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintVertical_bias="0.9"> | ||
app:layout_constraintVertical_bias="0.7"> | ||
|
||
<LinearLayout | ||
android:id="@+id/btn_holder" | ||
style="@style/FirebaseUI.AuthMethodPicker.ButtonHolder" /> | ||
|
||
style="@style/FirebaseUI.AuthMethodPicker.ButtonHolder"/> | ||
</ScrollView> | ||
|
||
<TextView | ||
android:id="@+id/main_tos_and_pp" | ||
style="@style/FirebaseUI.Text.BodyText" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="@dimen/fui_field_padding_vert" | ||
android:textColor="?android:textColorTertiary" | ||
|
||
android:textIsSelectable="false" | ||
android:gravity="center" | ||
app:layout_constraintTop_toBottomOf="@id/container"/> | ||
|
||
</android.support.constraint.ConstraintLayout> | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be clearer if it accepted a
TextView
argument and theTextView
was located byonViewCreated