Skip to content

Instantly share code, notes, and snippets.

@bendk
Created April 19, 2022 20:31
Show Gist options
  • Save bendk/f9e664549635062b5696a2259f7d6a76 to your computer and use it in GitHub Desktop.
Save bendk/f9e664549635062b5696a2259f7d6a76 to your computer and use it in GitHub Desktop.
Output from cargo run -p nimbus-fml -- fixtures/fe/fenix.yaml android features -o /dev/stdout --r-package org.mozilla.fenix
// This file was autogenerated by some hot garbage in the `nimbus-fml` crate.
// Trust me, you don't want to mess with it!
import android.content.Context
import android.graphics.drawable.Drawable
import org.mozilla.experiments.nimbus.FeaturesInterface
import org.mozilla.experiments.nimbus.NullVariables
import org.mozilla.experiments.nimbus.Res
import org.mozilla.experiments.nimbus.StringHolder
import org.mozilla.experiments.nimbus.Variables
import org.mozilla.experiments.nimbus.internal.FeatureHolder
import org.mozilla.experiments.nimbus.internal.mapKeysNotNull
import org.mozilla.experiments.nimbus.internal.mergeWith
import org.mozilla.fenix.R
/**
* An object for safely accessing feature configuration from Nimbus.
*
* This is generated.
*
* Before use to configure the application or any of its features, this class needs
* to be wired up to the SDK API. This is an object created by the application which connects to
* the Nimbus SDK and thence to the server.
*
* ```
* val nimbus: Nimbus = connectToNimbusSDK()
* MyNimbus.api = nimbus
* ```
*
* Once initialized, this can be used to access typesafe configuration object via the `features` member.
*
* This class should not be edited manually, but changed by editing the `nimbus.fml.yaml` file, and
* re-running the `nimbus-fml` tool, which is likely already being used by the build script.
*/
object MyNimbus {
class Features {
/**
* The homescreen that the user goes to when they press home or new tab.
*/
val homescreen: FeatureHolder<Homescreen> by lazy {
FeatureHolder({ MyNimbus.api }, "homescreen") { variables ->
Homescreen(variables)
}
}
/**
* A feature that does not correspond to an application feature suitable
* for showing that Nimbus is working.
*/
val nimbusValidation: FeatureHolder<NimbusValidation> by lazy {
FeatureHolder({ MyNimbus.api }, "nimbus-validation") { variables ->
NimbusValidation(variables)
}
}
/**
* A feature allowing the grouping of URLs around the search term that
* it came from.
*/
val searchTermGroups: FeatureHolder<SearchTermGroups> by lazy {
FeatureHolder({ MyNimbus.api }, "search-term-groups") { variables ->
SearchTermGroups(variables)
}
}
}
/**
* This should be populated at app launch.
*/
var api: FeaturesInterface? = null
/**
* Accessor object for generated configuration classes extracted from Nimbus, with built-in
* default values.
*/
val features = Features()
}
// Public interface members begin here.
/**
* The homescreen that the user goes to when they press home or new tab.
*/
public class Homescreen
private constructor(
private val _variables: Variables,
private val _defaults: Defaults) {
private data class Defaults(
val sectionsEnabled: Map<HomeScreenSection, Boolean>
)
constructor(_variables: Variables = NullVariables.instance,
sectionsEnabled: Map<HomeScreenSection, Boolean> = mapOf(HomeScreenSection.JUMP_BACK_IN to false, HomeScreenSection.POCKET to false, HomeScreenSection.RECENT_EXPLORATIONS to false, HomeScreenSection.RECENTLY_SAVED to false, HomeScreenSection.TOP_SITES to true)
) : this(
_variables = _variables,
_defaults = Defaults(sectionsEnabled = sectionsEnabled )
)
/**
* This property provides a lookup table of whether or not the given section
* should be enabled. If the section is enabled, it should be toggleable in
* the settings screen, and on by default.
*/
val sectionsEnabled: Map<HomeScreenSection, Boolean> by lazy {
_variables.getBoolMap("sections-enabled")?.mapKeysNotNull(HomeScreenSection::enumValue)?.mergeWith(_defaults.sectionsEnabled) ?: _defaults.sectionsEnabled
}
}
/**
* A feature that does not correspond to an application feature suitable for
* showing that Nimbus is working.
*/
public class NimbusValidation
private constructor(
private val _variables: Variables,
private val _defaults: Defaults) {
private data class Defaults(
val stringMap: Map<String, String>,
val settingsIcon: Int,
val settingsTitle: StringHolder?,
val stringIntMap: Map<String, Int>,
val eumMap: Map<IconType, Int>,
val settingsPunctuation: StringHolder,
val iconType: IconType?
)
constructor(_variables: Variables = NullVariables.instance,
stringMap: Map<String, String> = mapOf(),
settingsIcon: Int = R.drawable.mozac_ic_settings,
settingsTitle: StringHolder? = Res.string(R.string.app_menu_settings_title),
stringIntMap: Map<String, Int> = mapOf(),
eumMap: Map<IconType, Int> = mapOf(IconType.FAVICON to 3, IconType.LETTER to 2, IconType.SCREENSHOT to 1),
settingsPunctuation: StringHolder = Res.string(R.string.app_menu_settings_punctuation),
iconType: IconType? = null
) : this(
_variables = _variables,
_defaults = Defaults(stringMap = stringMap, settingsIcon = settingsIcon, settingsTitle = settingsTitle, stringIntMap = stringIntMap, eumMap = eumMap, settingsPunctuation = settingsPunctuation, iconType = iconType )
)
/**
* A string map that was causing problem
*/
val stringMap: Map<String, String> by lazy {
_variables.getStringMap("string-map")?.mergeWith(_defaults.stringMap) ?: _defaults.stringMap
}
/**
* The drawable displayed in the app menu for Settings
*/
val settingsIcon: Res<Drawable> by lazy {
_variables.getImage("settings-icon") ?: Res.drawable(_variables.context, _defaults.settingsIcon)
}
/**
* The title of displayed in the Settings screen and app menu.
*/
val settingsTitle: String? by lazy {
_variables.getText("settings-title") ?: _defaults.settingsTitle?.let { it.toString(_variables.context) }
}
/**
* A string map that was causing problem
*/
val stringIntMap: Map<String, Int> by lazy {
_variables.getIntMap("string-int-map")?.mergeWith(_defaults.stringIntMap) ?: _defaults.stringIntMap
}
/**
* A string map that was causing problem
*/
val eumMap: Map<IconType, Int> by lazy {
_variables.getIntMap("eum-map")?.mapKeysNotNull(IconType::enumValue)?.mergeWith(_defaults.eumMap) ?: _defaults.eumMap
}
/**
* The emoji displayed in the Settings screen title.
*/
val settingsPunctuation: String by lazy {
_variables.getText("settings-punctuation") ?: _defaults.settingsPunctuation.toString(_variables.context)
}
/**
* Testing an enum value
*/
val iconType: IconType? by lazy {
_variables.getString("icon-type") ?: _defaults.iconType
}
}
/**
* A feature allowing the grouping of URLs around the search term that it came
* from.
*/
public class SearchTermGroups
private constructor(
private val _variables: Variables,
private val _defaults: Defaults) {
private data class Defaults(
val enabled: Boolean
)
constructor(_variables: Variables = NullVariables.instance,
enabled: Boolean = false
) : this(
_variables = _variables,
_defaults = Defaults(enabled = enabled )
)
/**
* If true, the feature shows up on the homescreen and on the new tab
* screen.
*/
val enabled: Boolean by lazy {
_variables.getBool("enabled") ?: _defaults.enabled
}
}
/**
* The identifiers for the sections of the homescreen.
*/
enum class HomeScreenSection {
/**
* The tabs the user was looking immediately before being interrupted.
*/
JUMP_BACK_IN,
/**
* The sites the user has bookmarked recently.
*/
RECENTLY_SAVED,
/**
* The pocket section. This should only be available in the US.
*/
POCKET,
/**
* The frecency and pinned sites.
*/
TOP_SITES,
/**
* The tab groups
*/
RECENT_EXPLORATIONS;
companion object {
private val enumMap: Map<String, HomeScreenSection> by lazy {
mapOf(
"jump-back-in" to HomeScreenSection.JUMP_BACK_IN,
"recently-saved" to HomeScreenSection.RECENTLY_SAVED,
"pocket" to HomeScreenSection.POCKET,
"top-sites" to HomeScreenSection.TOP_SITES,
"recent-explorations" to HomeScreenSection.RECENT_EXPLORATIONS)
}
fun enumValue(string: String): HomeScreenSection? = enumMap[string]
}
}
/**
* The different types of icons
*/
enum class IconType {
/**
* A screenshot icon
*/
SCREENSHOT,
/**
* A favicon icon
*/
FAVICON,
/**
* A letter icon
*/
LETTER;
companion object {
private val enumMap: Map<String, IconType> by lazy {
mapOf(
"screenshot" to IconType.SCREENSHOT,
"favicon" to IconType.FAVICON,
"letter" to IconType.LETTER)
}
fun enumValue(string: String): IconType? = enumMap[string]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment