Created
June 15, 2017 05:38
-
-
Save SubhrajyotiSen/e235cb852f0fbaca3a8836c6cc0d721b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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