Skip to content

Commit

Permalink
refactor(auth): remove RelativeLayout usage (firebase#1237)
Browse files Browse the repository at this point in the history
  • Loading branch information
thatfiredev authored Jan 13, 2021
1 parent 368ff73 commit 52007fe
Show file tree
Hide file tree
Showing 15 changed files with 480 additions and 415 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private void updateUI(FirebaseUser user) {
mBinding.mfaInfo.setText(sb.toString());
}

mBinding.emailPasswordButtons.setVisibility(View.GONE);
mBinding.emailSignInButton.setVisibility(View.GONE);
mBinding.signedInButtons.setVisibility(View.VISIBLE);

int reloadVisibility = secondFactors.isEmpty() ? View.VISIBLE : View.GONE;
Expand All @@ -193,7 +193,7 @@ private void updateUI(FirebaseUser user) {
mBinding.detail.setText(null);
mBinding.mfaInfo.setText(null);

mBinding.emailPasswordButtons.setVisibility(View.VISIBLE);
mBinding.emailSignInButton.setVisibility(View.VISIBLE);
mBinding.signedInButtons.setVisibility(View.GONE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ private void updateUI(@Nullable FirebaseUser user) {
mBinding.status.setText(getString(R.string.passwordless_status_fmt,
user.getEmail(), user.isEmailVerified()));

mBinding.passwordlessFields.setVisibility(View.GONE);
mBinding.fieldEmail.setVisibility(View.GONE);
mBinding.passwordlessButtons.setVisibility(View.GONE);
mBinding.signedInButtons.setVisibility(View.VISIBLE);
mBinding.signOutButton.setVisibility(View.VISIBLE);
} else {
mBinding.passwordlessFields.setVisibility(View.VISIBLE);
mBinding.fieldEmail.setVisibility(View.VISIBLE);
mBinding.passwordlessButtons.setVisibility(View.VISIBLE);
mBinding.signedInButtons.setVisibility(View.GONE);
mBinding.signOutButton.setVisibility(View.GONE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,13 @@ private void updateUI(int uiState, FirebaseUser user, PhoneAuthCredential cred)
if (user == null) {
// Signed out
mBinding.phoneAuthFields.setVisibility(View.VISIBLE);
mBinding.signedInButtons.setVisibility(View.GONE);
mBinding.signOutButton.setVisibility(View.GONE);

mBinding.status.setText(R.string.signed_out);
} else {
// Signed in
mBinding.phoneAuthFields.setVisibility(View.GONE);
mBinding.signedInButtons.setVisibility(View.VISIBLE);
mBinding.signOutButton.setVisibility(View.VISIBLE);

enableViews(mBinding.fieldPhoneNumber, mBinding.fieldVerificationCode);
mBinding.fieldPhoneNumber.setText(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class MultiFactorActivity : BaseActivity(), View.OnClickListener {
sb.setLength(sb.length - delimiter.length)
binding.mfaInfo.text = sb.toString()
}
findViewById<View>(R.id.emailPasswordButtons).visibility = View.GONE
findViewById<View>(R.id.emailSignInButton).visibility = View.GONE
findViewById<View>(R.id.signedInButtons).visibility = View.VISIBLE
val reloadVisibility = if (secondFactors.isEmpty()) View.VISIBLE else View.GONE
findViewById<View>(R.id.reloadButton).visibility = reloadVisibility
Expand All @@ -143,7 +143,7 @@ class MultiFactorActivity : BaseActivity(), View.OnClickListener {
binding.status.setText(R.string.multi_factor_signed_out)
binding.detail.text = null
binding.mfaInfo.text = null
findViewById<View>(R.id.emailPasswordButtons).visibility = View.VISIBLE
findViewById<View>(R.id.emailSignInButton).visibility = View.VISIBLE
findViewById<View>(R.id.signedInButtons).visibility = View.GONE
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,11 @@ class PasswordlessActivity : BaseActivity(), View.OnClickListener {
if (user != null) {
binding.status.text = getString(R.string.passwordless_status_fmt,
user.email, user.isEmailVerified)

binding.passwordlessFields.visibility = View.GONE
binding.passwordlessButtons.visibility = View.GONE
binding.signedInButtons.visibility = View.VISIBLE
binding.signOutButton.visibility = View.VISIBLE
} else {
binding.passwordlessFields.visibility = View.VISIBLE
binding.passwordlessButtons.visibility = View.VISIBLE
binding.signedInButtons.visibility = View.GONE
binding.signOutButton.visibility = View.GONE
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,13 @@ class PhoneAuthActivity : AppCompatActivity(), View.OnClickListener {
if (user == null) {
// Signed out
binding.phoneAuthFields.visibility = View.VISIBLE
binding.signedInButtons.visibility = View.GONE
binding.signOutButton.visibility = View.GONE

binding.status.setText(R.string.signed_out)
} else {
// Signed in
binding.phoneAuthFields.visibility = View.GONE
binding.signedInButtons.visibility = View.VISIBLE
binding.signOutButton.visibility = View.VISIBLE

enableViews(binding.fieldPhoneNumber, binding.fieldVerificationCode)
binding.fieldPhoneNumber.text = null
Expand Down
70 changes: 46 additions & 24 deletions auth/app/src/main/res/layout/activity_anonymous_auth.xml
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.google.firebase.quickstart.auth.java.AnonymousAuthActivity">

<ProgressBar
android:id="@+id/progressBar"
android:indeterminate="true"
android:layout_width="match_parent"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="invisible"
style="?android:attr/progressBarStyleHorizontal"/>
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/progressBar"
android:contentDescription="@string/desc_firebase_lockup"
android:src="@drawable/firebase_lockup_400" />
android:src="@drawable/firebase_lockup_400"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/progressBar" />

<TextView
android:id="@+id/titleAnonymous"
style="@style/TextAppearance.AppCompat.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/icon"
android:layout_marginBottom="8dp"
android:text="Anonymous Sign In" />
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:text="Anonymous Sign In"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/icon" />

<TextView
android:id="@+id/anonymousStatusId"
Expand All @@ -42,14 +47,18 @@
android:layout_below="@+id/titleAnonymous"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/signed_out" />
android:layout_marginTop="8dp"
android:text="@string/signed_out"
app:layout_constraintStart_toStartOf="@+id/titleAnonymous"
app:layout_constraintTop_toBottomOf="@+id/titleAnonymous" />

<TextView
android:id="@+id/anonymousStatusEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/anonymousStatusId"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="@+id/anonymousStatusId"
app:layout_constraintTop_toBottomOf="@+id/anonymousStatusId"
tools:text="Email: none" />

<Button
Expand All @@ -59,7 +68,10 @@
android:layout_width="@dimen/field_width_standard"
android:layout_height="wrap_content"
android:layout_below="@+id/anonymousStatusEmail"
android:text="@string/sign_in" />
android:text="@string/sign_in"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="@+id/anonymousStatusEmail"
app:layout_constraintTop_toBottomOf="@+id/anonymousStatusEmail" />

<Button
android:id="@+id/buttonAnonymousSignOut"
Expand All @@ -68,28 +80,35 @@
android:layout_width="@dimen/field_width_standard"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/buttonAnonymousSignIn"
android:layout_toEndOf="@+id/buttonAnonymousSignIn"
android:layout_toRightOf="@+id/buttonAnonymousSignIn"
android:enabled="false"
android:text="@string/sign_out"
android:layout_toEndOf="@+id/buttonAnonymousSignIn" />
app:layout_constraintBottom_toBottomOf="@+id/buttonAnonymousSignIn"
app:layout_constraintStart_toEndOf="@+id/buttonAnonymousSignIn"
app:layout_constraintTop_toTopOf="@+id/buttonAnonymousSignIn" />

<TextView
android:id="@+id/titleLinking"
style="@style/TextAppearance.AppCompat.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/buttonAnonymousSignIn"
android:layout_marginBottom="8dp"
android:layout_marginTop="24dp"
android:text="Account Linking" />
android:text="Account Linking"
app:layout_constraintStart_toStartOf="@+id/buttonAnonymousSignIn"
app:layout_constraintTop_toBottomOf="@+id/buttonAnonymousSignIn" />

<EditText
android:id="@+id/fieldEmail"
android:layout_width="@dimen/field_width_standard"
android:layout_height="wrap_content"
android:layout_below="@+id/titleLinking"
android:hint="@string/hint_email"
android:inputType="textEmailAddress" />
android:layout_marginTop="8dp"
android:inputType="textEmailAddress"
app:layout_constraintStart_toStartOf="@+id/titleLinking"
app:layout_constraintTop_toBottomOf="@+id/titleLinking" />

<EditText
android:id="@+id/fieldPassword"
Expand All @@ -98,7 +117,10 @@
android:layout_alignTop="@+id/fieldEmail"
android:layout_toRightOf="@+id/fieldEmail"
android:hint="@string/hint_password"
android:inputType="textPassword" />
android:inputType="textPassword"
app:layout_constraintBottom_toBottomOf="@+id/fieldEmail"
app:layout_constraintStart_toEndOf="@+id/fieldEmail"
app:layout_constraintTop_toTopOf="@+id/fieldEmail" />

<Button
android:id="@+id/buttonLinkAccount"
Expand All @@ -108,8 +130,8 @@
android:layout_height="wrap_content"
android:layout_below="@+id/fieldEmail"
android:enabled="false"
android:text="Link Account" />


android:text="Link Account"
app:layout_constraintStart_toStartOf="@+id/fieldEmail"
app:layout_constraintTop_toBottomOf="@+id/fieldEmail" />

</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit 52007fe

Please sign in to comment.