-
Notifications
You must be signed in to change notification settings - Fork 1.3k
closes #23504: download focus wallpapers at runtime #23505
Conversation
a16e40f
to
2e6e3fc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a first pass it looks good in general, just added some suggestions
|
||
@OptIn(DelicateCoroutinesApi::class) | ||
private fun downloadWallpapers() { | ||
GlobalScope.launch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be explicit about the dispatcher GlobalScope.launch(Dispatchers.IO)
, is there any specific reason for using the default value? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like to switch the dispatcher closest to the code that actually needs to be on the different dispatcher. That way, calling code doesn't need to introspect the async code to discover it needs to change dispatchers. This is a suggested practice, and is something that can be observed in Room and in Retrofit I believe.
That is, it's safe to call suspend
functions defined in Room and Retrofit from any Dispatcher
, because the libraries ensure they switch to IO
before performing async tasks. I like to mirror that behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fun Wallpaper.getLocalPath(orientation: String, theme: String): String = | ||
"$orientation/$theme/${themeCollection.directoryName()}/$name.png" | ||
|
||
private fun Context.isLandscape(): Boolean { | ||
return resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE | ||
} | ||
|
||
private fun Context.isDark(): Boolean { | ||
return resources.configuration.uiMode and | ||
Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This look more like responsibilities that could be on the Wallpaper manager
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could move these extensions into that file if that makes more organizational sense, but Wallpaper.getLocal
path is also used by WallpaperDownloader
. WallpaperDownloader
is a child of WallpaperManager
, and so should not receive it as a dependency.
I could also just copy the functions into both, if that makes more sense. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also have a Extensions.kt
file under the wallpapers
package similar to what we do here
that could be covered in follow up, let's leave it as it's for now.
app/src/main/java/org/mozilla/fenix/wallpapers/WallpaperDownloader.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/org/mozilla/fenix/settings/wallpaper/WallpaperSettings.kt
Show resolved
Hide resolved
app/src/main/java/org/mozilla/fenix/wallpapers/WallpaperManager.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/org/mozilla/fenix/wallpapers/WallpaperManager.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/org/mozilla/fenix/settings/wallpaper/WallpaperSettings.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/org/mozilla/fenix/wallpapers/WallpaperDownloader.kt
Outdated
Show resolved
Hide resolved
Added a commit addressing feedback, will squash them before landing. @Amejia481 and I decided that we'll land a separate PR for switching the local wallpapers from |
c4a0d07
to
213575e
Compare
213575e
to
e99a283
Compare
fun WallpaperThemeCollection.directoryName(): String = when (this) { | ||
WallpaperThemeCollection.NONE, | ||
WallpaperThemeCollection.FIREFOX -> "" | ||
WallpaperThemeCollection.FOCUS -> "focus" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This could be a property on the WallpaperThemeCollection
:)
We could do that in follow up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better name might actually be what we want here. This function returns the remote directory name, so I don't think it's necessarily an applicable property for all theme collections
} | ||
}.onFailure { | ||
logger.error(it.message ?: "Download failed: no throwable message included.", it) | ||
context.components.analytics.crashReporter.submitCaughtException(it) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: For future testing purpose we could the reference of crashReporter
to WallpaperDownloader
, we could do this in a follow up.
@@ -127,6 +127,7 @@ open class FenixApplication : LocaleAwareApplication(), Provider { | |||
|
|||
setupInMainProcessOnly() | |||
|
|||
downloadWallpapers() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I almost missed this one, this should be under a feature validation FeatureFlags.showWallpapers
+ FeatureFlags.isThemedWallpapersFeatureEnabled
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could add FeatureFlags.isThemedWallpapersFeatureEnabled
later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏 good catch, TYVM
3fbf45d
to
a6595eb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally and it's working like a charm!
…zilla-mobile#23505) * closes mozilla-mobile#23504: download focus wallpapers at runtime * address pr feedback * only download wallpapers if feature flag is set
To download an APK when reviewing a PR: