diff --git a/app/src/main/java/com/example/oplogy/FirestoreReception.java b/app/src/main/java/com/example/oplogy/FirestoreReception.java index 1082f09..232bfb7 100644 --- a/app/src/main/java/com/example/oplogy/FirestoreReception.java +++ b/app/src/main/java/com/example/oplogy/FirestoreReception.java @@ -27,6 +27,7 @@ public class FirestoreReception { //ClassIdを引数にデータの作成を行う public void getDocumentsByClassId(int classId) { + myDataList.clear(); CollectionReference collectionRef = db.collection("QuestionnaireForms"); // classIdが引数のものを取得する diff --git a/app/src/main/java/com/example/oplogy/MainActivity.java b/app/src/main/java/com/example/oplogy/MainActivity.java index b844925..e759dc1 100644 --- a/app/src/main/java/com/example/oplogy/MainActivity.java +++ b/app/src/main/java/com/example/oplogy/MainActivity.java @@ -84,10 +84,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe db = FirebaseFirestore.getInstance(); firestoreReception = new FirestoreReception(); - if(classId!=100000){ - firestoreReception.getDocumentsByClassId(classId); - } - } @@ -107,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(); // 画面遷移後元の状態に戻す } @@ -177,7 +174,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe CountDownLatch latch = new CountDownLatch(2); - // タスク1: ローカルDBから生徒数を取得 + // タスク1: ローカルDBから生徒数を取得してtotalStudentと比較 executor.execute(() -> { AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build(); SetUpTableDao setUpTableDao = db.setUpTableDao(); @@ -196,7 +193,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe }); }); - // タスク2: Firestoreからデータを取得 + // タスク2: ルート作成を行う executor.execute(() -> { List myDataList = null; while (myDataList == null) { @@ -341,9 +338,15 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe @Override protected void onResume(){ super.onResume(); - if (classId != 100000) { + //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); } } - } \ No newline at end of file diff --git a/app/src/main/java/com/example/oplogy/SetUpActivity.java b/app/src/main/java/com/example/oplogy/SetUpActivity.java index 8b3385d..851d0f1 100644 --- a/app/src/main/java/com/example/oplogy/SetUpActivity.java +++ b/app/src/main/java/com/example/oplogy/SetUpActivity.java @@ -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 ); // 同じ名前のエントリが存在するかどうかを確認 diff --git a/app/src/main/java/com/example/oplogy/SetUpTable.java b/app/src/main/java/com/example/oplogy/SetUpTable.java index a61ed27..dfb21ad 100644 --- a/app/src/main/java/com/example/oplogy/SetUpTable.java +++ b/app/src/main/java/com/example/oplogy/SetUpTable.java @@ -16,12 +16,12 @@ public class SetUpTable { public String endBreakTime; public int totalStudent; - //TODO: ここのコードをあとで実装する。roomにString 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 +30,7 @@ public class SetUpTable { this.startBreakTime = startBreakTime; this.endBreakTime = endBreakTime; this.totalStudent = totalStudent; + this.classId = classId; } //getter public int getId() { diff --git a/app/src/main/java/com/example/oplogy/SetUpTableDao.java b/app/src/main/java/com/example/oplogy/SetUpTableDao.java index ec59624..5c21478 100644 --- a/app/src/main/java/com/example/oplogy/SetUpTableDao.java +++ b/app/src/main/java/com/example/oplogy/SetUpTableDao.java @@ -39,4 +39,7 @@ public interface SetUpTableDao { String getStartBreakTime(); @Query("SELECT EndBreakTime FROM SetUpTable") String getEndBreakTime(); + //クラスIDの取得 + @Query("SELECT classId FROM SetUpTable") + int getClassId(); }