バグ修正
This commit is contained in:
commit
13120b9856
|
@ -1,9 +1,9 @@
|
|||
package com.example.oplogy;
|
||||
|
||||
import androidx.room.Database;
|
||||
import androidx.room.RoomDatabase;
|
||||
import androidx.room.TypeConverters;
|
||||
|
||||
@Database(entities = {SetUpTable.class}, version = 1)
|
||||
@Database(entities = {SetUpTable.class}, version = 2)
|
||||
public abstract class AppDatabase extends RoomDatabase {
|
||||
// データベースにアクセスするためのメソッドを提供する
|
||||
public abstract SetUpTableDao setUpTableDao();
|
||||
|
|
|
@ -1,18 +1,82 @@
|
|||
package com.example.oplogy;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.room.Room;
|
||||
|
||||
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;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
|
||||
public class CreateRoot {
|
||||
public void receiveData(List<MyDataClass> myDataList) {
|
||||
private Context context;
|
||||
private AppDatabase db;
|
||||
|
||||
// デバッグ用ログ
|
||||
for(MyDataClass data : myDataList){
|
||||
Log.d("CreateRoot", "data: "+ data.toString());
|
||||
public CreateRoot(MainActivity activity) {
|
||||
this.context = activity;
|
||||
this.db = Room.databaseBuilder(activity.getApplicationContext(), AppDatabase.class, "SetUpTable").build();
|
||||
}
|
||||
Log.d("CreateRoot", "myDataList[0]: " + myDataList.get(0).toString());
|
||||
|
||||
public void receiveData(List<MyDataClass> myDataList) {
|
||||
for (int i = 0; i < myDataList.size(); i++) {
|
||||
//希望時間帯の終了時刻から開始時刻を引いて希望時間帯の長さ(timezone)に入れる
|
||||
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);
|
||||
|
||||
//TimeStampを日付に変換
|
||||
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→timezoneが短い順に並べる
|
||||
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));
|
||||
|
||||
}
|
||||
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
executor.execute(() -> {
|
||||
SetUpTableDao setUpTableDao = db.setUpTableDao();
|
||||
String startTime=setUpTableDao.getStartTime();
|
||||
String endTime=setUpTableDao.getEndTime();
|
||||
Log.d("CreateRoot", "開始時間" + startTime);
|
||||
Log.d("CreateRoot", "終了時刻" + endTime);
|
||||
|
||||
});
|
||||
}
|
||||
}
|
|
@ -64,8 +64,6 @@ public class FirestoreReception {
|
|||
for(MyDataClass data :myDataList){
|
||||
Log.i("FirestoreReceptiond", "data: " + data.toString());
|
||||
}
|
||||
CreateRoot createRoot=new CreateRoot();
|
||||
createRoot.receiveData(myDataList);
|
||||
} else {
|
||||
Log.w("FirestoreReceptiond", "Error getting documents.", task.getException());
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ import androidx.room.Room;
|
|||
|
||||
import com.google.firebase.firestore.FirebaseFirestore;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
|
@ -93,27 +95,48 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
// ルート作成のクリック処理
|
||||
if(view == root){
|
||||
imageRoot.setImageResource(R.drawable.pin);
|
||||
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
|
||||
CountDownLatch latch = new CountDownLatch(2);
|
||||
|
||||
executor.execute(() -> {
|
||||
AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build();
|
||||
SetUpTableDao setUpTableDao = db.setUpTableDao();
|
||||
|
||||
// データベースに登録されている生徒の数、formにデータを送信した生徒の合計数をを取得
|
||||
Log.d("MainActivity", "db" + setUpTableDao.getAll());
|
||||
|
||||
int totalStudent = setUpTableDao.getTotalStudent();
|
||||
int myDataListSize = firestoreReception.myDataList.size();
|
||||
int myDataListSize = firestoreReception.getMyDataListSize();
|
||||
|
||||
runOnUiThread(() -> {
|
||||
if (totalStudent != myDataListSize) {
|
||||
// 値が一致しない場合、ダイアログを表示
|
||||
showRouteCreationDialog();
|
||||
showRouteCreationDialog(latch);
|
||||
} else {
|
||||
Intent toRoot = new Intent(MainActivity.this,Maps.class);
|
||||
startActivity(toRoot);
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
executor.execute(() -> {
|
||||
List<MyDataClass> myDataList = firestoreReception.getMyDataList();
|
||||
CreateRoot createRoot = new CreateRoot(MainActivity.this);
|
||||
createRoot.receiveData(myDataList);
|
||||
latch.countDown();
|
||||
});
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
latch.await(); // Both tasks must call countDown() before this returns
|
||||
runOnUiThread(() -> {
|
||||
Intent toRoot = new Intent(MainActivity.this, Maps.class);
|
||||
startActivity(toRoot);
|
||||
});
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
|
||||
executor.shutdown();
|
||||
}
|
||||
// 提出状況のクリック処理
|
||||
if(view == submission){
|
||||
|
@ -145,15 +168,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
builder.show();
|
||||
}
|
||||
//ルート作成のダイアログ
|
||||
private void showRouteCreationDialog() {
|
||||
private void showRouteCreationDialog(CountDownLatch latch) {
|
||||
new AlertDialog.Builder(MainActivity.this)
|
||||
.setTitle("警告")
|
||||
.setMessage("人数が足りてませんがそれでもルート作成を行いますか?")
|
||||
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent toRoot = new Intent(MainActivity.this,Maps.class);
|
||||
startActivity(toRoot);
|
||||
latch.countDown();
|
||||
}
|
||||
})
|
||||
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||
|
|
|
@ -14,6 +14,9 @@ public class MyDataClass {
|
|||
List<Timestamp> thirdDay;
|
||||
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;
|
||||
|
@ -39,60 +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;
|
||||
}
|
||||
|
||||
public String getStartDateString() {
|
||||
return startDateString;
|
||||
}
|
||||
public void setStartDateString(String startDateString) {
|
||||
this.startDateString = startDateString;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -19,7 +19,6 @@ import androidx.fragment.app.FragmentActivity;
|
|||
import androidx.room.Room;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
|
@ -125,7 +124,9 @@ public class SetUpActivity extends FragmentActivity
|
|||
getApplicationContext(),
|
||||
AppDatabase.class,
|
||||
"SetUpTable"
|
||||
).build();
|
||||
)
|
||||
.fallbackToDestructiveMigration()
|
||||
.build();
|
||||
SetUpTableDao setUpTableDao = db.setUpTableDao();
|
||||
// Roomの操作を行う
|
||||
SetUpTable setUpTable = new SetUpTable(
|
||||
|
|
|
@ -9,22 +9,24 @@ public class SetUpTable {
|
|||
public int id;
|
||||
public String teacherName;
|
||||
public String startPoint;
|
||||
public String endPoint;
|
||||
public String startTime;
|
||||
public String endTime;
|
||||
public String breakStartTime;
|
||||
public String breakEndTime;
|
||||
public String intervalTime;
|
||||
public String startBreakTime;
|
||||
public String endBreakTime;
|
||||
public int totalStudent;
|
||||
|
||||
|
||||
//コンストラクタ
|
||||
public SetUpTable(String teacherName, String startPoint, String endPoint, String startTime, String endTime, String breakStartTime,String breakEndTime, int totalStudent) {
|
||||
public SetUpTable(String teacherName, String startPoint, String startTime, String endTime,
|
||||
String intervalTime, String startBreakTime, String endBreakTime, int totalStudent) {
|
||||
this.teacherName = teacherName;
|
||||
this.startPoint = startPoint;
|
||||
this.endPoint = endPoint;
|
||||
this.startTime = startTime;
|
||||
this.endTime = endTime;
|
||||
this.breakStartTime = breakStartTime;
|
||||
this.breakEndTime = breakEndTime;
|
||||
this.intervalTime = intervalTime;
|
||||
this.startBreakTime = startBreakTime;
|
||||
this.endBreakTime = endBreakTime;
|
||||
this.totalStudent = totalStudent;
|
||||
}
|
||||
//getter
|
||||
|
@ -37,21 +39,12 @@ public class SetUpTable {
|
|||
public String getStartPoint() {
|
||||
return startPoint;
|
||||
}
|
||||
public String getEndPoint() {
|
||||
return endPoint;
|
||||
}
|
||||
public String getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
public String getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
public String getBreakStartTime() {
|
||||
return breakStartTime;
|
||||
}
|
||||
public String getBreakEndTime() {
|
||||
return breakEndTime;
|
||||
}
|
||||
public int getTotalStudent() {
|
||||
return totalStudent;
|
||||
}
|
||||
|
@ -65,21 +58,12 @@ public class SetUpTable {
|
|||
public void setStartPoint(String startPoint) {
|
||||
this.startPoint = startPoint;
|
||||
}
|
||||
public void setEndPoint(String endPoint) {
|
||||
this.endPoint = endPoint;
|
||||
}
|
||||
public void setStartTime(String startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
public void setEndTime(String endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
public void setBreakStartTime(String breakStartTime) {
|
||||
this.breakStartTime = breakStartTime;
|
||||
}
|
||||
public void setBreakEndTime(String breakEndTime) {
|
||||
this.breakEndTime = breakEndTime;
|
||||
}
|
||||
public void setTotalStudent(int totalStudent) {
|
||||
this.totalStudent = totalStudent;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,9 @@ public interface SetUpTableDao {
|
|||
//削除処理
|
||||
@Query("DELETE FROM SetUpTable")
|
||||
void deleteAll();
|
||||
//全件取得
|
||||
@Query("SELECT * FROM SetUpTable")
|
||||
List<SetUpTable> getAll();
|
||||
|
||||
@Query("SELECT * FROM SetUpTable WHERE teacherName = :name LIMIT 1")
|
||||
SetUpTable findByName(String name);
|
||||
|
|
Loading…
Reference in New Issue
Block a user