Merge branch 'master' into CreateUi

This commit is contained in:
oKikuti 2024-06-11 16:00:29 +09:00
commit 64f08d1c6c
3 changed files with 115 additions and 13 deletions

View File

@ -1,14 +1,12 @@
package com.example.oplogy; package com.example.oplogy;
import androidx.appcompat.app.AppCompatActivity; import java.util.UUID;
import android.os.Bundle; public class CreateUUID {
public class CreateUUID extends AppCompatActivity { public static String generateUUID() {
// UUIDを生成する処理
@Override UUID uuid = UUID.randomUUID();
protected void onCreate(Bundle savedInstanceState) { return uuid.toString();
super.onCreate(savedInstanceState);
setContentView(R.layout.create_uuid);
} }
} }

View File

@ -0,0 +1,66 @@
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.Timestamp;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.QueryDocumentSnapshot;
import com.google.firebase.firestore.QuerySnapshot;
import java.util.List;
import java.util.Map;
public class FirestoreReception {
private FirebaseFirestore db;
public FirestoreReception() {
db = FirebaseFirestore.getInstance();
}
//ClassIdを引数にデータの作成を行う
public void getDocumentsByClassId(int classId) {
CollectionReference collectionRef = db.collection("QuestionnaireForms");
// classIdが引数のものを取得する
collectionRef.whereEqualTo("classId", classId).get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
// データの取得に成功した場合
for (QueryDocumentSnapshot document : task.getResult()) {
Map<String, Object> data = document.getData();
// デバッグ用のログ出力
Log.d("FirestoreReception", "Document ID: " + document.getId());
Log.d("FirestoreReception", "Data: " + data);
// ここでデータを取得し必要に応じて処理を行います
// String parentName = (String) data.get("patronName");
// String childName = (String) data.get("childName");
// String studentId = (String) data.get("studentNumber");
//// Timestamp address = (Timestamp) data.get("address");
// List<Timestamp> firstDay = (List<Timestamp>) data.get("firstDay");
// List<Timestamp> secondDay = (List<Timestamp>) data.get("secondDay");
// List<Timestamp> thirdDay = (List<Timestamp>) data.get("thirdDay");
//
// // 取得したデータを使って必要な処理を行う
// Log.d("FirestoreReception", "ParentName: " + parentName);
// Log.d("FirestoreReception", "ChildName: " + childName);
// Log.d("FirestoreReception", "StudentNumber: " + studentId);
//// Log.d("FirestoreReception", "Address: " + address.toDate());
// Log.d("FirestoreReception", "First Day: " + firstDay);
// Log.d("FirestoreReception", "Second Day: " + secondDay);
// Log.d("FirestoreReception", "Third Day: " + thirdDay);
}
} else {
Log.w("FirestoreReception", "Error getting documents.", task.getException());
}
}
});
}
}

View File

@ -1,13 +1,19 @@
package com.example.oplogy; package com.example.oplogy;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.google.firebase.firestore.FirebaseFirestore;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{ public class MainActivity extends AppCompatActivity implements View.OnClickListener{
@ -28,6 +34,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private int previousRoot = 0; //元の画像のインデックス private int previousRoot = 0; //元の画像のインデックス
// 提出状況のTextViewとImageView // 提出状況のTextViewとImageView
private TextView submission; private TextView submission;
//firestoreの受信関連
private FirebaseFirestore db;
private FirestoreReception firestoreReception;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -51,6 +63,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
submission = findViewById(R.id.submission); submission = findViewById(R.id.submission);
submission.setOnClickListener(this); submission.setOnClickListener(this);
// firestoreの受信関連
db = FirebaseFirestore.getInstance();
firestoreReception = new FirestoreReception();
firestoreReception.getDocumentsByClassId(100);
} }
@ -61,8 +81,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
// ID作成のクリック処理 // ID作成のクリック処理
if(view == creatUUID){ if(view == creatUUID){
imageUuid.setImageResource(R.drawable.ischecked_uuid); imageUuid.setImageResource(R.drawable.ischecked_uuid);
Intent toCreateUUID = new Intent(MainActivity.this, CreateUUID.class); showUUIDYesNoDialog();//UUIDを表示するかのダイアログ
startActivity(toCreateUUID);
} }
// セットアップのクリック処理 // セットアップのクリック処理
@ -83,9 +102,28 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
Intent toSubmission = new Intent(MainActivity.this,SubmissionActivity.class); Intent toSubmission = new Intent(MainActivity.this,SubmissionActivity.class);
startActivity(toSubmission); startActivity(toSubmission);
} }
} }
private void showUUIDYesNoDialog() {
//ダイアログの表示
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("クラスID");
builder.setMessage("あなたのクラスIDを表示しますか");
//YESのときは初回はUUIDを生成表示
//二回目以降は保存されたUUIDを表示
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String classId = CreateUUID.generateUUID();//classIDにuuidが入ってる
Toast.makeText(MainActivity.this, "クラスID: " + classId, Toast.LENGTH_SHORT).show();//テスト用
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.d("DialogNO","DialogでNoが選ばれました");
}
});
builder.show();
}
} }