| |
---|
| | |
---|
| | import com.example.citrusclient.Citrus; |
---|
| | import com.example.citrusclient.R; |
---|
| | import com.example.citrusclient.models.Book; |
---|
| | import com.example.citrusclient.models.Schedule; |
---|
| | import com.example.citrusclient.models.Todo; |
---|
| | import com.example.citrusclient.viewmodels.ScheduleViewModel; |
---|
| | import com.example.citrusclient.viewmodels.TodosViewModel; |
---|
| | import com.google.android.material.floatingactionbutton.FloatingActionButton; |
---|
| | |
---|
| | import java.util.ArrayList; |
---|
| |
---|
| | mParam2 = getArguments().getString(ARG_PARAM2); |
---|
| | } |
---|
| | |
---|
| | todosViewModel = new ViewModelProvider(this).get(TodosViewModel.class); |
---|
| | scheduleViewModel = new ViewModelProvider(this).get(ScheduleViewModel.class); |
---|
| | |
---|
| | } |
---|
| | |
---|
| | |
---|
| |
---|
| | } |
---|
| | |
---|
| | private List<Todo> todoList; |
---|
| | TodosViewModel todosViewModel; |
---|
| | private List<Schedule> scheduleList; |
---|
| | ScheduleViewModel scheduleViewModel; |
---|
| | |
---|
| | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { |
---|
| | super.onViewCreated(view, savedInstanceState); |
---|
| | |
---|
| |
---|
| | String token = citrus.getToken(); |
---|
| | String accountId = citrus.getAccountId(); |
---|
| | |
---|
| | todoList = new ArrayList<>(); |
---|
| | todoList.add(new Todo("a", true, 2024, 06, 27, 1)); |
---|
| | |
---|
| | RecyclerView recyclerView = view.findViewById(R.id.my_todos_list); |
---|
| | recyclerView.setHasFixedSize(true); |
---|
| | todoList.add(new Todo("a", true, 2024, 7, 2, 1)); |
---|
| | scheduleList = new ArrayList<>(); |
---|
| | scheduleList.add(new Schedule("a", "1", "1", 1, 1)); |
---|
| | |
---|
| | |
---|
| | RecyclerView todoRecyclerView = view.findViewById(R.id.my_todos_list); |
---|
| | todoRecyclerView.setHasFixedSize(true); |
---|
| | RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(view.getContext()); |
---|
| | recyclerView.setLayoutManager(layoutManager); |
---|
| | todoRecyclerView.setLayoutManager(layoutManager); |
---|
| | MyTodoshelfAdapter todoAdapter = new MyTodoshelfAdapter(todoList); |
---|
| | recyclerView.setAdapter(todoAdapter); |
---|
| | todoRecyclerView.setAdapter(todoAdapter); |
---|
| | |
---|
| | RecyclerView scheduleRecyclerView = view.findViewById(R.id.my_schedule_list); |
---|
| | scheduleRecyclerView.setHasFixedSize(true); |
---|
| | RecyclerView.LayoutManager scheduleLayoutManager = new LinearLayoutManager(view.getContext()); |
---|
| | scheduleRecyclerView.setLayoutManager(scheduleLayoutManager); |
---|
| | MyScheduleshelfAdapter scheduleAdapter = new MyScheduleshelfAdapter(scheduleList); |
---|
| | scheduleRecyclerView.setAdapter(scheduleAdapter); |
---|
| | |
---|
| | todosViewModel.getTodosByDayLiveData().observe(getViewLifecycleOwner(), new Observer<HashMap<Integer, Todo>>() { |
---|
| | @Override |
---|
| | public void onChanged(HashMap<Integer, Todo> idTodoHashMap) { |
---|
| |
---|
| | } |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | todosViewModel.loadTodosByDay("bird", 1, 2024, 6, 2, "xyz"); |
---|
| | scheduleViewModel.getSchedulesByDay().observe(getViewLifecycleOwner(), new Observer<HashMap<Integer, Schedule>>() { |
---|
| | @Override |
---|
| | public void onChanged(HashMap<Integer, Schedule> idScheduleHashMap) { |
---|
| | if(idScheduleHashMap != null) { |
---|
| | scheduleList = new ArrayList<>(idScheduleHashMap.values()); |
---|
| | scheduleAdapter.setSchedules(scheduleList); |
---|
| | } |
---|
| | } |
---|
| | }); |
---|
| | scheduleViewModel.updateSchedulesByDay("bird", 2024, 5, 28, "xyz"); |
---|
| | todosViewModel.loadTodosByDay("bird", 1, 2024, 7, 2, "xyz"); |
---|
| | |
---|
| | } |
---|
| | |
---|
| | } |
---|
| | |
---|
| | class MyTodoshelfAdapter extends RecyclerView.Adapter<MyTodoshelfAdapter.MyTodoViewHolder> { |
---|
| | |
---|
| | private List<Todo> todoList; |
---|
| | |
---|
| | MyTodoshelfAdapter(List<Todo> todo) { |
---|
| | this.todoList = todo; |
---|
| | MyTodoshelfAdapter(List<Todo> todos) { |
---|
| | this.todoList = todos; |
---|
| | } |
---|
| | |
---|
| | public void setTodos(List<Todo> todos) { |
---|
| | todoList = todos; |
---|
| |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | class MyScheduleshelfAdapter extends RecyclerView.Adapter<MyScheduleshelfAdapter.MyScheduleViewHolder> { |
---|
| | |
---|
| | private List<Schedule> scheduleList; |
---|
| | |
---|
| | MyScheduleshelfAdapter(List<Schedule> schedules) { |
---|
| | this.scheduleList = schedules; |
---|
| | } |
---|
| | |
---|
| | public void setSchedules(List<Schedule> schedules) { |
---|
| | scheduleList = schedules; |
---|
| | notifyDataSetChanged(); |
---|
| | } |
---|
| | |
---|
| | @NonNull |
---|
| | @Override |
---|
| | public MyScheduleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
---|
| | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.a_schedule, parent, false); |
---|
| | return new MyScheduleViewHolder(view); |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public void onBindViewHolder(@NonNull MyScheduleViewHolder holder, int position) { |
---|
| | Schedule scheduleData = this.scheduleList.get(position); |
---|
| | holder.scheduleButton.setText(scheduleData.getTitle()); |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public int getItemCount() { |
---|
| | return scheduleList.size(); |
---|
| | } |
---|
| | |
---|
| | static class MyScheduleViewHolder extends RecyclerView.ViewHolder { |
---|
| | Button scheduleButton; |
---|
| | public MyScheduleViewHolder(@NonNull View itemView) { |
---|
| | super(itemView); |
---|
| | scheduleButton = itemView.findViewById(R.id.schedule_button); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | |