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"> <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="jbr-17" /> <option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />

View File

@ -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();

View File

@ -1,12 +1,28 @@
package com.example.oplogy; package com.example.oplogy;
import java.util.UUID;
import java.util.List;
public class CreateUUID { public class CreateUUID {
public static String generateUUID() { public static int generateUUID(List<String> classIdList ){
// UUIDを生成する処理 while (true){
UUID uuid = UUID.randomUUID(); String uuid = String.valueOf((int)(Math.random() * 1000000));
return uuid.toString(); 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の受信関連 //firestoreの受信関連
private FirebaseFirestore db; private FirebaseFirestore db;
private FirestoreReception firestoreReception; private FirestoreReception firestoreReception;
private FirestoreReception_classIdDatabase firestoreReception_classIdDatabase;
//取得するためのクラスID
private int classId=100000;
@Override @Override
@ -80,33 +84,35 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
db = FirebaseFirestore.getInstance(); db = FirebaseFirestore.getInstance();
firestoreReception = new FirestoreReception(); firestoreReception = new FirestoreReception();
firestoreReception.getDocumentsByClassId(100); if(classId!=100000){
firestoreReception.getDocumentsByClassId(classId);
}
} }
// クリック処理 // クリック処理
@Override @Override
public void onClick(View view) { public void onClick(View view) {
// ID作成のクリック処理 // ID作成のクリック処理
if (view == creatUUID) { if(view == creatUUID){
imageUuid.setImageResource(R.drawable.ischecked_uuid); imageUuid.setImageResource(R.drawable.ischecked_uuid);
showUUIDYesNoDialog();//UUIDを表示するかのダイアログ showUUIDYesNoDialog();//UUIDを表示するかのダイアログ
} }
if (view == imageUuid) { if(view == imageUuid){
imageUuid.setImageResource(R.drawable.ischecked_uuid); imageUuid.setImageResource(R.drawable.ischecked_uuid);
showUUIDYesNoDialog();//UUIDを表示するかのダイアログ showUUIDYesNoDialog();//UUIDを表示するかのダイアログ
} }
// セットアップのクリック処理 // セットアップのクリック処理
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);
startActivity(toSetup); startActivity(toSetup);
finish(); // 画面遷移後元の状態に戻す finish(); // 画面遷移後元の状態に戻す
} }
if (view == imageSetup) { if (view == imageSetup){
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);
startActivity(toSetup); startActivity(toSetup);
finish(); // 画面遷移後元の状態に戻す finish(); // 画面遷移後元の状態に戻す
} }
@ -117,12 +123,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
fetchDataAndCreateRoute(); fetchDataAndCreateRoute();
} }
if (view == imageRoot) { if(view == imageRoot){
imageRoot.setImageResource(R.drawable.pin); imageRoot.setImageResource(R.drawable.pin);
fetchDataAndCreateRoute(); fetchDataAndCreateRoute();
} }
// 提出状況のクリック処理 // 提出状況のクリック処理
if (view == submission) { if(view == submission){
ArrayList<SubmissionStudent> submissionStudents = getSubmissionStudents(); ArrayList<SubmissionStudent> submissionStudents = getSubmissionStudents();
Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class); Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class);
toSubmission.putParcelableArrayListExtra("submissionStudents", submissionStudents); toSubmission.putParcelableArrayListExtra("submissionStudents", submissionStudents);
@ -135,17 +141,20 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
startActivity(toSubmission); startActivity(toSubmission);
} }
} }
//UUIDを表示するかのダイアログ //UUIDを表示するかのダイアログ
private void showUUIDYesNoDialog() { 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.setTitle("クラスID");
builder.setMessage("あなたのクラスIDを表示しますか"); builder.setMessage("あなたのクラスIDを表示しますか");
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(); classId = CreateUUID.generateUUID(classIdList);
Toast.makeText(MainActivity.this, "クラスID: " + classId, Toast.LENGTH_SHORT).show(); Toast.makeText(MainActivity.this, "クラスID: " + classId, Toast.LENGTH_SHORT).show();
} }
}); });
@ -278,7 +287,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
.show(); .show();
} }
//Main //提出状況の取得
private ArrayList<SubmissionStudent> getSubmissionStudents() { private ArrayList<SubmissionStudent> getSubmissionStudents() {
ArrayList<SubmissionStudent> submissionStudents = new ArrayList<>(); ArrayList<SubmissionStudent> submissionStudents = new ArrayList<>();
List<MyDataClass> myDataList = firestoreReception.getMyDataList(); 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画面へ戻る処理 Intent intent = new Intent(SetUpActivity.this,MainActivity.class); //main画面へ戻る処理
startActivity(intent); startActivity(intent);
}); });
//TODO:.SetUpの際にclassIdを挿入すること
setUp.setOnClickListener(view -> { setUp.setOnClickListener(view -> {

View File

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