Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ANDROID-14297 Get Tweaks as suspend functions and non null #39

Merged
merged 4 commits into from
Feb 9, 2024

Conversation

jdelga
Copy link
Member

@jdelga jdelga commented Feb 7, 2024

🎟️ Jira ticket

ANDROID-14297

🥅 What's the goal?

  • Provide a way to get the app tweaks with a non-null value providing a default one
  • Allow get the tweak value as suspend function as Tweaks are going to return only one item

🚧 How do we do it?

Provide new useful functions

📘 Documentation changes?

  • No docs to update nor create

🧪 How can I test this?

@@ -39,6 +41,12 @@ open class Tweaks {

open fun <T> getTweakValue(key: String): Flow<T?> = tweaksBusinessLogic.getValue(key)

open fun <T> getTweakValue(key: String, defaultValue: T): Flow<T> = getTweakValue<T>(key).map { it ?: defaultValue }
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 it should return a Flow of nullable T (T?). defaultValue should be nullable as well

Copy link
Contributor

@yamal-alm yamal-alm Feb 7, 2024

Choose a reason for hiding this comment

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

well, after having thought more about it, if you want a null default value you would probably be using the existing method. So ignore my comment 😄

Copy link
Member Author

@jdelga jdelga Feb 7, 2024

Choose a reason for hiding this comment

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

Exactly, the idea is to avoid having a nullable result. The nullable one is the current one.

flowOf(defaultValue)

open suspend fun <T> getTweak(key: String): T? =
null
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 something is missing here 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the no-op module. We use it to provide an implementation of Tweaks that don't do anything, so we provide it to the release build, while the real one only goes to debug: https://github.com/Telefonica/b2p-germany-android/blob/main/app/build.gradle#L250

You can check it correctly in the flavors view

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, sorry, didn't know that. I will see it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added a better implementation for the no-op scenario, where we try to find a default value provided in the app, instead returning the default one or null

library/src/noop/java/com/telefonica/tweaks/Tweaks.kt Outdated Show resolved Hide resolved
@jdelga jdelga changed the title Get Tweaks as suspend functions and non null ANDROID-14297 Get Tweaks as suspend functions and non null Feb 9, 2024
@jdelga jdelga merged commit 4647e78 into main Feb 9, 2024
3 checks passed
@jdelga jdelga deleted the jdelga/get-tweaks-as-suspend-functions branch February 9, 2024 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants