aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/Account/AccountRepository.java
blob: c495579d7ef4bc9efce51f3e50b15f966b4c9c1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package Account;

import android.os.AsyncTask;

import androidx.lifecycle.LiveData;

import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;

public class AccountRepository {
    private AccountDao mAccountDao;
    private LiveData<Account> mAccountLiveData;

    AccountRepository(RedditDataRoomDatabase redditDataRoomDatabase, String username) {
        mAccountDao = redditDataRoomDatabase.accountDao();
        mAccountLiveData = mAccountDao.getAccountLiveData(username);
    }

    LiveData<Account> getAccountLiveData() {
        return mAccountLiveData;
    }

    public void insert(Account Account) {
        new InsertAsyncTask(mAccountDao).execute(Account);
    }

    private static class InsertAsyncTask extends AsyncTask<Account, Void, Void> {

        private AccountDao mAsyncTaskDao;

        InsertAsyncTask(AccountDao dao) {
            mAsyncTaskDao = dao;
        }

        @Override
        protected Void doInBackground(final Account... params) {
            mAsyncTaskDao.insert(params[0]);
            return null;
        }
    }
}