Unverified Commit dfded8e6 authored by Mihai Adrian's avatar Mihai Adrian Committed by GitHub
Browse files

For #9687: Refactor onboarding cards to follow app architecture (#9743)

* For #9687: Refactor onboarding cards to follow app architecture

* For #9687: Update unit test to new controller parameters
parent 025656d8
......@@ -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)
......@@ -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,
......
......@@ -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()
}
......
......@@ -144,6 +144,16 @@ interface SessionControlController {
*/
fun handleOpenSettingsClicked()
/**
* @see [OnboardingInteractor.onWhatsNewGetAnswersClicked]
*/
fun handleWhatsNewGetAnswersClicked()
/**
* @see [OnboardingInteractor.onReadPrivacyNoticeClicked]
*/
fun handleReadPrivacyNoticeClicked()
/**
* @see [CollectionInteractor.onToggleCollectionExpanded]
*/
......@@ -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
......@@ -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))
}
......
......@@ -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()
}
/**
......@@ -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)
}
......
......@@ -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)
......@@ -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()
}
}
......
......@@ -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)
......@@ -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()
}
}
......
......@@ -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)
......@@ -96,7 +98,9 @@ class DefaultSessionControlControllerTest {
scrollToTheTop = scrollToTheTop,
showDeleteCollectionPrompt = showDeleteCollectionPrompt,
openSettingsScreen = openSettingsScreen,
openSearchScreen = openSearchScreen
openSearchScreen = openSearchScreen,
openWhatsNewLink = openWhatsNewLink,
openPrivacyNotice = openPrivacyNotice
)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment