package Account; import android.os.AsyncTask; import androidx.lifecycle.LiveData; import java.util.List; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; public class AccountRepository { private AccountDao mAccountDao; private LiveData mAccountLiveData; private LiveData> mAccountsExceptCurrentAccountLiveData; AccountRepository(RedditDataRoomDatabase redditDataRoomDatabase, String username) { mAccountDao = redditDataRoomDatabase.accountDao(); mAccountLiveData = mAccountDao.getAccountLiveData(username); mAccountsExceptCurrentAccountLiveData = mAccountDao.getAccountsExceptCurrentAccountLiveData(); } LiveData getAccountLiveData() { return mAccountLiveData; } public LiveData> getAccountsExceptCurrentAccountLiveData() { return mAccountsExceptCurrentAccountLiveData; } public void insert(Account Account) { new InsertAsyncTask(mAccountDao).execute(Account); } private static class InsertAsyncTask extends AsyncTask { private AccountDao mAsyncTaskDao; InsertAsyncTask(AccountDao dao) { mAsyncTaskDao = dao; } @Override protected Void doInBackground(final Account... params) { mAsyncTaskDao.insert(params[0]); return null; } } }