murakumo_UUIDを何とかするの会 #21

Merged
murakumo merged 3 commits from murakumo_UUIDを何とかするの会 into master 2024-06-28 02:02:01 +00:00
7 changed files with 109 additions and 25 deletions

View File

@ -4,8 +4,9 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<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

@ -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

@ -1,12 +1,28 @@
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 int generateUUID(List<String> classIdList ){
while (true){
String uuid = String.valueOf((int)(Math.random() * 1000000));
boolean isDuplicate = false;
for(String classId : classIdList){
if(classId.equals(uuid)){
//重複があればフラグを立てループを抜ける
isDuplicate = true;
break;
}
}
//重複がなければ生成したUUIDを返す
if (!isDuplicate) {
//firestoreに挿入処理
//テスト用
uuid="100";
return Integer.parseInt(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,33 +84,35 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
db = FirebaseFirestore.getInstance();
firestoreReception = new FirestoreReception();
firestoreReception.getDocumentsByClassId(100);
if(classId!=100000){
firestoreReception.getDocumentsByClassId(classId);
}
}
// クリック処理
// クリック処理
@Override
public void onClick(View view) {
// ID作成のクリック処理
if (view == creatUUID) {
if(view == creatUUID){
imageUuid.setImageResource(R.drawable.ischecked_uuid);
showUUIDYesNoDialog();//UUIDを表示するかのダイアログ
}
if (view == imageUuid) {
if(view == imageUuid){
imageUuid.setImageResource(R.drawable.ischecked_uuid);
showUUIDYesNoDialog();//UUIDを表示するかのダイアログ
}
// セットアップのクリック処理
if (view == setUp) {
if(view == setUp){
imageSetup.setImageResource(R.drawable.ischecked_uuid);
Intent toSetup = new Intent(MainActivity.this, SetUpActivity.class);
Intent toSetup = new Intent(MainActivity.this,SetUpActivity.class);
startActivity(toSetup);
finish(); // 画面遷移後元の状態に戻す
}
if (view == imageSetup) {
if (view == imageSetup){
imageSetup.setImageResource(R.drawable.ischecked_uuid);
Intent toSetup = new Intent(MainActivity.this, SetUpActivity.class);
Intent toSetup = new Intent(MainActivity.this,SetUpActivity.class);
startActivity(toSetup);
finish(); // 画面遷移後元の状態に戻す
}
@ -117,12 +123,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
fetchDataAndCreateRoute();
}
if (view == imageRoot) {
if(view == imageRoot){
imageRoot.setImageResource(R.drawable.pin);
fetchDataAndCreateRoute();
}
// 提出状況のクリック処理
if (view == submission) {
if(view == submission){
ArrayList<SubmissionStudent> submissionStudents = getSubmissionStudents();
Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class);
toSubmission.putParcelableArrayListExtra("submissionStudents", submissionStudents);
@ -135,17 +141,20 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
startActivity(toSubmission);
}
}
//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();
classId = CreateUUID.generateUUID(classIdList);
Toast.makeText(MainActivity.this, "クラスID: " + classId, Toast.LENGTH_SHORT).show();
}
});
@ -278,7 +287,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();
@ -329,8 +338,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}
}
}
@Override
protected void onResume(){
super.onResume();
if (classId != 100000) {
firestoreReception.getDocumentsByClassId(classId);
}
}
}

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,