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 0d9935a..ae0fd60 100644 --- a/app/src/main/java/com/example/citrusclient/viewmodels/TodosViewModel.java +++ b/app/src/main/java/com/example/citrusclient/viewmodels/TodosViewModel.java @@ -23,9 +23,11 @@ //LiveData private final MutableLiveData>>>> allTodosLiveData; - private final MutableLiveData>> TodosByMonthLiveData; - private final MutableLiveData> TodosByDayLiveData; - private final MutableLiveData TodoByIdLiveData; + private final MutableLiveData>> todosByMonthLiveData; + private final MutableLiveData> todosByDayLiveData; + private final MutableLiveData todoLiveData; + private final MutableLiveData successSetCheckLiveData; + private final MutableLiveData successDeleteTodoLiveData; private final MutableLiveData errorLiveData; //Constructor @@ -37,9 +39,11 @@ .build(); this.todosRest = retrofit.create(TodosRest.class); this.allTodosLiveData = new MutableLiveData<>(); - this.TodosByMonthLiveData = new MutableLiveData<>(); - this.TodosByDayLiveData = new MutableLiveData<>(); - this.TodoByIdLiveData = new MutableLiveData<>(); + this.todosByMonthLiveData = new MutableLiveData<>(); + this.todosByDayLiveData = new MutableLiveData<>(); + this.todoLiveData = new MutableLiveData<>(); + this.successSetCheckLiveData = new MutableLiveData<>(); + this.successDeleteTodoLiveData = new MutableLiveData<>(); this.errorLiveData = new MutableLiveData<>(); } @@ -48,13 +52,13 @@ { return allTodosLiveData; } - public MutableLiveData>> getTodosByMonthLiveData() {return TodosByMonthLiveData;} - public MutableLiveData> getTodosByDayLiveData() {return TodosByDayLiveData;} - public MutableLiveData getTodoByIdLiveData() {return TodoByIdLiveData;} + public MutableLiveData>> getTodosByMonthLiveData() {return todosByMonthLiveData;} + public MutableLiveData> getTodosByDayLiveData() {return todosByDayLiveData;} + public MutableLiveData getTodoByIdLiveData() {return todoLiveData;} public MutableLiveData getErrorLiveData() {return errorLiveData;} - public void getAllTodos(String accountId,Integer bookId, String token) + public void loadAllTodos(String accountId,Integer bookId, String token) { Call>>>> call = todosRest.getAllTodos(accountId, bookId, token); call.enqueue(new Callback>>>>() { @@ -70,14 +74,14 @@ } @Override public void onFailure(Call>>>> call, Throwable t) { - System.out.println("CommunicationError: getAllTodos" + t); + System.out.println("NetworkError : getAllTodos" + t); errorLiveData.setValue(parseStatusCode(-1)); } }); } - public void getTodosByMonth(String accountId,Integer bookId, Integer year, Integer month, + public void loadTodosByMonth(String accountId,Integer bookId, Integer year, Integer month, String token) { Call>> call = todosRest.getTodosByMonth(accountId, bookId, year, month, token); @@ -86,21 +90,21 @@ public void onResponse(Call>> call, Response>> response) { if (response.isSuccessful()) { System.out.println("Success: getTodosByMonth"); - TodosByMonthLiveData.setValue(response.body()); + todosByMonthLiveData.setValue(response.body()); } else { System.out.println("Error: getTodosByMonth" + response.code()); } } @Override public void onFailure(Call>> call, Throwable t) { - System.out.println("CommunicationError: getTodosByMonth" + t); + System.out.println("NetworkError : getTodosByMonth" + t); errorLiveData.setValue(parseStatusCode(-1)); } }); } - public void getTodosByDay(String accountId,Integer bookId, Integer year, Integer month, + public void loadTodosByDay(String accountId,Integer bookId, Integer year, Integer month, Integer day, String token) { Call> call = todosRest.getTodosByDay(accountId, bookId, year, month, day, token); @@ -109,21 +113,21 @@ public void onResponse(Call> call, Response> response) { if (response.isSuccessful()) { System.out.println("Success: getTodosByDay"); - TodosByDayLiveData.setValue(response.body()); + todosByDayLiveData.setValue(response.body()); } else { System.out.println("Error: getTodosByDay" + response.code()); } } @Override public void onFailure(Call> call, Throwable t) { - System.out.println("CommunicationError: getTodosByDay" + t); + System.out.println("NetworkError : getTodosByDay" + t); errorLiveData.setValue(parseStatusCode(-1)); } }); } - public void getTodoById(String accountId,Integer bookId, Integer year, Integer month, + public void loadTodoById(String accountId,Integer bookId, Integer year, Integer month, Integer day, Integer todoId, String token) { Call call = todosRest.getTodoById(accountId, bookId, year, month, day, todoId, token); @@ -132,14 +136,14 @@ public void onResponse(Call call, Response response) { if (response.isSuccessful()) { System.out.println("Success: getTodoById"); - TodoByIdLiveData.setValue(response.body()); + todoLiveData.setValue(response.body()); } else { System.out.println("Error: getTodoById" + response.code()); } } @Override public void onFailure(Call call, Throwable t) { - System.out.println("CommunicationError: getTodoById" + t); + System.out.println("NetworkError : getTodoById" + t); errorLiveData.setValue(parseStatusCode(-1)); } @@ -155,14 +159,13 @@ public void onResponse(Call call, Response response) { if (response.isSuccessful()) { System.out.println("Success: createTodo"); - TodoByIdLiveData.setValue(response.body()); } else { System.out.println("Error: createTodo" + response.code()); } } @Override public void onFailure(Call call, Throwable t) { - System.out.println("CommunicationError: createTodo" + t); + System.out.println("NetworkError : createTodo" + t); errorLiveData.setValue(parseStatusCode(-1)); } @@ -178,14 +181,14 @@ public void onResponse(Call call, Response response) { if (response.isSuccessful()) { System.out.println("Success: setCheck"); - + successSetCheckLiveData.setValue(true); } else { System.out.println("Error: setCheck" + response.code()); } } @Override public void onFailure(Call call, Throwable t) { - System.out.println("CommunicationError: setCheck" + t); + System.out.println("NetworkError : setCheck" + t); errorLiveData.setValue(parseStatusCode(-1)); } }); @@ -200,14 +203,14 @@ public void onResponse(Call call, Response response) { if (response.isSuccessful()) { System.out.println("Success: deleteTodo"); - + successDeleteTodoLiveData.setValue(true); } else { System.out.println("Error: deleteTodo" + response.code()); } } @Override public void onFailure(Call call, Throwable t) { - System.out.println("CommunicationError: deleteTodo" + t); + System.out.println("NetworkError : deleteTodo" + t); errorLiveData.setValue(parseStatusCode(-1)); } });