classIdを受け取るロジックが画面遷移から戻ってきたときにも実行されるように変更

This commit is contained in:
nemukemo 2024-06-26 16:30:37 +09:00
parent 1c210f62aa
commit 9b56412cb0
4 changed files with 17 additions and 6 deletions

View File

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

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

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

View File

@ -156,7 +156,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 +292,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
} }
} }
@Override
protected void onResume(){
super.onResume();
if (classId != 100000) {
firestoreReception.getDocumentsByClassId(classId);
}
}
} }