Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #9687: Refactor onboarding cards to follow app architecture (#9743)
Browse files Browse the repository at this point in the history
* For #9687: Refactor onboarding cards to follow app architecture

* For #9687: Update unit test to new controller parameters
  • Loading branch information
mcarare committed Apr 6, 2020
1 parent 025656d commit dfded8e
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 13 deletions.
11 changes: 10 additions & 1 deletion app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ class HomeFragment : Fragment() {
scrollToTheTop = ::scrollToTheTop,
showDeleteCollectionPrompt = ::showDeleteCollectionPrompt,
openSettingsScreen = ::openSettingsScreen,
openSearchScreen = ::navigateToSearch
openSearchScreen = ::navigateToSearch,
openWhatsNewLink = { openCustomTab(SupportUtils.getWhatsNewUrl(view.context)) },
openPrivacyNotice = { openCustomTab(SupportUtils.getPrivacyNoticeUrl()) }
)
)
updateLayout(view)
Expand Down Expand Up @@ -592,6 +594,13 @@ class HomeFragment : Fragment() {
nav(R.id.homeFragment, directions)
}

private fun openCustomTab(url: String) {
context?.let { context ->
val intent = SupportUtils.createCustomTabIntent(context, url)
startActivity(intent)
}
}

@SuppressWarnings("ComplexMethod", "LongMethod")
private fun createHomeMenu(context: Context, menuButtonView: WeakReference<MenuButton>) = HomeMenu(
this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ class SessionControlAdapter(
OnboardingThemePickerViewHolder.LAYOUT_ID -> OnboardingThemePickerViewHolder(view)
OnboardingTrackingProtectionViewHolder.LAYOUT_ID -> OnboardingTrackingProtectionViewHolder(view)
OnboardingPrivateBrowsingViewHolder.LAYOUT_ID -> OnboardingPrivateBrowsingViewHolder(view, interactor)
OnboardingPrivacyNoticeViewHolder.LAYOUT_ID -> OnboardingPrivacyNoticeViewHolder(view)
OnboardingPrivacyNoticeViewHolder.LAYOUT_ID -> OnboardingPrivacyNoticeViewHolder(view, interactor)
OnboardingFinishViewHolder.LAYOUT_ID -> OnboardingFinishViewHolder(view, interactor)
OnboardingWhatsNewViewHolder.LAYOUT_ID -> OnboardingWhatsNewViewHolder(view)
OnboardingWhatsNewViewHolder.LAYOUT_ID -> OnboardingWhatsNewViewHolder(view, interactor)
OnboardingToolbarPositionPickerViewHolder.LAYOUT_ID -> OnboardingToolbarPositionPickerViewHolder(view)
else -> throw IllegalStateException()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ interface SessionControlController {
*/
fun handleOpenSettingsClicked()

/**
* @see [OnboardingInteractor.onWhatsNewGetAnswersClicked]
*/
fun handleWhatsNewGetAnswersClicked()

/**
* @see [OnboardingInteractor.onReadPrivacyNoticeClicked]
*/
fun handleReadPrivacyNoticeClicked()

/**
* @see [CollectionInteractor.onToggleCollectionExpanded]
*/
Expand Down Expand Up @@ -172,7 +182,9 @@ class DefaultSessionControlController(
private val scrollToTheTop: () -> Unit,
private val showDeleteCollectionPrompt: (tabCollection: TabCollection) -> Unit,
private val openSettingsScreen: () -> Unit,
private val openSearchScreen: () -> Unit
private val openSearchScreen: () -> Unit,
private val openWhatsNewLink: () -> Unit,
private val openPrivacyNotice: () -> Unit
) : SessionControlController {
private val metrics: MetricController
get() = activity.components.analytics.metrics
Expand Down Expand Up @@ -358,6 +370,14 @@ class DefaultSessionControlController(
openSettingsScreen()
}

override fun handleWhatsNewGetAnswersClicked() {
openWhatsNewLink()
}

override fun handleReadPrivacyNoticeClicked() {
openPrivacyNotice()
}

override fun handleToggleCollectionExpanded(collection: TabCollection, expand: Boolean) {
fragmentStore.dispatch(HomeFragmentAction.CollectionExpanded(collection, expand))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ interface OnboardingInteractor {
* Hides the onboarding and navigates to Settings. Called when a user clicks on the "Open settings" button.
*/
fun onOpenSettingsClicked()

/**
* Opens a custom tab to what's new url. Called when a user clicks on the "Get answers here" link.
*/
fun onWhatsNewGetAnswersClicked()

/**
* Opens a custom tab to privacy notice url. Called when a user clicks on the "read our privacy notice" button.
*/
fun onReadPrivacyNoticeClicked()
}

/**
Expand Down Expand Up @@ -276,6 +286,14 @@ class SessionControlInteractor(
controller.handleOpenSettingsClicked()
}

override fun onWhatsNewGetAnswersClicked() {
controller.handleWhatsNewGetAnswersClicked()
}

override fun onReadPrivacyNoticeClicked() {
controller.handleReadPrivacyNoticeClicked()
}

override fun onToggleCollectionExpanded(collection: TabCollection, expand: Boolean) {
controller.handleToggleCollectionExpanded(collection, expand)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import android.view.View
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.onboarding_privacy_notice.view.*
import org.mozilla.fenix.R
import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.home.sessioncontrol.OnboardingInteractor

class OnboardingPrivacyNoticeViewHolder(view: View) : RecyclerView.ViewHolder(view) {
class OnboardingPrivacyNoticeViewHolder(
view: View,
private val interactor: OnboardingInteractor
) : RecyclerView.ViewHolder(view) {

init {
view.header_text.setOnboardingIcon(R.drawable.ic_onboarding_privacy_notice)
Expand All @@ -19,8 +22,7 @@ class OnboardingPrivacyNoticeViewHolder(view: View) : RecyclerView.ViewHolder(vi
view.description_text.text = view.context.getString(R.string.onboarding_privacy_notice_description, appName)

view.read_button.setOnClickListener {
val intent = SupportUtils.createCustomTabIntent(view.context, SupportUtils.getPrivacyNoticeUrl())
view.context.startActivity(intent)
interactor.onReadPrivacyNoticeClicked()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import android.view.View
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.onboarding_whats_new.view.*
import org.mozilla.fenix.R
import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.home.sessioncontrol.OnboardingInteractor

class OnboardingWhatsNewViewHolder(view: View) : RecyclerView.ViewHolder(view) {
class OnboardingWhatsNewViewHolder(
view: View,
private val interactor: OnboardingInteractor
) : RecyclerView.ViewHolder(view) {

init {
view.header_text.setOnboardingIcon(R.drawable.ic_whats_new)
Expand All @@ -27,8 +30,7 @@ class OnboardingWhatsNewViewHolder(view: View) : RecyclerView.ViewHolder(view) {

view.get_answers.text = textWithLink
view.get_answers.setOnClickListener {
val intent = SupportUtils.createCustomTabIntent(view.context, SupportUtils.getWhatsNewUrl(view.context))
view.context.startActivity(intent)
interactor.onWhatsNewGetAnswersClicked()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class DefaultSessionControlControllerTest {
private val hideOnboarding: () -> Unit = mockk(relaxed = true)
private val openSettingsScreen: () -> Unit = mockk(relaxed = true)
private val openSearchScreen: () -> Unit = mockk(relaxed = true)
private val openWhatsNewLink: () -> Unit = mockk(relaxed = true)
private val openPrivacyNotice: () -> Unit = mockk(relaxed = true)
private val invokePendingDeleteJobs: () -> Unit = mockk(relaxed = true)
private val registerCollectionStorageObserver: () -> Unit = mockk(relaxed = true)
private val scrollToTheTop: () -> Unit = mockk(relaxed = true)
Expand Down Expand Up @@ -96,7 +98,9 @@ class DefaultSessionControlControllerTest {
scrollToTheTop = scrollToTheTop,
showDeleteCollectionPrompt = showDeleteCollectionPrompt,
openSettingsScreen = openSettingsScreen,
openSearchScreen = openSearchScreen
openSearchScreen = openSearchScreen,
openWhatsNewLink = openWhatsNewLink,
openPrivacyNotice = openPrivacyNotice
)
}

Expand Down

0 comments on commit dfded8e

Please sign in to comment.