Skip to content

Instantly share code, notes, and snippets.

@jjjlyn
Last active May 19, 2020 02:38
Show Gist options
  • Save jjjlyn/219b45f25050ff6580d7d368b82f3ad2 to your computer and use it in GitHub Desktop.
Save jjjlyn/219b45f25050ff6580d7d368b82f3ad2 to your computer and use it in GitHub Desktop.
class HistoryViewModel : ViewModel() {
private val mAppDatabase : AppDatabase
private val mHistoryDAO: HistoryDAO
private val mDate = MutableLiveData<String>()
init {
mAppDatabse = AppDatabase.getAppDatabase()
mHistoryDAO = mAppDatabase.historyDAO()
}
val date : LiveData<String>
get() = mDate
fun loadHistory() : LiveData<History> {
return Transformations.switchMap(mDate) { date ->
mHistoryDAO.loadHistory(date)
}
}
fun setDate(date: String){
mDate.value = date
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment