uuid:値をテストデータに固定中
main:各メソッドが何の処理をしているかのコメント追加 SubmissionActivity:nullチェックと謎のコード削除 SubmissionAdapter:色のセットなどをメソッド化 submission.xml:recyclerviewがマッチョペアレントだったから-1されるフレンズでした。てへぺろ
This commit is contained in:
parent
f28fd3c4ff
commit
bb4912f123
|
@ -22,7 +22,7 @@ public class CreateUUID {
|
||||||
InsertClassIdforFirebase insertClassIdforFirebase = new InsertClassIdforFirebase();
|
InsertClassIdforFirebase insertClassIdforFirebase = new InsertClassIdforFirebase();
|
||||||
insertClassIdforFirebase.insertClassId(uuidInt);
|
insertClassIdforFirebase.insertClassId(uuidInt);
|
||||||
//テスト用
|
//テスト用
|
||||||
uuidInt = 100;
|
uuidInt = 328071;
|
||||||
return uuidInt;
|
return uuidInt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -343,6 +343,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
// `fetchDataAndCreateRoute`メソッド内では、shutdownを呼び出さない
|
// `fetchDataAndCreateRoute`メソッド内では、shutdownを呼び出さない
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 未提出者がいることの警告ダイアログ
|
||||||
private void showRouteCreationDialog() {
|
private void showRouteCreationDialog() {
|
||||||
new AlertDialog.Builder(MainActivity.this)
|
new AlertDialog.Builder(MainActivity.this)
|
||||||
.setTitle("警告")
|
.setTitle("警告")
|
||||||
|
@ -359,6 +360,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ルート作成の非同期処理
|
||||||
|
|
||||||
private void createRoute(ExecutorService executor) {
|
private void createRoute(ExecutorService executor) {
|
||||||
// ProgressDialogを作成
|
// ProgressDialogを作成
|
||||||
ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
|
ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
|
||||||
|
@ -414,7 +417,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 作成したルートを(Mapに渡せるように)保存するメソッド
|
||||||
private void saveMyDataList(List<MyDataClass> myDataList) {
|
private void saveMyDataList(List<MyDataClass> myDataList) {
|
||||||
// 共有プリファレンスのインスタンスを取得
|
// 共有プリファレンスのインスタンスを取得
|
||||||
SharedPreferences sharedPreferences = getSharedPreferences("MyDataList", MODE_PRIVATE);
|
SharedPreferences sharedPreferences = getSharedPreferences("MyDataList", MODE_PRIVATE);
|
||||||
|
@ -429,6 +432,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 保護者の重複による警告ダイアログ
|
||||||
private void showErrorDialog(List<MyDataClass> myDataList) {
|
private void showErrorDialog(List<MyDataClass> myDataList) {
|
||||||
List<Integer> studentNumbers = new ArrayList<>();
|
List<Integer> studentNumbers = new ArrayList<>();
|
||||||
for (MyDataClass data : myDataList) {
|
for (MyDataClass data : myDataList) {
|
||||||
|
@ -462,14 +466,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// データベースのインスタンスを取得するメソッド
|
||||||
private AppDatabase getDatabaseInstance() {
|
private AppDatabase getDatabaseInstance() {
|
||||||
return Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build();
|
return Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//提出状況の取得
|
//提出状況の取得
|
||||||
private ArrayList<SubmissionStudent> getSubmissionStudents() {
|
public ArrayList<SubmissionStudent> getSubmissionStudents() {
|
||||||
ArrayList<SubmissionStudent> submissionStudents = new ArrayList<>();
|
ArrayList<SubmissionStudent> submissionStudents = new ArrayList<>();
|
||||||
List<MyDataClass> myDataList = firestoreReception.getMyDataList();
|
List<MyDataClass> myDataList = firestoreReception.getMyDataList();
|
||||||
|
|
||||||
|
@ -477,40 +481,44 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
|
||||||
executor.execute(() -> {
|
executor.execute(() -> {
|
||||||
// 1. Roomデータベースから全生徒数を取得
|
try {
|
||||||
AppDatabase db = getDatabaseInstance();
|
// 1. Roomデータベースから全生徒数を取得
|
||||||
SetUpTableDao setUpTableDao = db.setUpTableDao();
|
AppDatabase db = getDatabaseInstance();
|
||||||
int totalStudentInt = setUpTableDao.getTotalStudent();
|
SetUpTableDao setUpTableDao = db.setUpTableDao();
|
||||||
// 2. Firestoreから生徒番号のリストを取得
|
int totalStudentInt = setUpTableDao.getTotalStudent();
|
||||||
ArrayList<Integer> firestoreStudentNumbersList = new ArrayList<>();
|
|
||||||
for (MyDataClass myData : myDataList) {
|
|
||||||
int studentNumberInt = myData.getStudentNumber();
|
|
||||||
firestoreStudentNumbersList.add(studentNumberInt);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. SubmissionStudentオブジェクトのリストを作成
|
// 2. Firestoreから生徒番号のリストを取得
|
||||||
for (int i = 1; i <= totalStudentInt; i++) {
|
ArrayList<Integer> firestoreStudentNumbersList = new ArrayList<>();
|
||||||
boolean submitted = firestoreStudentNumbersList.contains(i);
|
for (MyDataClass myData : myDataList) {
|
||||||
submissionStudents.add(new SubmissionStudent(i, submitted));
|
int studentNumberInt = myData.getStudentNumber();
|
||||||
}
|
firestoreStudentNumbersList.add(studentNumberInt);
|
||||||
|
}
|
||||||
|
|
||||||
// 4. データベース操作が完了したことを通知
|
// 3. SubmissionStudentオブジェクトのリストを作成
|
||||||
latch.countDown();
|
for (int i = 1; i <= totalStudentInt; i++) {
|
||||||
|
boolean submitted = firestoreStudentNumbersList.contains(i);
|
||||||
|
submissionStudents.add(new SubmissionStudent(i, submitted));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace(); // ログにエラーメッセージを出力
|
||||||
|
} finally {
|
||||||
|
// 4. データベース操作が完了したことを通知
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// データベース操作が完了するのを待つ
|
latch.await(); // 非同期処理が完了するまで待機
|
||||||
latch.await();
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
executor.shutdown(); // ExecutorServiceをシャットダウン
|
||||||
}
|
}
|
||||||
|
|
||||||
executor.shutdown();
|
|
||||||
|
|
||||||
// SubmissionStudentオブジェクトのリストを返す
|
|
||||||
return submissionStudents;
|
return submissionStudents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package com.example.oplogy;
|
package com.example.oplogy;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
@ -11,10 +13,9 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SubmissionActivity extends AppCompatActivity {
|
public class SubmissionActivity extends AppCompatActivity {
|
||||||
|
private final List<SubmissionStudent> studentsList = new ArrayList<>();
|
||||||
private RecyclerView recyclerView;
|
private RecyclerView recyclerView;
|
||||||
private SubmissionAdapter submissionAdapter;
|
private SubmissionAdapter submissionAdapter;
|
||||||
private final List<SubmissionStudent> studentsList = new ArrayList<>();
|
|
||||||
ArrayList<Integer> studentNumbersList = new ArrayList<>();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -25,10 +26,7 @@ public class SubmissionActivity extends AppCompatActivity {
|
||||||
ImageView backButton = findViewById(R.id.BackMain_fromSubmission);
|
ImageView backButton = findViewById(R.id.BackMain_fromSubmission);
|
||||||
backButton.setOnClickListener(v -> finish());
|
backButton.setOnClickListener(v -> finish());
|
||||||
|
|
||||||
|
// RecyclerViewとアダプターの初期化
|
||||||
// インテントから提出状況の生徒の数を取得
|
|
||||||
studentNumbersList=getIntent().getIntegerArrayListExtra("submissionStudents");
|
|
||||||
|
|
||||||
recyclerView = findViewById(R.id.recyclerView);
|
recyclerView = findViewById(R.id.recyclerView);
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||||
submissionAdapter = new SubmissionAdapter(studentsList);
|
submissionAdapter = new SubmissionAdapter(studentsList);
|
||||||
|
@ -37,15 +35,21 @@ public class SubmissionActivity extends AppCompatActivity {
|
||||||
// 生徒のリストを取得
|
// 生徒のリストを取得
|
||||||
fetchStudents();
|
fetchStudents();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchStudents() {
|
private void fetchStudents() {
|
||||||
// インテントから生徒のリストを取得
|
// インテントから生徒のリストを取得
|
||||||
ArrayList<SubmissionStudent> submissionStudentsList = getIntent().getParcelableArrayListExtra("submissionStudents");
|
ArrayList<SubmissionStudent> submissionStudentsList = getIntent().getParcelableArrayListExtra("submissionStudents");
|
||||||
|
|
||||||
// 生徒のリストを反復処理し、それをRecyclerViewに表示
|
if (submissionStudentsList != null) {
|
||||||
studentsList.addAll(submissionStudentsList);
|
Log.d("SubmissionActivity", "Size of submissionStudentsList: " + submissionStudentsList.size());
|
||||||
|
|
||||||
|
studentsList.addAll(submissionStudentsList);
|
||||||
|
} else {
|
||||||
|
Log.e("SubmissionActivity", "submissionStudentsList is null");
|
||||||
|
Toast.makeText(this, "生徒のリストが取得できませんでした", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
// データが変更されたことをアダプターに通知
|
// データが変更されたことをアダプターに通知
|
||||||
submissionAdapter.notifyDataSetChanged();
|
submissionAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,24 +8,13 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SubmissionAdapter extends RecyclerView.Adapter<SubmissionAdapter.StudentViewHolder> {
|
public class SubmissionAdapter extends RecyclerView.Adapter<SubmissionAdapter.StudentViewHolder> {
|
||||||
|
|
||||||
private final List<SubmissionStudent> studentsList;
|
private final List<SubmissionStudent> studentsList;
|
||||||
|
|
||||||
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) {
|
public SubmissionAdapter(List<SubmissionStudent> students) {
|
||||||
this.studentsList = students;
|
this.studentsList = students;
|
||||||
}
|
}
|
||||||
|
@ -42,24 +31,42 @@ public class SubmissionAdapter extends RecyclerView.Adapter<SubmissionAdapter.St
|
||||||
public void onBindViewHolder(StudentViewHolder holder, int position) {
|
public void onBindViewHolder(StudentViewHolder holder, int position) {
|
||||||
SubmissionStudent student = studentsList.get(position);
|
SubmissionStudent student = studentsList.get(position);
|
||||||
holder.studentNumberTextView.setText(String.valueOf(student.getStudentNumber()));
|
holder.studentNumberTextView.setText(String.valueOf(student.getStudentNumber()));
|
||||||
// 提出済みかどうかで表示を変える
|
updateStatus(holder, student.isSubmitted());
|
||||||
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
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return studentsList.size();
|
return studentsList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//真偽値に応じて提出済みか未提出をセットする
|
||||||
|
private void updateStatus(StudentViewHolder holder, boolean isSubmitted) {
|
||||||
|
if (isSubmitted) {
|
||||||
|
holder.statusTextView.setText("提出済み");
|
||||||
|
setColors(holder, Color.BLACK, Color.WHITE);
|
||||||
|
} else {
|
||||||
|
holder.statusTextView.setText("未提出");
|
||||||
|
setColors(holder, Color.RED, Color.WHITE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//真偽値に応じて色をセットする
|
||||||
|
private void setColors(StudentViewHolder holder, int backgroundColor, int textColor) {
|
||||||
|
holder.statusTextView.setBackgroundColor(backgroundColor);
|
||||||
|
holder.statusTextView.setTextColor(textColor);
|
||||||
|
holder.studentNumberTextView.setBackgroundColor(backgroundColor);
|
||||||
|
holder.studentNumberTextView.setTextColor(textColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/studentNumberTextView"
|
android:id="@+id/studentNumberTextView"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
@ -22,10 +21,10 @@
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="3"
|
android:layout_weight="3"
|
||||||
android:text="提出状況"
|
android:background="@android:color/white"
|
||||||
android:textSize="36sp"
|
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:paddingStart="8dp"
|
android:paddingStart="8dp"
|
||||||
android:background="@android:color/white"
|
android:text="提出状況"
|
||||||
android:textColor="@android:color/black" />
|
android:textColor="@android:color/black"
|
||||||
|
android:textSize="36sp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
|
@ -1,6 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout 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: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"
|
||||||
|
@ -10,7 +9,7 @@
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
|
@ -29,15 +28,15 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="4"
|
android:layout_weight="4"
|
||||||
android:hint="提出状況"
|
android:hint="提出状況"
|
||||||
android:textSize="40dp"
|
|
||||||
android:padding="8dp"
|
android:padding="8dp"
|
||||||
/>
|
android:textSize="40dp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/recyclerView"
|
android:id="@+id/recyclerView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="0dp"
|
||||||
/>
|
android:layout_weight="9"
|
||||||
|
android:scrollbars="vertical" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user