Beagle Multiple Instances é um recurso que permite a inicialização de fluxos server driven distintos com configurações de Beagle independentes. Isso permite que cada fluxo tenha seus próprios componentes, base url, ações, http client, etc.
Neste exemplo, você criará uma classe para definir a configuração do beagle.
Nesta etapa você pode configurar widgets, ações, httpclients e todas as outras configurações aceitas pelo beagle.
private const val CONFIG_NAME = "BeagleSetupNew"
class BeagleSetupNew: BeagleSdkWrapper {
override val logger = beagleConfigFactory<BeagleLogger> {
BeagleLoggerDefault()
}
override val config = beagleConfigFactory<BeagleConfig> {
it.logInfo("$CONFIG_NAME:config")
AppBeagleConfig()
}
override val deepLinkHandler = beagleConfigFactory<DeepLinkHandler> {
it.logInfo("$CONFIG_NAME:deepLinkHandler")
AppDeepLinkHandler()
}
override val httpClientFactory = beagleConfigFactory<HttpClientFactory> {
it.logInfo("$CONFIG_NAME:httpClientFactory")
AppHttpClientFactory()
}
override val designSystem = beagleConfigFactory<DesignSystem> {
it.logInfo("$CONFIG_NAME:designSystem")
AppDesignSystem()
}
override val imageDownloader = beagleConfigFactory {
it.logInfo("BeagleSetupSecond:imageDownloader")
imageDownloaderObject
}
override val viewClient = beagleConfigFactory<ViewClient> {
it.logInfo("BeagleSetupSecond:viewClient")
AppViewClient(it.asBeagleSdk().httpClientFactory?.create())
}
override val controllerReference = beagleConfigFactory {
it.logInfo("$CONFIG_NAME:controllerReference")
beagleControllerReferenceObject
}
override val typeAdapterResolver = beagleConfigFactory {
it.logInfo("$CONFIG_NAME:typeAdapterResolver")
typeAdapterObject
}
override val analyticsProvider = beagleConfigFactory<AnalyticsProvider> {
it.logInfo("$CONFIG_NAME:analyticsProvider")
AppAnalytics()
}
override val urlBuilder = beagleConfigFactory<UrlBuilder> {
it.logInfo("$CONFIG_NAME:urlBuilder")
AppUrlBuilder()
}
override fun registeredWidgets() =
beagleConfigFactory {
it.logInfo("$CONFIG_NAME:registeredWidgets")
listOf(
Text3::class.java as Class<WidgetView>,
Input::class.java as Class<WidgetView>)
}
override fun registeredActions() =
beagleConfigFactory {
it.logInfo("$CONFIG_NAME:registeredActions")
listOf(
br.com.zup.beagle.sample.actions.CustomAndroidAction::class.java as Class<Action>,
)
}
override fun registeredOperations() =
beagleConfigFactory {
it.logInfo("$CONFIG_NAME:registeredOperations")
mapOf<String, Operation>(
"isValidCpf" to br.com.zup.beagle.sample.operations.IsValidCPFOperation(),
)
}
}
fun BeagleSdkWrapper.logInfo(message: String) {
this.asBeagleSdk().logger?.info(message)
}
fun BeagleSdkWrapper.logWarning(message: String) {
this.asBeagleSdk().logger?.warning(message)
}
fun BeagleSdkWrapper.logError(message: String, throwable: Throwable? = null) {
if (throwable != null) {
this.asBeagleSdk().logger?.error(message, throwable)
} else {
this.asBeagleSdk().logger?.error(message)
}
}
A função newServerDrivenIntent é responsável por exibir uma tela server driven. Para definir que esta tela usará a configuração definida acima, faça:
startActivity(
newServerDrivenIntent<ServerDrivenActivity>(
screenJson = SCREEN_JSON,
beagleSdk = BeagleSetupNew()
)
)
// or
startActivity(
newServerDrivenIntent<ServerDrivenActivity>(
requestData = RequestData(SAMPLE_ENDPOINT),
beagleSdk = BeagleSetupNew()
)
)
// or
binding.fragmentContent.loadView(
this,
RequestData("https://usebeagle.io/start/welcome"),
beagleSdk = BeagleSetupNew()
)
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.