diff --git a/app/src/main/java/com/example/citrusclient/views/HomeFragment.java b/app/src/main/java/com/example/citrusclient/views/HomeFragment.java index d2f14ab..252b9dc 100644 --- a/app/src/main/java/com/example/citrusclient/views/HomeFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/HomeFragment.java @@ -21,7 +21,9 @@ 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; @@ -76,6 +78,7 @@ } todosViewModel = new ViewModelProvider(this).get(TodosViewModel.class); + scheduleViewModel = new ViewModelProvider(this).get(ScheduleViewModel.class); } @@ -91,6 +94,8 @@ private List todoList; TodosViewModel todosViewModel; + private List scheduleList; + ScheduleViewModel scheduleViewModel; public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -101,14 +106,24 @@ String accountId = citrus.getAccountId(); todoList = new ArrayList<>(); - todoList.add(new Todo("a", true, 2024, 06, 27, 1)); + todoList.add(new Todo("a", true, 2024, 7, 2, 1)); + scheduleList = new ArrayList<>(); + scheduleList.add(new Schedule("a", "1", "1", 1, 1)); - RecyclerView recyclerView = view.findViewById(R.id.my_todos_list); - recyclerView.setHasFixedSize(true); + + 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>() { @Override @@ -120,16 +135,28 @@ } }); - todosViewModel.loadTodosByDay("bird", 1, 2024, 6, 2, "xyz"); + scheduleViewModel.getSchedulesByDay().observe(getViewLifecycleOwner(), new Observer>() { + @Override + public void onChanged(HashMap 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 { private List todoList; - MyTodoshelfAdapter(List todo) { - this.todoList = todo; + MyTodoshelfAdapter(List todos) { + this.todoList = todos; } public void setTodos(List todos) { @@ -166,3 +193,43 @@ } } } + +class MyScheduleshelfAdapter extends RecyclerView.Adapter { + + private List scheduleList; + + MyScheduleshelfAdapter(List schedules) { + this.scheduleList = schedules; + } + + public void setSchedules(List 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); + } + } +}