mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] closes https://github.com/mozilla-mobile/fenix/issues/22831: add wallpaper settings screen (https://github.com/mozilla-mobile/fenix/pull/23145)
* closes https://github.com/mozilla-mobile/fenix/issues/22831: add wallpaper settings screen * address PR and UX feedback * rebase upstream and adjust settings correctly
This commit is contained in:
parent
f9ca1a4e44
commit
f1c4082bba
@ -5,6 +5,7 @@
|
||||
package org.mozilla.fenix.settings
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceCategory
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
@ -69,6 +70,16 @@ class HomeSettingsFragment : PreferenceFragmentCompat() {
|
||||
val openingScreenAfterFourHours =
|
||||
requirePreference<RadioButtonPreference>(R.string.pref_key_start_on_home_after_four_hours)
|
||||
|
||||
requirePreference<Preference>(R.string.pref_key_wallpapers).apply {
|
||||
setOnPreferenceClickListener {
|
||||
view?.findNavController()?.navigate(
|
||||
HomeSettingsFragmentDirections.actionHomeSettingsFragmentToWallpaperSettingsFragment()
|
||||
)
|
||||
true
|
||||
}
|
||||
isVisible = FeatureFlags.showWallpapers
|
||||
}
|
||||
|
||||
requirePreference<PreferenceCategory>(R.string.pref_key_start_on_home_category).isVisible =
|
||||
FeatureFlags.showStartOnHomeSettings
|
||||
|
||||
|
@ -0,0 +1,142 @@
|
||||
/* 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.settings.wallpaper
|
||||
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.GridCells
|
||||
import androidx.compose.foundation.lazy.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.theme.FirefoxTheme
|
||||
import org.mozilla.fenix.wallpapers.Wallpaper
|
||||
|
||||
/**
|
||||
* The screen for controlling settings around Wallpapers.
|
||||
*
|
||||
* @param wallpapers Wallpapers to add to grid.
|
||||
* @param selectedWallpaper The currently selected wallpaper.
|
||||
* @param onSelectWallpaper Action to take when a new wallpaper is selected.
|
||||
*/
|
||||
@Composable
|
||||
fun WallpaperSettings(
|
||||
wallpapers: List<Wallpaper>,
|
||||
selectedWallpaper: Wallpaper,
|
||||
onSelectWallpaper: (Wallpaper) -> Unit,
|
||||
) {
|
||||
Surface(color = FirefoxTheme.colors.layer2) {
|
||||
WallpaperThumbnails(
|
||||
wallpapers = wallpapers,
|
||||
selectedWallpaper = selectedWallpaper,
|
||||
onSelectWallpaper = onSelectWallpaper
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A grid of selectable wallpaper thumbnails.
|
||||
*
|
||||
* @param wallpapers Wallpapers to add to grid.
|
||||
* @param selectedWallpaper The currently selected wallpaper.
|
||||
* @param numColumns The number of columns that will occupy the grid.
|
||||
* @param onSelectWallpaper Action to take when a new wallpaper is selected.
|
||||
*/
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
private fun WallpaperThumbnails(
|
||||
wallpapers: List<Wallpaper>,
|
||||
selectedWallpaper: Wallpaper,
|
||||
numColumns: Int = 3,
|
||||
onSelectWallpaper: (Wallpaper) -> Unit,
|
||||
) {
|
||||
LazyVerticalGrid(
|
||||
cells = GridCells.Fixed(numColumns),
|
||||
modifier = Modifier.padding(vertical = 30.dp, horizontal = 20.dp)
|
||||
) {
|
||||
items(wallpapers) { wallpaper ->
|
||||
WallpaperThumbnailItem(
|
||||
wallpaper = wallpaper,
|
||||
isSelected = selectedWallpaper == wallpaper,
|
||||
onSelect = onSelectWallpaper
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A single wallpaper thumbnail.
|
||||
*
|
||||
* @param wallpaper The wallpaper to display.
|
||||
* @param isSelected Whether the wallpaper is currently selected.
|
||||
* @param aspectRatio The ratio of height to width of the thumbnail.
|
||||
* @param onSelect Action to take when this wallpaper is selected.
|
||||
*/
|
||||
@Composable
|
||||
private fun WallpaperThumbnailItem(
|
||||
wallpaper: Wallpaper,
|
||||
isSelected: Boolean,
|
||||
aspectRatio: Float = 1.1f,
|
||||
onSelect: (Wallpaper) -> Unit
|
||||
) {
|
||||
val thumbnailShape = RoundedCornerShape(8.dp)
|
||||
val border = if (isSelected) {
|
||||
Modifier.border(
|
||||
BorderStroke(width = 2.dp, color = FirefoxTheme.colors.borderAccent),
|
||||
thumbnailShape
|
||||
)
|
||||
} else {
|
||||
Modifier
|
||||
}
|
||||
|
||||
Surface(
|
||||
elevation = 4.dp,
|
||||
shape = thumbnailShape,
|
||||
color = FirefoxTheme.colors.layer1,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.aspectRatio(aspectRatio)
|
||||
.padding(4.dp)
|
||||
.then(border)
|
||||
.clickable { onSelect(wallpaper) }
|
||||
) {
|
||||
if (wallpaper != Wallpaper.NONE) {
|
||||
val contentDescription = stringResource(
|
||||
R.string.wallpapers_item_name_content_description, wallpaper.name
|
||||
)
|
||||
Image(
|
||||
painterResource(id = wallpaper.drawable),
|
||||
contentScale = ContentScale.FillBounds,
|
||||
contentDescription = contentDescription,
|
||||
modifier = Modifier.fillMaxSize()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
private fun WallpaperThumbnailsPreview() {
|
||||
WallpaperSettings(
|
||||
wallpapers = Wallpaper.values().toList(),
|
||||
onSelectWallpaper = {},
|
||||
selectedWallpaper = Wallpaper.NONE
|
||||
)
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/* 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.settings.wallpaper
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||
import androidx.fragment.app.Fragment
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
import org.mozilla.fenix.theme.FirefoxTheme
|
||||
import org.mozilla.fenix.wallpapers.Wallpaper
|
||||
|
||||
class WallpaperSettingsFragment : Fragment() {
|
||||
private val wallpaperManager by lazy {
|
||||
requireComponents.wallpaperManager
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
return ComposeView(requireContext()).apply {
|
||||
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
|
||||
setContent {
|
||||
FirefoxTheme {
|
||||
var currentWallpaper by remember { mutableStateOf(wallpaperManager.currentWallpaper) }
|
||||
WallpaperSettings(
|
||||
wallpapers = Wallpaper.values().toList(),
|
||||
selectedWallpaper = currentWallpaper,
|
||||
onSelectWallpaper = { selectedWallpaper: Wallpaper ->
|
||||
currentWallpaper = selectedWallpaper
|
||||
wallpaperManager.currentWallpaper = selectedWallpaper
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ import org.mozilla.fenix.R
|
||||
* A enum that represents the available wallpapers and their states.
|
||||
*/
|
||||
enum class Wallpaper(val drawable: Int, val isDark: Boolean) {
|
||||
NONE(drawable = R.attr.homeBackground, isDark = false),
|
||||
FIRST(drawable = R.drawable.wallpaper_1, isDark = true),
|
||||
SECOND(drawable = R.drawable.wallpaper_2, isDark = false),
|
||||
NONE(drawable = R.attr.homeBackground, isDark = false);
|
||||
SECOND(drawable = R.drawable.wallpaper_2, isDark = false);
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ class WallpaperManager(private val settings: Settings) {
|
||||
) {
|
||||
settings.shouldUseDarkTheme = useDarkTheme
|
||||
settings.shouldUseLightTheme = useLightTheme
|
||||
settings.shouldFollowDeviceTheme = false
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -620,7 +620,19 @@
|
||||
<fragment
|
||||
android:id="@+id/homeSettingsFragment"
|
||||
android:name="org.mozilla.fenix.settings.HomeSettingsFragment"
|
||||
android:label="@string/preferences_home_2" />
|
||||
android:label="@string/preferences_home_2">
|
||||
<action
|
||||
android:id="@+id/action_homeSettingsFragment_to_wallpaperSettingsFragment"
|
||||
app:destination="@id/wallpaperSettingsFragment"
|
||||
app:enterAnim="@anim/slide_in_right"
|
||||
app:exitAnim="@anim/slide_out_left"
|
||||
app:popEnterAnim="@anim/slide_in_left"
|
||||
app:popExitAnim="@anim/slide_out_right" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/wallpaperSettingsFragment"
|
||||
android:name="org.mozilla.fenix.settings.wallpaper.WallpaperSettingsFragment"
|
||||
android:label="@string/customize_wallpapers"/>
|
||||
<fragment
|
||||
android:id="@+id/dataChoicesFragment"
|
||||
android:name="org.mozilla.fenix.settings.DataChoicesFragment"
|
||||
|
@ -188,6 +188,7 @@
|
||||
<string name="pref_key_adjust_creative" translatable="false">pref_key_adjust_creative</string>
|
||||
|
||||
<!-- Wallpaper Settings -->
|
||||
<string name="pref_key_wallpapers" translatable="false">pref_key_wallpapers</string>
|
||||
<string name="pref_key_current_wallpaper" translatable="false">pref_key_current_wallpaper</string>
|
||||
|
||||
<string name="pref_key_encryption_key_generated" translatable="false">pref_key_encryption_key_generated</string>
|
||||
|
@ -452,6 +452,12 @@
|
||||
<string name="customize_toggle_recent_searches" moz:removedIn="96" tools:ignore="UnusedResources">Recent searches</string>
|
||||
<!-- Title for the customize home screen section with Pocket. -->
|
||||
<string name="customize_toggle_pocket">Pocket</string>
|
||||
<!-- Title for the opening wallpaper settings screen -->
|
||||
<string name="customize_wallpapers">Wallpapers</string>
|
||||
|
||||
<!-- Wallpapers -->
|
||||
<!-- Content description for various wallpapers. The first parameter is the name of the wallpaper -->
|
||||
<string name="wallpapers_item_name_content_description">Wallpaper Item: %1$s</string>
|
||||
|
||||
<!-- Add-on Installation from AMO-->
|
||||
<!-- Error displayed when user attempts to install an add-on from AMO (addons.mozilla.org) that is not supported -->
|
||||
|
@ -29,6 +29,11 @@
|
||||
android:title="@string/customize_toggle_pocket"
|
||||
app:isPreferenceVisible="false" />
|
||||
|
||||
<androidx.preference.Preference
|
||||
android:key="@string/pref_key_wallpapers"
|
||||
android:title="@string/customize_wallpapers"
|
||||
app:isPreferenceVisible="false" />
|
||||
|
||||
<androidx.preference.PreferenceCategory
|
||||
android:layout="@layout/preference_cat_style"
|
||||
android:title="@string/preferences_opening_screen"
|
||||
|
Loading…
Reference in New Issue
Block a user