削除機能の実装

This commit is contained in:
nemukemo 2024-06-20 18:27:17 +09:00
parent b99aa2973d
commit 410d4f2402
3 changed files with 40 additions and 17 deletions

View File

@ -107,23 +107,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
runOnUiThread(() -> { runOnUiThread(() -> {
if (totalStudent != myDataListSize) { if (totalStudent != myDataListSize) {
// 値が一致しない場合ダイアログを表示 // 値が一致しない場合ダイアログを表示
new AlertDialog.Builder(MainActivity.this) showRouteCreationDialog();
.setTitle("警告")
.setMessage("人数が足りてませんがそれでもルート作成を行いますか?")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent toRoot = new Intent(MainActivity.this,Maps.class);
startActivity(toRoot);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.show();
} else { } else {
Intent toRoot = new Intent(MainActivity.this,Maps.class); Intent toRoot = new Intent(MainActivity.this,Maps.class);
startActivity(toRoot); startActivity(toRoot);
@ -160,4 +144,24 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}); });
builder.show(); builder.show();
} }
//ルート作成のダイアログ
private void showRouteCreationDialog() {
new AlertDialog.Builder(MainActivity.this)
.setTitle("警告")
.setMessage("人数が足りてませんがそれでもルート作成を行いますか?")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent toRoot = new Intent(MainActivity.this,Maps.class);
startActivity(toRoot);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.show();
}
} }

View File

@ -177,6 +177,8 @@ public class SetUpActivity extends FragmentActivity
showTimePickerDialog(); showTimePickerDialog();
}); });
//リセットボタンの処理
reset.setOnClickListener(v -> { //テキストとラジオボタンの選択を消去 reset.setOnClickListener(v -> { //テキストとラジオボタンの選択を消去
setTeacherName.setText(""); setTeacherName.setText("");
setStartPoint.setText(""); setStartPoint.setText("");
@ -188,6 +190,13 @@ public class SetUpActivity extends FragmentActivity
setStartBreakTime.setText(""); setStartBreakTime.setText("");
setEndBreakTime.setText(""); setEndBreakTime.setText("");
setTotalStudent.setText(""); setTotalStudent.setText("");
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(() -> {
AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build();
SetUpTableDao setUpTableDao = db.setUpTableDao();
setUpTableDao.deleteAll();
});
}); });
} }

View File

@ -14,9 +14,19 @@ public interface SetUpTableDao {
@Update @Update
void update(SetUpTable setUpTable); void update(SetUpTable setUpTable);
//名前が一致しているかの確認 //名前が一致しているかの確認
//削除処理
@Query("DELETE FROM SetUpTable")
void deleteAll();
@Query("SELECT * FROM SetUpTable WHERE teacherName = :name LIMIT 1") @Query("SELECT * FROM SetUpTable WHERE teacherName = :name LIMIT 1")
SetUpTable findByName(String name); SetUpTable findByName(String name);
@Query("SELECT totalStudent FROM SetUpTable") @Query("SELECT totalStudent FROM SetUpTable")
int getTotalStudent(); int getTotalStudent();
//開始時間と終了時間の取得
@Query("SELECT startTime FROM SetUpTable")
String getStartTime();
@Query("SELECT endTime FROM SetUpTable")
String getEndTime();
} }