Merge pull request '・コード整形' (#41) from finishing into master

Reviewed-on: #41
This commit is contained in:
Utahshi 2024-07-08 01:23:52 +00:00
commit 1730c9b601
15 changed files with 102 additions and 46 deletions

View File

@ -1,4 +1,5 @@
package com.example.oplogy;
import androidx.room.TypeConverter;
import com.google.firebase.Timestamp;

View File

@ -26,6 +26,8 @@ import java.util.concurrent.Executors;
//保護者の希望とSetUpActivityによって設定された情報をもとにスケジュールとルートを作成する
public class CreateSchedule {
MyDataClass data;//Firestoreから受け取ったdataを入れる変数
String startPointString;//家庭訪問の開始地点
String startTimeHomeVisitString;//家庭訪問の開始時間
String endTimeHomeVisitString;//家庭訪問の終了時間
String intervalTimeString;//家庭訪問の一家庭当たりの時間
@ -42,22 +44,23 @@ public class CreateSchedule {
boolean notSecondDuplicatesBoolean = true;//スケジュールの重複の有無(第一希望日のみで通った場合も考えて初期はtrue)
String[] testdate;
String[] date;
public CreateSchedule(AppCompatActivity activity) {
this.db = Room.databaseBuilder(activity.getApplicationContext(), AppDatabase.class, "SetUpTable").build();
SharedPreferences sharedPreferences= activity.getSharedPreferences("visitingDate",Context.MODE_PRIVATE);
SharedPreferences sharedPreferences = activity.getSharedPreferences("visitingDate", Context.MODE_PRIVATE);
String firstDay=sharedPreferences.getString("day1",null);
String secondDay=sharedPreferences.getString("day2",null);
String thirdDay=sharedPreferences.getString("day3",null);
String firstDay = sharedPreferences.getString("day1", null);
String secondDay = sharedPreferences.getString("day2", null);
String thirdDay = sharedPreferences.getString("day3", null);
testdate=new String[]{firstDay,secondDay,thirdDay};
date = new String[]{firstDay, secondDay, thirdDay};
}
//MainActivityからデータを受け取る
public Boolean receiveData(List<MyDataClass> myDataList, Context context) {
public String receiveData(List<MyDataClass> myDataList, Context context) {
//myDataListの要素data第一希望日と第二希望日に以下を追加する
//保護者の希望時間帯の長さ
@ -107,14 +110,18 @@ public class CreateSchedule {
notSecondDuplicatesBoolean = secondCreateSchedule(myDataList, intervalArrayInt);
}
});
//重複がなければ開始地点の緯度経度を返す
if (notSecondDuplicatesBoolean) {
//スケジュールを基準にソートする
sortSchedule(myDataList);
geocodeAddress(myDataList, context);
String startPointLatLngString = geocodeAddress(myDataList, context);
Log.d("CreateSchedule", "startPointLatLngString" + startPointLatLngString);
outPutLogSchedule(myDataList);
return notSecondDuplicatesBoolean;
return startPointLatLngString;
}
//重複があるときは""を返す
Log.d("CreateSchedule", "重複によるエラー");
return !notSecondDuplicatesBoolean;
return "";
}
@ -234,6 +241,7 @@ public class CreateSchedule {
// setUpActivityによって入力されRoomに保存された値を取り出す処理
//Roomの操作の定義
SetUpTableDao setUpTableDao = db.setUpTableDao();
startPointString = setUpTableDao.getStartPoint();
startTimeHomeVisitString = setUpTableDao.getStartTime();
endTimeHomeVisitString = setUpTableDao.getEndTime();
intervalTimeString = setUpTableDao.getIntervalTime();
@ -305,7 +313,7 @@ public class CreateSchedule {
for (int x = 0; x < 3; x++) {
//家庭訪問の日目が保護者の第一希望日かを判定する
//まだスケジュールを割り当てていない保護者かを判定する
if (testdate[x].equals(myDataList.get(i).getStartDateString()) && myDataList.get(i).getSchedule() == 0) {
if (date[x].equals(myDataList.get(i).getStartDateString()) && myDataList.get(i).getSchedule() == 0) {
checkSchedule(myDataList, intervalArrayInt, i, j, x, myDataList.get(i).getStartDateString());
break;
}
@ -328,7 +336,7 @@ public class CreateSchedule {
for (int x = 0; x < 3; x++) {
//家庭訪問の日目が保護者の第一希望日かを判定する
//まだスケジュールを割り当てていない保護者かを判定する
if (testdate[x].equals(myDataList.get(i).getSecondDayStartDateString()) && myDataList.get(i).getSchedule() == 0) {
if (date[x].equals(myDataList.get(i).getSecondDayStartDateString()) && myDataList.get(i).getSchedule() == 0) {
checkSchedule(myDataList, intervalArrayInt, i, j, x, myDataList.get(i).getSecondDayStartDateString());
}
}
@ -358,7 +366,7 @@ public class CreateSchedule {
}
private void geocodeAddress(List<MyDataClass> myDataList, Context context) {
private String geocodeAddress(List<MyDataClass> myDataList, Context context) {
try {
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
for (int i = 0; i < myDataList.size(); i++) {
@ -372,9 +380,14 @@ public class CreateSchedule {
myDataList.get(i).setLatLngString(String.valueOf(new LatLng(latitudeDouble, longitudeDouble)));
}
}
//SetUpで設定した家庭訪問の開始地点を緯度経度に変換
String startPointLatLngString = String.valueOf(geocoder.getFromLocationName(startPointString, 1));
Log.d("CreateSchedule", "startPointLatLngString" + startPointLatLngString);
return startPointLatLngString;
} catch (IOException e) {
Log.e("CreateSchedule", "緯度経度の取得に失敗: " + e);
}
return null;
}
private void outPutLogSchedule(List<MyDataClass> myDataList) {

View File

@ -22,7 +22,7 @@ public class CreateUUID {
InsertClassIdforFirebase insertClassIdforFirebase = new InsertClassIdforFirebase();
insertClassIdforFirebase.insertClassId(uuid);
//テスト用
uuid=100;
uuid = 100;
return uuid;
}
}

View File

@ -7,8 +7,8 @@ import android.widget.DatePicker;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import java.util.Calendar;
import java.util.Objects;
public class DatePick extends DialogFragment implements
DatePickerDialog.OnDateSetListener {

View File

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

View File

@ -4,8 +4,6 @@ import android.util.Log;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.QueryDocumentSnapshot;
import com.google.firebase.firestore.QuerySnapshot;
@ -14,10 +12,10 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class FirestoreReception_classIdDatabase {
private FirebaseFirestore db;
private List<Integer> classIdList= new ArrayList<>();
private List<Integer> classIdList = new ArrayList<>();
public FirestoreReception_classIdDatabase() {
db = FirebaseFirestore.getInstance();

View File

@ -55,8 +55,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
//取得するためのクラスID
private int classId;
private String address;
private final AppDatabase appDatabase = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -319,13 +318,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
//final宣言することによってスレッドセーフになる(ラムダ式内で使えるようにする)
final List<MyDataClass> finalMyDataList = myDataList;
CreateSchedule createSchedule = new CreateSchedule(MainActivity.this);
Boolean notDuplicates = createSchedule.receiveData(myDataList, getApplicationContext());
String startPointLatLngString = createSchedule.receiveData(myDataList, getApplicationContext());
runOnUiThread(() -> {
if (notDuplicates) {
if ( !startPointLatLngString.equals("")) {
Log.d("MainActivity", "スケジュール作成成功");
saveMyDataList(finalMyDataList);
Intent toRoot = new Intent(MainActivity.this, Maps.class);
toRoot.putExtra("startPointLatLngString", startPointLatLngString);
startActivity(toRoot);
} else {
//保護者の重複による警告ダイアログ

View File

@ -26,7 +26,8 @@ public class Maps extends FragmentActivity implements View.OnClickListener {
private WebView webView;
ImageView backMain;
private MapsBinding binding;
private ArrayList<Parcelable> myDataList;;
private ArrayList<Parcelable> myDataList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -41,9 +42,19 @@ public class Maps extends FragmentActivity implements View.OnClickListener {
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
List<MyDataClass> myDataList=getMyDataList();
// startPointLatLngStringの取得
String startPointLatLngString = getIntent().getStringExtra("startPointLatLngString");
//MyDataListの取得
List<MyDataClass> myDataList = getMyDataList();
String latlngString = "";
for (int i = 0; i < myDataList.size(); i++) {
for (int i = -1; i < myDataList.size(); i++) {
if (i < 0) {
//家庭訪問の開始地点の緯度経度
latlngString += startPointLatLngString + "/";
} else {
//各家庭の緯度経度
String latlng = myDataList.get(i).getLatLngString();
int startIndex = latlng.indexOf("(") + 1;
int endIndex = latlng.indexOf(")");
@ -53,7 +64,9 @@ public class Maps extends FragmentActivity implements View.OnClickListener {
latlngString += "/";
}
}
Log.d("Maps","latlngString"+latlngString);
}
Log.d("Maps", "startPointLatLngString" + startPointLatLngString);
Log.d("Maps", "latlngString" + latlngString);
loadMapInWebView(latlngString);
}
@ -67,13 +80,14 @@ public class Maps extends FragmentActivity implements View.OnClickListener {
// JSON形式のデータをMyDataListに変換
Gson gson = new Gson();
Type type = new TypeToken<List<MyDataClass>>() {}.getType();
Type type = new TypeToken<List<MyDataClass>>() {
}.getType();
List<MyDataClass> myDataList = gson.fromJson(json, type);
return myDataList;
}
// WebViewの処理ですMapの中の処理をやっています
// WebViewの処理ですMapの中の処理をやっています
private void loadMapInWebView(String locations) {
// 区切ることで追加の地点を入れて最終地点にピンを打ってある状態です
String[] locArray = locations.split("/");

View File

@ -239,7 +239,7 @@ public class MyDataClass {
}
public void setLatLngString(String latLng) {
this.latLngString=latLng;
this.latLngString = latLng;
}
public String getLatLngString() {

View File

@ -1,4 +1,5 @@
package com.example.oplogy;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
@ -21,7 +22,7 @@ public class SetUpTable {
//コンストラクタ
public SetUpTable(String teacherName, String startPoint, String startTime, String endTime,
String intervalTime, String startBreakTime, String endBreakTime, int totalStudent,int classId) {
String intervalTime, String startBreakTime, String endBreakTime, int totalStudent, int classId) {
this.teacherName = teacherName;
this.startPoint = startPoint;
this.startTime = startTime;
@ -32,41 +33,53 @@ public class SetUpTable {
this.totalStudent = totalStudent;
this.classId = classId;
}
//getter
public int getId() {
return id;
}
public String getTeacherName() {
return teacherName;
}
public String getStartPoint() {
return startPoint;
}
public String getStartTime() {
return startTime;
}
public String getEndTime() {
return endTime;
}
public int getTotalStudent() {
return totalStudent;
}
//setter
public void setId(int id) {
this.id = id;
}
public void setTeacherName(String teacherName) {
this.teacherName = teacherName;
}
public void setStartPoint(String startPoint) {
this.startPoint = startPoint;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public void setTotalStudent(int totalStudent) {
this.totalStudent = totalStudent;
}

View File

@ -1,4 +1,5 @@
package com.example.oplogy;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
@ -10,6 +11,7 @@ import java.util.List;
public interface SetUpTableDao {
@Insert
void insertAll(SetUpTable... setUpTables);
//更新処理
@Update
void update(SetUpTable setUpTable);
@ -18,6 +20,7 @@ public interface SetUpTableDao {
//削除処理
@Query("DELETE FROM SetUpTable")
void deleteAll();
//全件取得
@Query("SELECT * FROM SetUpTable")
List<SetUpTable> getAll();
@ -27,19 +30,30 @@ public interface SetUpTableDao {
@Query("SELECT totalStudent FROM SetUpTable")
int getTotalStudent();
//開始時間と終了時間の取得
@Query("SELECT startTime FROM SetUpTable")
String getStartTime();
@Query("SELECT endTime FROM SetUpTable")
String getEndTime();
//教師名の取得
@Query("SELECT intervalTime FROM SetUpTable")
String getIntervalTime();
@Query("SELECT StartBreakTime FROM SetUpTable")
String getStartBreakTime();
@Query("SELECT EndBreakTime FROM SetUpTable")
String getEndBreakTime();
//クラスIDの取得
@Query("SELECT classId FROM SetUpTable")
int getClassId();
@Query("SELECT startPoint FROM setuptable")
String getStartPoint();
}

View File

@ -1,13 +1,11 @@
package com.example.oplogy;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import android.widget.ImageView;
import com.example.oplogy.databinding.SubmissionBinding;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
@ -32,7 +30,7 @@ public class SubmissionActivity extends AppCompatActivity {
// インテントから提出状況の生徒の数を取得
studentNumbers=getIntent().getIntegerArrayListExtra("submissionStudents");
studentNumbers = getIntent().getIntegerArrayListExtra("submissionStudents");
recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
@ -42,6 +40,7 @@ public class SubmissionActivity extends AppCompatActivity {
// 生徒のリストを取得
fetchStudents();
}
private void fetchStudents() {
// インテントから生徒のリストを取得
ArrayList<SubmissionStudent> submissionStudents = getIntent().getParcelableArrayListExtra("submissionStudents");

View File

@ -5,7 +5,9 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
public class SubmissionAdapter extends RecyclerView.Adapter<SubmissionAdapter.StudentViewHolder> {

View File

@ -1,4 +1,5 @@
package com.example.oplogy;
import android.os.Parcel;
import android.os.Parcelable;

View File

@ -12,7 +12,7 @@ import androidx.fragment.app.DialogFragment;
import java.util.Calendar;
public class TimePick extends DialogFragment implements
TimePickerDialog.OnTimeSetListener{
TimePickerDialog.OnTimeSetListener {
@NonNull
@Override