diff --git a/app/src/main/java/com/example/oplogy/SetUpActivity.java b/app/src/main/java/com/example/oplogy/SetUpActivity.java
index d533095..d982431 100644
--- a/app/src/main/java/com/example/oplogy/SetUpActivity.java
+++ b/app/src/main/java/com/example/oplogy/SetUpActivity.java
@@ -10,6 +10,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Paint;
import android.os.Bundle;
+import android.text.TextUtils;
import android.util.Log;
import android.widget.Button;
import android.widget.DatePicker;
@@ -24,6 +25,7 @@ import androidx.fragment.app.FragmentActivity;
import androidx.room.Room;
import java.util.Locale;
+import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -42,15 +44,15 @@ public class SetUpActivity extends FragmentActivity
String startBreakTime;
String endBreakTime;
int totalStudent;
- private TextView setTeacherName;
- private TextView setStartPoint;
- private TextView setStartTime;
- private TextView setEndTime;
- private TextView setStartBreakTime;
- private TextView setEndBreakTime;
- private TextView setTotalStudent;
- private int isDateSelected;
- private int isStartTimeSelected;
+ private TextView textViewTeacherName;
+ private TextView textViewStartPoint;
+ private TextView textViewStartTime;
+ private TextView textViewEndTime;
+ private TextView textViewStartBreakTime;
+ private TextView textViewEndBreakTime;
+ private TextView textViewTotalStudent;
+ private int intIsDateSelected;
+ private int intIsStartTimeSelected;
String stringYear;
String stringMonth;
@@ -60,11 +62,11 @@ public class SetUpActivity extends FragmentActivity
String stringHourOfDay;
String stringMinute;
- Button setFirstDay;
- Button setSecondDay;
- Button setThirdDay;
- Button setStartTimeButton;
- Button setEndTimeButton;
+ Button buttonFirstDay;
+ Button buttonSecondDay;
+ Button buttonThirdDay;
+ Button buttonStartTimeButton;
+ Button buttonEndTimeButton;
@@ -76,28 +78,28 @@ public class SetUpActivity extends FragmentActivity
int classId= getIntent().getIntExtra("classId", 100000);
- setTeacherName = findViewById(R.id.teacherName); //先生の名前
- setStartPoint = findViewById(R.id.startPoint); //開始地点
+ textViewTeacherName = findViewById(R.id.teacherName); //先生の名前
+ textViewStartPoint = findViewById(R.id.startPoint); //開始地点
- setFirstDay = findViewById(R.id.setFirstDayButton); //1日目の日付
- setSecondDay = findViewById(R.id.setSecondDayButton); //2日目の日付
- setThirdDay = findViewById(R.id.setThirdDayButton); //3日目の日付
+ buttonFirstDay = findViewById(R.id.setFirstDayButton); //1日目の日付
+ buttonSecondDay = findViewById(R.id.setSecondDayButton); //2日目の日付
+ buttonThirdDay = findViewById(R.id.setThirdDayButton); //3日目の日付
- setStartTimeButton = findViewById(R.id.startTimeSetButton); //開始時刻を設定するボタン
- setStartTime = findViewById(R.id.startTime); //開始時刻を出力するTextView
- setEndTimeButton = findViewById(R.id.endTimeSetButton); //終了時刻を設定するボタン
- setEndTime = findViewById(R.id.endTime); //終了時刻を出力するTextView
+ buttonStartTimeButton = findViewById(R.id.startTimeSetButton); //開始時刻を設定するボタン
+ textViewStartTime = findViewById(R.id.startTime); //開始時刻を出力するTextView
+ buttonEndTimeButton = findViewById(R.id.endTimeSetButton); //終了時刻を設定するボタン
+ textViewEndTime = findViewById(R.id.endTime); //終了時刻を出力するTextView
- RadioButton setTenMinute = findViewById(R.id.tenMinute); //訪問間隔(10分)
- RadioButton setFifteenMinute = findViewById(R.id.fifteenMinute); //訪問間隔(15分)
- RadioButton setThirtyMinute = findViewById(R.id.thirtyMinute); //訪問間隔(30分)
+ RadioButton radioButtonTenMinute = findViewById(R.id.tenMinute); //訪問間隔(10分)
+ RadioButton radioButtonFifteenMinute = findViewById(R.id.fifteenMinute); //訪問間隔(15分)
+ RadioButton radioButtonThirtyMinute = findViewById(R.id.thirtyMinute); //訪問間隔(30分)
- setStartBreakTime = findViewById(R.id.startBreakTime); //休憩開始時刻
- setStartBreakTime.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
- setEndBreakTime = findViewById(R.id.endBreakTime); //休憩終了時刻
- setEndBreakTime.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
+ textViewStartBreakTime = findViewById(R.id.startBreakTime); //休憩開始時刻
+ textViewStartBreakTime.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
+ textViewEndBreakTime = findViewById(R.id.endBreakTime); //休憩終了時刻
+ textViewEndBreakTime.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
- setTotalStudent = findViewById(R.id.totalStudent); //クラスの人数
+ textViewTotalStudent = findViewById(R.id.totalStudent); //クラスの人数
ImageView toMain = findViewById(R.id.toMain);
Button setUp = findViewById(R.id.setUpButton); //画面下の設定ボタン
@@ -110,20 +112,20 @@ public class SetUpActivity extends FragmentActivity
setUp.setOnClickListener(view -> {
- teacherName = setTeacherName.getText().toString(); //各変数に値を挿入
+ teacherName = textViewTeacherName.getText().toString(); //各変数に値を挿入
Log.d(TAG, "Teacher Name: " + teacherName);
- startPoint = setStartPoint.getText().toString();
+ startPoint = textViewStartPoint.getText().toString();
Log.d(TAG, "Start Point: " + startPoint);
Log.d(TAG, "First Day:" + firstDay);
Log.d(TAG, "Second Day:" + secondDay);
Log.d(TAG, "Third Day:" + thirdDay);
Log.d(TAG, "Start Time" + startTime);
Log.d(TAG, "End Time" + endTime);
- if (setTenMinute.isChecked()){ //ラジオボタンの状態を取得
+ if (radioButtonTenMinute.isChecked()){ //ラジオボタンの状態を取得
intervalTime = "10";
- } else if (setFifteenMinute.isChecked()) {
+ } else if (radioButtonFifteenMinute.isChecked()) {
intervalTime = "15";
- } else if (setThirtyMinute.isChecked()) {
+ } else if (radioButtonThirtyMinute.isChecked()) {
intervalTime = "30";
} else {
intervalTime = "0";
@@ -131,10 +133,25 @@ public class SetUpActivity extends FragmentActivity
Log.d(TAG, "Interval Time" + intervalTime);
Log.d(TAG, "Start Break Time" + startBreakTime);
Log.d(TAG, "End Break Time" + endBreakTime);
- totalStudent = Integer.parseInt(setTotalStudent.getText().toString()); //数値型に変更
Log.d(TAG, "Total Student" + totalStudent);
Log.d(TAG, "onClick: できてるよ");
+ // クラスの人数を数値に変換して取得
+ try {
+ totalStudent = Integer.parseInt(textViewTotalStudent.getText().toString());
+ } catch (NumberFormatException e) {
+ totalStudent = 0; // デフォルト値を設定するか、エラー処理を追加することも考慮する必要があります
+ }
+
+ // 入力データのバリデーション
+ if (TextUtils.isEmpty(teacherName) || TextUtils.isEmpty(startPoint) || TextUtils.isEmpty(startTime)
+ || TextUtils.isEmpty(firstDay) || TextUtils.isEmpty(secondDay) || TextUtils.isEmpty(thirdDay)
+ || TextUtils.isEmpty(endTime) || Objects.equals(intervalTime, "0") || TextUtils.isEmpty(startBreakTime)
+ || TextUtils.isEmpty(endBreakTime) || totalStudent <= 0) {
+ Toast.makeText(SetUpActivity.this, "必須項目を入力してください", Toast.LENGTH_SHORT).show();
+ return;
+ }
+
// データベースへの登録処理
ExecutorService executor = Executors.newSingleThreadExecutor();
@@ -175,9 +192,10 @@ public class SetUpActivity extends FragmentActivity
SharedPreferences sharedPreferences=getSharedPreferences("visitingDate",MODE_PRIVATE);
SharedPreferences.Editor editor= sharedPreferences.edit();
- editor.putString("day1",firstDay);
- editor.putString("day2",secondDay);
- editor.putString("day3",thirdDay);
+ //editorに値を渡す
+ editor.putString("day1",firstDay); //1日目
+ editor.putString("day2",secondDay); //2日目
+ editor.putString("day3",thirdDay); //3日目
editor.apply();
@@ -186,52 +204,71 @@ public class SetUpActivity extends FragmentActivity
});
- setFirstDay.setOnClickListener(v ->{
- isDateSelected = 1;
+ //DatePicker用
+ buttonFirstDay.setOnClickListener(v ->{
+ intIsDateSelected = 1; //ボタンの判別(Date)
showDatePickerDialog(); //DatePickerの表示
});
- setSecondDay.setOnClickListener(v ->{
- isDateSelected = 2;
+ buttonSecondDay.setOnClickListener(v ->{
+ intIsDateSelected = 2;
showDatePickerDialog();
});
- setThirdDay.setOnClickListener(v ->{
- isDateSelected = 3;
+ buttonThirdDay.setOnClickListener(v ->{
+ intIsDateSelected = 3;
showDatePickerDialog();
});
- setStartTimeButton.setOnClickListener(v -> {
- isStartTimeSelected = 1; //ボタンの判別
- showTimePickerDialog(); //TimePickerの表示
+ //TimePicker用
+ buttonStartTimeButton.setOnClickListener(v -> {
+ intIsStartTimeSelected = 1; //ボタンの判別(Time)
+ showTimePickerDialog(); //TimePickerの表示
});
- setEndTimeButton.setOnClickListener(v -> {
- isStartTimeSelected = 2;
+ buttonEndTimeButton.setOnClickListener(v -> {
+ intIsStartTimeSelected = 2;
showTimePickerDialog();
});
- setStartBreakTime.setOnClickListener(v -> {
- isStartTimeSelected = 3;
+ textViewStartBreakTime.setOnClickListener(v -> {
+ intIsStartTimeSelected = 3;
showTimePickerDialog();
});
- setEndBreakTime.setOnClickListener(v -> {
- isStartTimeSelected = 4;
+ textViewEndBreakTime.setOnClickListener(v -> {
+ intIsStartTimeSelected = 4;
showTimePickerDialog();
});
//リセットボタンの処理
reset.setOnClickListener(v -> { //テキストとラジオボタンの選択を消去
- setTeacherName.setText("");
- setStartPoint.setText("");
- setTenMinute.setChecked(false);
- setFifteenMinute.setChecked(false);
- setThirtyMinute.setChecked(false);
- setStartBreakTime.setText("");
- setEndBreakTime.setText("");
- setTotalStudent.setText("");
+ textViewTeacherName.setText("");
+ textViewStartPoint.setText("");
+ buttonFirstDay.setText("");
+ buttonSecondDay.setText("");
+ buttonThirdDay.setText("");
+ radioButtonTenMinute.setChecked(false);
+ radioButtonFifteenMinute.setChecked(false);
+ radioButtonThirtyMinute.setChecked(false);
+ textViewStartTime.setText("");
+ textViewEndTime.setText("");
+ textViewStartBreakTime.setText("");
+ textViewEndBreakTime.setText("");
+ textViewTotalStudent.setText("");
+
+ teacherName = "";
+ startPoint = "";
+ firstDay = "";
+ secondDay = "";
+ thirdDay = "";
+ startTime = "";
+ endTime = "";
+ intervalTime = "";
+ startBreakTime = "";
+ endBreakTime ="" ;
+
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(() -> {
@@ -247,26 +284,27 @@ public class SetUpActivity extends FragmentActivity
// DatePickerDialogで選択された日付を処理する
String str = String.format(Locale.JAPAN, "%02d/%02d", month + 1, dayOfMonth); // TextViewに表示する日付の形式を設定
- if (isDateSelected == 1) {
+ if (intIsDateSelected == 1) {
stringYear = String.valueOf(year); //年
stringMonth = String.format(Locale.JAPAN, "%02d", month + 1); //月
stringDayOfMonth = String.format(Locale.JAPAN, "%02d", dayOfMonth); //日
- firstDay = stringYear + stringMonth + stringDayOfMonth;
- setFirstDay.setText(str);
- } else if (isDateSelected == 2) {
+ firstDay = stringYear + stringMonth + stringDayOfMonth; //8桁の文字列を作成 例)20240604
+ buttonFirstDay.setText(str); //buttonにformatされた文字列を挿入
+
+ } else if (intIsDateSelected == 2) {
stringYear = String.valueOf(year);
stringMonth = String.format(Locale.JAPAN, "%02d", month + 1);
stringDayOfMonth = String.format(Locale.JAPAN, "%02d", dayOfMonth);
secondDay = stringYear + stringMonth + stringDayOfMonth;
- setSecondDay.setText(str);
+ buttonSecondDay.setText(str);
- } else if (isDateSelected == 3) {
+ } else if (intIsDateSelected == 3) {
stringYear = String.valueOf(year);
stringMonth = String.format(Locale.JAPAN, "%02d", month + 1);
stringDayOfMonth = String.format(Locale.JAPAN, "%02d", dayOfMonth);
thirdDay = stringYear + stringMonth + stringDayOfMonth;
- setThirdDay.setText(str);
+ buttonThirdDay.setText(str);
}
}
@@ -276,38 +314,38 @@ public class SetUpActivity extends FragmentActivity
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
String str = String.format(Locale.JAPAN, "%02d:%02d", hourOfDay, minute); // Textviewに保存する形式を設定
- if (isStartTimeSelected == 1) {
- stringHourOfDay = String.format("%02d", hourOfDay);
- stringMinute = String.format("%02d", minute);
- startTime = stringHourOfDay + stringMinute;
- setStartTime.setText(str);
+ if (intIsStartTimeSelected == 1) {
+ stringHourOfDay = String.format("%02d", hourOfDay); //時
+ stringMinute = String.format("%02d", minute); //分
+ startTime = stringHourOfDay + stringMinute; //4桁の文字列を作成 例)0930
+ textViewStartTime.setText(str); //textViewにformatされている文字列を挿入
- } else if (isStartTimeSelected == 2) {
+ } else if (intIsStartTimeSelected == 2) {
stringHourOfDay = String.format("%02d", hourOfDay);
stringMinute = String.format("%02d", minute);
endTime = stringHourOfDay + stringMinute;
- setEndTime.setText(str);
+ textViewEndTime.setText(str);
- } else if (isStartTimeSelected == 3) {
+ } else if (intIsStartTimeSelected == 3) {
stringHourOfDay = String.format("%02d", hourOfDay);
stringMinute = String.format("%02d", minute);
startBreakTime =stringHourOfDay + stringMinute;
- setStartBreakTime.setText(" " + str + " ");
+ textViewStartBreakTime.setText(" " + str + " ");
- } else if (isStartTimeSelected == 4) {
+ } else if (intIsStartTimeSelected == 4) {
stringHourOfDay = String.format("%02d", hourOfDay);
stringMinute = String.format("%02d", minute);
endBreakTime = stringHourOfDay + stringMinute;
- setEndBreakTime.setText(" " + str + " ");
+ textViewEndBreakTime.setText(" " + str + " ");
}
}
- private void showDatePickerDialog() {
+ private void showDatePickerDialog() { //DatePickerDialogを表示する
DialogFragment newFragment = new DatePick();
newFragment.show(getSupportFragmentManager(), "datePicker");
}
- private void showTimePickerDialog() { // Dialogを表示する
+ private void showTimePickerDialog() { // TimePickerDialogを表示する
DialogFragment newFragment = new TimePick();
newFragment.show(getSupportFragmentManager(), "timePicker");
}
diff --git a/app/src/main/res/layout/activity_set_up.xml b/app/src/main/res/layout/activity_set_up.xml
index 84bc0c8..bc037db 100644
--- a/app/src/main/res/layout/activity_set_up.xml
+++ b/app/src/main/res/layout/activity_set_up.xml
@@ -1,6 +1,5 @@
+ android:layout_gravity="start"
+ android:layout_marginStart="10dp"
+ android:src="@drawable/back_button"
+ android:contentDescription="@string/todo" />
@@ -76,7 +76,7 @@
android:layout_height="wrap_content"
android:hint="@string/startpoint"
android:autofillHints=""
- android:inputType=""
+ android:inputType="text"
tools:ignore="LabelFor" />
@@ -91,7 +91,7 @@
@@ -109,7 +109,7 @@
android:id="@+id/setFirstDayButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="1日目"
+ android:hint="@string/firstDay"
android:layout_marginStart="7sp"
android:layout_marginEnd="7sp"
tools:ignore="DuplicateIds" />
@@ -118,7 +118,7 @@
android:id="@+id/setSecondDayButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="2日目"
+ android:hint="@string/secondDay"
android:layout_marginStart="7sp"
android:layout_marginEnd="7sp"
tools:ignore="DuplicateIds" />
@@ -127,7 +127,7 @@
android:id="@+id/setThirdDayButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="3日目"
+ android:hint="@string/threeDay"
android:layout_marginStart="7sp"
android:layout_marginEnd="7sp"
tools:ignore="DuplicateIds" />
@@ -151,7 +151,7 @@
android:id="@+id/startTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:hint="未設定"
+ android:hint="@string/notSetUp"
android:textSize="20sp"
android:textAlignment="center"
android:autofillHints=""
@@ -186,7 +186,7 @@
android:id="@+id/endTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:hint="未設定"
+ android:hint="@string/notSetUp"
android:textSize="20sp"
android:textAlignment="center"
android:autofillHints=""
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 7d0fc4a..639e09a 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -16,4 +16,24 @@
10分
15分
30分
+ TODO
+ 日付設定
+ 1日目
+ 2日目
+ 3日目
+ 未設定
+
+ - 1月
+ - 2月
+ - 3月
+ - 4月
+ - 5月
+ - 6月
+ - 7月
+ - 8月
+ - 9月
+ - 10月
+ - 11月
+ - 12月
+
\ No newline at end of file