1
0
Fork 0

For #2717 - Hides onboarding card when signed into a firefox account

master
Jeff Boek 2019-05-22 21:40:10 -07:00
parent ab590df18b
commit bf28462c47
4 changed files with 30 additions and 10 deletions

View File

@ -26,6 +26,9 @@ import kotlinx.coroutines.runBlocking
import mozilla.components.browser.menu.BrowserMenu
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile
import org.jetbrains.anko.constraint.layout.ConstraintSetBuilder.Side.BOTTOM
import org.jetbrains.anko.constraint.layout.ConstraintSetBuilder.Side.END
import org.jetbrains.anko.constraint.layout.ConstraintSetBuilder.Side.START
@ -67,7 +70,7 @@ import kotlin.coroutines.CoroutineContext
import kotlin.math.roundToInt
@SuppressWarnings("TooManyFunctions", "LargeClass")
class HomeFragment : Fragment(), CoroutineScope {
class HomeFragment : Fragment(), CoroutineScope, AccountObserver {
private val bus = ActionBusFactory.get(this)
private var sessionObserver: SessionManager.Observer? = null
private var tabCollectionObserver: Observer<List<TabCollection>>? = null
@ -209,6 +212,8 @@ class HomeFragment : Fragment(), CoroutineScope {
homeLayout?.progress =
if (homeViewModel?.motionLayoutProgress ?: 0F > MOTION_LAYOUT_PROGRESS_ROUND_POINT) 1.0f else 0f
(activity as AppCompatActivity).supportActionBar?.hide()
requireComponents.backgroundServices.accountManager.register(this, owner = this)
}
@SuppressWarnings("ComplexMethod")
@ -613,6 +618,11 @@ class HomeFragment : Fragment(), CoroutineScope {
)
}
private fun emitAccountChanges() {
val mode = currentMode()
getManagedEmitter<SessionControlChange>().onNext(SessionControlChange.ModeChange(mode))
}
private fun showCollectionCreationFragment(
selectedTabId: String? = null,
selectedTabCollection: TabCollection? = null,
@ -639,7 +649,6 @@ class HomeFragment : Fragment(), CoroutineScope {
}
private fun currentMode(): Mode = if (!onboarding.userHasBeenOnboarded()) {
// TODO monitor account state changes somewhere in this class via AccountObserver + `accountManager.register()`.
val account = requireComponents.backgroundServices.accountManager.authenticatedAccount()
if (account == null) {
Mode.Onboarding(OnboardingState.SignedOut)
@ -652,6 +661,11 @@ class HomeFragment : Fragment(), CoroutineScope {
Mode.Normal
}
override fun onAuthenticated(account: OAuthAccount) { emitAccountChanges() }
override fun onError(error: Exception) { emitAccountChanges() }
override fun onLoggedOut() { emitAccountChanges() }
override fun onProfileUpdated(profile: Profile) { emitAccountChanges() }
companion object {
private const val toolbarPaddingDp = 12f
private const val MOTION_LAYOUT_PROGRESS_ROUND_POINT = 0.25f

View File

@ -69,11 +69,11 @@ fun List<Tab>.toSessionBundle(context: Context): MutableList<Session> {
* Describes various onboarding states.
*/
enum class OnboardingState {
// signed out, no account carried over from Fennec.
// Signed out, no account carried over from Fennec.
SignedOut,
// auto-signed in, via a Fennec account.
// Auto-signed in, via a Fennec account.
AutoSignedIn,
// manually signed in while in onboarding.
// Manually signed in while in onboarding.
ManuallySignedIn
}

View File

@ -64,7 +64,6 @@ private fun privateModeAdapterItems(tabs: List<Tab>): List<AdapterItem> {
private fun onboardingAdapterItems(onboardingState: OnboardingState): List<AdapterItem> {
val items: MutableList<AdapterItem> = mutableListOf(AdapterItem.OnboardingHeader)
// TODO customize the UI based on different account states.
// Customize FxA items based on where we are with the account state:
items.addAll(when (onboardingState) {
OnboardingState.SignedOut -> {

View File

@ -20,6 +20,17 @@ class OnboardingFirefoxAccountViewHolder(private val view: View) : RecyclerView.
}
fun bind(autoSignedIn: Boolean) {
updateHeaderText(autoSignedIn)
updateButtonVisibility(autoSignedIn)
}
private fun updateButtonVisibility(autoSignedIn: Boolean) {
view.turn_on_sync_button.visibility = if (autoSignedIn) View.GONE else View.VISIBLE
view.stay_signed_in_button.visibility = if (autoSignedIn) View.VISIBLE else View.GONE
view.sign_out_button.visibility = if (autoSignedIn) View.VISIBLE else View.GONE
}
private fun updateHeaderText(autoSignedIn: Boolean) {
val appName = view.context.getString(R.string.app_name)
val icon =
@ -30,10 +41,6 @@ class OnboardingFirefoxAccountViewHolder(private val view: View) : RecyclerView.
view.header_text.text =
if (!autoSignedIn) view.context.getString(R.string.onboarding_firefox_account_auto_signin_header)
else view.context.getString(R.string.onboarding_firefox_account_header, appName)
view.turn_on_sync_button.visibility = if (autoSignedIn) View.GONE else View.VISIBLE
view.stay_signed_in_button.visibility = if (autoSignedIn) View.VISIBLE else View.GONE
view.sign_out_button.visibility = if (autoSignedIn) View.VISIBLE else View.GONE
}
companion object {