重複した出席番号を表示する処理を追加 #20

Merged
Utahshi merged 1 commits from CreateRoot2 into master 2024-06-28 01:32:30 +00:00
Showing only changes of commit 5a9d1d83be - Show all commits

View File

@ -21,7 +21,7 @@ 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;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{ public class MainActivity extends AppCompatActivity implements View.OnClickListener {
// ダイアログの宣言 // ダイアログの宣言
private AlertDialog alertDialog; private AlertDialog alertDialog;
@ -89,52 +89,53 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
@Override @Override
public void onClick(View view) { public void onClick(View view) {
// ID作成のクリック処理 // ID作成のクリック処理
if(view == creatUUID){ if (view == creatUUID) {
imageUuid.setImageResource(R.drawable.ischecked_uuid); imageUuid.setImageResource(R.drawable.ischecked_uuid);
showUUIDYesNoDialog();//UUIDを表示するかのダイアログ showUUIDYesNoDialog();//UUIDを表示するかのダイアログ
} }
if(view == imageUuid){ if (view == imageUuid) {
imageUuid.setImageResource(R.drawable.ischecked_uuid); imageUuid.setImageResource(R.drawable.ischecked_uuid);
showUUIDYesNoDialog();//UUIDを表示するかのダイアログ showUUIDYesNoDialog();//UUIDを表示するかのダイアログ
} }
// セットアップのクリック処理 // セットアップのクリック処理
if(view == setUp){ if (view == setUp) {
imageSetup.setImageResource(R.drawable.ischecked_uuid); imageSetup.setImageResource(R.drawable.ischecked_uuid);
Intent toSetup = new Intent(MainActivity.this,SetUpActivity.class); Intent toSetup = new Intent(MainActivity.this, SetUpActivity.class);
startActivity(toSetup); startActivity(toSetup);
finish(); // 画面遷移後元の状態に戻す finish(); // 画面遷移後元の状態に戻す
} }
if (view == imageSetup){ if (view == imageSetup) {
imageSetup.setImageResource(R.drawable.ischecked_uuid); imageSetup.setImageResource(R.drawable.ischecked_uuid);
Intent toSetup = new Intent(MainActivity.this,SetUpActivity.class); Intent toSetup = new Intent(MainActivity.this, SetUpActivity.class);
startActivity(toSetup); startActivity(toSetup);
finish(); // 画面遷移後元の状態に戻す finish(); // 画面遷移後元の状態に戻す
} }
// ルート作成のクリック処理 // ルート作成のクリック処理
if(view == root){ if (view == root) {
imageRoot.setImageResource(R.drawable.pin); imageRoot.setImageResource(R.drawable.pin);
fetchDataAndCreateRoute(); fetchDataAndCreateRoute();
} }
if(view == imageRoot){ if (view == imageRoot) {
imageRoot.setImageResource(R.drawable.pin); imageRoot.setImageResource(R.drawable.pin);
fetchDataAndCreateRoute(); fetchDataAndCreateRoute();
} }
// 提出状況のクリック処理 // 提出状況のクリック処理
if(view == submission){ if (view == submission) {
ArrayList<SubmissionStudent> submissionStudents = getSubmissionStudents(); ArrayList<SubmissionStudent> submissionStudents = getSubmissionStudents();
Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class); Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class);
toSubmission.putParcelableArrayListExtra("submissionStudents", submissionStudents); toSubmission.putParcelableArrayListExtra("submissionStudents", submissionStudents);
startActivity(toSubmission); startActivity(toSubmission);
} }
if(view == imageSubmission){ if (view == imageSubmission) {
ArrayList<SubmissionStudent> submissionStudents = getSubmissionStudents(); ArrayList<SubmissionStudent> submissionStudents = getSubmissionStudents();
Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class); Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class);
toSubmission.putParcelableArrayListExtra("submissionStudents", submissionStudents); toSubmission.putParcelableArrayListExtra("submissionStudents", submissionStudents);
startActivity(toSubmission); startActivity(toSubmission);
} }
} }
//UUIDを表示するかのダイアログ //UUIDを表示するかのダイアログ
private void showUUIDYesNoDialog() { private void showUUIDYesNoDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this); // この 'this' が問題でないか確認 AlertDialog.Builder builder = new AlertDialog.Builder(this); // この 'this' が問題でないか確認
@ -159,6 +160,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
alertDialog.show(); alertDialog.show();
} }
//ルート作成の非同期処理 //ルート作成の非同期処理
private void fetchDataAndCreateRoute() { private void fetchDataAndCreateRoute() {
//非同期処理の開始 //非同期処理の開始
@ -192,20 +194,20 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
myDataList = firestoreReception.getMyDataList(); myDataList = firestoreReception.getMyDataList();
try { try {
Thread.sleep(3000); Thread.sleep(3000);
Log.d("MainActivity","myDataList"+ myDataList.size()); Log.d("MainActivity", "myDataList" + myDataList.size());
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
Log.d("MainActivity","myDataList"+ myDataList.size()); Log.d("MainActivity", "myDataList" + myDataList.size());
CreateRoot createRoot = new CreateRoot(MainActivity.this); CreateRoot createRoot = new CreateRoot(MainActivity.this);
Boolean notDuplicates=createRoot.receiveData(myDataList); Boolean notDuplicates = createRoot.receiveData(myDataList);
latch.countDown(); latch.countDown();
if(notDuplicates){ if (notDuplicates) {
Log.d("MainActivity","スケジュール作成成功"); Log.d("MainActivity", "スケジュール作成成功");
}else{ } else {
showErrorDialog(latch); showErrorDialog(latch, myDataList);
} }
}); });
@ -223,6 +225,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
executor.shutdown(); executor.shutdown();
} }
//ルート作成のダイアログ //ルート作成のダイアログ
private void showRouteCreationDialog(CountDownLatch latch) { private void showRouteCreationDialog(CountDownLatch latch) {
new AlertDialog.Builder(MainActivity.this) new AlertDialog.Builder(MainActivity.this)
@ -242,11 +245,24 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}) })
.show(); .show();
} }
public void showErrorDialog(CountDownLatch latch) {
public void showErrorDialog(CountDownLatch latch, List<MyDataClass> myDataList) {
List<Integer> studentNumbers = new ArrayList<>();
for (int i = 0; i < myDataList.size(); i++) {
if (myDataList.get(i).getSchedule() == 0) {
studentNumbers.add(myDataList.get(i).getStudentNumber());
}
}
StringBuilder message = new StringBuilder("保護者の重複が重大でルート作成ができません。調整してください。\n出席番号: ");
for (int i = 0; i < studentNumbers.size(); i++) {
message.append(studentNumbers.get(i));
if (i < studentNumbers.size() - 1) {
message.append(", ");
}
}
new AlertDialog.Builder(MainActivity.this) new AlertDialog.Builder(MainActivity.this)
.setTitle("警告") .setTitle("警告")
.setMessage("保護者の重複が重大でルート作成ができません。調整してください") .setMessage(message.toString())
.setPositiveButton("OK", new DialogInterface.OnClickListener() { .setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {