diff --git a/app/src/main/java/com/example/citrusclient/views/CreateBookFragment.java b/app/src/main/java/com/example/citrusclient/views/CreateBookFragment.java index 353d6b8..8cd28e4 100644 --- a/app/src/main/java/com/example/citrusclient/views/CreateBookFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/CreateBookFragment.java @@ -1,5 +1,6 @@ package com.example.citrusclient.views; +import android.annotation.SuppressLint; import android.content.Intent; import android.content.DialogInterface; //import android.support.v4.app.DialogFragment; @@ -13,6 +14,7 @@ import androidx.lifecycle.ViewModelProvider; import android.text.Editable; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -26,9 +28,11 @@ import android.graphics.Color;//ボタンの色変更 import android.os.Bundle; import android.widget.Button; +import android.widget.CompoundButton; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; +import android.widget.Switch; import android.widget.TextView; import org.w3c.dom.Text; @@ -80,7 +84,6 @@ mParam1 = getArguments().getString(ARG_PARAM1); mParam2 = getArguments().getString(ARG_PARAM2); } - booksViewModel = new ViewModelProvider(this).get(BooksViewModel.class); } @@ -93,13 +96,17 @@ } - private String color; + private String color; //色 + //private Switch mSwitch = null;//本の公開状況の切り替えボタン + private boolean publicity; + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); //親クラスである Fragment の onViewCreated() メソッドを呼び出す Citrus citrus = (Citrus)(getActivity().getApplication()); String token = citrus.getToken(); String accountId = citrus.getAccountId(); + //ここから書く // MainActivityにこのフラグメントを設定するした二つのどっちか //((MainActivity) getContext()).setCreateBookFragment(this);//フラグメントとアクティビティ間での情報のやり取りがあるとき @@ -110,10 +117,11 @@ @Override public void onClick(View view2) { EditText editname = (EditText) view.findViewById(R.id.book_name); //本の名前を入力する - Editable bookeditable = editname.getText(); TextView textbookname = (TextView) view.findViewById(R.id.set_book_name); //本の名前が無かったら入力してと表示する +// boolean isChecked = mSwitch.isChecked(); //本の公開状況 +// publicity = isChecked; if (bookeditable == null) { //本の名前がなかったら System.out.println("本の名前を入力してください"); @@ -136,16 +144,18 @@ } } else { System.out.println(bookname); - // String textbook = textbookname.getText().toString().trim(); + // String textbook = textbookname.getText().toString().trim(); String accountId = ((Citrus) getActivity().getApplication()).getAccountId(); String token = ((Citrus) getActivity().getApplication()).getToken(); if(color == null){ color = "#D5D5D5"; //色が選択されてなかったらグレー } - booksViewModel.createBook(accountId, bookname, color, true, token); //BooksViewModelを呼び出して本を作る + + booksViewModel.createBook(accountId, bookname, color, publicity, token); //BooksViewModelを呼び出して本を作る //画面が本棚に戻る + ((MainActivity) getActivity()).showFragment(new MyBookshelfFragment()); //本棚に戻る } } @@ -171,8 +181,35 @@ } }); + + //View view = getView(); + Switch sw = view.findViewById(R.id.switch1); + sw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { + publicity = true; + } else { + publicity = false; + } + } + }); } +// public void returnPublicity(String pub) { +// View view = getView(); +// Switch sw = view.findViewById(R.id.switch1); +// sw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { +// public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { +// if (isChecked) { +// publicity = true; +// } else { +// publicity = false; +// } +// } +// }); +// } + public void returnValue(String colorIn){ color = colorIn;//createBookの変数colorに入る diff --git a/app/src/main/java/com/example/citrusclient/views/CreateTodoFragment.java b/app/src/main/java/com/example/citrusclient/views/CreateTodoFragment.java index a980aa1..e63dc14 100644 --- a/app/src/main/java/com/example/citrusclient/views/CreateTodoFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/CreateTodoFragment.java @@ -8,6 +8,7 @@ import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; +import android.text.Editable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -23,6 +24,7 @@ import com.example.citrusclient.viewmodels.BooksViewModel; import com.example.citrusclient.viewmodels.ScheduleViewModel; import com.example.citrusclient.viewmodels.TodosViewModel; +import com.google.android.material.snackbar.Snackbar; import java.util.ArrayList; import java.util.Calendar; @@ -116,12 +118,25 @@ numberPickerMonth.setMaxValue(12); numberPickerMonth.setValue(citrus.getCurMonth()); // 月の初期値を設定 - NumberPicker numberPickerDay = view.findViewById(R.id.numberPickerDay); numberPickerDay.setMinValue(1); - numberPickerDay.setMaxValue(31); + numberPickerDay.setMaxValue(getDaysInMonth(citrus.getCurYear(), citrus.getCurMonth())); // 日の初期値を設定 numberPickerDay.setValue(citrus.getCurDay()); // 日の初期値を設定 + // 月が変更されたとき + numberPickerMonth.setOnValueChangedListener((picker, oldVal, newVal) -> { + int year = numberPickerYear.getValue(); + int daysInMonth = getDaysInMonth(year, newVal); + numberPickerDay.setMaxValue(daysInMonth); + }); + + // 年が変更されたとき + numberPickerYear.setOnValueChangedListener((picker, oldVal, newVal) -> { + int month = numberPickerMonth.getValue(); + int daysInMonth = getDaysInMonth(newVal, month); + numberPickerDay.setMaxValue(daysInMonth); + }); + Spinner spinner = view.findViewById(R.id.select_todo_spinner); bookTitles = new ArrayList<>(); bookTitles.add("本を選択しない"); @@ -146,7 +161,7 @@ Button cancelButton = view.findViewById(R.id.todo_cancel_button); cancelButton.setOnClickListener(v->{ - ((MainActivity)getActivity()).backFragment(); + ((MainActivity)getActivity()).showFragment(new HomeFragment()); }); Button createButton = view.findViewById(R.id.todo_create_button); @@ -155,9 +170,25 @@ int month = numberPickerMonth.getValue(); // 設定月を取得 int day = numberPickerDay.getValue(); // 設定日を取得 String title = titleField.getText().toString(); + Editable tmp = titleField.getText(); + if(tmp == null){ + Snackbar.make(view, "タイトルを入力してください", Snackbar.LENGTH_SHORT).show(); + return; + } + if(title == null || title.isEmpty()){ + Snackbar.make(view, "タイトルを入力してください", Snackbar.LENGTH_SHORT).show(); + return; + } todosViewModel.createTodo(accountId,spinner.getSelectedItemPosition(),year,month,day,title,token); - ((MainActivity)getActivity()).backFragment(); + ((MainActivity)getActivity()).showFragment(new HomeFragment()); }); } + private int getDaysInMonth(int year, int month) { + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.YEAR, year); + calendar.set(Calendar.MONTH, month - 1); // Calendar.MONTHは0から始まるので-1する + return calendar.getActualMaximum(Calendar.DAY_OF_MONTH); + } + } \ No newline at end of file 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 91d0f1f..a73523a 100644 --- a/app/src/main/java/com/example/citrusclient/views/HomeFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/HomeFragment.java @@ -1,6 +1,9 @@ package com.example.citrusclient.views; +import android.app.Activity; +import android.content.Context; import android.graphics.Color; +import android.media.Image; import android.os.Bundle; import androidx.annotation.NonNull; @@ -17,6 +20,7 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.CheckBox; +import android.widget.TextView; import com.example.citrusclient.Citrus; import com.example.citrusclient.R; @@ -30,9 +34,12 @@ import java.security.PrivateKey; import java.util.ArrayList; +import java.util.Calendar; import java.util.HashMap; import java.util.List; +import java.time.LocalDate; + /** * A simple {@link Fragment} subclass. * Use the {@link HomeFragment#newInstance} factory method to @@ -103,6 +110,11 @@ private HashMap integerBookHashMap; BooksViewModel booksViewModel; + private LocalDate openDate; + int year; + int month; + int day; + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -110,21 +122,26 @@ Citrus citrus = (Citrus)(getActivity().getApplication()); String token = citrus.getToken(); String accountId = citrus.getAccountId(); - int year = citrus.getCurYear(); - int month = citrus.getCurMouth(); - int day = citrus.getCurDay(); + year = citrus.getCurYear(); + month = citrus.getCurMonth(); + day = citrus.getCurDay(); + int curBookId = citrus.getCurBookId(); - todoList = new ArrayList<>(); + openDate = LocalDate.of(year, month, day); + todoList = new ArrayList<>(); scheduleList = new ArrayList<>(); + TextView curDate = view.findViewById(R.id.year_month_day); + curDate.setText(year + "年" + month + "月" + day + "日"); + RecyclerView todoRecyclerView = view.findViewById(R.id.my_todos_list); todoRecyclerView.setHasFixedSize(true); RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(view.getContext()); todoRecyclerView.setLayoutManager(layoutManager); - MyTodoshelfAdapter todoAdapter = new MyTodoshelfAdapter(todoList, integerBookHashMap); + MyTodoshelfAdapter todoAdapter = new MyTodoshelfAdapter(todoList, integerBookHashMap, todosViewModel, citrus); todoRecyclerView.setAdapter(todoAdapter); RecyclerView scheduleRecyclerView = view.findViewById(R.id.my_schedule_list); @@ -141,10 +158,19 @@ booksViewModel.getBookLiveData().observe(getViewLifecycleOwner(), new Observer>() { @Override public void onChanged(HashMap idBookHashMap) { - if(idBookHashMap != null) { - integerBookHashMap = new HashMap<>(idBookHashMap); - for (Book book : integerBookHashMap.values()){ - todosViewModel.loadTodosByDay(accountId, book.getBookId(), year , month, day, token); + if (idBookHashMap != null) { + if(curBookId != -1) { + integerBookHashMap = new HashMap<>(); + Book book = idBookHashMap.get(curBookId); + integerBookHashMap.put(curBookId, book); + todosViewModel.loadTodosByDay(accountId, curBookId, year, month, day, token); + citrus.setCurBookId(-1); + } else { + todoList = new ArrayList<>(); + integerBookHashMap = new HashMap<>(idBookHashMap); + for (Book book : integerBookHashMap.values()) { + todosViewModel.loadTodosByDay(accountId, book.getBookId(), year, month, day, token); + } } scheduleViewModel.updateSchedulesByDay(accountId, year, month, day, token); } @@ -171,24 +197,48 @@ } }); + FloatingActionButton todoAddButton = view.findViewById(R.id.todo_add_button); + todoAddButton.setOnClickListener(v -> { + ((MainActivity) getActivity()).showFragment(new CreateTodoFragment()); + }); + FloatingActionButton scheduleAddButton = view.findViewById(R.id.schedule_add_button); + scheduleAddButton.setOnClickListener(v -> { + ((MainActivity) getActivity()).showFragment(new CreateScheduleFragment()); + }); +// FloatingActionButton prevBotton = view.findViewById(R.id.prev_day_botton); +// prevBotton.setOnClickListener(v -> { +// openDate = openDate.minusDays(1); +// year = openDate.getYear(); +// month = openDate.getMonthValue(); +// day = openDate.getDayOfMonth(); +// }); } } class MyTodoshelfAdapter extends RecyclerView.Adapter { - private List todoList; private HashMap idBookHashMap; - MyTodoshelfAdapter(List todos, HashMap idBookHashMap) { + private TodosViewModel todosViewModel; + private Citrus citrus; + private String accountId; + private String token; + + MyTodoshelfAdapter(List todos, HashMap idBookHashMap, TodosViewModel todosViewModel, Citrus citrus) { + this.citrus = citrus; + this.token = citrus.getToken(); + this.accountId = citrus.getAccountId(); this.todoList = todos; + this.todosViewModel = todosViewModel; if (idBookHashMap != null) { this.idBookHashMap = new HashMap<>(idBookHashMap); } else { this.idBookHashMap = new HashMap<>(); // 空のHashMapを作成 - } } + } + } public void setTodos(List todos ,HashMap idBookHashMap) { todoList = todos; @@ -221,6 +271,17 @@ holder.todoButton.setTextColor(Color.rgb(255 - red, 255 - green, 255 - blue)); } + holder.todoCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -> { + // チェック状態が変更された時の処理を記述 + if (isChecked) { + // チェックされた時の処理 + todosViewModel.setCheck(accountId, book.getBookId(), todoData.getYear(), todoData.getMonth(), todoData.getDay(), todoData.getTodoId(), true, token); + } else { + // チェックが外された時の処理 + todosViewModel.setCheck(accountId, book.getBookId(), todoData.getYear(), todoData.getMonth(), todoData.getDay(), todoData.getTodoId(), false, token); + } + }); + } @Override @@ -270,16 +331,19 @@ @Override public void onBindViewHolder(@NonNull MyScheduleViewHolder holder, int position) { + int red = 169; + int green = 169; + int blue = 169; Schedule scheduleData = this.scheduleList.get(position); holder.scheduleButton.setText(scheduleData.getTitle()); Book book = idBookHashMap.get(scheduleData.getBookId()); if(book != null) { - int red = Integer.parseInt(book.getColor().substring(1, 3), 16); - int green = Integer.parseInt(book.getColor().substring(3, 5), 16); - int blue = Integer.parseInt(book.getColor().substring(5, 7), 16); - holder.scheduleButton.setBackgroundColor(Color.rgb(red, green, blue)); - holder.scheduleButton.setTextColor(Color.rgb(255 - red, 255 - green, 255 - blue)); + red = Integer.parseInt(book.getColor().substring(1, 3), 16); + green = Integer.parseInt(book.getColor().substring(3, 5), 16); + blue = Integer.parseInt(book.getColor().substring(5, 7), 16); } + holder.scheduleButton.setBackgroundColor(Color.rgb(red, green, blue)); + holder.scheduleButton.setTextColor(Color.rgb(255 - red, 255 - green, 255 - blue)); } diff --git a/app/src/main/res/layout/fragment_create_todo.xml b/app/src/main/res/layout/fragment_create_todo.xml index 4ecaa63..605204b 100644 --- a/app/src/main/res/layout/fragment_create_todo.xml +++ b/app/src/main/res/layout/fragment_create_todo.xml @@ -96,71 +96,72 @@ - - + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0.255" /> + android:selectionDividerHeight="0dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.527" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0.199" /> + app:layout_constraintHorizontal_bias="0.875" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0.187" /> + + + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toTopOf="parent" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index e92cc5d..9612eab 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -6,7 +6,7 @@ tools:context=".views.HomeFragment"> + + + + @@ -75,9 +94,30 @@ android:layout_height="match_parent" android:layout_gravity="right" android:layout_marginTop="170dp" - android:layout_marginBottom="10dp" + android:layout_marginBottom="80dp" android:layout_marginLeft="210dp" android:layout_marginRight="10dp" /> + + + +