| |
---|
| | |
---|
| | private final Retrofit retrofit; |
---|
| | private final BooksRest booksRest; |
---|
| | private final MutableLiveData<HashMap<Integer, Book>> booksLiveData; |
---|
| | private final MutableLiveData<Book> book; |
---|
| | private final MutableLiveData<String> titleLiveData; |
---|
| | private final MutableLiveData<String> colorLiveData; |
---|
| | private final MutableLiveData<String> publicityLiveData; |
---|
| | private final MutableLiveData<String> favoritedLiveData; |
---|
| |
---|
| | this.titleLiveData = new MutableLiveData<>(); |
---|
| | this.colorLiveData = new MutableLiveData<>(); |
---|
| | this.publicityLiveData = new MutableLiveData<>(); |
---|
| | this.favoritedLiveData = new MutableLiveData<>(); |
---|
| | this.book = new MutableLiveData<>(); |
---|
| | } |
---|
| | |
---|
| | public MutableLiveData<HashMap<Integer, Book>> getBookLiveData() { return this.booksLiveData;}//本の一覧を返す |
---|
| | public MutableLiveData<String> getTitleLiveData() {return this.titleLiveData;}//本のタイトルを返す |
---|
| | public MutableLiveData<String> getPublicityLiveData() {return this.publicityLiveData;}//本の公開状態を返す |
---|
| | |
---|
| | public MutableLiveData<Book> getBook() {return this.book;}; |
---|
| | |
---|
| | public void createBook(String accountId, String title, String color, Boolean publicity, String token ){ |
---|
| | Call<HashMap<Integer, Book>> call = booksRest.createBook(accountId , title, color, publicity, token); |
---|
| | |
---|
| |
---|
| | } |
---|
| | }); |
---|
| | } |
---|
| | |
---|
| | public void loadBook(String accountId, String token, int bookId) { |
---|
| | Call<Book> call = booksRest.getBook(accountId, bookId, token); |
---|
| | call.enqueue(new Callback<Book>() { |
---|
| | @Override |
---|
| | public void onResponse(Call<Book> call, Response<Book> response) { |
---|
| | if(response.isSuccessful()) { |
---|
| | book.setValue(response.body()); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public void onFailure(Call<Book> call, Throwable t) { |
---|
| | System.out.println("network error"); |
---|
| | } |
---|
| | }); |
---|
| | } |
---|
| | |
---|
| | public void deleteBook(String accountId, Integer bookId, String token){ |
---|
| | Call<HashMap<Integer, Book>> call = booksRest.deleteBook(accountId, bookId, token); |
---|
| | |
---|
| | call.enqueue(new Callback<HashMap<Integer, Book>>() { |
---|
| |
---|
| | |