Compare commits
3 Commits
master
...
reception_
Author | SHA1 | Date | |
---|---|---|---|
|
ae904cfb21 | ||
|
3149a5c498 | ||
|
8c0f2530a5 |
29
app/src/google-services.json
Normal file
29
app/src/google-services.json
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"project_info": {
|
||||
"project_number": "317219128586",
|
||||
"project_id": "oplogy-b6971",
|
||||
"storage_bucket": "oplogy-b6971.appspot.com"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:317219128586:android:c29583456e8fbd5f12a6f3",
|
||||
"android_client_info": {
|
||||
"package_name": "com.example.oplogy"
|
||||
}
|
||||
},
|
||||
"oauth_client": [],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyDaULi2TFHLiscR7DSZBCKS08d76Rtb49c"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": []
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"configuration_version": "1"
|
||||
}
|
66
app/src/main/java/com/example/oplogy/FirestoreReception.java
Normal file
66
app/src/main/java/com/example/oplogy/FirestoreReception.java
Normal 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("adress");
|
||||
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());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,8 +1,6 @@
|
|||
package com.example.oplogy;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
@ -11,133 +9,37 @@ import android.widget.TextView;
|
|||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.google.firebase.firestore.FirebaseFirestore;
|
||||
import com.google.firebase.firestore.QueryDocumentSnapshot;
|
||||
|
||||
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
||||
private TextView textView;
|
||||
private Button btnShow;
|
||||
private Button btnAdd;
|
||||
private EditText number;
|
||||
private EditText address;
|
||||
private EditText date;
|
||||
private EditText time;
|
||||
private FirebaseFirestore db = FirebaseFirestore.getInstance();
|
||||
private TextView showText;
|
||||
private EditText selectText;
|
||||
|
||||
private Button btnshow;
|
||||
|
||||
private FirebaseFirestore db;
|
||||
private FirestoreReception firestoreReception;
|
||||
|
||||
Button button;
|
||||
// TextView textView;
|
||||
EditText editText;
|
||||
@SuppressLint("MissingInflatedId")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
|
||||
textView=findViewById(R.id.showText);
|
||||
btnShow=findViewById(R.id.btnShow);
|
||||
btnAdd=findViewById(R.id.btnAdd);
|
||||
db = FirebaseFirestore.getInstance();
|
||||
firestoreReception = new FirestoreReception();
|
||||
showText = findViewById(R.id.showText);
|
||||
btnshow = findViewById(R.id.btnShow);
|
||||
selectText = findViewById(R.id.selectEdit);
|
||||
|
||||
number=findViewById(R.id.editNumber);
|
||||
address=findViewById(R.id.editAddress);
|
||||
date=findViewById(R.id.editDate);
|
||||
time=findViewById(R.id.editTime);
|
||||
|
||||
|
||||
//データの追加(適当なデータを追加しています。実際にはデータベースに保存したいデータを追加してください。)
|
||||
|
||||
findViewById(R.id.btnAdd).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
User user = new User(number.getText().toString(), address.getText().toString(),date.getText().toString(),time.getText().toString());
|
||||
|
||||
|
||||
db.collection("users")
|
||||
.add(user)
|
||||
.addOnSuccessListener(documentReference -> Log.d("@FB1", "DocumentSnapshot added with ID: " + documentReference.getId()))
|
||||
.addOnFailureListener(e -> Log.w("@FB1", "Error adding document", e));
|
||||
}
|
||||
btnshow.setOnClickListener(v -> {
|
||||
String classId = selectText.getText().toString();
|
||||
firestoreReception.getDocumentsByClassId(Integer.parseInt(classId));
|
||||
});
|
||||
|
||||
|
||||
btnShow.setOnClickListener(v -> {
|
||||
// ⑤Read Data
|
||||
// Firestoreのコレクション「users」のドキュメント一覧を取得する
|
||||
// 非同期で取得処理が動作する。結果を受け取るために処理完了時のリスナーをセットする
|
||||
db.collection("users").get().addOnCompleteListener(task -> {
|
||||
String data = "";
|
||||
if (task.isSuccessful()) {
|
||||
for (QueryDocumentSnapshot document : task.getResult()) {
|
||||
Log.d("@FB1", document.getId() + "=>" + document.getData());
|
||||
User user = document.toObject(User.class);
|
||||
data += user + "\n";
|
||||
}
|
||||
} else {
|
||||
data = "Error getting documents." + task.getException().getMessage();
|
||||
}
|
||||
textView.setText(data);//編集したデータを画面下部に表示
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
findViewById(R.id.mapmapcreate).setOnClickListener(
|
||||
view->{
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
public void onClick(View view) {
|
||||
|
||||
}
|
||||
}
|
||||
class User {
|
||||
private String number;
|
||||
private String address;
|
||||
private String date;
|
||||
private String time;
|
||||
|
||||
public User() {
|
||||
}
|
||||
|
||||
public User(String number, String address, String data, String time) {
|
||||
this.number = number;
|
||||
this.address = address;
|
||||
this.date = data;
|
||||
this.time = time;
|
||||
}
|
||||
//getterとsetter
|
||||
public String getNumber() {
|
||||
return number;
|
||||
}
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
public void setNumber(String number) {
|
||||
this.number = number;
|
||||
}
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
public void setDate(String date) {
|
||||
this.date = date;
|
||||
}
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
}
|
|
@ -8,62 +8,4 @@
|
|||
android:orientation="vertical">
|
||||
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editNumber"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="番号" />
|
||||
<EditText
|
||||
android:id="@+id/editAddress"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="住所" />
|
||||
<EditText
|
||||
android:id="@+id/editDate"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="日付" />
|
||||
<EditText
|
||||
android:id="@+id/editTime"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="時間" />
|
||||
<Button
|
||||
android:id="@+id/btnAdd"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="追加"/>
|
||||
<Button
|
||||
android:id="@+id/btnShow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="表示" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/showText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="" />
|
||||
|
||||
|
||||
=======
|
||||
<Button
|
||||
android:id="@+id/mapmapcreate"
|
||||
android:text="マップ生成"
|
||||
android:textSize="50px"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/textview1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="100px"
|
||||
android:hint="ここだよ"
|
||||
android:text=""
|
||||
/>
|
||||
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user