Merge branch 'master' into finishing

# Conflicts:
#	app/src/main/java/com/example/oplogy/SetUpActivity.java
This commit is contained in:
it232115 2024-07-08 10:23:14 +09:00
commit ef4cf1c934
4 changed files with 206 additions and 105 deletions

View File

@ -8,6 +8,7 @@ import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
@ -18,9 +19,13 @@ import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
@ -87,7 +92,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
Log.d("MainActivity", "geocodeAddress");
//TODO:classIdの初期値を取得
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(() -> {
try {
@ -136,9 +140,28 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
// ルート作成のクリック処理
if (view == root) {
imageRoot.setImageResource(R.drawable.pin);
if (isClassIdSet()) {
isSetupExists(classId).thenAccept(setupExists -> {
if (setupExists) {
fetchDataAndCreateRoute();
} else {
runOnUiThread(() -> {
Toast.makeText(this, "セットアップが設定されていません", Toast.LENGTH_SHORT).show();
});
}
}).exceptionally(ex -> {
ex.printStackTrace();
runOnUiThread(() -> {
Toast.makeText(this, "エラーが発生しました", Toast.LENGTH_SHORT).show();
});
return null;
});
} else {
Toast.makeText(this, "クラスIDが設定されていません", Toast.LENGTH_SHORT).show();
}
}
if (view == imageRoot) {
imageRoot.setImageResource(R.drawable.pin);
fetchDataAndCreateRoute();
@ -219,6 +242,25 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
dialog.show();
}
private boolean isClassIdSet() {
// classIdが0より大きい場合trueを返す
return classId > 0;
}
private CompletableFuture<Boolean> isSetupExists(int classId) {
final ExecutorService executorService = Executors.newSingleThreadExecutor();
return CompletableFuture.supplyAsync(() -> {
AppDatabase db = getDatabaseInstance();
SetUpTableDao setUpTableDao = db.setUpTableDao();
List<SetUpTable> checkData = setUpTableDao.getAll();
for (SetUpTable setUpTable : checkData) {
if (setUpTable.classId == classId) {
return true;
}
}
return false;
}, executorService).whenComplete((result, throwable) -> executorService.shutdown());
}
//ルート作成の非同期処理
private void fetchDataAndCreateRoute() {
@ -334,7 +376,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private AppDatabase getDatabaseInstance() {
return Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build();
return Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").fallbackToDestructiveMigration().build();
}

View File

@ -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,12 @@ 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;
@SuppressLint("MissingInflatedId")
@ -75,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); //画面下の設定ボタン
@ -109,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";
@ -130,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();
@ -174,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();
@ -185,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; //ボタンの判別
//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(() -> {
@ -246,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);
}
}
@ -275,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");
}

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -23,9 +22,10 @@
android:id="@+id/toMain"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:src="@drawable/back_button"/>
android:layout_gravity="start"
android:layout_marginStart="10dp"
android:src="@drawable/back_button"
android:contentDescription="@string/todo" />
<TextView
@ -52,7 +52,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints=""
android:inputType=""
android:inputType="text"
tools:ignore="LabelFor" />
</LinearLayout>
@ -76,7 +76,7 @@
android:layout_height="wrap_content"
android:hint="@string/startpoint"
android:autofillHints=""
android:inputType=""
android:inputType="text"
tools:ignore="LabelFor" />
</LinearLayout>
@ -91,7 +91,7 @@
<TextView
android:layout_width="90sp"
android:layout_height="wrap_content"
android:text="日付設定"
android:text="@string/setUpDate"
android:gravity="center"/>
<!-- <TextView-->
@ -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=""

View File

@ -16,4 +16,24 @@
<string name="tenMinute">10分</string>
<string name="fifteenMinute">15分</string>
<string name="thirtyMinute">30分</string>
<string name="todo">TODO</string>
<string name="setUpDate">日付設定</string>
<string name="firstDay">1日目</string>
<string name="secondDay">2日目</string>
<string name="threeDay">3日目</string>
<string name="notSetUp">未設定</string>
<string-array name="months_array">
<item>1月</item>
<item>2月</item>
<item>3月</item>
<item>4月</item>
<item>5月</item>
<item>6月</item>
<item>7月</item>
<item>8月</item>
<item>9月</item>
<item>10月</item>
<item>11月</item>
<item>12月</item>
</string-array>
</resources>