diff --git a/app/src/main/java/com/example/citrusclient/viewmodels/TodosViewModel.java b/app/src/main/java/com/example/citrusclient/viewmodels/TodosViewModel.java index 9246ef4..79e9411 100644 --- a/app/src/main/java/com/example/citrusclient/viewmodels/TodosViewModel.java +++ b/app/src/main/java/com/example/citrusclient/viewmodels/TodosViewModel.java @@ -9,6 +9,7 @@ import java.util.ArrayList; +import java.util.HashMap; import retrofit2.Call; import retrofit2.Callback; @@ -21,8 +22,10 @@ private final TodosRest todosRest; //LiveData - private final MutableLiveData curBookLiveData; - private final MutableLiveData> todosLiveData; + private final MutableLiveData>>>> allTodosLiveData; + private final MutableLiveData>> TodosByMonthLiveData; + private final MutableLiveData> TodosByDayLiveData; + private final MutableLiveData TodoByIdLiveData; private final MutableLiveData errorLiveData; //Constructor @@ -33,32 +36,37 @@ .addConverterFactory(JacksonConverterFactory.create()) .build(); this.todosRest = retrofit.create(TodosRest.class); - this.curBookLiveData = new MutableLiveData<>(); - this.todosLiveData = new MutableLiveData<>(); + this.allTodosLiveData = new MutableLiveData<>(); + this.TodosByMonthLiveData = new MutableLiveData<>(); + this.TodosByDayLiveData = new MutableLiveData<>(); + this.TodoByIdLiveData = new MutableLiveData<>(); this.errorLiveData = new MutableLiveData<>(); } //getter - public MutableLiveData getCurBookLiveData() {return curBookLiveData;} - public MutableLiveData> getTodosLiveData() {return todosLiveData;} + public MutableLiveData>>>> getTodosLiveData() + { + return allTodosLiveData; + } public MutableLiveData getErrorLiveData() {return errorLiveData;} + public void getAllTodos(String accountId,Integer bookId, String token) { - Call> call = todosRest.getAllTodos(accountId, bookId, token); - call.enqueue(new Callback>() { + Call>>>> call = todosRest.getAllTodos(accountId, bookId, token); + call.enqueue(new Callback>>>>() { @Override - public void onResponse(Call> call, Response> response) { + public void onResponse(Call>>>> call, Response>>>> response) { if (response.isSuccessful()) { System.out.println("Success: getAllTodos"); - + allTodosLiveData.setValue(response.body()); } else { System.out.println("Error: getAllTodos" + response.code()); errorLiveData.setValue(parseStatusCode(response.code())); } } @Override - public void onFailure(Call> call, Throwable t) { + public void onFailure(Call>>>> call, Throwable t) { System.out.println("UnknownError: getAllTodos" + t); errorLiveData.setValue(parseStatusCode(-1)); } @@ -69,19 +77,19 @@ public void getTodosByMonth(String accountId,Integer bookId, Integer year, Integer month, String token) { - Call> call = todosRest.getTodosByMonth(accountId, bookId, year, month, token); - call.enqueue(new Callback>() { + Call>> call = todosRest.getTodosByMonth(accountId, bookId, year, month, token); + call.enqueue(new Callback>>() { @Override - public void onResponse(Call> call, Response> response) { + public void onResponse(Call>> call, Response>> response) { if (response.isSuccessful()) { System.out.println("Success: getTodosByMonth"); - + TodosByMonthLiveData.setValue(response.body()); } else { System.out.println("Error: getTodosByMonth" + response.code()); } } @Override - public void onFailure(Call> call, Throwable t) { + public void onFailure(Call>> call, Throwable t) { System.out.println("UnknownError: getTodosByMonth" + t); errorLiveData.setValue(parseStatusCode(-1)); } @@ -92,19 +100,19 @@ public void getTodosByDay(String accountId,Integer bookId, Integer year, Integer month, Integer day, String token) { - Call> call = todosRest.getTodosByDay(accountId, bookId, year, month, day, token); - call.enqueue(new Callback>() { + Call> call = todosRest.getTodosByDay(accountId, bookId, year, month, day, token); + call.enqueue(new Callback>() { @Override - public void onResponse(Call> call, Response> response) { + public void onResponse(Call> call, Response> response) { if (response.isSuccessful()) { System.out.println("Success: getTodosByDay"); - + TodosByDayLiveData.setValue(response.body()); } else { System.out.println("Error: getTodosByDay" + response.code()); } } @Override - public void onFailure(Call> call, Throwable t) { + public void onFailure(Call> call, Throwable t) { System.out.println("UnknownError: getTodosByDay" + t); errorLiveData.setValue(parseStatusCode(-1)); } @@ -121,7 +129,7 @@ public void onResponse(Call call, Response response) { if (response.isSuccessful()) { System.out.println("Success: getTodoById"); - + TodoByIdLiveData.setValue(response.body()); } else { System.out.println("Error: getTodoById" + response.code()); }