murakumo_UUIDを何とかするの会_roomに追加し隊 #22

Merged
murakumo merged 3 commits from murakumo_UUIDを何とかするの会_roomに追加し隊 into master 2024-06-28 02:15:45 +00:00
8 changed files with 40 additions and 16 deletions
Showing only changes of commit 4a873ffd39 - Show all commits

View File

@ -4,6 +4,7 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
<option name="modules">

View File

@ -3,7 +3,7 @@ package com.example.oplogy;
import androidx.room.Database;
import androidx.room.RoomDatabase;
@Database(entities = {SetUpTable.class}, version = 2)
@Database(entities = {SetUpTable.class}, version = 2, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
// データベースにアクセスするためのメソッドを提供する
public abstract SetUpTableDao setUpTableDao();

View File

@ -5,12 +5,12 @@ import java.util.List;
public class CreateUUID {
public static String generateUUID(List<String> classIdList ){
public static int generateUUID(List<String> classIdList ){
while (true){
String uuid = String.valueOf((int)(Math.random()*100000));
String uuid = String.valueOf((int)(Math.random() * 1000000));
boolean isDuplicate = false;
for(String classId : classIdList){
if(Integer.parseInt(classId) == Integer.parseInt(uuid)){
if(classId.equals(uuid)){
//重複があればフラグを立てループを抜ける
isDuplicate = true;
break;
@ -19,7 +19,9 @@ public class CreateUUID {
//重複がなければ生成したUUIDを返す
if (!isDuplicate) {
//firestoreに挿入処理
return uuid;
//テスト用
uuid="100";
return Integer.parseInt(uuid);
}
}
}

View File

@ -28,6 +28,7 @@ public class FirestoreReception {
//ClassIdを引数にデータの作成を行う
public void getDocumentsByClassId(int classId) {
myDataList.clear();
CollectionReference collectionRef = db.collection("QuestionnaireForms");
// classIdが引数のものを取得する

View File

@ -84,12 +84,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
db = FirebaseFirestore.getInstance();
firestoreReception = new FirestoreReception();
//TODO:3.classIdをmainアクティビティで取得する手段を作る
//4.以上のことを実装するためにユーザーにid作成setupをすることを促すような制限をかける
if(classId!=100000){
firestoreReception.getDocumentsByClassId(classId);
}
}
@ -109,6 +103,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
if(view == setUp){
imageSetup.setImageResource(R.drawable.ischecked_uuid);
Intent toSetup = new Intent(MainActivity.this,SetUpActivity.class);
toSetup.putExtra("classId", classId);
startActivity(toSetup);
finish(); // 画面遷移後元の状態に戻す
}
@ -156,7 +151,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String classId = CreateUUID.generateUUID(classIdList);
classId = CreateUUID.generateUUID(classIdList);
Toast.makeText(MainActivity.this, "クラスID: " + classId, Toast.LENGTH_SHORT).show();
Log .d("classIdList", classIdList.toString());
@ -292,4 +287,19 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}
}
}
@Override
protected void onResume(){
super.onResume();
//roomからclassIdを取得
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(() -> {
AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build();
SetUpTableDao setUpTableDao = db.setUpTableDao();
classId = setUpTableDao.getClassId();
});
if (classId != 100000 ) {
firestoreReception.getDocumentsByClassId(classId);
}
}
}

View File

@ -50,6 +50,8 @@ public class SetUpActivity extends FragmentActivity
Button startTimeSetButton;
Button endTimeSetButton;
@ -61,6 +63,8 @@ public class SetUpActivity extends FragmentActivity
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set_up);
int classId= getIntent().getIntExtra("classId", 100000);
setTeacherName = findViewById(R.id.teacherName); //先生の名前
setStartPoint = findViewById(R.id.startPoint); //開始地点
@ -139,7 +143,8 @@ public class SetUpActivity extends FragmentActivity
intervalTime,
startBreakTime,
endBreakTime,
totalStudent
totalStudent,
classId
);
// 同じ名前のエントリが存在するかどうかを確認

View File

@ -16,12 +16,13 @@ public class SetUpTable {
public String endBreakTime;
public int totalStudent;
//TODO: ここのコードをあとで実装するroomにString classIdの作成
//TODO: ここのコードをあとで実装するroomにint classIdの作成
int classId;
//コンストラクタ
public SetUpTable(String teacherName, String startPoint, String startTime, String endTime,
String intervalTime, String startBreakTime, String endBreakTime, int totalStudent) {
String intervalTime, String startBreakTime, String endBreakTime, int totalStudent,int classId) {
this.teacherName = teacherName;
this.startPoint = startPoint;
this.startTime = startTime;
@ -30,6 +31,7 @@ public class SetUpTable {
this.startBreakTime = startBreakTime;
this.endBreakTime = endBreakTime;
this.totalStudent = totalStudent;
this.classId = classId;
}
//getter
public int getId() {

View File

@ -39,4 +39,7 @@ public interface SetUpTableDao {
String getStartBreakTime();
@Query("SELECT EndBreakTime FROM SetUpTable")
String getEndBreakTime();
//クラスIDの取得
@Query("SELECT classId FROM SetUpTable")
int getClassId();
}