コメント追加

This commit is contained in:
nemukemo 2024-07-08 11:29:59 +09:00
parent 02b96cb10f
commit a492a8e70b

View File

@ -243,23 +243,28 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
dialog.show(); dialog.show();
} }
// クラスIDが設定されているかどうかを判定
private boolean isClassIdSet() { private boolean isClassIdSet() {
// classIdが0より大きい場合trueを返す // classIdが0より大きい場合trueを返す
return classId > 0; return classId > 0;
} }
// セットアップが存在するかどうかを判定
private CompletableFuture<Boolean> isSetupExists(int classId) { private CompletableFuture<Boolean> isSetupExists(int classId) {
final ExecutorService executorService = Executors.newSingleThreadExecutor(); final ExecutorService executorService = Executors.newSingleThreadExecutor();
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
AppDatabase db = getDatabaseInstance(); AppDatabase db = getDatabaseInstance();
SetUpTableDao setUpTableDao = db.setUpTableDao(); SetUpTableDao setUpTableDao = db.setUpTableDao();
//データベースの値を全取得
List<SetUpTable> checkData = setUpTableDao.getAll(); List<SetUpTable> checkData = setUpTableDao.getAll();
for (SetUpTable setUpTable : checkData) { for (SetUpTable setUpTable : checkData) {
//SetUpTableのclassIdと引数のclassIdが一致する場合trueを返す
if (setUpTable.classId == classId) { if (setUpTable.classId == classId) {
return true; return true;
} }
} }
return false; return false;
//処理完了時にexecutorServiceをシャットダウン
}, executorService).whenComplete((result, throwable) -> executorService.shutdown()); }, executorService).whenComplete((result, throwable) -> executorService.shutdown());
} }
@ -375,6 +380,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
} }
//Room作成のメソッド
private AppDatabase getDatabaseInstance() { private AppDatabase getDatabaseInstance() {
return Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").fallbackToDestructiveMigration().build(); return Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").fallbackToDestructiveMigration().build();
} }