UUIDの作成完了したけど、
1.roomにString classIdの作成 2.SetUpの際に、classIdを挿入すること 3.classIdをmainアクティビティで取得する手段を作る 4.以上のことを実装するためにユーザーにid作成、setupをすることを促すような制限をかける
This commit is contained in:
parent
9bad03da2d
commit
1c210f62aa
|
@ -5,7 +5,7 @@
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
<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$" />
|
||||||
|
|
|
@ -1,12 +1,26 @@
|
||||||
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 String generateUUID(List<String> classIdList ){
|
||||||
// UUIDを生成する処理
|
while (true){
|
||||||
UUID uuid = UUID.randomUUID();
|
String uuid = String.valueOf((int)(Math.random()*100000));
|
||||||
return uuid.toString();
|
boolean isDuplicate = false;
|
||||||
|
for(String classId : classIdList){
|
||||||
|
if(Integer.parseInt(classId) == Integer.parseInt(uuid)){
|
||||||
|
//重複があればフラグを立て、ループを抜ける
|
||||||
|
isDuplicate = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//重複がなければ生成したUUIDを返す
|
||||||
|
if (!isDuplicate) {
|
||||||
|
//firestoreに挿入処理
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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,7 +84,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
db = FirebaseFirestore.getInstance();
|
db = FirebaseFirestore.getInstance();
|
||||||
firestoreReception = new FirestoreReception();
|
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を表示するかのダイアログ
|
//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();
|
String 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());
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||||
|
@ -227,8 +241,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();
|
||||||
|
|
|
@ -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 -> {
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user