diff --git a/app/src/main/java/com/example/citrusclient/views/CalendarFragment.java b/app/src/main/java/com/example/citrusclient/views/CalendarFragment.java index 4fd89f9..cc44f19 100644 --- a/app/src/main/java/com/example/citrusclient/views/CalendarFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/CalendarFragment.java @@ -12,6 +12,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.LinearLayout; import android.widget.TableLayout; import android.widget.TableRow; import android.widget.TextView; @@ -20,7 +21,9 @@ import com.example.citrusclient.models.Schedule; import com.example.citrusclient.viewmodels.ScheduleViewModel; +import java.io.ObjectInputStream; import java.util.ArrayList; +import java.util.Calendar; import java.util.List; /** @@ -86,22 +89,71 @@ private List scheduleList; ScheduleViewModel scheduleViewModel; + int month; + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); + tableLayout = view.findViewById(R.id.calendarlayout); + Calendar calendar = Calendar.getInstance(); + month = calendar.get(Calendar.MONTH) + 1; + int date = calendar.get(Calendar.DATE); + int lastdate = calendar.getActualMaximum(Calendar.DATE); + int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); + + Button nextMonth = view.findViewById(R.id.nextMonth); + Button prevMonth = view.findViewById(R.id.prevMonth); + TextView curMonth = view.findViewById(R.id.month); + curMonth.setText("" + month + "月"); + nextMonth.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + month++; + if(month > 12){ + month = 1; + } + curMonth.setText("" + month + "月"); + } + }); + + prevMonth.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + month--; + if(month < 1) { + month = 12; + } + curMonth.setText("" + month + "月"); + } + }); + + for(int i = 0; i < 6; i++) { tableRows[i] = (TableRow) tableLayout.getChildAt(i); for(int j = 0; j < 7; j++) { - RecyclerView recyclerView = new RecyclerView(requireContext());//RecyclerView.LayoutParams.MATCH_PARENT + LinearLayout layout = new LinearLayout(requireContext()); + layout.setOrientation(LinearLayout.VERTICAL); + + TextView textView = new TextView(requireContext()); + textView.setText("" + i); + + RecyclerView recyclerView = new RecyclerView(requireContext()); recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); - recyclerView.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT)); + recyclerView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); List schedules = new ArrayList<>(); schedules.add(new Schedule("abc", "3232", "yyyy", 0, 1)); + schedules.add(new Schedule("123", "3232", "yyyy", 0, 2)); recyclerView.setAdapter(new MyScheduleAdapter(schedules)); - TableRow.LayoutParams p = (TableRow.LayoutParams) recyclerView.getLayoutParams(); + LinearLayout.LayoutParams p = (LinearLayout.LayoutParams) recyclerView.getLayoutParams(); p.weight = 1; - tableRows[i].addView(recyclerView); + + layout.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT)); + TableRow.LayoutParams p2 = (TableRow.LayoutParams) layout.getLayoutParams(); + p2.weight = 1; + layout.addView(textView); + layout.addView(recyclerView); + tableRows[i].addView(layout); } } } @@ -119,13 +171,13 @@ } @NonNull @Override - public MyScheduleAdapter.MyScheduleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + public MyScheduleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.a_calendar_schedule, parent, false); return new MyScheduleViewHolder(view); } @Override - public void onBindViewHolder(@NonNull MyScheduleAdapter.MyScheduleViewHolder holder, int position) { + public void onBindViewHolder(@NonNull MyScheduleViewHolder holder, int position) { Schedule scheduleData = this.scheduleList.get(position); holder.scheduleText.setText(scheduleData.getTitle()); }