Fixes: #26052 remove WallpaperManager::updateWallpaper

This commit is contained in:
MatthewTighe 2022-07-29 15:44:00 -07:00 committed by mergify[bot]
parent cedb040e84
commit 9fb6eeb8cf
5 changed files with 29 additions and 61 deletions

View File

@ -11,7 +11,6 @@ import androidx.test.uiautomator.Until
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.RetryTestRule
@ -154,19 +153,4 @@ class HomeScreenTest {
verifyWelcomeHeader()
}
}
@SmokeTest
@Test
fun tapLogoToChangeWallpaperTest() {
homeScreen {
clickFirefoxLogo()
verifyWallpaperImageApplied(true)
clickFirefoxLogo()
verifyWallpaperImageApplied(true)
clickFirefoxLogo()
verifyWallpaperImageApplied(true)
clickFirefoxLogo()
verifyWallpaperImageApplied(false)
}
}
}

View File

@ -120,7 +120,7 @@ import org.mozilla.fenix.tabstray.TabsTrayAccessPoint
import org.mozilla.fenix.utils.Settings.Companion.TOP_SITES_PROVIDER_MAX_THRESHOLD
import org.mozilla.fenix.utils.ToolbarPopupWindow
import org.mozilla.fenix.utils.allowUndo
import org.mozilla.fenix.wallpapers.WallpaperManager
import org.mozilla.fenix.wallpapers.Wallpaper
import java.lang.ref.WeakReference
import kotlin.math.min
@ -754,10 +754,6 @@ class HomeFragment : Fragment() {
themeCollection = newWallpaper::class.simpleName
)
)
manager.updateWallpaper(
wallpaperContainer = binding.wallpaperImageView,
newWallpaper = newWallpaper
)
}
}
}
@ -967,12 +963,17 @@ class HomeFragment : Fragment() {
.onEach { state ->
// We only want to update the wallpaper when it's different from the default one
// as the default is applied already on xml by default.
val currentWallpaper = state.wallpaperState.currentWallpaper
if (currentWallpaper != WallpaperManager.defaultWallpaper) {
requireComponents.wallpaperManager.updateWallpaper(
binding.wallpaperImageView,
currentWallpaper
)
when (val currentWallpaper = state.wallpaperState.currentWallpaper) {
is Wallpaper.Default -> {
binding.wallpaperImageView.visibility = View.GONE
}
else -> {
with(requireComponents.wallpaperManager) {
val bitmap = currentWallpaper.load(requireContext()) ?: return@onEach
bitmap.scaleBitmapToBottomOfView(binding.wallpaperImageView)
}
binding.wallpaperImageView.visibility = View.VISIBLE
}
}
}
.launchIn(viewLifecycleOwner.lifecycleScope)

View File

@ -297,8 +297,8 @@ private fun WallpaperThumbnailsPreview() {
WallpaperSettings(
defaultWallpaper = WallpaperManager.defaultWallpaper,
loadWallpaperResource = {
wallpaperManager.loadSavedWallpaper(context, it)
loadWallpaperResource = { wallpaper ->
with(wallpaperManager) { wallpaper.load(context) }
},
wallpapers = wallpaperManager.wallpapers,
selectedWallpaper = wallpaperManager.currentWallpaper,

View File

@ -49,8 +49,8 @@ class WallpaperSettingsFragment : Fragment() {
WallpaperSettings(
wallpapers = wallpaperManager.wallpapers,
defaultWallpaper = WallpaperManager.defaultWallpaper,
loadWallpaperResource = {
wallpaperManager.loadSavedWallpaper(requireContext(), it)
loadWallpaperResource = { wallpaper ->
with(wallpaperManager) { wallpaper.load(context) }
},
selectedWallpaper = currentWallpaper,
onSelectWallpaper = { selectedWallpaper: Wallpaper ->

View File

@ -58,30 +58,6 @@ class WallpaperManager(
fileManager.clean(currentWallpaper, wallpapers.filterIsInstance<Wallpaper.Remote>())
}
/**
* Apply the [newWallpaper] into the [wallpaperContainer] and update the [currentWallpaper].
*/
fun updateWallpaper(wallpaperContainer: ImageView, newWallpaper: Wallpaper) {
val context = wallpaperContainer.context
if (newWallpaper == defaultWallpaper) {
wallpaperContainer.visibility = View.GONE
logger.info("Wallpaper update to default background")
} else {
val bitmap = loadSavedWallpaper(context, newWallpaper)
if (bitmap == null) {
val message = "Could not load wallpaper bitmap. Resetting to default."
logger.error(message)
currentWallpaper = defaultWallpaper
wallpaperContainer.visibility = View.GONE
return
} else {
wallpaperContainer.visibility = View.VISIBLE
scaleBitmapToBottom(bitmap, wallpaperContainer)
}
}
currentWallpaper = newWallpaper
}
/**
* Download all known remote wallpapers.
*/
@ -104,7 +80,7 @@ class WallpaperManager(
} else {
values[index]
}.also {
appStore.dispatch(AppAction.WallpaperAction.UpdateCurrentWallpaper(it))
currentWallpaper = it
}
}
@ -139,10 +115,10 @@ class WallpaperManager(
/**
* Load a wallpaper that is saved locally.
*/
fun loadSavedWallpaper(context: Context, wallpaper: Wallpaper): Bitmap? =
when (wallpaper) {
is Wallpaper.Local -> loadWallpaperFromDrawables(context, wallpaper)
is Wallpaper.Remote -> loadWallpaperFromDisk(context, wallpaper)
fun Wallpaper.load(context: Context): Bitmap? =
when (this) {
is Wallpaper.Local -> loadWallpaperFromDrawables(context, this)
is Wallpaper.Remote -> loadWallpaperFromDisk(context, this)
else -> null
}
@ -163,7 +139,14 @@ class WallpaperManager(
}
}.getOrNull()
private fun scaleBitmapToBottom(bitmap: Bitmap, view: ImageView) {
/**
* This will scale the received [Bitmap] to the size of the [view]. It retains the bitmap's
* original aspect ratio, but will shrink or enlarge it to fit the viewport. If bitmap does not
* correctly fit the aspect ratio of the view, it will be shifted to prioritize the bottom-left
* of the bitmap.
*/
fun Bitmap.scaleBitmapToBottomOfView(view: ImageView) {
val bitmap = this
view.setImageBitmap(bitmap)
view.scaleType = ImageView.ScaleType.MATRIX
val matrix = Matrix()