diff --git a/app/src/main/java/com/example/citrusclient/viewmodels/BooksViewModel.java b/app/src/main/java/com/example/citrusclient/viewmodels/BooksViewModel.java index cbf3f2a..e96c043 100644 --- a/app/src/main/java/com/example/citrusclient/viewmodels/BooksViewModel.java +++ b/app/src/main/java/com/example/citrusclient/viewmodels/BooksViewModel.java @@ -20,6 +20,7 @@ private final Retrofit retrofit; private final BooksRest booksRest; private final MutableLiveData> booksLiveData; + private final MutableLiveData book; private final MutableLiveData titleLiveData; private final MutableLiveData colorLiveData; private final MutableLiveData publicityLiveData; @@ -36,12 +37,15 @@ this.colorLiveData = new MutableLiveData<>(); this.publicityLiveData = new MutableLiveData<>(); this.favoritedLiveData = new MutableLiveData<>(); + this.book = new MutableLiveData<>(); } public MutableLiveData> getBookLiveData() { return this.booksLiveData;}//本の一覧を返す public MutableLiveData getTitleLiveData() {return this.titleLiveData;}//本のタイトルを返す public MutableLiveData getPublicityLiveData() {return this.publicityLiveData;}//本の公開状態を返す + public MutableLiveData getBook() {return this.book;}; + public void createBook(String accountId, String title, String color, Boolean publicity, String token ){ Call> call = booksRest.createBook(accountId , title, color, publicity, token); @@ -84,6 +88,23 @@ }); } + public void loadBook(String accountId, String token, int bookId) { + Call call = booksRest.getBook(accountId, bookId, token); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if(response.isSuccessful()) { + book.setValue(response.body()); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + System.out.println("network error"); + } + }); + } + public void deleteBook(String accountId, Integer bookId, String token){ Call> call = booksRest.deleteBook(accountId, bookId, token);