Skip to content

Commit

Permalink
For mozilla-mobile#26169 - MR Home Onboarding Dialog for upgrading users
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielluong committed Aug 23, 2022
1 parent 627447a commit 5485e1d
Show file tree
Hide file tree
Showing 15 changed files with 357 additions and 364 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ dependencies {
implementation Deps.androidx_constraintlayout
implementation Deps.androidx_coordinatorlayout
implementation Deps.google_accompanist_drawablepainter
implementation Deps.google_accompanist_insets

implementation Deps.sentry

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/mozilla/fenix/FeatureFlags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ object FeatureFlags {
/**
* Enables showing the homescreen onboarding card.
*/
const val showHomeOnboarding = false
val showHomeOnboarding = Config.channel.isDebug

/**
* Enables history improvement features.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import mozilla.components.support.ktx.android.view.showKeyboard
import mozilla.components.support.ktx.kotlin.isUrl
import mozilla.telemetry.glean.private.NoExtras
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.GleanMetrics.Collections
import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.GleanMetrics.HomeScreen
Expand Down Expand Up @@ -508,12 +507,10 @@ class DefaultSessionControlController(
}

override fun handleShowOnboardingDialog() {
if (FeatureFlags.showHomeOnboarding) {
navController.nav(
R.id.homeFragment,
HomeFragmentDirections.actionGlobalHomeOnboardingDialog()
)
}
navController.nav(
R.id.homeFragment,
HomeFragmentDirections.actionGlobalHomeOnboardingDialog()
)
}

override fun handleReadPrivacyNoticeClicked() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,6 @@ private fun AppState.toAdapterList(settings: Settings): List<AdapterItem> = when
is Mode.Onboarding -> onboardingAdapterItems(mode.state)
}

@VisibleForTesting
internal fun AppState.shouldShowHomeOnboardingDialog(settings: Settings): Boolean {
val isAnySectionsVisible = recentTabs.isNotEmpty() || recentBookmarks.isNotEmpty() ||
recentHistory.isNotEmpty() || pocketStories.isNotEmpty()
return isAnySectionsVisible && !settings.hasShownHomeOnboardingDialog
}

private fun collectionTabItems(collection: TabCollection) =
collection.tabs.mapIndexed { index, tab ->
AdapterItem.TabInCollectionItem(collection, tab, index == collection.tabs.lastIndex)
Expand Down Expand Up @@ -211,7 +204,7 @@ class SessionControlView(
}

fun update(state: AppState, shouldReportMetrics: Boolean = false) {
if (state.shouldShowHomeOnboardingDialog(view.context.settings())) {
if (view.context.settings().showHomeOnboardingDialog) {
interactor.showOnboardingDialog()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,72 @@

package org.mozilla.fenix.onboarding

import android.annotation.SuppressLint
import android.content.pm.ActivityInfo
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.fragment.app.DialogFragment
import androidx.navigation.fragment.findNavController
import com.google.accompanist.insets.ProvideWindowInsets
import mozilla.components.lib.state.ext.observeAsComposableState
import org.mozilla.fenix.R
import org.mozilla.fenix.databinding.FragmentOnboardingHomeDialogBinding
import org.mozilla.fenix.components.components
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.onboarding.view.Onboarding
import org.mozilla.fenix.theme.FirefoxTheme

/**
* Dialog displayed once when one or multiples of these sections are shown in the home screen
* recentTabs,recentBookmarks,historyMetadata or pocketArticles.
* Dialog displaying a welcome and sync sign in onboarding.
*/
class HomeOnboardingDialogFragment : DialogFragment() {
@SuppressLint("SourceLockedOrientationActivity")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NO_TITLE, R.style.HomeOnboardingDialogStyle)
activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}

override fun onDestroy() {
super.onDestroy()
activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? = inflater.inflate(R.layout.fragment_onboarding_home_dialog, container, false)

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val binding = FragmentOnboardingHomeDialogBinding.bind(view)

val appName = requireContext().getString(R.string.app_name)
binding.welcomeTitle.text =
requireContext().getString(R.string.onboarding_home_screen_title_3, appName)
binding.homeTitle.text = requireContext().getString(
R.string.onboarding_home_screen_section_home_title_3,
appName
)

binding.finishButton.setOnClickListener {
context?.settings()?.let { settings ->
settings.hasShownHomeOnboardingDialog = true
): View = ComposeView(requireContext()).apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)

setContent {
ProvideWindowInsets {
FirefoxTheme {
val account =
components.backgroundServices.syncStore.observeAsComposableState { state -> state.account }

Onboarding(
isSyncSignIn = account.value != null,
onDismiss = ::onDismiss,
onSignInButtonClick = {
findNavController().nav(
R.id.homeOnboardingDialogFragment,
HomeOnboardingDialogFragmentDirections.actionGlobalTurnOnSync()
)
onDismiss()
},
)
}
}
dismiss()
}
}

private fun onDismiss() {
context?.settings()?.showHomeOnboardingDialog = false
dismiss()
}
}
Loading

0 comments on commit 5485e1d

Please sign in to comment.