firestoreから送られてくるデータのmap化 #1
|
@ -7,6 +7,7 @@
|
||||||
<option name="testRunner" value="GRADLE" />
|
<option name="testRunner" value="GRADLE" />
|
||||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="gradleJvm" value="jbr-17" />
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|
|
@ -4,11 +4,15 @@ import android.util.Log;
|
||||||
|
|
||||||
import com.google.android.gms.tasks.OnCompleteListener;
|
import com.google.android.gms.tasks.OnCompleteListener;
|
||||||
import com.google.android.gms.tasks.Task;
|
import com.google.android.gms.tasks.Task;
|
||||||
|
import com.google.firebase.Timestamp;
|
||||||
import com.google.firebase.firestore.CollectionReference;
|
import com.google.firebase.firestore.CollectionReference;
|
||||||
import com.google.firebase.firestore.FirebaseFirestore;
|
import com.google.firebase.firestore.FirebaseFirestore;
|
||||||
import com.google.firebase.firestore.QueryDocumentSnapshot;
|
import com.google.firebase.firestore.QueryDocumentSnapshot;
|
||||||
import com.google.firebase.firestore.QuerySnapshot;
|
import com.google.firebase.firestore.QuerySnapshot;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class FirestoreReception {
|
public class FirestoreReception {
|
||||||
|
@ -19,6 +23,9 @@ public class FirestoreReception {
|
||||||
db = FirebaseFirestore.getInstance();
|
db = FirebaseFirestore.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//firestoreから受け取ったデータを束ねるためのマップ
|
||||||
|
public List<MyDataClass>myDataList = new ArrayList<>();
|
||||||
|
|
||||||
//ClassIdを引数にデータの作成を行う
|
//ClassIdを引数にデータの作成を行う
|
||||||
public void getDocumentsByClassId(int classId, MainActivity context) {
|
public void getDocumentsByClassId(int classId, MainActivity context) {
|
||||||
CollectionReference collectionRef = db.collection("QuestionnaireForms");
|
CollectionReference collectionRef = db.collection("QuestionnaireForms");
|
||||||
|
@ -33,14 +40,33 @@ public class FirestoreReception {
|
||||||
for (QueryDocumentSnapshot document : task.getResult()) {
|
for (QueryDocumentSnapshot document : task.getResult()) {
|
||||||
Map<String, Object> data = document.getData();
|
Map<String, Object> data = document.getData();
|
||||||
|
|
||||||
// CreateRootクラスのインスタンスを作成し、dataを引数として渡す
|
//CreateRootクラスのインスタンスを生成、dataを渡す
|
||||||
GeoCoder geoCoder = new GeoCoder();
|
// GeoCoder geoCoder = new GeoCoder();
|
||||||
geoCoder.processData(data, context);
|
// geoCoder.processData(data, context);
|
||||||
|
|
||||||
|
// ドキュメントのデータをMyDataClassのインスタンスにマッピング
|
||||||
|
MyDataClass myData = new MyDataClass(
|
||||||
|
(String) data.get("patronName"),
|
||||||
|
((Long) data.get("classId")).intValue(),
|
||||||
|
(List<String>) data.get("address"),
|
||||||
|
(List<Timestamp>) data.get("firstDay"),
|
||||||
|
((Long) data.get("studentNumber")).intValue(),
|
||||||
|
(String) data.get("childName"),
|
||||||
|
(List<Timestamp>) data.get("thirdDay"),
|
||||||
|
(List<Timestamp>) data.get("secondDay")
|
||||||
|
);
|
||||||
|
//リストに追加
|
||||||
|
myDataList.add(myData);
|
||||||
|
}
|
||||||
|
//取得したデータをログ表示
|
||||||
|
for(MyDataClass data :myDataList){
|
||||||
|
Log.i("FirestoreReceptiond", "data: " + data.toString());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.w("FirestoreReception", "Error getting documents.", task.getException());
|
Log.w("FirestoreReceptiond", "Error getting documents.", task.getException());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
42
app/src/main/java/com/example/oplogy/MyDataClass.java
Normal file
42
app/src/main/java/com/example/oplogy/MyDataClass.java
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
package com.example.oplogy;
|
||||||
|
|
||||||
|
import com.google.firebase.Timestamp;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MyDataClass {
|
||||||
|
String patronName;
|
||||||
|
int classId;
|
||||||
|
List<String> address;
|
||||||
|
List<Timestamp> firstDay;
|
||||||
|
int studentNumber;
|
||||||
|
String childName;
|
||||||
|
List<Timestamp> thirdDay;
|
||||||
|
List<Timestamp> secondDay;
|
||||||
|
double latitude;
|
||||||
|
|
||||||
|
public MyDataClass(String patronName, int classId, List<String> address, List<Timestamp> firstDay, int studentNumber, String childName, List<Timestamp> thirdDay, List<Timestamp> secondDay) {
|
||||||
|
this.patronName = patronName;
|
||||||
|
this.classId = classId;
|
||||||
|
this.address = address;
|
||||||
|
this.firstDay = firstDay;
|
||||||
|
this.studentNumber = studentNumber;
|
||||||
|
this.childName = childName;
|
||||||
|
this.thirdDay = thirdDay;
|
||||||
|
this.secondDay = secondDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "MyDataClass{" +
|
||||||
|
"patronName='" + patronName + '\'' +
|
||||||
|
", classId=" + classId +
|
||||||
|
", address=" + address +
|
||||||
|
", firstDay=" + firstDay +
|
||||||
|
", studentNumber=" + studentNumber +
|
||||||
|
", childName='" + childName + '\'' +
|
||||||
|
", thirdDay=" + thirdDay +
|
||||||
|
", secondDay=" + secondDay +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user