Created
September 25, 2018 15:05
-
-
Save MwBakker/d51e2b0a3dd3dbfafdfc46225e713753 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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