This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #26750: add Wallpapers Onboarding dialog
- Loading branch information
1 parent
9361543
commit 65bee4b
Showing
24 changed files
with
360 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
app/src/main/java/org/mozilla/fenix/onboarding/WallpaperOnboardingDialogFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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.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.material.ExperimentalMaterialApi | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.ui.platform.ComposeView | ||
import androidx.compose.ui.platform.ViewCompositionStrategy | ||
import androidx.navigation.fragment.findNavController | ||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment | ||
import kotlinx.coroutines.launch | ||
import mozilla.components.lib.state.ext.observeAsComposableState | ||
import org.mozilla.fenix.NavGraphDirections | ||
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. | ||
*/ | ||
@OptIn(ExperimentalMaterialApi::class) | ||
class WallpaperOnboardingDialogFragment : BottomSheetDialogFragment() { | ||
private val appStore by lazy { | ||
requireComponents.appStore | ||
} | ||
|
||
private val wallpaperUseCases by lazy { | ||
requireComponents.useCases.wallpaperUseCases | ||
} | ||
|
||
@SuppressLint("SourceLockedOrientationActivity") | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setStyle(STYLE_NO_TITLE, R.style.WallpaperOnboardingDialogStyle) | ||
activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
requireContext().settings().showWallpaperOnboarding = false | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle?, | ||
): View = ComposeView(requireContext()).apply { | ||
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) | ||
|
||
setContent { | ||
FirefoxTheme { | ||
val wallpapers = appStore.observeAsComposableState { state -> | ||
state.wallpaperState.availableWallpapers.take(THUMBNAILS_COUNT) | ||
}.value ?: listOf() | ||
val currentWallpaper = appStore.observeAsComposableState { state -> | ||
state.wallpaperState.currentWallpaper | ||
}.value ?: Wallpaper.Default | ||
|
||
val coroutineScope = rememberCoroutineScope() | ||
|
||
WallpaperOnboarding( | ||
wallpapers = wallpapers, | ||
currentWallpaper = currentWallpaper, | ||
onCloseClicked = { dismiss() }, | ||
onExploreMoreButtonClicked = { | ||
val directions = NavGraphDirections.actionGlobalWallpaperSettingsFragment() | ||
findNavController().navigate(directions) | ||
}, | ||
loadWallpaperResource = { wallpaperUseCases.loadThumbnail(it) }, | ||
onSelectWallpaper = { | ||
coroutineScope.launch { wallpaperUseCases.selectWallpaper(it) } | ||
}, | ||
) | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
const val THUMBNAILS_COUNT = 6 | ||
} | ||
} |
Oops, something went wrong.