ルート作成と提出状況のアクティビティにそれぞれ警告用のtoastの追加

This commit is contained in:
nemukemo 2024-07-08 18:03:19 +09:00
parent 9a32016403
commit 8ef78642a9

View File

@ -141,47 +141,53 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
// ルート作成のクリック処理 // ルート作成のクリック処理
if (view == root) { if (view == root) {
imageRoot.setImageResource(R.drawable.pin); imageRoot.setImageResource(R.drawable.pin);
checkSetupAndCreateRoute(); checkSetupAndCreateRoute(this::fetchDataAndCreateRoute);
} }
if (view == imageRoot) { if (view == imageRoot) {
imageRoot.setImageResource(R.drawable.pin); imageRoot.setImageResource(R.drawable.pin);
checkSetupAndCreateRoute(); checkSetupAndCreateRoute(this::fetchDataAndCreateRoute);
} }
// 提出状況のクリック処理 // 提出状況のクリック処理
if (view == submission) { if (view == submission) {
checkSetupAndCreateRoute(() -> {
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) {
checkSetupAndCreateRoute(() -> {
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);
});
} }
} }
//IDに関する処理 //ID作成表示に関する処理
private void showUUIDYesNoDialog() { private void showUUIDYesNoDialog() {
firestoreReception_classIdDatabase = new FirestoreReception_classIdDatabase(); firestoreReception_classIdDatabase = new FirestoreReception_classIdDatabase();
List<Integer> classIdList = firestoreReception_classIdDatabase.getAllDocumentsFromClassIdDatabase(); List<Integer> classIdList = firestoreReception_classIdDatabase.getAllDocumentsFromClassIdDatabase();
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("クラスID"); builder.setTitle("ID");
builder.setMessage("あなたのクラスIDを表示/もしくは新規で作成しますか?"); builder.setMessage("あなたのIDを表示/もしくは新規で作成しますか?");
//作成処理
builder.setPositiveButton("作成", new DialogInterface.OnClickListener() { builder.setPositiveButton("作成", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
classId = CreateUUID.generateUUID(classIdList); classId = CreateUUID.generateUUID(classIdList);
// 生成されたクラスIDを表示するメソッド // 生成されたIDを表示するメソッド
showClassIdDialog("生成されたクラスID",classId); showClassIdDialog("生成されたID",classId);
} }
}); });
//表示処理
builder.setNegativeButton("表示", new DialogInterface.OnClickListener() { builder.setNegativeButton("表示", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@ -192,7 +198,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
int currentClassId = getCurrentClassIdFromRoom(); int currentClassId = getCurrentClassIdFromRoom();
runOnUiThread(() -> { runOnUiThread(() -> {
// 現在のクラスIDを表示するダイアログ // 現在のクラスIDを表示するダイアログ
showClassIdDialog("現在のクラスID",currentClassId); showClassIdDialog("現在のID",currentClassId);
}); });
}); });
executor.shutdown(); executor.shutdown();
@ -214,7 +220,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private void showClassIdDialog(String title, int classId) { private void showClassIdDialog(String title, int classId) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(title); builder.setTitle(title);
builder.setMessage("クラスID: " + classId); builder.setMessage("ID: " + classId);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@ -229,26 +235,26 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
//ルート作成の前チェックを行う処理 //ルート作成提出状況遷移を行うチェックを行う処理
private void checkSetupAndCreateRoute() { private void checkSetupAndCreateRoute(Runnable onSetupComplete) {
if (isClassIdSet()) { if (isClassIdSet()) {
isSetupExists(classId).thenAccept(setupExists -> { isSetupExists(classId).thenAccept(setupExists -> {
if (setupExists) { if (setupExists) {
fetchDataAndCreateRoute(); runOnUiThread(onSetupComplete);
} else { } else {
runOnUiThread(() -> { runOnUiThread(() -> {
Toast.makeText(this, "先にセットアップを済ませてください", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "先にセットアップを済ませてください", Toast.LENGTH_LONG).show();
}); });
} }
}).exceptionally(ex -> { }).exceptionally(ex -> {
ex.printStackTrace(); ex.printStackTrace();
runOnUiThread(() -> { runOnUiThread(() -> {
Toast.makeText(this, "エラーが発生しました", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "エラーが発生しました", Toast.LENGTH_LONG).show();
}); });
return null; return null;
}); });
} else { } else {
Toast.makeText(this, "先にIDの作成を行ってください", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "先にIDの作成を行ってください", Toast.LENGTH_LONG).show();
} }
} }
// クラスIDが設定されているかどうかを判定 // クラスIDが設定されているかどうかを判定