マージのためのコミット

This commit is contained in:
it232115 2024-06-28 10:16:08 +09:00
commit af694c67f0
8 changed files with 353 additions and 108 deletions

View File

@ -4,8 +4,6 @@
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="jbr-17" /> <option name="gradleJvm" value="jbr-17" />
<option name="modules"> <option name="modules">
@ -14,6 +12,7 @@
<option value="$PROJECT_DIR$/app" /> <option value="$PROJECT_DIR$/app" />
</set> </set>
</option> </option>
<option name="resolveExternalAnnotations" value="false" />
</GradleProjectSettings> </GradleProjectSettings>
</option> </option>
</component> </component>

View File

@ -15,12 +15,16 @@ import androidx.room.Room;
import com.google.firebase.firestore.FirebaseFirestore; import com.google.firebase.firestore.FirebaseFirestore;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
public class MainActivity extends AppCompatActivity implements View.OnClickListener { public class MainActivity extends AppCompatActivity implements View.OnClickListener{
// ダイアログの宣言
private AlertDialog alertDialog;
// ID作成のTextViewとImageView // ID作成のTextViewとImageView
private TextView creatUUID; private TextView creatUUID;
@ -81,41 +85,88 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
} }
// クリック処理 // クリック処理
@Override @Override
public void onClick(View view) { public void onClick(View view) {
// ID作成のクリック処理 // ID作成のクリック処理
if (view == creatUUID) { if(view == creatUUID){
imageUuid.setImageResource(R.drawable.ischecked_uuid); imageUuid.setImageResource(R.drawable.ischecked_uuid);
showUUIDYesNoDialog();//UUIDを表示するかのダイアログ showUUIDYesNoDialog();//UUIDを表示するかのダイアログ
finish(); // 画面遷移後元の状態に戻す
} }
if (view == imageUuid) { if(view == imageUuid){
imageUuid.setImageResource(R.drawable.ischecked_uuid); imageUuid.setImageResource(R.drawable.ischecked_uuid);
showUUIDYesNoDialog();//UUIDを表示するかのダイアログ showUUIDYesNoDialog();//UUIDを表示するかのダイアログ
finish();
} }
// セットアップのクリック処理 // セットアップのクリック処理
if (view == setUp) { if(view == setUp){
imageSetup.setImageResource(R.drawable.ischecked_uuid); imageSetup.setImageResource(R.drawable.ischecked_uuid);
Intent toSetup = new Intent(MainActivity.this, SetUpActivity.class); Intent toSetup = new Intent(MainActivity.this,SetUpActivity.class);
startActivity(toSetup); startActivity(toSetup);
finish(); // 画面遷移後元の状態に戻す finish(); // 画面遷移後元の状態に戻す
} }
if (view == imageSetup) { if (view == imageSetup){
imageSetup.setImageResource(R.drawable.ischecked_uuid); imageSetup.setImageResource(R.drawable.ischecked_uuid);
Intent toSetup = new Intent(MainActivity.this, SetUpActivity.class); Intent toSetup = new Intent(MainActivity.this,SetUpActivity.class);
startActivity(toSetup); startActivity(toSetup);
finish(); // 画面遷移後元の状態に戻す finish(); // 画面遷移後元の状態に戻す
} }
// ルート作成のクリック処理 // ルート作成のクリック処理
if (view == root) { if(view == root){
imageRoot.setImageResource(R.drawable.pin); imageRoot.setImageResource(R.drawable.pin);
fetchDataAndCreateRoute();
}
if(view == imageRoot){
imageRoot.setImageResource(R.drawable.pin);
fetchDataAndCreateRoute();
}
// 提出状況のクリック処理
if(view == submission){
ArrayList<SubmissionStudent> submissionStudents = getSubmissionStudents();
Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class);
toSubmission.putParcelableArrayListExtra("submissionStudents", submissionStudents);
startActivity(toSubmission);
}
if(view == imageSubmission){
ArrayList<SubmissionStudent> submissionStudents = getSubmissionStudents();
Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class);
toSubmission.putParcelableArrayListExtra("submissionStudents", submissionStudents);
startActivity(toSubmission);
}
}
//UUIDを表示するかのダイアログ
private void showUUIDYesNoDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this); // この 'this' が問題でないか確認
builder.setTitle("クラスID");
builder.setMessage("あなたのクラスIDを表示しますか");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String classId = CreateUUID.generateUUID();
Toast.makeText(MainActivity.this, "クラスID: " + classId, Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.d("DialogNO", "DialogでNoが選ばれました");
}
});
alertDialog = builder.create();
alertDialog.show();
}
//ルート作成の非同期処理
private void fetchDataAndCreateRoute() {
//非同期処理の開始
ExecutorService executor = Executors.newSingleThreadExecutor(); ExecutorService executor = Executors.newSingleThreadExecutor();
CountDownLatch latch = new CountDownLatch(2); CountDownLatch latch = new CountDownLatch(2);
// タスク1: ローカルDBから生徒数を取得
executor.execute(() -> { executor.execute(() -> {
AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build(); AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build();
SetUpTableDao setUpTableDao = db.setUpTableDao(); SetUpTableDao setUpTableDao = db.setUpTableDao();
@ -131,31 +182,15 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
} else { } else {
latch.countDown(); latch.countDown();
} }
}); });
}); });
// タスク2: Firestoreからデータを取得
executor.execute(() -> { executor.execute(() -> {
List<MyDataClass> myDataList = null; List<MyDataClass> myDataList = firestoreReception.getMyDataList();
while (myDataList == null) {
myDataList = firestoreReception.getMyDataList();
try {
Thread.sleep(3000);
Log.d("MainActivity","myDataList"+ myDataList.size());
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
Log.d("MainActivity","myDataList"+ myDataList.size());
CreateRoot createRoot = new CreateRoot(MainActivity.this); CreateRoot createRoot = new CreateRoot(MainActivity.this);
Boolean notDuplicates=createRoot.receiveData(myDataList); createRoot.receiveData(myDataList);
latch.countDown(); latch.countDown();
if(notDuplicates){
Log.d("MainActivity","スケジュール作成成功");
}else{
showErrorDialog(latch);
}
}); });
new Thread(() -> { new Thread(() -> {
@ -172,46 +207,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
executor.shutdown(); executor.shutdown();
} }
if (view == imageRoot) {
imageRoot.setImageResource(R.drawable.pin);
Intent toRoot = new Intent(MainActivity.this, Maps.class);
startActivity(toRoot);
}
// 提出状況のクリック処理
if (view == submission) {
Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class);
startActivity(toSubmission);
}
if (view == imageSubmission) {
Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class);
startActivity(toSubmission);
}
}
private void showUUIDYesNoDialog() {
//ダイアログの表示
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("クラスID");
builder.setMessage("あなたのクラスIDを表示しますか");
//YESのときは初回はUUIDを生成表示
//二回目以降は保存されたUUIDを表示
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String classId = CreateUUID.generateUUID();//classIDにuuidが入ってる
Toast.makeText(MainActivity.this, "クラスID: " + classId, Toast.LENGTH_SHORT).show();//テスト用
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.d("DialogNO", "DialogでNoが選ばれました");
}
});
builder.show();
}
//ルート作成のダイアログ //ルート作成のダイアログ
private void showRouteCreationDialog(CountDownLatch latch) { private void showRouteCreationDialog(CountDownLatch latch) {
new AlertDialog.Builder(MainActivity.this) new AlertDialog.Builder(MainActivity.this)
@ -222,7 +217,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
latch.countDown(); latch.countDown();
} }
}) })
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override @Override
@ -233,23 +227,56 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
.show(); .show();
} }
public void showErrorDialog(CountDownLatch latch) {
new AlertDialog.Builder(MainActivity.this) //Main
.setTitle("警告") private ArrayList<SubmissionStudent> getSubmissionStudents() {
.setMessage("保護者の重複が重大でルート作成ができません。調整してください") ArrayList<SubmissionStudent> submissionStudents = new ArrayList<>();
.setPositiveButton("OK", new DialogInterface.OnClickListener() { List<MyDataClass> myDataList = firestoreReception.getMyDataList();
@Override
public void onClick(DialogInterface dialog, int which) { ExecutorService executor = Executors.newSingleThreadExecutor();
CountDownLatch latch = new CountDownLatch(1);
executor.execute(() -> {
// 1. Roomデータベースから全生徒数を取得
AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build();
SetUpTableDao setUpTableDao = db.setUpTableDao();
int totalStudent = setUpTableDao.getTotalStudent();
// 2. Firestoreから生徒番号のリストを取得
ArrayList<Integer> firestoreStudentNumbers = new ArrayList<>();
for (MyDataClass myData : myDataList) {
int studentNumber = myData.getStudentNumber();
firestoreStudentNumbers.add(studentNumber);
}
// 3. SubmissionStudentオブジェクトのリストを作成
for (int i = 1; i <= totalStudent; i++) {
boolean submitted = firestoreStudentNumbers.contains(i);
submissionStudents.add(new SubmissionStudent(i, submitted));
}
// 4. データベース操作が完了したことを通知
latch.countDown(); latch.countDown();
});
try {
// データベース操作が完了するのを待つ
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
} }
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { executor.shutdown();
// SubmissionStudentオブジェクトのリストを返す
return submissionStudents;
}
@Override @Override
public void onClick(DialogInterface dialog, int which) { protected void onDestroy() {
dialog.dismiss(); super.onDestroy();
if (alertDialog != null && alertDialog.isShowing()) {
alertDialog.dismiss();
} }
})
.show();
} }
} }

View File

@ -127,7 +127,6 @@ public class SetUpActivity extends FragmentActivity
AppDatabase.class, AppDatabase.class,
"SetUpTable" "SetUpTable"
) )
.fallbackToDestructiveMigration()
.build(); .build();
SetUpTableDao setUpTableDao = db.setUpTableDao(); SetUpTableDao setUpTableDao = db.setUpTableDao();
// Roomの操作を行う // Roomの操作を行う

View File

@ -1,14 +1,58 @@
package com.example.oplogy; package com.example.oplogy;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle; import android.os.Bundle;
import android.widget.ImageView;
import com.example.oplogy.databinding.SubmissionBinding;
import java.util.ArrayList;
import java.util.List;
public class SubmissionActivity extends AppCompatActivity { public class SubmissionActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private SubmissionAdapter submissionAdapter;
private List<SubmissionStudent> students = new ArrayList<>();
ArrayList<Integer> studentNumbers = new ArrayList<>();
private int totalStudent = 10;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.submission); setContentView(R.layout.submission);
// 戻るボタンの処理
ImageView backButton = findViewById(R.id.BackMain_fromSubmission);
backButton.setOnClickListener(v -> {
finish();
});
// インテントから提出状況の生徒の数を取得
studentNumbers=getIntent().getIntegerArrayListExtra("submissionStudents");
recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
submissionAdapter = new SubmissionAdapter(students);
recyclerView.setAdapter(submissionAdapter);
// 生徒のリストを取得
fetchStudents();
}
private void fetchStudents() {
// インテントから生徒のリストを取得
ArrayList<SubmissionStudent> submissionStudents = getIntent().getParcelableArrayListExtra("submissionStudents");
// 生徒のリストを反復処理しそれをRecyclerViewに表示
for (SubmissionStudent student : submissionStudents) {
students.add(student);
}
// データが変更されたことをアダプターに通知
submissionAdapter.notifyDataSetChanged();
} }
} }

View File

@ -0,0 +1,62 @@
package com.example.oplogy;
import android.graphics.Color;
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> {
private List<SubmissionStudent> students;
public static class StudentViewHolder extends RecyclerView.ViewHolder {
public TextView studentNumberTextView;
public TextView statusTextView;
public StudentViewHolder(View view) {
super(view);
// レイアウトファイルのTextViewを取得
studentNumberTextView = view.findViewById(R.id.studentNumberTextView);
statusTextView = view.findViewById(R.id.statusTextView);
}
}
public SubmissionAdapter(List<SubmissionStudent> students) {
this.students = students;
}
@Override
public StudentViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.row_submission, parent, false);
return new StudentViewHolder(view);
}
@Override
public void onBindViewHolder(StudentViewHolder holder, int position) {
SubmissionStudent student = students.get(position);
holder.studentNumberTextView.setText(String.valueOf(student.getStudentNumber()));
// 提出済みかどうかで表示を変える
if (student.isSubmitted()) {
holder.statusTextView.setText("提出済み");
holder.statusTextView.setBackgroundColor(Color.BLACK);
holder.statusTextView.setTextColor(Color.WHITE);
holder.studentNumberTextView.setBackgroundColor(Color.BLACK);
holder.studentNumberTextView.setTextColor(Color.WHITE);
} else {
holder.statusTextView.setText("未提出");
holder.statusTextView.setBackgroundColor(Color.RED);
holder.statusTextView.setTextColor(Color.WHITE);
holder.studentNumberTextView.setBackgroundColor(Color.RED);
holder.studentNumberTextView.setTextColor(Color.WHITE);
}
}
@Override
public int getItemCount() {
return students.size();
}
}

View File

@ -0,0 +1,49 @@
package com.example.oplogy;
import android.os.Parcel;
import android.os.Parcelable;
public class SubmissionStudent implements Parcelable {
private int studentNumber;
private boolean submitted;
public SubmissionStudent(int studentNumber, boolean submitted) {
this.studentNumber = studentNumber;
this.submitted = submitted;
}
protected SubmissionStudent(Parcel in) {
studentNumber = in.readInt();
submitted = in.readByte() != 0;
}
public static final Creator<SubmissionStudent> CREATOR = new Creator<SubmissionStudent>() {
@Override
public SubmissionStudent createFromParcel(Parcel in) {
return new SubmissionStudent(in);
}
@Override
public SubmissionStudent[] newArray(int size) {
return new SubmissionStudent[size];
}
};
public int getStudentNumber() {
return studentNumber;
}
public boolean isSubmitted() {
return submitted;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeInt(studentNumber);
parcel.writeByte((byte) (submitted ? 1 : 0));
}
}

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/studentNumberTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/white"
android:gravity="center_vertical"
android:text="番号"
android:textColor="@android:color/black"
android:textSize="36sp"
android:textStyle="bold" />
<TextView
android:id="@+id/statusTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="提出状況"
android:textSize="36sp"
android:gravity="center_vertical"
android:paddingStart="8dp"
android:background="@android:color/white"
android:textColor="@android:color/black" />
</LinearLayout>

View File

@ -1,9 +1,43 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10"
tools:context=".SubmissionActivity"> tools:context=".SubmissionActivity">
</androidx.constraintlayout.widget.ConstraintLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="10">
<ImageView
android:id="@+id/BackMain_fromSubmission"
android:layout_width="36dp"
android:layout_height="74dp"
android:layout_weight="2"
android:src="@drawable/back_button" />
<TextView
android:id="@+id/imageSubmission"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="4"
android:hint="提出状況"
android:textSize="40dp"
android:padding="8dp"
/>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>