murakumo_UUIDを何とかするの会_roomに追加し隊 #22
|
@ -4,6 +4,7 @@
|
||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
|
<option name="testRunner" value="GRADLE" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
|
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
|
|
|
@ -3,7 +3,7 @@ package com.example.oplogy;
|
||||||
import androidx.room.Database;
|
import androidx.room.Database;
|
||||||
import androidx.room.RoomDatabase;
|
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 class AppDatabase extends RoomDatabase {
|
||||||
// データベースにアクセスするためのメソッドを提供する
|
// データベースにアクセスするためのメソッドを提供する
|
||||||
public abstract SetUpTableDao setUpTableDao();
|
public abstract SetUpTableDao setUpTableDao();
|
||||||
|
|
|
@ -5,12 +5,12 @@ import java.util.List;
|
||||||
|
|
||||||
public class CreateUUID {
|
public class CreateUUID {
|
||||||
|
|
||||||
public static String generateUUID(List<String> classIdList ){
|
public static int generateUUID(List<String> classIdList ){
|
||||||
while (true){
|
while (true){
|
||||||
String uuid = String.valueOf((int)(Math.random()*100000));
|
String uuid = String.valueOf((int)(Math.random() * 1000000));
|
||||||
boolean isDuplicate = false;
|
boolean isDuplicate = false;
|
||||||
for(String classId : classIdList){
|
for(String classId : classIdList){
|
||||||
if(Integer.parseInt(classId) == Integer.parseInt(uuid)){
|
if(classId.equals(uuid)){
|
||||||
//重複があればフラグを立て、ループを抜ける
|
//重複があればフラグを立て、ループを抜ける
|
||||||
isDuplicate = true;
|
isDuplicate = true;
|
||||||
break;
|
break;
|
||||||
|
@ -19,7 +19,9 @@ public class CreateUUID {
|
||||||
//重複がなければ生成したUUIDを返す
|
//重複がなければ生成したUUIDを返す
|
||||||
if (!isDuplicate) {
|
if (!isDuplicate) {
|
||||||
//firestoreに挿入処理
|
//firestoreに挿入処理
|
||||||
return uuid;
|
//テスト用
|
||||||
|
uuid="100";
|
||||||
|
return Integer.parseInt(uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ public class FirestoreReception {
|
||||||
|
|
||||||
//ClassIdを引数にデータの作成を行う
|
//ClassIdを引数にデータの作成を行う
|
||||||
public void getDocumentsByClassId(int classId) {
|
public void getDocumentsByClassId(int classId) {
|
||||||
|
myDataList.clear();
|
||||||
CollectionReference collectionRef = db.collection("QuestionnaireForms");
|
CollectionReference collectionRef = db.collection("QuestionnaireForms");
|
||||||
|
|
||||||
// classIdが引数のものを取得する
|
// classIdが引数のものを取得する
|
||||||
|
|
|
@ -84,12 +84,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
db = FirebaseFirestore.getInstance();
|
db = FirebaseFirestore.getInstance();
|
||||||
firestoreReception = new FirestoreReception();
|
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){
|
if(view == setUp){
|
||||||
imageSetup.setImageResource(R.drawable.ischecked_uuid);
|
imageSetup.setImageResource(R.drawable.ischecked_uuid);
|
||||||
Intent toSetup = new Intent(MainActivity.this,SetUpActivity.class);
|
Intent toSetup = new Intent(MainActivity.this,SetUpActivity.class);
|
||||||
|
toSetup.putExtra("classId", classId);
|
||||||
startActivity(toSetup);
|
startActivity(toSetup);
|
||||||
finish(); // 画面遷移後元の状態に戻す
|
finish(); // 画面遷移後元の状態に戻す
|
||||||
}
|
}
|
||||||
|
@ -156,7 +151,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
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();
|
Toast.makeText(MainActivity.this, "クラスID: " + classId, Toast.LENGTH_SHORT).show();
|
||||||
Log .d("classIdList", classIdList.toString());
|
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);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,8 @@ public class SetUpActivity extends FragmentActivity
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Button startTimeSetButton;
|
Button startTimeSetButton;
|
||||||
Button endTimeSetButton;
|
Button endTimeSetButton;
|
||||||
|
|
||||||
|
@ -61,6 +63,8 @@ public class SetUpActivity extends FragmentActivity
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_set_up);
|
setContentView(R.layout.activity_set_up);
|
||||||
|
|
||||||
|
int classId= getIntent().getIntExtra("classId", 100000);
|
||||||
|
|
||||||
setTeacherName = findViewById(R.id.teacherName); //先生の名前
|
setTeacherName = findViewById(R.id.teacherName); //先生の名前
|
||||||
setStartPoint = findViewById(R.id.startPoint); //開始地点
|
setStartPoint = findViewById(R.id.startPoint); //開始地点
|
||||||
|
|
||||||
|
@ -139,7 +143,8 @@ public class SetUpActivity extends FragmentActivity
|
||||||
intervalTime,
|
intervalTime,
|
||||||
startBreakTime,
|
startBreakTime,
|
||||||
endBreakTime,
|
endBreakTime,
|
||||||
totalStudent
|
totalStudent,
|
||||||
|
classId
|
||||||
);
|
);
|
||||||
|
|
||||||
// 同じ名前のエントリが存在するかどうかを確認
|
// 同じ名前のエントリが存在するかどうかを確認
|
||||||
|
|
|
@ -16,12 +16,13 @@ public class SetUpTable {
|
||||||
public String endBreakTime;
|
public String endBreakTime;
|
||||||
public int totalStudent;
|
public int totalStudent;
|
||||||
|
|
||||||
//TODO: ここのコードをあとで実装する。roomにString classIdの作成
|
//TODO: ここのコードをあとで実装する。roomにint classIdの作成
|
||||||
|
int classId;
|
||||||
|
|
||||||
|
|
||||||
//コンストラクタ
|
//コンストラクタ
|
||||||
public SetUpTable(String teacherName, String startPoint, String startTime, String endTime,
|
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.teacherName = teacherName;
|
||||||
this.startPoint = startPoint;
|
this.startPoint = startPoint;
|
||||||
this.startTime = startTime;
|
this.startTime = startTime;
|
||||||
|
@ -30,6 +31,7 @@ public class SetUpTable {
|
||||||
this.startBreakTime = startBreakTime;
|
this.startBreakTime = startBreakTime;
|
||||||
this.endBreakTime = endBreakTime;
|
this.endBreakTime = endBreakTime;
|
||||||
this.totalStudent = totalStudent;
|
this.totalStudent = totalStudent;
|
||||||
|
this.classId = classId;
|
||||||
}
|
}
|
||||||
//getter
|
//getter
|
||||||
public int getId() {
|
public int getId() {
|
||||||
|
|
|
@ -39,4 +39,7 @@ public interface SetUpTableDao {
|
||||||
String getStartBreakTime();
|
String getStartBreakTime();
|
||||||
@Query("SELECT EndBreakTime FROM SetUpTable")
|
@Query("SELECT EndBreakTime FROM SetUpTable")
|
||||||
String getEndBreakTime();
|
String getEndBreakTime();
|
||||||
|
//クラスIDの取得
|
||||||
|
@Query("SELECT classId FROM SetUpTable")
|
||||||
|
int getClassId();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user