keyPlaysData
Provides a flow of key plays data managed by the client app that the SDK will collect and display.
Overview
This method returns a StateFlow that the SDK observes to get the latest key plays data. Your app is responsible for managing this flow, loading data, and emitting updates whenever the key plays change. The MaestroLoadableResult wrapper allows you to represent loading and error states.
Syntax
abstract fun keyPlaysData(): StateFlow<MaestroLoadableResult<MaestroKeyPlaysResponse>>
Example
class MyActivity : ComponentActivity(), MaestroEventDelegate {
private val _keyPlaysState = MutableStateFlow<MaestroLoadableResult<MaestroKeyPlaysResponse>>(
MaestroLoadableResult.Loading
)
override fun keyPlaysData(): StateFlow<MaestroLoadableResult<MaestroKeyPlaysResponse>> {
return _keyPlaysState
}
// Load key plays data
private suspend fun loadKeyPlays() {
_keyPlaysState.value = MaestroLoadableResult.Loading
try {
val response = apiClient.fetchKeyPlays()
_keyPlaysState.value = MaestroLoadableResult.Success(response)
} catch (e: Exception) {
_keyPlaysState.value = MaestroLoadableResult.Error(e)
}
}
}
Notes
- The SDK observes this flow and automatically updates when values change
- Emit
Loadingstate when fetching new data - Emit
Successwith the response when data loads successfully - Emit
Errorif loading fails - The flow should remain active for the SDK's lifecycle
Related Methods
- onKeyPlaysRefreshNeeded() - SDK requests fresh key plays data