・重複時のダイアログに保護者の情報が表示されるように調整しました。 #50

Merged
Utahshi merged 2 commits from api into master 2024-07-10 07:31:26 +00:00
2 changed files with 37 additions and 14 deletions

View File

@ -42,13 +42,14 @@ public class CreateSchedule {
private final AppDatabase db; private final AppDatabase db;
private int arraySizeInt; private int arraySizeInt;
boolean notSecondDuplicatesBoolean = true;//スケジュールの重複の有無(第一希望日のみで通った場合も考えて初期はtrue) private boolean notSecondDuplicatesBoolean;//スケジュールの重複の有無(第一希望日のみで通った場合も考えて初期はtrue)
String[] homeVisitDaysString; String[] homeVisitDaysString;
public CreateSchedule(AppCompatActivity activity) { public CreateSchedule(AppCompatActivity activity) {
this.db = Room.databaseBuilder(activity.getApplicationContext(), AppDatabase.class, "SetUpTable").build(); this.db = Room.databaseBuilder(activity.getApplicationContext(), AppDatabase.class, "SetUpTable").build();
this.notSecondDuplicatesBoolean = true; // 初期値をtrueに設定する
SharedPreferences sharedPreferences = activity.getSharedPreferences("visitingDate", Context.MODE_PRIVATE); SharedPreferences sharedPreferences = activity.getSharedPreferences("visitingDate", Context.MODE_PRIVATE);
String firstDay = sharedPreferences.getString("day1", null); String firstDay = sharedPreferences.getString("day1", null);
@ -57,7 +58,6 @@ public class CreateSchedule {
Log.d("createSchedule","day1"+firstDay+"day2"+secondDay+"thirdday"+thirdDay); Log.d("createSchedule","day1"+firstDay+"day2"+secondDay+"thirdday"+thirdDay);
homeVisitDaysString = new String[]{firstDay, secondDay, thirdDay}; homeVisitDaysString = new String[]{firstDay, secondDay, thirdDay};
} }
//MainActivityからデータを受け取る //MainActivityからデータを受け取る
@ -116,17 +116,18 @@ public class CreateSchedule {
sortSchedule(myDataList); sortSchedule(myDataList);
} }
}); });
//重複がなければ開始地点の緯度経度を返す // 重複がなければ開始地点の緯度経度を返す
if (notSecondDuplicatesBoolean) { if (notSecondDuplicatesBoolean) {
//保護者の住所を緯度経度に変換する // 保護者の住所を緯度経度に変換する
String startPointLatLngString = geocodeAddress(myDataList, context); String startPointLatLngString = geocodeAddress(myDataList, context);
Log.d("CreateSchedule", "startPointLatLngString" + startPointLatLngString); Log.d("CreateSchedule", "startPointLatLngString" + startPointLatLngString);
outPutLogSchedule(myDataList); outPutLogSchedule(myDataList);
return startPointLatLngString; return startPointLatLngString;
} else {
// 重複があるときは""を返す
Log.d("CreateSchedule", "重複によるエラー");
return "";
} }
//重複があるときは""を返す
Log.d("CreateSchedule", "重複によるエラー");
return "";
} }
@ -348,6 +349,7 @@ public class CreateSchedule {
} }
} }
for (int i = 0; i < myDataList.size(); i++) { for (int i = 0; i < myDataList.size(); i++) {
if (myDataList.get(i).getSchedule() == 0) {//重複により割り当てがされていない保護者がいないかの確認 if (myDataList.get(i).getSchedule() == 0) {//重複により割り当てがされていない保護者がいないかの確認
return false; return false;

View File

@ -20,6 +20,7 @@ import com.google.gson.Gson;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -334,9 +335,19 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
final List<MyDataClass> finalMyDataList = myDataList; final List<MyDataClass> finalMyDataList = myDataList;
CreateSchedule createSchedule = new CreateSchedule(MainActivity.this); CreateSchedule createSchedule = new CreateSchedule(MainActivity.this);
String startPointLatLngString = createSchedule.receiveData(myDataList, getApplicationContext()); String startPointLatLngString = createSchedule.receiveData(myDataList, getApplicationContext());
Boolean notDuplicatesBoolean = null;
for (int i = 0; i < myDataList.size(); i++) {
if (myDataList.get(i).getSchedule() == 0) {
notDuplicatesBoolean = false;
break;
} else {
notDuplicatesBoolean = true;
}
}
Boolean finalNotDuplicatesBoolean = notDuplicatesBoolean;
Log.d("MainActivity", "重複判定" + String.valueOf(finalNotDuplicatesBoolean));
runOnUiThread(() -> { runOnUiThread(() -> {
if (!startPointLatLngString.equals("")) { if (finalNotDuplicatesBoolean) {
Log.d("MainActivity", "スケジュール作成成功"); Log.d("MainActivity", "スケジュール作成成功");
saveMyDataList(finalMyDataList); saveMyDataList(finalMyDataList);
Intent toRoot = new Intent(MainActivity.this, Maps.class); Intent toRoot = new Intent(MainActivity.this, Maps.class);
@ -374,12 +385,22 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
studentNumbers.add(data.getStudentNumber()); studentNumbers.add(data.getStudentNumber());
} }
} }
StringBuilder message = new StringBuilder("保護者の重複が重大でルート作成ができません。調整してください。\n出席番号: "); StringBuilder message = new StringBuilder("保護者の重複が重大でルート作成ができません。保護者に連絡して調整してください。\n\n");
for (int i = 0; i < studentNumbers.size(); i++) { for (int i = 0; i < studentNumbers.size(); i++) {
message.append(studentNumbers.get(i)); message.append("出席番号:" + studentNumbers.get(i));
if (i < studentNumbers.size() - 1) { message.append("\n保護者名:" + myDataList.get(i).getPatronName());
message.append(", "); message.append("\n第一希望 " + myDataList.get(i).getStartDateString().substring(4,6)+"");
} message.append(myDataList.get(i).getStartDateString().substring(6,8)+"");
message.append(" " + myDataList.get(i).getParentStartTimeString().substring(0, 2));
message.append(":" + myDataList.get(i).getParentStartTimeString().substring(2, 4));
message.append("" + myDataList.get(i).getParentEndTimeString().substring(0, 2));
message.append(":" + myDataList.get(i).getParentEndTimeString().substring(2, 4));
message.append("\n第二希望 " + myDataList.get(i).getSecondDayStartDateString().substring(4,6)+"");
message.append(myDataList.get(i).getSecondDayStartDateString().substring(6,8)+"");
message.append(" " + myDataList.get(i).getSecondDayParentStartTimeString().substring(0, 2));
message.append(":" + myDataList.get(i).getSecondDayParentStartTimeString().substring(2, 4));
message.append("" + myDataList.get(i).getSecondDayParentEndTimeString().substring(0, 2));
message.append(":" + myDataList.get(i).getSecondDayParentEndTimeString().substring(2, 4) + "\n\n");
} }
new AlertDialog.Builder(MainActivity.this) new AlertDialog.Builder(MainActivity.this)
.setTitle("警告") .setTitle("警告")