firestoreから送られてくるデータのmap化 #1
|
@ -4,11 +4,15 @@ 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.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class FirestoreReception {
|
||||
|
@ -20,7 +24,7 @@ public class FirestoreReception {
|
|||
}
|
||||
|
||||
//firestoreから受け取ったデータを束ねるためのマップ
|
||||
public Map<String, Object> firestoreData;
|
||||
public List<MyDataClass>myDataList = new ArrayList<>();
|
||||
|
||||
//ClassIdを引数にデータの作成を行う
|
||||
public void getDocumentsByClassId(int classId, MainActivity context) {
|
||||
|
@ -36,18 +40,31 @@ public class FirestoreReception {
|
|||
for (QueryDocumentSnapshot document : task.getResult()) {
|
||||
Map<String, Object> data = document.getData();
|
||||
|
||||
// CreateRootクラスのインスタンスを作成し、dataを引数として渡す
|
||||
GeoCoder geoCoder = new GeoCoder();
|
||||
geoCoder.processData(data, context);
|
||||
|
||||
// firestoreDataにdataを追加
|
||||
firestoreData = data;
|
||||
//CreateRootクラスのインスタンスを生成、dataを渡す
|
||||
// GeoCoder geoCoder = new GeoCoder();
|
||||
// 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 {
|
||||
Log.w("FirestoreReception", "Error getting documents.", task.getException());
|
||||
Log.w("FirestoreReceptiond", "Error getting documents.", task.getException());
|
||||
}
|
||||
Log.w ("FirestoreReception", "firestoreData: " + firestoreData.size());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
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