Skip to content

Instantly share code, notes, and snippets.

@fayaz07
Created September 3, 2022 01:30
Show Gist options
  • Save fayaz07/fa13fbf17d59dce5bd3cf3dddeb1b3dd to your computer and use it in GitHub Desktop.
Save fayaz07/fa13fbf17d59dce5bd3cf3dddeb1b3dd to your computer and use it in GitHub Desktop.
class MainViewModel(private val todoDao: TodoDao) : ViewModel() {
fun getTodos() = todoDao.getList().asLiveData()
fun toggleTodoStatus(id: Int, updatedStatus: Boolean) {
viewModelScope.launch {
todoDao.toggleTodo(id, updatedStatus)
}
}
override fun onCleared() {
Log.d("test", "viewmodel destroyed")
super.onCleared()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment