Using the Android Renderer

Project requirements

The Android Renderer sdk was built using the following tool versions:
  • Gradle 6.5
  • SDK Build Tools 4.1.2
  • Kotlin 1.5.31
  • Koin 3.1.3

Installing the library

The SDK works with apps that use Koin for DI and LiveData

Add dependency

  • Add Nexus repository details in the project settings.gradle file
1
maven {
2
credentials {
3
username "USERNAME"
4
password "PASSWORD"
5
}
6
url 'NEXUS_REPO_URL'
7
8
}
Copied!
  • Add the dependency in the module-level build.gradle file
1
implementation "ai.flowx.android:android-sdk:1.0.1"
Copied!

Using the library

Configure the process renderer

1
ProcessRenderer.Builder()
2
.baseApiUrl(YOUR_API)
3
.tokenCall { YOUR_TOKEN }
4
.useAuthenticator(YOUR_AUTHENTICATOR)
5
.addInterceptor(YOUR_INTERCEPTOR) //optional
6
.apiDateFormat(YOUR_API_DATE_FORMAT)
7
.build()
Copied!

Usage

Implement ProcessRenderer.Listener and its method display(templateConfig: FXTemplateConfig) and register for listening
1
class MainViewModel: ProcessRenderer.Listener {
2
3
private val flowX: ProcessRenderer by inject()
4
5
override fun display(templateConfig: FXTemplateConfig) {
6
when (templateConfig.componentIdentifier) {
7
// navigate to the required UI component based on the componentIdentifier
8
}
9
}
10
11
fun register() {
12
flowX.addListener(this)
13
}
14
15
fun unregister() {
16
flowX.removeListener(this)
17
}
18
}
Copied!
It is recommended to unregister from listening in order to avoid unwanted behavior.

Start a process:

1
flowx.startProcess(processName: String, processData: Any, replaceProcess: Boolean)
Copied!
processName - the name of the process
processData - request body for starting the process (if needed)
replaceProcess - start a process by replacing the existing process (default is false)

Listen for data

1
class BaseFXViewModel : BaseViewModel() {
2
3
internal val flowX: ProcessRenderer by inject()
4
var actions: List<Action> = emptyList()
5
lateinit var data: YOUR_CLASS
6
private val dataObserver = Observer<JsonObject> {
7
data = it.toString().fromJson(gson, YOUR_CLASS)
8
processData()
9
}
10
11
private val actionsObserver = Observer<Array<Action>> {
12
actions = it.toList()
13
processData()
14
}
15
16
fun startListening() {
17
flowX.observeData(YOUR_PROCESS_NAME, YOUR_COMPONENT_NAME) { dataLiveData, actionsLiveData ->
18
19
dataLiveData.observeForever(dataObserver)
20
actionsLiveData.observeForever(actionsObserver)
21
}
22
}
23
24
fun clear {
25
flowX.observeData(YOUR_PROCESS_NAME, YOUR_COMPONENT_NAME) { dataLiveData, actionsLiveData ->
26
dataLiveData.removeObserver(dataObserver)
27
actionsLiveData.removeObserver(actionsObserver)
28
}
29
}
30
}
Copied!

Run an action

The classic way to run an action is:
1
flowX.executeAction(YOUR_PROCESS_NAME, action, customParams, {
2
// action executed successfully
3
4
}, {
5
// error
6
})
Copied!
where customParams represents the custom parameters that should be sent for this action; usually a JSONObject
In order to run an internal action, you need to call the following method:
1
flowX.executeInternalAction(processId, tokenId, actionName, { fxResult->
2
fxResult.handle(onSuccess, onError)
Copied!

Cleanup

You can dismiss one process by running the following:
1
flowX.dismissProcess(YOUR_PROCESS_NAME)
Copied!
You can dismiss all the existing processes and close all the socket connections using:
1
flowX.clear()
Copied!
Last modified 2d ago