forked from mozilla-mobile/fenix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes mozilla-mobile#2593: FxA automatic sign-in integration
- Loading branch information
Grisha Kruglov
committed
Aug 1, 2019
1 parent
a9e3a37
commit 6cf64c8
Showing
9 changed files
with
192 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...a/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingAutomaticSignInViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding | ||
|
||
import android.view.View | ||
import androidx.appcompat.content.res.AppCompatResources | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.google.android.material.snackbar.Snackbar | ||
import kotlinx.android.synthetic.main.onboarding_automatic_signin.view.turn_on_sync_button | ||
import kotlinx.android.synthetic.main.onboarding_automatic_signin.view.header_text | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import mozilla.components.service.fxa.sharing.ShareableAccount | ||
import mozilla.components.support.ktx.android.view.putCompoundDrawablesRelativeWithIntrinsicBounds | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.components.FenixSnackbar | ||
import org.mozilla.fenix.ext.components | ||
|
||
class OnboardingAutomaticSignInViewHolder(private val view: View) : RecyclerView.ViewHolder(view) { | ||
private val avatarAnonymousDrawable by lazy { | ||
AppCompatResources.getDrawable(view.context, R.drawable.ic_onboarding_avatar_anonymous) | ||
} | ||
private val firefoxAccountsDrawable by lazy { | ||
AppCompatResources.getDrawable(view.context, R.drawable.ic_onboarding_firefox_accounts) | ||
} | ||
|
||
private lateinit var shareableAccount: ShareableAccount | ||
|
||
init { | ||
view.turn_on_sync_button.setOnClickListener { | ||
it.turn_on_sync_button.text = it.context.getString( | ||
R.string.onboarding_firefox_account_signing_in | ||
) | ||
it.turn_on_sync_button.isEnabled = false | ||
|
||
CoroutineScope(Dispatchers.Main).launch { | ||
val result = view.context.components.backgroundServices.accountManager | ||
.signInWithShareableAccountAsync(shareableAccount).await() | ||
if (result) { | ||
// Success. | ||
} else { | ||
// Failed to sign-in (either network problem, or bad credentials). Allow to try again. | ||
it.turn_on_sync_button.text = it.context.getString( | ||
R.string.onboarding_firefox_account_auto_signin_confirm | ||
) | ||
it.turn_on_sync_button.isEnabled = true | ||
FenixSnackbar.make(it, Snackbar.LENGTH_SHORT).setText( | ||
it.context.getString(R.string.onboarding_firefox_account_automatic_signin_failed) | ||
).show() | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun bind(account: ShareableAccount) { | ||
shareableAccount = account | ||
updateHeaderText(account) | ||
} | ||
|
||
private fun updateHeaderText(account: ShareableAccount) { | ||
val icon = avatarAnonymousDrawable | ||
view.header_text.putCompoundDrawablesRelativeWithIntrinsicBounds(start = icon) | ||
|
||
view.header_text.text = view.context.getString( | ||
R.string.onboarding_firefox_account_auto_signin_header_2, account.email | ||
) | ||
} | ||
|
||
companion object { | ||
const val LAYOUT_ID = R.layout.onboarding_automatic_signin | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- This Source Code Form is subject to the terms of the Mozilla Public | ||
- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> | ||
<LinearLayout | ||
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" | ||
style="@style/OnboardingCardDark" | ||
android:id="@+id/onboarding_card" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical"> | ||
|
||
<androidx.appcompat.widget.AppCompatTextView | ||
android:id="@+id/header_text" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="14dp" | ||
tools:text="@string/onboarding_firefox_account_auto_signin_header_2" | ||
tools:drawableStart="@drawable/ic_onboarding_firefox_accounts" | ||
android:drawablePadding="12dp" | ||
android:textAppearance="@style/Header16TextStyle" | ||
android:textColor="@color/onboarding_card_primary_text_dark" /> | ||
|
||
<Button | ||
android:id="@+id/turn_on_sync_button" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="16dp" | ||
android:background="@drawable/button_background" | ||
android:clickable="true" | ||
android:focusable="true" | ||
android:gravity="center" | ||
android:padding="10dp" | ||
android:text="@string/onboarding_firefox_account_auto_signin_confirm" | ||
android:textAllCaps="false" | ||
android:textColor="?neutral" | ||
android:textSize="14sp" | ||
android:textStyle="bold" | ||
app:backgroundTint="@color/onboarding_card_button_background_dark" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.