Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

closes #23504: download focus wallpapers at runtime #23505

Merged
merged 3 commits into from
Feb 1, 2022

Conversation

MatthewTighe
Copy link
Contributor

To download an APK when reviewing a PR:

  1. click on Show All Checks,
  2. click Details next to "Taskcluster (pull_request)" after it appears and then finishes with a green checkmark,
  3. click on the "Fenix - assemble" task, then click "Run Artifacts".
  4. the APK links should be on the left side of the screen, named for each CPU architecture

Copy link
Contributor

@Amejia481 Amejia481 left a 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 {
Copy link
Contributor

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? :)

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have some previous discussion about using the Dispatchers.Default when was strictly needed you could read more #19574 @mcomella and @csadilek could provide more pointers as they were more involved on the ticket.

Comment on lines 73 to 76
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
}
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

@Amejia481 Amejia481 Feb 1, 2022

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

https://github.com/mozilla-mobile/android-components/blob/main/components/feature/addons/src/main/java/mozilla/components/feature/addons/ui/Extensions.kt

that could be covered in follow up, let's leave it as it's for now.

@MatthewTighe
Copy link
Contributor Author

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 assets to drawables, and that will include the discussed changes to the Wallpaper type.

@MatthewTighe MatthewTighe force-pushed the wallpaper-network branch 2 times, most recently from c4a0d07 to 213575e Compare February 1, 2022 19:24
Comment on lines 38 to 42
fun WallpaperThemeCollection.directoryName(): String = when (this) {
WallpaperThemeCollection.NONE,
WallpaperThemeCollection.FIREFOX -> ""
WallpaperThemeCollection.FOCUS -> "focus"
}
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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()
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏 good catch, TYVM

Copy link
Contributor

@Amejia481 Amejia481 left a 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!

@MatthewTighe MatthewTighe added the pr:needs-landing-squashed PRs that are ready to land (squashed) [Will be merged by Mergify] label Feb 1, 2022
@mergify mergify bot merged commit 9dc0506 into mozilla-mobile:main Feb 1, 2022
pkirakosyan pushed a commit to gexsi/user-agent-android that referenced this pull request Mar 10, 2022
…zilla-mobile#23505)

* closes mozilla-mobile#23504: download focus wallpapers at runtime

* address pr feedback

* only download wallpapers if feature flag is set
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr:needs-landing-squashed PRs that are ready to land (squashed) [Will be merged by Mergify]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants