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 f892e37..0a00eb2 100644 --- a/app/src/main/java/com/example/citrusclient/viewmodels/TodosViewModel.java +++ b/app/src/main/java/com/example/citrusclient/viewmodels/TodosViewModel.java @@ -3,18 +3,26 @@ import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; +import com.example.citrusclient.models.Todo; +import com.example.citrusclient.models.Book; import com.example.citrusclient.rest.TodosRest; + +import java.util.ArrayList; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; import retrofit2.Retrofit; import retrofit2.converter.jackson.JacksonConverterFactory; public class TodosViewModel extends ViewModel { - private final Retrofit retrofit; private final TodosRest todosRest; //LiveData - private final MutableLiveData titleLiveData; + private final MutableLiveData curBookLiveData; + private final MutableLiveData> todosLiveData; //Constructor public TodosViewModel() @@ -24,25 +32,156 @@ .addConverterFactory(JacksonConverterFactory.create()) .build(); this.todosRest = retrofit.create(TodosRest.class); - this.titleLiveData = new MutableLiveData<>(); + this.curBookLiveData = new MutableLiveData<>(); + this.todosLiveData = new MutableLiveData>(); } //getter - public MutableLiveData getTitleLiveData() {return titleLiveData;}; + public MutableLiveData getCurBookLiveData() {return curBookLiveData;} + public MutableLiveData> getTodosLiveData() {return todosLiveData;} - public void getTodos() + public void getAllTodos(String accountId,Integer bookId, String token) { + Call> call = todosRest.getAllTodos(accountId, bookId, token); + call.enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + if (response.isSuccessful()) { + } else { + + } + } + @Override + public void onFailure(Call> call, Throwable t) { + System.out.println("ChangePw NetworkError" + t); + } + + }); } - public void putTodo() + 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>() { + @Override + public void onResponse(Call> call, Response> response) { + if (response.isSuccessful()) { + } else { + + } + } + @Override + public void onFailure(Call> call, Throwable t) { + System.out.println("ChangePw NetworkError" + t); + } + + }); } - public void deleteTodo() + 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>() { + @Override + public void onResponse(Call> call, Response> response) { + if (response.isSuccessful()) { + } else { + + } + } + @Override + public void onFailure(Call> call, Throwable t) { + System.out.println("ChangePw NetworkError" + t); + } + + }); + } + + public void getTodoById(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); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + + } else { + + } + } + @Override + public void onFailure(Call call, Throwable t) { + System.out.println("ChangePw NetworkError" + t); + } + + }); + } + + public void createTodo(String accountId,Integer bookId, Integer year, Integer month, + Integer day, String title, String token) + { + Call call = todosRest.createTodo(accountId, bookId, year, month, day, title, token); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + + } else { + + } + } + @Override + public void onFailure(Call call, Throwable t) { + System.out.println("ChangePw NetworkError" + t); + } + + }); + } + + public void setCheck(String accountId, Integer BookId, Integer year, Integer month, + Integer day, Integer todoId, boolean check, String token) + { + Call call = todosRest.setCheck(accountId, BookId, year, month, day, todoId, check, token); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + + } else { + + } + } + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + } + + public void deleteTodo(String accountId, Integer BookId, Integer year, Integer month, + Integer day, Integer todoId, String token) + { + Call call = todosRest.deleteTodoById(accountId, BookId, year, month, day, todoId, token); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + + } else { + + } + } + @Override + public void onFailure(Call call, Throwable t) { + + } + }); } }