Compare commits

...

3 Commits

Author SHA1 Message Date
nemukemo
ae904cfb21 クラスIDを基にデータの受信を行う
ログに出力してます
追記:mainactivityの削除
2024-06-11 14:22:16 +09:00
nemukemo
3149a5c498 クラスIDを基にデータの受信を行う
ログに出力してます
2024-06-11 14:07:48 +09:00
nemukemo
8c0f2530a5 クラウドからデータを取得はできるけどtimestampが1970年からの秒数になっているため改良しましょう6/6 2024-06-06 18:46:27 +09:00
4 changed files with 110 additions and 171 deletions

View 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"
}

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("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());
}
}
});
}
}

View File

@ -1,8 +1,6 @@
package com.example.oplogy; package com.example.oplogy;
import android.annotation.SuppressLint;
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.EditText; import android.widget.EditText;
@ -11,133 +9,37 @@ import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import com.google.firebase.firestore.FirebaseFirestore; import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.QueryDocumentSnapshot;
public class MainActivity extends AppCompatActivity implements View.OnClickListener { public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private TextView textView; private TextView showText;
private Button btnShow; private EditText selectText;
private Button btnAdd;
private EditText number;
private EditText address;
private EditText date;
private EditText time;
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private Button btnshow;
private FirebaseFirestore db;
private FirestoreReception firestoreReception;
Button button;
// TextView textView;
EditText editText;
@SuppressLint("MissingInflatedId")
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
textView=findViewById(R.id.showText); db = FirebaseFirestore.getInstance();
btnShow=findViewById(R.id.btnShow); firestoreReception = new FirestoreReception();
btnAdd=findViewById(R.id.btnAdd); showText = findViewById(R.id.showText);
btnshow = findViewById(R.id.btnShow);
selectText = findViewById(R.id.selectEdit);
number=findViewById(R.id.editNumber); btnshow.setOnClickListener(v -> {
address=findViewById(R.id.editAddress); String classId = selectText.getText().toString();
date=findViewById(R.id.editDate); firestoreReception.getDocumentsByClassId(Integer.parseInt(classId));
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 -> {
// 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 @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;
}
}

View File

@ -8,62 +8,4 @@
android:orientation="vertical"> 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> </LinearLayout>