Skip to content

Commit

Permalink
Merge pull request #937 from UweTrottmann/gh-926-no-cloud-auto-sign-in
Browse files Browse the repository at this point in the history
Cloud: no auto sign-in from auth screen, add note about choosing email
  • Loading branch information
UweTrottmann authored Aug 4, 2023
2 parents a3b39f3 + a76cc5f commit 011ea7b
Show file tree
Hide file tree
Showing 44 changed files with 150 additions and 43 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Version 69
*in development*

* 🔧 Streaming search: add latest supported countries.
* 🔧 Cloud: do not automatically sign in (if e.g. signed in previously or on other devices).
* 📝 Latest user interface translations from Crowdin.

Version 68
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ import com.battlelancer.seriesguide.util.Errors
import com.battlelancer.seriesguide.util.ThemeUtils
import com.battlelancer.seriesguide.util.Utils
import com.battlelancer.seriesguide.util.safeShow
import com.firebase.ui.auth.AuthMethodPickerLayout
import com.firebase.ui.auth.AuthUI
import com.firebase.ui.auth.ErrorCodes
import com.firebase.ui.auth.IdpResponse
import com.google.android.gms.tasks.Task
import com.google.android.material.snackbar.Snackbar
import com.google.firebase.auth.AuthResult
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.FirebaseUser
import org.greenrobot.eventbus.EventBus
Expand All @@ -37,7 +36,8 @@ import timber.log.Timber

/**
* Manages signing in and out with Cloud and account removal.
* Tries to silent sign-in when started. Enables Cloud on sign-in.
* Does not auto/silent sign-in when started so users need to explicitly sign in.
* Enables Cloud on sign-in.
* If Cloud is still enabled, but the account requires validation
* enables to retry sign-in or to sign out (actually just disable Cloud).
*/
Expand Down Expand Up @@ -101,7 +101,7 @@ class CloudSetupFragment : Fragment() {

override fun onStart() {
super.onStart()
trySilentSignIn()
checkSignedIn()
}

override fun onResume() {
Expand Down Expand Up @@ -136,45 +136,13 @@ class CloudSetupFragment : Fragment() {
binding?.syncStatusCloud?.setProgress(event)
}

private fun trySilentSignIn() {
val firebaseUser = FirebaseAuth.getInstance().currentUser
if (firebaseUser != null) {
changeAccount(firebaseUser, null)
return
}

// check if the user is still signed in
val signInTask = AuthUI.getInstance()
.silentSignIn(requireContext(), hexagonTools.firebaseSignInProviders)
if (signInTask.isSuccessful) {
// If the user's cached credentials are valid, the OptionalPendingResult will be "done"
// and the GoogleSignInResult will be available instantly.
Timber.d("Got cached sign-in")
handleSilentSignInResult(signInTask)
} else {
// If the user has not previously signed in on this device or the sign-in has expired,
// this asynchronous branch will attempt to sign in the user silently. Cross-device
// single sign-on will occur in this branch.
Timber.d("Trying async sign-in")
signInTask.addOnCompleteListener { task ->
if (isAdded) {
handleSilentSignInResult(task)
}
}
}
}

/**
* @param task A completed sign-in task.
* If there is a signed in account, displays it.
*/
private fun handleSilentSignInResult(task: Task<AuthResult>) {
val account = if (task.isSuccessful) {
task.result?.user
} else {
null
}
// Note: Do not show error message if silent sign-in fails, just update UI.
changeAccount(account, null)
private fun checkSignedIn() {
val firebaseUser = FirebaseAuth.getInstance().currentUser
// If not signed in account will be null.
changeAccount(firebaseUser, null)
}

/**
Expand Down Expand Up @@ -256,12 +224,20 @@ class CloudSetupFragment : Fragment() {
}

private fun signIn() {
// Note: no need to provide a layout when just email sign-in is available
// as Firebase UI will just directly proceed without asking for the provider.
val authPickerLayout = AuthMethodPickerLayout.Builder(R.layout.auth_picker_email_google)
.setEmailButtonId(R.id.buttonAuthSignInEmail)
.setGoogleButtonId(R.id.buttonAuthSignInGoogle)
.build()

// Create and launch sign-in intent
val intent = AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(hexagonTools.firebaseSignInProviders)
.setIsSmartLockEnabled(hexagonTools.isGoogleSignInAvailable)
.setTheme(SeriesGuidePreferences.THEME)
.setAuthMethodPickerLayout(authPickerLayout)
.build()

signInWithFirebase.launch(intent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import android.text.format.DateUtils
import androidx.preference.PreferenceManager
import com.battlelancer.seriesguide.backend.CloudEndpointUtils.updateBuilder
import com.battlelancer.seriesguide.backend.settings.HexagonSettings
import com.battlelancer.seriesguide.modules.ApplicationContext
import com.battlelancer.seriesguide.jobs.NetworkJobProcessor
import com.battlelancer.seriesguide.modules.ApplicationContext
import com.battlelancer.seriesguide.util.Errors
import com.battlelancer.seriesguide.util.Errors.Companion.logAndReportHexagon
import com.battlelancer.seriesguide.util.isRetryError
Expand Down Expand Up @@ -227,7 +227,8 @@ class HexagonTools @Inject constructor(
// still signed in
httpRequestInitializer.firebaseUser = account
} else {
// try to silently sign in
// Try to silently sign in. This is fine as Cloud was enabled by the user
// and they reasonably expect to stay signed in.
val signInTask = AuthUI.getInstance().silentSignIn(context, firebaseSignInProviders)
try {
val authResult = Tasks.await(signInTask)
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_email_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M22,6c0,-1.1 -0.9,-2 -2,-2L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6zM20,6l-8,5 -8,-5h16zM20,18L4,18L4,8l8,5 8,-5v10z" />
</vector>
80 changes: 80 additions & 0 deletions app/src/main/res/layout/auth_picker_email_google.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="32dp">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/imageViewAuthUser"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="32dp"
android:contentDescription="@null"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_account_circle_black_24dp" />

<TextView
android:id="@+id/textViewAuthTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:gravity="center"
android:text="@string/hexagon"
android:textAppearance="@style/TextAppearance.SeriesGuide.Body1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageViewAuthUser" />

<TextView
android:id="@+id/textViewAuthInfo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
android:gravity="center_horizontal"
android:maxWidth="@dimen/max_width_text_size_body"
android:text="@string/hexagon_signin_choose"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewAuthTitle" />

<Button
android:id="@+id/buttonAuthSignInEmail"
style="@style/Widget.SeriesGuide.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/fui_sign_in_with_email"
app:icon="@drawable/ic_email_black_24dp"
app:iconGravity="start"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewAuthInfo" />

<Button
android:id="@+id/buttonAuthSignInGoogle"
style="@style/Widget.SeriesGuide.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/fui_sign_in_with_google"
app:icon="@drawable/ic_account_circle_black_24dp"
app:iconGravity="start"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/buttonAuthSignInEmail" />

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.core.widget.NestedScrollView>
1 change: 1 addition & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@
<string name="hexagon_signed_out">تسجيل الخروج من سحابة SeriesGuide.</string>
<string name="hexagon_signin_fail_format">خطأ في تسجيل الدخول (%s)</string>
<string name="hexagon_signin_google_only">يتطلب عنوان البريد الإلكتروني تسجيل دخول Google</string>
<string name="hexagon_signin_choose">Choose email to sign in if you are using SeriesGuide on other devices that do not support Google sign-in.</string>
<!-- trakt -->
<string name="trakt_submitqueued">جارٍ الإرسال إلى Trakt.</string>
<string name="checkin_success_trakt">تم فحص %s على Trakt.</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-bg/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
<string name="hexagon_signed_out">Излизане от облака SeriesGuide.</string>
<string name="hexagon_signin_fail_format">Грешка при влизане с (%s)</string>
<string name="hexagon_signin_google_only">Email адресът изисква Google Sign-In</string>
<string name="hexagon_signin_choose">Choose email to sign in if you are using SeriesGuide on other devices that do not support Google sign-in.</string>
<!-- trakt -->
<string name="trakt_submitqueued">Подаване към trakt.</string>
<string name="checkin_success_trakt">Отметнато %s в trakt.</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ca/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
<string name="hexagon_signed_out">Has desconnectat de SeriesGuide Cloud.</string>
<string name="hexagon_signin_fail_format">Error amb l\'inici de sessió (%s)</string>
<string name="hexagon_signin_google_only">L\'adreça de correu electrònic requereix iniciar sessió amb Google</string>
<string name="hexagon_signin_choose">Choose email to sign in if you are using SeriesGuide on other devices that do not support Google sign-in.</string>
<!-- trakt -->
<string name="trakt_submitqueued">S\'està enviant a trakt.</string>
<string name="checkin_success_trakt">S\'ha enregistrat a %s de trakt.</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@
<string name="hexagon_signed_out">Odhlášeno z SeriesGuide Cloudu.</string>
<string name="hexagon_signin_fail_format">Chyba při přihlášení (%s)</string>
<string name="hexagon_signin_google_only">E-mailová adresa vyžaduje přihlášení Google</string>
<string name="hexagon_signin_choose">Choose email to sign in if you are using SeriesGuide on other devices that do not support Google sign-in.</string>
<!-- trakt -->
<string name="trakt_submitqueued">Odesílání na Trakt.</string>
<string name="checkin_success_trakt">Ohlášen u %s na traktu.</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-cy/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@
<string name="hexagon_signed_out">Llofnodwyd allan o SeriesGuide Cloud</string>
<string name="hexagon_signin_fail_format">Gwall wrth fewngofnodi (%s)</string>
<string name="hexagon_signin_google_only">Mae cyfeiriad Google yn gofyn am Google Sign-In</string>
<string name="hexagon_signin_choose">Choose email to sign in if you are using SeriesGuide on other devices that do not support Google sign-in.</string>
<!-- trakt -->
<string name="trakt_submitqueued">Anfon at Trakt.</string>
<string name="checkin_success_trakt">Wedi\'i wirio i mewn i %s ar Trakt</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-da/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
<string name="hexagon_signed_out">Logget ud af SeriesGuide Cloud.</string>
<string name="hexagon_signin_fail_format">Fejl i login (%s)</string>
<string name="hexagon_signin_google_only">E-mail-adresse kræver Google Sign-In</string>
<string name="hexagon_signin_choose">Choose email to sign in if you are using SeriesGuide on other devices that do not support Google sign-in.</string>
<!-- trakt -->
<string name="trakt_submitqueued">Sender til trakt.</string>
<string name="checkin_success_trakt">%s tjekket ind på trakt.</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
<string name="hexagon_signed_out">Von SeriesGuide Cloud abgemeldet</string>
<string name="hexagon_signin_fail_format">Fehler beim Anmelden (%s)</string>
<string name="hexagon_signin_google_only">E-Mail-Adresse erfordert Anmeldung mit Google</string>
<string name="hexagon_signin_choose">Wählen Sie E-Mail zum Anmelden wenn Sie SeriesGuide auf anderen Geräten verwenden die keine Anmeldung mit Google unterstützen.</string>
<!-- trakt -->
<string name="trakt_submitqueued">Sende an Trakt.</string>
<string name="checkin_success_trakt">Auf Trakt in %s eingecheckt</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
<string name="hexagon_signed_out">Αποσυνδεθείτε από το SeriesGuide Cloud.</string>
<string name="hexagon_signin_fail_format">Σφάλμα με την είσοδο (%s)</string>
<string name="hexagon_signin_google_only">Η διεύθυνση ηλεκτρονικού ταχυδρομείου απαιτεί είσοδο στο Google</string>
<string name="hexagon_signin_choose">Choose email to sign in if you are using SeriesGuide on other devices that do not support Google sign-in.</string>
<!-- trakt -->
<string name="trakt_submitqueued">Υποβολή στο trakt.</string>
<string name="checkin_success_trakt">Ελέγχεται σε %s στο trakt.</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-eo/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
<string name="hexagon_signed_out">Elsalutis el SeriesGuide Cloud</string>
<string name="hexagon_signin_fail_format">Error with sign-in (%s)</string>
<string name="hexagon_signin_google_only">Email address requires Google Sign-In</string>
<string name="hexagon_signin_choose">Choose email to sign in if you are using SeriesGuide on other devices that do not support Google sign-in.</string>
<!-- trakt -->
<string name="trakt_submitqueued">Sendado al Trakt.</string>
<string name="checkin_success_trakt">Markis je %s je Trakt</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ Asegúrate de quitarla también en tus otros dispositivos conectados.</string>
<string name="hexagon_signed_out">Desconectado de SeriesGuide Cloud.</string>
<string name="hexagon_signin_fail_format">Error al iniciar sesión (%s)</string>
<string name="hexagon_signin_google_only">La dirección de correo electrónico requiere inicio de sesión de Google</string>
<string name="hexagon_signin_choose">Choose email to sign in if you are using SeriesGuide on other devices that do not support Google sign-in.</string>
<!-- trakt -->
<string name="trakt_submitqueued">Enviando a trakt.</string>
<string name="checkin_success_trakt">Registrado en %s en trakt.</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
<string name="hexagon_signed_out">از فضای ابری SeriesGuide خارج شدید.</string>
<string name="hexagon_signin_fail_format">خطا در ورود (%s)</string>
<string name="hexagon_signin_google_only">نشانی رایانامه نیازمند ورود گوگلی است</string>
<string name="hexagon_signin_choose">Choose email to sign in if you are using SeriesGuide on other devices that do not support Google sign-in.</string>
<!-- trakt -->
<string name="trakt_submitqueued">ارسال به trakt.</string>
<string name="checkin_success_trakt">%s روی trakt ثبت شد.</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
<string name="hexagon_signed_out">Kirjauduttu ulos SeriesGuide Cloudista.</string>
<string name="hexagon_signin_fail_format">Virhe sisäänkirjautumisessa (%s)</string>
<string name="hexagon_signin_google_only">Sähköpostiosoite vaatii Googlen sisäänkirjautumisen</string>
<string name="hexagon_signin_choose">Choose email to sign in if you are using SeriesGuide on other devices that do not support Google sign-in.</string>
<!-- trakt -->
<string name="trakt_submitqueued">Lähetetään Traktiin.</string>
<string name="checkin_success_trakt">Kuitattu kohteeseen %s Traktissa</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
<string name="hexagon_signed_out">Déconnecté du cloud SeriesGuide.</string>
<string name="hexagon_signin_fail_format">Erreur lors de la connexion (%s)</string>
<string name="hexagon_signin_google_only">L\'adresse e-mail nécessite une connexion à Google</string>
<string name="hexagon_signin_choose">Choose email to sign in if you are using SeriesGuide on other devices that do not support Google sign-in.</string>
<!-- trakt -->
<string name="trakt_submitqueued">Envoi vers trakt.</string>
<string name="checkin_success_trakt">Check-in de %s sur trakt effectué.</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-gl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
<string name="hexagon_signed_out">Desconectado de SeriesGuide Cloud</string>
<string name="hexagon_signin_fail_format">Error with sign-in (%s)</string>
<string name="hexagon_signin_google_only">Email address requires Google Sign-In</string>
<string name="hexagon_signin_choose">Choose email to sign in if you are using SeriesGuide on other devices that do not support Google sign-in.</string>
<!-- trakt -->
<string name="trakt_submitqueued">Enviando a trakt.</string>
<string name="checkin_success_trakt">Rexistrado en %s en trakt</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-hr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@
<string name="hexagon_signed_out">Odjavljeni ste sa SeriesGuide oblaka.</string>
<string name="hexagon_signin_fail_format">Error with sign-in (%s)</string>
<string name="hexagon_signin_google_only">Email address requires Google Sign-In</string>
<string name="hexagon_signin_choose">Choose email to sign in if you are using SeriesGuide on other devices that do not support Google sign-in.</string>
<!-- trakt -->
<string name="trakt_submitqueued">Poslano na trakt.</string>
<string name="checkin_success_trakt">Prijavljen u %s na traktu.</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
<string name="hexagon_signed_out">Kijelentkezett a SeriesGuide felhő tárhelyről.</string>
<string name="hexagon_signin_fail_format">Hiba történt a Bejelentkezéssel (%s)</string>
<string name="hexagon_signin_google_only">E-mail címhez Google bejelentkezés szükséges</string>
<string name="hexagon_signin_choose">Choose email to sign in if you are using SeriesGuide on other devices that do not support Google sign-in.</string>
<!-- trakt -->
<string name="trakt_submitqueued">Elküldés a traktnak.</string>
<string name="checkin_success_trakt">Bejelentkezve trakttal ide: %s.</string>
Expand Down
Loading

0 comments on commit 011ea7b

Please sign in to comment.