Extending DeepLink annotations
I have two screens (activities) working under A/B tests. They should share the same deeplink, the only difference is that if a feature flag is enabled, it should show one activity and if not, show the other.
How can I extend the annotations in order to implement this?
Ideally I would like to have something like:
@AppDeepLink(value = "invite/{id}", ifFeatureFlagTrue = "myResource#useA.bool")
public class InviteActivityA ...
@AppDeepLink(value = "invite/{id}", ifFeatureFlagFalse = "myResource#useA.bool")
public class InviteActivityB ...
Then implement the logic to grab the feature flag value in the loader or somewhere. By the way, I'm using Swrve for the feature flags.
This is quite old but I would suggest creating a static function (or Kotlin object nowadays) for the deep link, then inside the handleDeepLink function, check your feature flag and launch the appropriate intent. I think inside the annotation is the wrong place for this logic.
Example (this uses Dagger/Hilt for injection of the featureFlag):
@AppDeepLink("invite/{id}")
object InviteDeepLinkHandler : DeepLinkHandler<Args> {
@EntryPoint
@InstallIn(SingletonComponent::class)
interface Dependencies {
fun getFeatureFlag(): FeatureFlag
}
private fun getDependencies(@ApplicationContext context: Context): Dependencies = EntryPointAccessors.fromApplication(
context,
Dependencies::class.java
)
data class Args(@DeeplinkParam(name ="id", DeepLinkParamType.Path) val id: String)
override fun handleDeepLink(context: Context, deepLinkArgs: Args) {
val featureFlag = getDependencies(context).getFeatureFlag();
if (featureFlag.showActivityA) {
context.startActivity(Intent(context, InviteActivityA::class.java))
} else {
context.startActivity(Intent(context, InviteActivityB::class.java))
}
}
}