KeyPlay Error States
As we are sending the data in fun keyPlaysData(eventID: String): StateFlow<MaestroResource<MaestroKeyPlaysResponse?>>
I have added three error states in MaestroKeyPlaysResponse
data class MaestroKeyPlaysResponse(
val teams: List<MaestroKeyPlaysTeam>? = null,
val athletes: List<MaestroKeyPlaysAthlete>? = null,
val sections: List<MaestroKeyPlaysSection>? = null
)
sealed class MaestroResource<out T> {
data class Success<out T>(val data: T?) : MaestroResource<T>()
data object Loading : MaestroResource<Nothing>()
data class Error(val errorType: MaestroKeyPlaysErrorState?) : MaestroResource<Nothing>()
}
enum class MaestroKeyPlaysErrorState {
UNSUPPORTED_EVENT,
UNPOPULATED_EVENT,
LOAD_FAILURE,
NOT_SPECIFIED // or just send null
}
//now you can send data like
maestroKeyPlaysResponse.emit(MaestroResource.Success(FakeDataUtil.parseJsonToObjects()))
maestroKeyPlaysResponse.emit(MaestroResource.Success(null))
maestroKeyPlaysResponse.emit(MaestroResource.Loading())
maestroKeyPlaysResponse.emit(MaestroResource.Error(MaestroKeyPlaysErrorState.UNSUPPORTED_EVENT))
maestroKeyPlaysResponse.emit(MaestroResource.Error(MaestroKeyPlaysErrorState.UNPOPULATED_EVENT))
maestroKeyPlaysResponse.emit(MaestroResource.Error(MaestroKeyPlaysErrorState.LOAD_FAILURE))
maestroKeyPlaysResponse.emit(MaestroResource.Error(null))
Error Load Failure
When there is an error on your side and you want to show the retry button for user to try to load again
maestroKeyPlaysResponse.emit(MaestroResource.Error(MaestroKeyPlaysErrorState.LOAD_FAILURE))
Error Unsupported Event
When key play are not supported on specific event
maestroKeyPlaysResponse.emit(MaestroResource.Error(MaestroKeyPlaysErrorState.UNSUPPORTED_EVENT))
Error Unpopulated Event
If you want to show the loading screen then you can use this
maestroKeyPlaysResponse.emit(MaestroResource.Error(MaestroKeyPlaysErrorState.UNPOPULATED_EVENT))
// or
maestroKeyPlaysResponse.emit(MaestroResource.Loading())
Single Clip failure
When any clip is failed to play the you should call
maestroEventViewModel?.clipDidFailToPlay(index)
If you played the failed clip from clicking the panel clip and the focus stays there for 5sec then only panel will play next clip and move focus to it