Skip to content

Commit

Permalink
Closes mozilla-mobile#26750: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mike a committed Sep 5, 2022
1 parent 54ad6c6 commit b737bdf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import org.mozilla.fenix.home.recentvisits.RecentlyVisitedItem.RecentHistoryGrou
import org.mozilla.fenix.home.recentvisits.RecentlyVisitedItem.RecentHistoryHighlight
import org.mozilla.fenix.home.recentvisits.controller.RecentVisitsController
import org.mozilla.fenix.home.recentvisits.interactor.RecentVisitsInteractor
import org.mozilla.fenix.onboarding.WallpaperOnboardingDialogFragment
import org.mozilla.fenix.wallpapers.Wallpaper

/**
* Interface for tab related actions in the [SessionControlInteractor].
Expand Down Expand Up @@ -164,9 +166,10 @@ interface OnboardingInteractor {
fun onReadPrivacyNoticeClicked()

/**
* Show the Wallpapers onboarding dialog to onboard users about the feature.
* Show Wallpapers onboarding dialog to onboard users about the feature if conditions are met.
* Returns true if the call has been passed down to the controller.
*/
fun showWallpapersOnboardingDialog()
fun showWallpapersOnboardingDialog(state: AppState?): Boolean
}

interface CustomizeHomeIteractor {
Expand Down Expand Up @@ -327,8 +330,19 @@ class SessionControlInteractor(
controller.handleReadPrivacyNoticeClicked()
}

override fun showWallpapersOnboardingDialog() {
controller.handleShowWallpapersOnboardingDialog()
override fun showWallpapersOnboardingDialog(state: AppState?): Boolean {
return state?.wallpaperState?.availableWallpapers?.let { wallpapers ->
wallpapers.filter { wallpaper ->
wallpaper.thumbnailFileState == Wallpaper.ImageFileState.Downloaded
}.size.let { downloadedCount ->
downloadedCount >= WallpaperOnboardingDialogFragment.THUMBNAILS_COUNT &&
downloadedCount == wallpapers.size
}.also { isThumbnailsDownloaded ->
if (isThumbnailsDownloaded) {
controller.handleShowWallpapersOnboardingDialog()
}
}
} ?: false
}

override fun onToggleCollectionExpanded(collection: TabCollection, expand: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import org.mozilla.fenix.home.recentvisits.RecentlyVisitedItem
import org.mozilla.fenix.onboarding.JumpBackInCFRDialog
import org.mozilla.fenix.onboarding.SyncCFRPresenter
import org.mozilla.fenix.utils.Settings
import org.mozilla.fenix.wallpapers.Wallpaper
import org.mozilla.fenix.wallpapers.WallpaperOnboardingDialogFragment

// This method got a little complex with the addition of the tab tray feature flag
// When we remove the tabs from the home screen this will get much simpler again.
Expand Down Expand Up @@ -234,19 +232,8 @@ class SessionControlView(
context.settings().showWallpaperOnboarding &&
!isCFRDisplayed
) {
val isThumbnailsDownloaded =
this@SessionControlView.state?.wallpaperState?.availableWallpapers?.let {
it.filter { wallpaper ->
wallpaper.thumbnailFileState == Wallpaper.ImageFileState.Downloaded
}.size.run {
this >= WallpaperOnboardingDialogFragment.THUMBNAILS_COUNT &&
this == it.size
}
} ?: false
if (isThumbnailsDownloaded) {
interactor.showWallpapersOnboardingDialog()
isCFRDisplayed = true
}
isCFRDisplayed =
interactor.showWallpapersOnboardingDialog(this@SessionControlView.state)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.fenix.wallpapers
package org.mozilla.fenix.onboarding

import android.annotation.SuppressLint
import android.content.pm.ActivityInfo
Expand All @@ -23,6 +23,8 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.theme.FirefoxTheme
import org.mozilla.fenix.wallpapers.Wallpaper
import org.mozilla.fenix.wallpapers.WallpaperOnboarding

/**
* Dialog displaying the wallpapers onboarding.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@

<dialog
android:id="@+id/wallpaperOnboardingDialogFragment"
android:name="org.mozilla.fenix.wallpapers.WallpaperOnboardingDialogFragment" />
android:name="org.mozilla.fenix.onboarding.WallpaperOnboardingDialogFragment" />

<dialog
android:id="@+id/searchDialogFragment"
Expand Down

0 comments on commit b737bdf

Please sign in to comment.