mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-05 21:20:45 +00:00
Closes #2713: Weave in "onboarding state" and split adapter items accordingly
we're ensuring that it has been initialized. I wonder if we could just make background services load eagerly (they're lazy init now), instead.
This commit is contained in:
parent
763c8be815
commit
f4f35bdde0
@ -55,6 +55,7 @@ import org.mozilla.fenix.home.sessioncontrol.SessionControlViewModel
|
||||
import org.mozilla.fenix.home.sessioncontrol.Tab
|
||||
import org.mozilla.fenix.home.sessioncontrol.TabAction
|
||||
import org.mozilla.fenix.home.sessioncontrol.TabCollection
|
||||
import org.mozilla.fenix.home.sessioncontrol.OnboardingState
|
||||
import org.mozilla.fenix.lib.Do
|
||||
import org.mozilla.fenix.mvi.ActionBusFactory
|
||||
import org.mozilla.fenix.mvi.getAutoDisposeObservable
|
||||
@ -638,7 +639,13 @@ class HomeFragment : Fragment(), CoroutineScope {
|
||||
}
|
||||
|
||||
private fun currentMode(): Mode = if (!onboarding.userHasBeenOnboarded()) {
|
||||
Mode.Onboarding
|
||||
// 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)
|
||||
} else {
|
||||
Mode.Onboarding(OnboardingState.ManuallySignedIn)
|
||||
}
|
||||
} else if ((activity as HomeActivity).browsingModeManager.isPrivate) {
|
||||
Mode.Private
|
||||
} else {
|
||||
|
@ -64,10 +64,23 @@ fun List<Tab>.toSessionBundle(context: Context): MutableList<Session> {
|
||||
|
||||
return sessionBundle
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes various onboarding states.
|
||||
*/
|
||||
enum class OnboardingState {
|
||||
// signed out, no account carried over from Fennec.
|
||||
SignedOut,
|
||||
// auto-signed in, via a Fennec account.
|
||||
AutoSignedIn,
|
||||
// manually signed in while in onboarding.
|
||||
ManuallySignedIn
|
||||
}
|
||||
|
||||
sealed class Mode {
|
||||
object Normal : Mode()
|
||||
object Private : Mode()
|
||||
object Onboarding : Mode()
|
||||
data class Onboarding(val state: OnboardingState) : Mode()
|
||||
}
|
||||
|
||||
data class SessionControlState(
|
||||
|
@ -61,25 +61,51 @@ private fun privateModeAdapterItems(tabs: List<Tab>): List<AdapterItem> {
|
||||
return items
|
||||
}
|
||||
|
||||
private fun onboardingAdapterItems(): List<AdapterItem> = listOf(
|
||||
AdapterItem.OnboardingHeader,
|
||||
AdapterItem.OnboardingSectionHeader() { it.getString(R.string.onboarding_fxa_section_header) },
|
||||
AdapterItem.OnboardingFirefoxAccount,
|
||||
AdapterItem.OnboardingSectionHeader() {
|
||||
val appName = it.getString(R.string.app_name)
|
||||
it.getString(R.string.onboarding_feature_section_header, appName)
|
||||
},
|
||||
AdapterItem.OnboardingThemePicker,
|
||||
AdapterItem.OnboardingTrackingProtection,
|
||||
AdapterItem.OnboardingPrivateBrowsing,
|
||||
AdapterItem.OnboardingPrivacyNotice,
|
||||
AdapterItem.OnboardingFinish
|
||||
)
|
||||
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 -> {
|
||||
listOf(
|
||||
AdapterItem.OnboardingSectionHeader { it.getString(R.string.onboarding_fxa_section_header) },
|
||||
AdapterItem.OnboardingFirefoxAccount
|
||||
)
|
||||
}
|
||||
OnboardingState.AutoSignedIn -> {
|
||||
listOf(
|
||||
AdapterItem.OnboardingSectionHeader { it.getString(R.string.onboarding_fxa_section_header) },
|
||||
AdapterItem.OnboardingFirefoxAccount
|
||||
)
|
||||
}
|
||||
OnboardingState.ManuallySignedIn -> {
|
||||
listOf(
|
||||
AdapterItem.OnboardingSectionHeader { it.getString(R.string.onboarding_fxa_section_header) },
|
||||
AdapterItem.OnboardingFirefoxAccount
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
items.addAll(listOf(
|
||||
AdapterItem.OnboardingSectionHeader {
|
||||
val appName = it.getString(R.string.app_name)
|
||||
it.getString(R.string.onboarding_feature_section_header, appName)
|
||||
},
|
||||
AdapterItem.OnboardingThemePicker,
|
||||
AdapterItem.OnboardingTrackingProtection,
|
||||
AdapterItem.OnboardingPrivateBrowsing,
|
||||
AdapterItem.OnboardingPrivacyNotice,
|
||||
AdapterItem.OnboardingFinish
|
||||
))
|
||||
|
||||
return items
|
||||
}
|
||||
|
||||
private fun SessionControlState.toAdapterList(): List<AdapterItem> = when (mode) {
|
||||
is Mode.Normal -> normalModeAdapterItems(tabs, collections, expandedCollections)
|
||||
is Mode.Private -> privateModeAdapterItems(tabs)
|
||||
is Mode.Onboarding -> onboardingAdapterItems()
|
||||
is Mode.Onboarding -> onboardingAdapterItems(mode.state)
|
||||
}
|
||||
|
||||
private fun collectionTabItems(collection: TabCollection) = collection.tabs.mapIndexed { index, tab ->
|
||||
|
Loading…
Reference in New Issue
Block a user