這篇我們實作get方法
@Override
public void getData(String roomNumber){
new Thread(() -> {
database.collection("RoomData")
.whereEqualTo("RoomNumber", roomNumber)
.get()
.addOnCompleteListener(task -> {
if(task.isSuccessful() && task.getResult() != null && task.getResult().getDocuments().size() > 0){
DocumentSnapshot documentSnapshot = task.getResult().getDocuments().get(0);
String getId = documentSnapshot.getId();
String getRoomNumber = documentSnapshot.getString("RoomNumber");
Boolean getPlayer1OnlineState = documentSnapshot.getBoolean("Player1OnlineState");
Boolean getPlayer2OnlineState = documentSnapshot.getBoolean("Player2OnlineState");
String getMoveState = documentSnapshot.getString("MoveState");
HashMap<String,Object> getChessboardData = (HashMap<String, Object>) documentSnapshot.get("ChessboardData");
HashMap<String,Object> getChessmanMoveData = (HashMap<String, Object>) documentSnapshot.get("ChessmanMoveData");
String getTurn = documentSnapshot.getString("Turn");
HashMap<String,Object> getPawnMove1 = (HashMap<String, Object>) documentSnapshot.get("PawnMove1");
HashMap<String,Object> getPawnMove2 = (HashMap<String, Object>) documentSnapshot.get("PawnMove2");
HashMap<String,Object> getCastlingMove1 = (HashMap<String, Object>) documentSnapshot.get("CastlingMove1");
HashMap<String,Object> getCastlingMove2 = (HashMap<String, Object>) documentSnapshot.get("CastlingMove2");
String getDate = documentSnapshot.getString("Date");
String getPlayer1message = documentSnapshot.getString("Player1message");
String getPlayer2message = documentSnapshot.getString("Player2message");
String getWinPlayer = documentSnapshot.getString("WinPlayer");
callback.getSuccess(getId,
getRoomNumber,
getPlayer1OnlineState,
getPlayer2OnlineState,
getMoveState,
getChessboardData,
getChessmanMoveData,
getTurn,
getPawnMove1,
getPawnMove2,
getCastlingMove1,
getCastlingMove2,
getDate,
getPlayer1message,
getPlayer2message,
getWinPlayer);
}
else{
callback.getError();
}
});
}).start();
}
這裡我們取得資料中各端點的快照,以獲得各項資料
下一篇來實作upload方法