CreateRoot2 #7

Merged
Utahshi merged 2 commits from CreateRoot2 into master 2024-06-19 09:39:27 +00:00
3 changed files with 102 additions and 41 deletions
Showing only changes of commit b3f6d3a9ab - Show all commits

View File

@ -4,25 +4,53 @@ import android.util.Log;
import com.google.firebase.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
public class CreateRoot {
public void receiveData(List<MyDataClass> myDataList) {
// デバッグ用ログ
for(MyDataClass data : myDataList){
Log.d("CreateRoot", "data: "+ data.toString());
}
Log.d("CreateRoot", "myDataList[0]: " + myDataList.get(0).toString());
for (MyDataClass data : myDataList) {
Log.d("CreateRoot", "data: " + data.toString());
Timestamp startTime = data.getFirstDay().get(0);
Timestamp endTime = data.getFirstDay().get(1);
for (int i = 0; i < myDataList.size(); i++) {
MyDataClass data = myDataList.get(i);
List<Timestamp> firstDay = data.getFirstDay();
Timestamp startTime = firstDay.get(0);
Timestamp endTime = firstDay.get(1);
Long timezone = endTime.getSeconds() - startTime.getSeconds();
data.setTimezone(timezone);
Log.d("CreateRoot", "timezone: " + timezone);
}
Date startDate = new Date(startTime.getSeconds() * 1000);
Date endDate = new Date(endTime.getSeconds() * 1000);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String startDateString = sdf.format(startDate);
String endDateString = sdf.format(endDate);
// myDataList の中の data に追加する処理
myDataList.get(i).setTimezone(timezone);
myDataList.get(i).setStartDateString(startDateString);
myDataList.get(i).setEndDateString(endDateString);
// ログ出力
Log.d("CreateRoot", "(index: " + i + ") timezone: " + myDataList.get(i).getTimezone());
Log.d("CreateRoot", "(index: " + i + ") startDate: " + myDataList.get(i).getStartDateString());
Log.d("CreateRoot", "(index: " + i + ") data: " + myDataList.get(i));
}
// timezoneを比較するComparatorを作成
Comparator<MyDataClass> comparator = new Comparator<MyDataClass>() {
@Override
public int compare(MyDataClass data1, MyDataClass data2) {
return data1.getTimezone().compareTo(data2.getTimezone());
}
};
// myDataListをtimezoneの値でソート
Collections.sort(myDataList, comparator);
// ソート後のmyDataListをログ出力
for (int i = 0; i < myDataList.size(); i++) {
Log.d("CreateRoot", "(index: " + i + ") timezone: " + myDataList.get(i).getTimezone());
Log.d("CreateRoot", "(index: " + i + ") startDate: " + myDataList.get(i).getStartDateString());
Log.d("CreateRoot", "(index: " + i + ") data: " + myDataList.get(i));
}
}
}
}

View File

@ -15,6 +15,8 @@ public class MyDataClass {
List<Timestamp> secondDay;
double latitude;
private Long Timezone;
private String startDateString;
private String endDateString;
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;
@ -40,66 +42,97 @@ public class MyDataClass {
", secondDay=" + secondDay +
'}';
}
//getter
public String getPatronName() {
return patronName;
}
public int getClassId() {
return classId;
}
public List<String> getAddress() {
return address;
}
public List<Timestamp> getFirstDay() {
return firstDay;
}
public int getStudentNumber() {
return studentNumber;
}
public String getChildName() {
return childName;
}
public List<Timestamp> getThirdDay() {
return thirdDay;
}
public List<Timestamp> getSecondDay() {
return secondDay;
}
public double getLatitude() {
return latitude;
}
//setter
public void setPatronName(String patronName) {
this.patronName = patronName;
}
public int getClassId() {
return classId;
}
public void setClassId(int classId) {
this.classId = classId;
}
public List<String> getAddress() {
return address;
}
public void setAddress(List<String> address) {
this.address = address;
}
public List<Timestamp> getFirstDay() {
return firstDay;
}
public void setFirstDay(List<Timestamp> firstDay) {
this.firstDay = firstDay;
}
public int getStudentNumber() {
return studentNumber;
}
public void setStudentNumber(int studentNumber) {
this.studentNumber = studentNumber;
}
public String getChildName() {
return childName;
}
public void setChildName(String childName) {
this.childName = childName;
}
public List<Timestamp> getThirdDay() {
return thirdDay;
}
public void setThirdDay(List<Timestamp> thirdDay) {
this.thirdDay = thirdDay;
}
public List<Timestamp> getSecondDay() {
return secondDay;
}
public void setSecondDay(List<Timestamp> secondDay) {
this.secondDay = secondDay;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public void setEndDateString(String endDateString) {
this.endDateString = endDateString;
}
public Long getTimezone() {
return Timezone;
}
public void setTimezone(Long Timezone) {
this.Timezone=Timezone;
this.Timezone = Timezone;
}
public String getStartDateString() {
return startDateString;
}
public void setStartDateString(String startDateString) {
this.startDateString = startDateString;
}
}

View File

@ -1,9 +1,9 @@
package com.example.oplogy;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class RootSearchActivity extends AppCompatActivity {
@Override