UUIDの作成完了したけど、

1.roomにString classIdの作成
2.SetUpの際に、classIdを挿入すること
3.classIdをmainアクティビティで取得する手段を作る
4.以上のことを実装するためにユーザーにid作成、setupをすることを促すような制限をかける
This commit is contained in:
nemukemo 2024-06-25 20:09:21 +09:00
parent 9bad03da2d
commit 1c210f62aa
6 changed files with 92 additions and 11 deletions

View File

@ -5,7 +5,7 @@
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="jbr-17" />
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />

View File

@ -1,12 +1,26 @@
package com.example.oplogy;
import java.util.UUID;
import java.util.List;
public class CreateUUID {
public static String generateUUID() {
// UUIDを生成する処理
UUID uuid = UUID.randomUUID();
return uuid.toString();
public static String generateUUID(List<String> classIdList ){
while (true){
String uuid = String.valueOf((int)(Math.random()*100000));
boolean isDuplicate = false;
for(String classId : classIdList){
if(Integer.parseInt(classId) == Integer.parseInt(uuid)){
//重複があればフラグを立てループを抜ける
isDuplicate = true;
break;
}
}
//重複がなければ生成したUUIDを返す
if (!isDuplicate) {
//firestoreに挿入処理
return uuid;
}
}
}
}

View File

@ -0,0 +1,51 @@
package com.example.oplogy;
import android.util.Log;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.QueryDocumentSnapshot;
import com.google.firebase.firestore.QuerySnapshot;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class FirestoreReception_classIdDatabase {
private FirebaseFirestore db;
private List<String> classIdList= new ArrayList<>();
public FirestoreReception_classIdDatabase() {
db = FirebaseFirestore.getInstance();
}
public List<String> getAllDocumentsFromClassIdDatabase() {
db.collection("classId_Database")
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Log.d("結果", document.getId() + " => " + document.getData());
//データをListに追加
classIdList.add((String) document.get("classId"));
}
} else {
Log.d("結果", "Error getting documents: ", task.getException());
}
}
});
return classIdList;
}
public List<String> getClassIdList() {
return classIdList;
}
}

View File

@ -45,6 +45,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
//firestoreの受信関連
private FirebaseFirestore db;
private FirestoreReception firestoreReception;
private FirestoreReception_classIdDatabase firestoreReception_classIdDatabase;
//取得するためのクラスID
private int classId=100000;
@Override
@ -80,7 +84,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
db = FirebaseFirestore.getInstance();
firestoreReception = new FirestoreReception();
firestoreReception.getDocumentsByClassId(100);
//TODO:3.classIdをmainアクティビティで取得する手段を作る
//4.以上のことを実装するためにユーザーにid作成setupをすることを促すような制限をかける
if(classId!=100000){
firestoreReception.getDocumentsByClassId(classId);
}
}
@ -137,15 +145,21 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}
//UUIDを表示するかのダイアログ
private void showUUIDYesNoDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this); // この 'this' が問題でないか確認
firestoreReception_classIdDatabase = new FirestoreReception_classIdDatabase();
List<String> classIdList = firestoreReception_classIdDatabase.getAllDocumentsFromClassIdDatabase();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("クラスID");
builder.setMessage("あなたのクラスIDを表示しますか");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String classId = CreateUUID.generateUUID();
String classId = CreateUUID.generateUUID(classIdList);
Toast.makeText(MainActivity.this, "クラスID: " + classId, Toast.LENGTH_SHORT).show();
Log .d("classIdList", classIdList.toString());
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@ -227,8 +241,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
.show();
}
//Main
//提出状況の取得
private ArrayList<SubmissionStudent> getSubmissionStudents() {
ArrayList<SubmissionStudent> submissionStudents = new ArrayList<>();
List<MyDataClass> myDataList = firestoreReception.getMyDataList();

View File

@ -91,6 +91,7 @@ public class SetUpActivity extends FragmentActivity
Intent intent = new Intent(SetUpActivity.this,MainActivity.class); //main画面へ戻る処理
startActivity(intent);
});
//TODO:.SetUpの際にclassIdを挿入すること
setUp.setOnClickListener(view -> {

View File

@ -16,6 +16,8 @@ public class SetUpTable {
public String endBreakTime;
public int totalStudent;
//TODO: ここのコードをあとで実装するroomにString classIdの作成
//コンストラクタ
public SetUpTable(String teacherName, String startPoint, String startTime, String endTime,