diff --git a/app/src/main/java/com/example/citrusclient/views/CreateScheduleFragment.java b/app/src/main/java/com/example/citrusclient/views/CreateScheduleFragment.java new file mode 100644 index 0000000..8fc862c --- /dev/null +++ b/app/src/main/java/com/example/citrusclient/views/CreateScheduleFragment.java @@ -0,0 +1,181 @@ +package com.example.citrusclient.views; + +import android.app.DatePickerDialog; +import android.app.Dialog; +import android.app.TimePickerDialog; +import android.content.Context; +import android.graphics.Color; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.Fragment; + +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.DatePicker; +import android.widget.Spinner; +import android.widget.Switch; +import android.widget.TimePicker; + +import com.example.citrusclient.R; + +import java.util.Calendar; + +/** + * A simple {@link Fragment} subclass. + * Use the {@link CreateScheduleFragment#newInstance} factory method to + * create an instance of this fragment. + */ +public class CreateScheduleFragment extends Fragment { + + // TODO: Rename parameter arguments, choose names that match + // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER + private static final String ARG_PARAM1 = "param1"; + private static final String ARG_PARAM2 = "param2"; + + // TODO: Rename and change types of parameters + private String mParam1; + private String mParam2; + + public CreateScheduleFragment() { + // Required empty public constructor + } + + /** + * Use this factory method to create a new instance of + * this fragment using the provided parameters. + * + * @param param1 Parameter 1. + * @param param2 Parameter 2. + * @return A new instance of fragment CreateScheduleFragment. + */ + // TODO: Rename and change types and number of parameters + public static CreateScheduleFragment newInstance(String param1, String param2) { + CreateScheduleFragment fragment = new CreateScheduleFragment(); + Bundle args = new Bundle(); + args.putString(ARG_PARAM1, param1); + args.putString(ARG_PARAM2, param2); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { + mParam1 = getArguments().getString(ARG_PARAM1); + mParam2 = getArguments().getString(ARG_PARAM2); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_create_schedule, container, false); + } + + String startDate; + String startTime; + String endDate; + String endTime; + + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + Calendar c = Calendar.getInstance(); + Button startDateButton = view.findViewById(R.id.start_date_button); + Button startTimeButton = view.findViewById(R.id.start_time_button); + Button endDateButton = view.findViewById(R.id.end_date_button); + Button endTimeButton = view.findViewById(R.id.end_time_button); + int year = c.get(Calendar.YEAR); + int month = c.get(Calendar.MONTH); + int day = c.get(Calendar.DAY_OF_MONTH); + int hour = c.get(Calendar.HOUR); + int minute = c.get(Calendar.MINUTE); + + startDateButton.setText(year + "/" + (month + 1) + "/" + day); + startTimeButton.setText("00:00"); + endDateButton.setText(year + "/" + (month + 1) + "/" + day); + endTimeButton.setText("23:59"); + + startDateButton.setOnClickListener(v->{ + DatePickerDialog datePickerDialog = new DatePickerDialog(requireContext(), new DatePickerDialog.OnDateSetListener() { + @Override + public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { + String date = year + "/" + (month + 1) + "/" + dayOfMonth; + startDateButton.setText(date); + } + }, year, month, day); + datePickerDialog.show(); + }); + startTimeButton.setOnClickListener(v -> { + TimePickerDialog timePickerDialog = new TimePickerDialog(requireContext(), new TimePickerDialog.OnTimeSetListener() { + @Override + public void onTimeSet(TimePicker view, int hourOfDay, int minute) { + String time = hourOfDay + ":" + minute; + startTimeButton.setText(time); + } + }, hour, minute, true); + timePickerDialog.show(); + }); + endDateButton.setOnClickListener(v->{ + DatePickerDialog datePickerDialog = new DatePickerDialog(requireContext(), new DatePickerDialog.OnDateSetListener() { + @Override + public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { + String date = year + "/" + (month + 1) + "/" + dayOfMonth; + endDateButton.setText(date); + } + }, year, month, day); + datePickerDialog.show(); + }); + endTimeButton.setOnClickListener(v -> { + TimePickerDialog timePickerDialog = new TimePickerDialog(requireContext(), new TimePickerDialog.OnTimeSetListener() { + @Override + public void onTimeSet(TimePicker view, int hourOfDay, int minute) { + String time = hourOfDay + ":" + minute; + endTimeButton.setText(time); + } + }, hour, minute, true); + timePickerDialog.show(); + }); + + Switch allDaySwitch = view.findViewById(R.id.all_day_switch); + allDaySwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { + if(isChecked){ + startTimeButton.setTextColor(Color.GRAY); + endDateButton.setTextColor(Color.GRAY); + endTimeButton.setTextColor(Color.GRAY); + }else{ + startTimeButton.setTextColor(Color.BLACK); + endDateButton.setTextColor(Color.BLACK); + endTimeButton.setTextColor(Color.BLACK); + } + startTimeButton.setEnabled(!isChecked); + endDateButton.setEnabled(!isChecked); + endTimeButton.setEnabled(!isChecked); + }); + + Button cancelButton = view.findViewById(R.id.schedule_cancel_button); + cancelButton.setOnClickListener(v->{ + ((MainActivity)getActivity()).backFragment(); + }); + + Spinner spinner; + spinner = view.findViewById(R.id.select_book_spinner); + String[] books = {"book1", "book2", "book3"}; + + ArrayAdapter adapter = new ArrayAdapter<>(requireContext(), androidx.appcompat.R.layout.support_simple_spinner_dropdown_item, books); + adapter.setDropDownViewResource(androidx.appcompat.R.layout.support_simple_spinner_dropdown_item); + spinner.setAdapter(adapter); + + } + +}