Skip to content

Instantly share code, notes, and snippets.

@lopspower
Last active September 30, 2023 10:50
Show Gist options
  • Save lopspower/b84f95ae6e61f87718d324510332409d to your computer and use it in GitHub Desktop.
Save lopspower/b84f95ae6e61f87718d324510332409d to your computer and use it in GitHub Desktop.
ViewModel Kotlin Android Studio Template
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}#end
import com.mstv.presentation.scenes.base.view.ContentState
import com.mstv.presentation.scenes.base.view.LoadingState
data class ${NAME}(val loadingState: LoadingState = LoadingState.NONE,
val contentState: ContentState = ContentState.NONE,
val data: ${DataType}? = null,
val errorMessage: String? = null,
val snackMessage: String? = null) {
companion object {
fun createLoading() = ${NAME}(loadingState = LoadingState.LOADING, contentState = ContentState.CONTENT)
fun createRetryLoading() = ${NAME}(loadingState = LoadingState.RETRY, contentState = ContentState.ERROR)
fun createData(data: ${DataType}) = ${NAME}(contentState = ContentState.CONTENT, data = data)
fun createError(error: String) = ${NAME}(contentState = ContentState.ERROR, errorMessage = error)
fun createSnack(snackMessage: String) = ${NAME}(contentState = ContentState.CONTENT, snackMessage = snackMessage)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment