Skip to content

Commit

Permalink
Transition to Material Components (#1904)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonas Knutsson <jonas.knutsson@thirdbase.se>
  • Loading branch information
samtstern and joknu1 authored Jul 9, 2021
1 parent f0e61e6 commit 015f262
Show file tree
Hide file tree
Showing 156 changed files with 647 additions and 1,051 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ android {
}

dependencies {
implementation(Config.Libs.Androidx.design)
implementation(Config.Libs.Androidx.materialDesign)
implementation(Config.Libs.Androidx.multidex)

implementation(project(":auth"))
Expand Down
31 changes: 6 additions & 25 deletions app/src/main/java/com/firebase/uidemo/auth/AuthUiActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
Expand All @@ -27,8 +26,8 @@
import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.auth.AuthUI.IdpConfig;
import com.firebase.ui.auth.ErrorCodes;
import com.firebase.ui.auth.IdpResponse;
import com.firebase.ui.auth.FirebaseAuthUIActivityResultContract;
import com.firebase.ui.auth.IdpResponse;
import com.firebase.ui.auth.data.model.FirebaseAuthUIAuthenticationResult;
import com.firebase.ui.auth.util.ExtraConstants;
import com.firebase.uidemo.R;
Expand Down Expand Up @@ -84,6 +83,9 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
mBinding = AuthUiLayoutBinding.inflate(getLayoutInflater());
setContentView(mBinding.getRoot());

// Workaround for vector drawables on API 19
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

if (ConfigurationUtils.isGoogleMisconfigured(this)) {
mBinding.googleProvider.setChecked(false);
mBinding.googleProvider.setEnabled(false);
Expand Down Expand Up @@ -146,16 +148,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
showSnackbar(R.string.configuration_required);
}

if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES) {
mBinding.darkTheme.setChecked(true);
}

catchEmailLinkSignIn();

mBinding.defaultTheme.setOnClickListener(toggleDarkThemeListener);
mBinding.greenTheme.setOnClickListener(toggleDarkThemeListener);
mBinding.purpleTheme.setOnClickListener(toggleDarkThemeListener);
mBinding.darkTheme.setOnClickListener(toggleDarkThemeListener);
}

public void catchEmailLinkSignIn() {
Expand Down Expand Up @@ -295,26 +288,14 @@ private void startSignedInActivity(@Nullable IdpResponse response) {
startActivity(SignedInActivity.createIntent(this, response));
}

private View.OnClickListener toggleDarkThemeListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
int mode = mBinding.darkTheme.isChecked() ?
AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
if (Build.VERSION.SDK_INT >= 17) {
AppCompatDelegate.setDefaultNightMode(mode);
getDelegate().setLocalNightMode(mode);
}
}
};

@StyleRes
private int getSelectedTheme() {
if (mBinding.greenTheme.isChecked()) {
return R.style.GreenTheme;
}

if (mBinding.purpleTheme.isChecked()) {
return R.style.PurpleTheme;
if (mBinding.appTheme.isChecked()) {
return R.style.AppTheme;
}

return AuthUI.getDefaultTheme();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.firebase.uidemo.storage.GlideApp;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
import com.google.firebase.auth.EmailAuthProvider;
import com.google.firebase.auth.FacebookAuthProvider;
Expand All @@ -48,7 +49,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import static com.firebase.ui.auth.AuthUI.EMAIL_LINK_PROVIDER;
Expand Down Expand Up @@ -102,7 +102,7 @@ public void signOut() {
}

public void deleteAccountClicked() {
new AlertDialog.Builder(this)
new MaterialAlertDialogBuilder(this)
.setMessage("Are you sure you want to delete this account?")
.setPositiveButton("Yes, nuke it!", (dialogInterface, i) -> deleteAccount())
.setNegativeButton("No", null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
in button. However this button is NOT considered part of the public API and you should not
use it in your own app.
-->
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton
<com.google.android.material.button.MaterialButton
android:id="@+id/custom_google_signin_button"
style="@style/FirebaseUI.Button.AccountChooser.GoogleButton"
android:layout_width="wrap_content"
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/layout/activity_anonymous_upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
android:orientation="vertical"
tools:context=".auth.AuthUiActivity">

<androidx.appcompat.widget.AppCompatTextView
style="@style/Base.TextAppearance.AppCompat.Headline"
<com.google.android.material.textview.MaterialTextView
style="@style/TextAppearance.MaterialComponents.Headline5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
Expand All @@ -31,15 +31,15 @@

<Button
android:id="@+id/anon_sign_in"
style="@style/Widget.AppCompat.Button.Colored"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/anonymous_sign_in" />

<Button
android:id="@+id/begin_flow"
style="@style/Widget.AppCompat.Button.Colored"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
Expand All @@ -48,7 +48,7 @@

<Button
android:id="@+id/resolve_merge"
style="@style/Widget.AppCompat.Button.Colored"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
Expand All @@ -57,7 +57,7 @@

<Button
android:id="@+id/sign_out"
style="@style/Widget.AppCompat.Button.Colored"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_chat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

<Button
android:id="@+id/sendButton"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_image.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
tools:context="com.firebase.uidemo.storage.ImageActivity">

<TextView
style="@style/TextAppearance.AppCompat.Medium"
style="@style/TextAppearance.MaterialComponents.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/upload" />
Expand All @@ -24,7 +24,7 @@
android:text="@string/choose_image" />

<TextView
style="@style/TextAppearance.AppCompat.Medium"
style="@style/TextAppearance.MaterialComponents.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
in button. However this button is NOT considered part of the public API and you should not
use it in your own app.
-->
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton
<com.google.android.material.button.MaterialButton
android:id="@+id/custom_google_signin_button"
style="@style/FirebaseUI.Button.AccountChooser.GoogleButton"
android:layout_width="wrap_content"
Expand Down
40 changes: 17 additions & 23 deletions app/src/main/res/layout/auth_ui_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
android:orientation="vertical"
android:paddingBottom="32dp">

<androidx.appcompat.widget.AppCompatTextView
style="@style/Base.TextAppearance.AppCompat.Headline"
<com.google.android.material.textview.MaterialTextView
style="@style/TextAppearance.MaterialComponents.Headline5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
Expand All @@ -31,7 +31,7 @@

<Button
android:id="@+id/sign_in"
style="@style/Widget.AppCompat.Button.Colored"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
Expand All @@ -40,15 +40,15 @@

<Button
android:id="@+id/sign_in_silent"
style="@style/Widget.AppCompat.Button.Colored"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="16dp"
android:text="@string/sign_in_silent" />

<TextView
style="@style/Base.TextAppearance.AppCompat.Subhead"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
Expand Down Expand Up @@ -132,7 +132,7 @@
android:text="@string/providers_github" />

<TextView
style="@style/Base.TextAppearance.AppCompat.Subhead"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
Expand Down Expand Up @@ -160,7 +160,7 @@
</RadioGroup>

<TextView
style="@style/Base.TextAppearance.AppCompat.Subhead"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
Expand All @@ -173,33 +173,27 @@
android:orientation="vertical">

<RadioButton
android:id="@+id/default_theme"
android:id="@+id/app_theme"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/theme_default" />
android:text="@string/theme_app" />

<RadioButton
android:id="@+id/purple_theme"
android:id="@+id/default_theme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/theme_purple" />
android:text="@string/theme_default" />

<RadioButton
android:id="@+id/green_theme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/theme_green" />

<RadioButton
android:id="@+id/dark_theme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/theme_dark" />
</RadioGroup>

<TextView
style="@style/Base.TextAppearance.AppCompat.Subhead"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
Expand Down Expand Up @@ -233,7 +227,7 @@
</RadioGroup>

<TextView
style="@style/Base.TextAppearance.AppCompat.Subhead"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
Expand Down Expand Up @@ -267,7 +261,7 @@

<TextView
android:id="@+id/google_scopes_header"
style="@style/Base.TextAppearance.AppCompat.Subhead"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
Expand All @@ -290,7 +284,7 @@

<TextView
android:id="@+id/facebook_permissions_header"
style="@style/Base.TextAppearance.AppCompat.Subhead"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
Expand All @@ -312,7 +306,7 @@
android:text="@string/facebook_permission_photos" />

<TextView
style="@style/Base.TextAppearance.AppCompat.Subhead"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/message.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<TextView
android:id="@+id/message_text"
style="@style/TextAppearance.AppCompat.Medium"
style="@style/TextAppearance.MaterialComponents.Subtitle2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
Expand All @@ -39,7 +39,7 @@

<TextView
android:id="@+id/name_text"
style="@style/TextAppearance.AppCompat.Small"
style="@style/TextAppearance.MaterialComponents.Subtitle2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/layout/signed_in_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
android:layout_marginBottom="16dp"
android:orientation="vertical">

<androidx.appcompat.widget.AppCompatTextView
style="@style/Base.TextAppearance.AppCompat.Headline"
<com.google.android.material.textview.MaterialTextView
style="@style/TextAppearance.MaterialComponents.Headline5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
Expand All @@ -34,7 +34,7 @@

<Button
android:id="@+id/sign_out"
style="@style/Widget.AppCompat.Button.Colored"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
Expand All @@ -54,7 +54,7 @@
</LinearLayout>

<TextView
style="@style/Base.TextAppearance.AppCompat.Subhead"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/user_profile_header" />
Expand Down Expand Up @@ -120,7 +120,7 @@
android:orientation="vertical">

<TextView
style="@style/Base.TextAppearance.AppCompat.Subhead"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/idp_token" />
Expand All @@ -140,7 +140,7 @@
android:orientation="vertical">

<TextView
style="@style/Base.TextAppearance.AppCompat.Subhead"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/idp_secret" />
Expand Down
Loading

0 comments on commit 015f262

Please sign in to comment.