2019-08-07 04:54:47 +02:00
|
|
|
package Account;
|
|
|
|
|
|
|
|
import android.os.AsyncTask;
|
|
|
|
|
|
|
|
import androidx.lifecycle.LiveData;
|
|
|
|
|
2019-08-07 17:28:02 +02:00
|
|
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
|
|
|
|
2019-08-07 04:54:47 +02:00
|
|
|
public class AccountRepository {
|
|
|
|
private AccountDao mAccountDao;
|
|
|
|
private LiveData<Account> mAccountLiveData;
|
|
|
|
|
2019-08-07 17:28:02 +02:00
|
|
|
AccountRepository(RedditDataRoomDatabase redditDataRoomDatabase, String username) {
|
|
|
|
mAccountDao = redditDataRoomDatabase.accountDao();
|
2019-08-07 04:54:47 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|