Skip to content

Instantly share code, notes, and snippets.

@MwBakker
Created September 25, 2018 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MwBakker/d51e2b0a3dd3dbfafdfc46225e713753 to your computer and use it in GitHub Desktop.
Save MwBakker/d51e2b0a3dd3dbfafdfc46225e713753 to your computer and use it in GitHub Desktop.
public class WordRepository {
private WordDao mWordDao;
private LiveData<List<Word>> mAllWords;
WordRepository(Application application) {
WordRoomDatabase db = WordRoomDatabase.getDatabase(application);
mWordDao = db.wordDao();
mAllWords = mWordDao.getAllWords();
}
LiveData<List<Word>> getAllWords() {
return mAllWords;
}
public void insert (Word word) {
new insertAsyncTask(mWordDao).execute(word);
}
private static class insertAsyncTask extends AsyncTask<Word, Void, Void> {
private WordDao mAsyncTaskDao;
insertAsyncTask(WordDao dao) {
mAsyncTaskDao = dao;
}
@Override
protected Void doInBackground(final Word... params) {
mAsyncTaskDao.insert(params[0]);
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment