diff --git a/app/src/main/java/com/example/citrusclient/views/CreateScheduleFragment.java b/app/src/main/java/com/example/citrusclient/views/CreateScheduleFragment.java index 67dfac5..00a6502 100644 --- a/app/src/main/java/com/example/citrusclient/views/CreateScheduleFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/CreateScheduleFragment.java @@ -21,6 +21,7 @@ import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.DatePicker; +import android.widget.EditText; import android.widget.Spinner; import android.widget.Switch; import android.widget.TimePicker; @@ -29,6 +30,7 @@ import com.example.citrusclient.R; import com.example.citrusclient.models.Book; import com.example.citrusclient.viewmodels.BooksViewModel; +import com.example.citrusclient.viewmodels.ScheduleViewModel; import java.util.ArrayList; import java.util.Calendar; @@ -82,11 +84,8 @@ BooksViewModel booksViewModel; + ScheduleViewModel scheduleViewModel; - String startDate; - String startTime; - String endDate; - String endTime; List bookTitles; @@ -109,6 +108,7 @@ } booksViewModel = new ViewModelProvider(this).get(BooksViewModel.class); + scheduleViewModel = new ViewModelProvider(this).get(ScheduleViewModel.class); Calendar c = Calendar.getInstance(); year = c.get(Calendar.YEAR); month = c.get(Calendar.MONTH); @@ -202,7 +202,6 @@ Spinner spinner = view.findViewById(R.id.select_book_spinner); bookTitles = new ArrayList<>(); bookTitles.add("本を選択しない"); - booksViewModel.getBookLiveData().observe(getViewLifecycleOwner(), new Observer>() { @Override public void onChanged(HashMap integerBookHashMap) { @@ -223,6 +222,22 @@ adapter.setDropDownViewResource(androidx.appcompat.R.layout.support_simple_spinner_dropdown_item); spinner.setAdapter(adapter); + + EditText scheduleTitle = view.findViewById(R.id.schedule_title); + Button confirmButton = view.findViewById(R.id.schedule_create_confirm); + confirmButton.setOnClickListener(v -> { + String[] dates = ((String)startDateButton.getText()).split("/"); + int year = Integer.parseInt(dates[0]); + int month = Integer.parseInt(dates[1]); + int day = Integer.parseInt(dates[2]); + String title = scheduleTitle.getText().toString(); + String startDateTime = startDateButton.getText() + " " + startTimeButton.getText(); + String endDateTime = endDateButton.getText() + " " + endTimeButton.getText(); + scheduleViewModel.createSchedule(accountId, year, month, day, token, title, startDateTime, endDateTime, spinner.getSelectedItemPosition()); + ((MainActivity)getActivity()).backFragment(); + }); + + } }