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 e1e54fe..784795f 100644 --- a/app/src/main/java/com/example/citrusclient/viewmodels/BooksViewModel.java +++ b/app/src/main/java/com/example/citrusclient/viewmodels/BooksViewModel.java @@ -18,39 +18,39 @@ public class BooksViewModel extends ViewModel { private final Retrofit retrofit; - private final BooksRest booksRest; - private final MutableLiveData> booksLiveData; - + private final MutableLiveData> booksIdLiveData; private final MutableLiveData titleLiveData; - private final MutableLiveData colorLiveData; - private final MutableLiveData publicityLiveData; - + private final MutableLiveData favoritedLiveData; private final MutableLiveData errorLiveData; - private final MutableLiveData successDeleteBookLiveData; - private final MutableLiveData delBookErrorLivedata; - public BooksViewModel() { + public BooksViewModel(MutableLiveData> booksIdLiveData) { this.retrofit = new Retrofit.Builder() .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/citrus/") .addConverterFactory(JacksonConverterFactory.create()) .build(); this.booksRest = retrofit.create(BooksRest.class); this.booksLiveData = new MutableLiveData<>(); + this.booksIdLiveData = booksIdLiveData; this.titleLiveData = new MutableLiveData<>(); this.colorLiveData = new MutableLiveData<>(); this.publicityLiveData = new MutableLiveData<>(); + this.favoritedLiveData = new MutableLiveData<>(); this.errorLiveData = new MutableLiveData<>(); this.successDeleteBookLiveData = new MutableLiveData<>(); this.delBookErrorLivedata = new MutableLiveData<>(); } - public MutableLiveData> getBookLiveData() { return this.booksLiveData;} + public MutableLiveData> getBookLiveData() { return this.booksLiveData;}//本の一覧を返す + public MutableLiveData> getBooksIdLiveData() {return this.booksIdLiveData;}//本の情報を取得 + public MutableLiveData getTitleLiveData() {return this.titleLiveData;}//本のタイトルを返す + public MutableLiveData getPublicityLiveData() {return this.publicityLiveData;}//本の公開状態を返す + public MutableLiveData getSuccessDeleteBookLiveData() {return successDeleteBookLiveData;} @@ -83,7 +83,6 @@ @Override public void onResponse(Call> call, Response> response) { if (response.isSuccessful()) { - System.out.println(response.code()); HashMap book = response.body(); booksLiveData.setValue(book); System.out.println(response.code()); @@ -96,13 +95,6 @@ } }); } -// private void setBooksLiveData(HashMap bookall){ -// HashMap books = new HashMap<>(); -// for(int i = 0; bookall.get(i).keySet().equals(null); i++){ -// -// } -// booksLiveData.setValue(books); -// } public void deleteBook(String account_id, Integer book_id, String token){ Call call = booksRest.deleteBook(account_id, book_id, token); @@ -111,7 +103,7 @@ @Override public void onResponse(Call call, Response response) { if (response.isSuccessful()) { - deleteBookLiveData(account_id, book_id); + successDeleteBookLiveData.setValue(true); System.out.println("DELETE"); } else { System.out.println("response error"); @@ -125,10 +117,16 @@ }); } - private void deleteBookLiveData(String account_id, Integer book_id) { - ArrayList delData = new ArrayList<>(); - - } + /*private void deleteBookLiveData(String account_id, Integer book_id) { + HashMap delData = new HashMap<>(); + for (Book book: booksLiveData.getValue()) { + if (book.getBookId().equals(book_id)) { + continue; + } + delData.add(book); + } + booksLiveData.setValue(delData); + }*/ public void setTitle(String account_id, Integer book_id, String title, String token){ Call call = booksRest.putTitle(account_id, book_id, title, token);