aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditRepository.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditRepository.java')
-rw-r--r--app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditRepository.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditRepository.java b/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditRepository.java
new file mode 100644
index 00000000..54b2ddfa
--- /dev/null
+++ b/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditRepository.java
@@ -0,0 +1,41 @@
+package SubscribedSubredditDatabase;
+
+import android.app.Application;
+import android.arch.lifecycle.LiveData;
+import android.os.AsyncTask;
+
+import java.util.List;
+
+public class SubscribedSubredditRepository {
+ private SubscribedSubredditDao mSubscribedSubredditDao;
+ private LiveData<List<SubscribedSubredditData>> mAllSubscribedSubreddits;
+
+ SubscribedSubredditRepository(Application application) {
+ SubscribedSubredditRoomDatabase db = SubscribedSubredditRoomDatabase.getDatabase(application);
+ mSubscribedSubredditDao = db.subscribedSubredditDao();
+ mAllSubscribedSubreddits = mSubscribedSubredditDao.getAllSubscribedSubreddits();
+ }
+
+ LiveData<List<SubscribedSubredditData>> getAllSubscribedSubreddits() {
+ return mAllSubscribedSubreddits;
+ }
+
+ public void insert(SubscribedSubredditData subscribedSubredditData) {
+ new insertAsyncTask(mSubscribedSubredditDao).execute(subscribedSubredditData);
+ }
+
+ private static class insertAsyncTask extends AsyncTask<SubscribedSubredditData, Void, Void> {
+
+ private SubscribedSubredditDao mAsyncTaskDao;
+
+ insertAsyncTask(SubscribedSubredditDao dao) {
+ mAsyncTaskDao = dao;
+ }
+
+ @Override
+ protected Void doInBackground(final SubscribedSubredditData... params) {
+ mAsyncTaskDao.insert(params[0]);
+ return null;
+ }
+ }
+}