diff --git a/app/src/main/java/com/example/citrusclient/rest/TodosRest.java b/app/src/main/java/com/example/citrusclient/rest/TodosRest.java index 3b38e87..a23a4f3 100644 --- a/app/src/main/java/com/example/citrusclient/rest/TodosRest.java +++ b/app/src/main/java/com/example/citrusclient/rest/TodosRest.java @@ -80,6 +80,22 @@ @Field("token") String token ); + @FormUrlEncoded + @PUT("accounts/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}") + Call setTodo( + @Path("account_id") String accountId, + @Path("book_id") Integer bookId, + @Path("year") Integer year, + @Path("month") Integer month, + @Path("day") Integer day, + @Path("todo_id") Integer todoId, + @Field("title") String title, + @Field("new_year") Integer newYear, + @Field("new_month") Integer newMonth, + @Field("new_day") Integer newDay, + @Field("token") String token + ); + @DELETE("accounts/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}") Call deleteTodoById( @Path("account_id") String accountId, 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 bfb88d3..857f912 100644 --- a/app/src/main/java/com/example/citrusclient/viewmodels/TodosViewModel.java +++ b/app/src/main/java/com/example/citrusclient/viewmodels/TodosViewModel.java @@ -27,6 +27,7 @@ private final MutableLiveData> todosByDayLiveData; private final MutableLiveData todoLiveData; private final MutableLiveData successSetCheckLiveData; + private final MutableLiveData successSetTodoLiveData; private final MutableLiveData successDeleteTodoLiveData; private final MutableLiveData errorLiveData; @@ -43,6 +44,7 @@ this.todosByDayLiveData = new MutableLiveData<>(); this.todoLiveData = new MutableLiveData<>(); this.successSetCheckLiveData = new MutableLiveData<>(); + this.successSetTodoLiveData = new MutableLiveData<>(); this.successDeleteTodoLiveData = new MutableLiveData<>(); this.errorLiveData = new MutableLiveData<>(); } @@ -56,6 +58,7 @@ public MutableLiveData> getTodosByDayLiveData() {return todosByDayLiveData;} public MutableLiveData getTodoLiveData() {return todoLiveData;} public MutableLiveData getSuccessSetCheckLiveData() {return successSetCheckLiveData;} + public MutableLiveData getSuccessSetTodoLiveData() {return successSetTodoLiveData;} public MutableLiveData getSuccessDeleteTodoLiveData() {return successDeleteTodoLiveData;} public MutableLiveData getErrorLiveData() {return errorLiveData;} @@ -197,6 +200,28 @@ }); } + public void setTodo(String accountId, Integer BookId, Integer year, Integer month, Integer day, + Integer todoId, String title, Integer newYear,Integer newMonth,Integer newDay, String token) + { + Call call = todosRest.setTodo(accountId, BookId, year, month, day, todoId, title, newYear, newMonth, newDay, token); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + System.out.println("Success: setTodo"); + successSetTodoLiveData.setValue(true); + } else { + System.out.println("Error: setTodo" + response.code()); + } + } + @Override + public void onFailure(Call call, Throwable t) { + System.out.println("NetworkError : setTodo" + t); + errorLiveData.setValue(parseStatusCode(-1)); + } + }); + } + public void deleteTodo(String accountId, Integer BookId, Integer year, Integer month, Integer day, Integer todoId, String token) { diff --git a/app/src/main/java/com/example/citrusclient/views/CreateTodoFragment.java b/app/src/main/java/com/example/citrusclient/views/CreateTodoFragment.java index ed88dab..5aef3d3 100644 --- a/app/src/main/java/com/example/citrusclient/views/CreateTodoFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/CreateTodoFragment.java @@ -244,8 +244,17 @@ Snackbar.make(view, "本を選択してください", Snackbar.LENGTH_SHORT).show(); return; } - todosViewModel.createTodo(accountId,spinner.getSelectedItemPosition(),year,month,day,title,token); - ((MainActivity)getActivity()).backFragment(); + if(isEdit){ + //編集時 + todosViewModel.setTodo(accountId,spinner.getSelectedItemPosition(),editTodo.getYear(),editTodo.getMonth(), + editTodo.getDay(), editTodo.getTodoId(), title, year, month, day, token); + ((MainActivity)getActivity()).backFragment(); + }else{ + //追加時 + todosViewModel.createTodo(accountId,spinner.getSelectedItemPosition(),year,month,day,title,token); + ((MainActivity)getActivity()).backFragment(); + } + }); }