microsoft/rural-crowdsourcing-toolkit

Make viewmodels consistent with UI objects

Opened this issue · 2 comments

Currently, each scenario/fragments each have its own state-holder class. This is simply a code repetition and is inconsistent in many places.

Instead of having a <Fragment>UiState class separately for each UiState, we can have a common generic class like

sealed class UiState<T>(
    val data: T? = null,
    val message: String? = null
) {
    class Success<T>(data: T) : UiState<T>(data)
    class Error<T>(message: String?, data: T? = null) : UiState<T>(data, message)
    class Loading<T> : UiState<T>()
    class Initial<T> : UiState<T>()
}

Where T would be the type of result we would be expecting. And then we can use this wrapper everywhere, thus maintaining the consistency.

Can be parallelly done with compose migration, so currently blocked by that.