Skip to content

Instantly share code, notes, and snippets.

@SubhrajyotiSen
Created June 15, 2017 05:38
Show Gist options
  • Save SubhrajyotiSen/e235cb852f0fbaca3a8836c6cc0d721b to your computer and use it in GitHub Desktop.
Save SubhrajyotiSen/e235cb852f0fbaca3a8836c6cc0d721b to your computer and use it in GitHub Desktop.
public class BorrowedListViewModel extends AndroidViewModel {
private final LiveData<List<BorrowModel>> itemAndPersonList;
private AppDatabase appDatabase;
public BorrowedListViewModel(Application application) {
super(application);
appDatabase = AppDatabase.getDatabase(this.getApplication());
itemAndPersonList = appDatabase.itemAndPersonModel().getAllBorrowedItems();
}
public LiveData<List<BorrowModel>> getItemAndPersonList() {
return itemAndPersonList;
}
public void deleteItem(BorrowModel borrowModel) {
new deleteAsyncTask(appDatabase).execute(borrowModel);
}
private static class deleteAsyncTask extends AsyncTask<BorrowModel, Void, Void> {
private AppDatabase db;
deleteAsyncTask(AppDatabase appDatabase) {
db = appDatabase;
}
@Override
protected Void doInBackground(final BorrowModel... params) {
db.itemAndPersonModel().deleteBorrow(params[0]);
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment