ルート作成画面の遷移時にformに送られた人数が足りてない場合、警告のダイアログを出すように変更 #9
|
@ -11,6 +11,7 @@ import com.google.firebase.firestore.QueryDocumentSnapshot;
|
||||||
import com.google.firebase.firestore.QuerySnapshot;
|
import com.google.firebase.firestore.QuerySnapshot;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ public class FirestoreReception {
|
||||||
}
|
}
|
||||||
|
|
||||||
//firestoreから受け取ったデータを束ねるためのマップ
|
//firestoreから受け取ったデータを束ねるためのマップ
|
||||||
public List<MyDataClass> myDataList = new ArrayList<>();
|
public List<MyDataClass>myDataList = new ArrayList<>();
|
||||||
|
|
||||||
//ClassIdを引数にデータの作成を行う
|
//ClassIdを引数にデータの作成を行う
|
||||||
public void getDocumentsByClassId(int classId) {
|
public void getDocumentsByClassId(int classId) {
|
||||||
|
@ -60,23 +61,23 @@ public class FirestoreReception {
|
||||||
|
|
||||||
|
|
||||||
//取得したデータをログ表示
|
//取得したデータをログ表示
|
||||||
for (MyDataClass data : myDataList) {
|
for(MyDataClass data :myDataList){
|
||||||
Log.i("FirestoreReceptiond", "data: " + data.toString());
|
Log.i("FirestoreReceptiond", "data: " + data.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Log.w("FirestoreReceptiond", "Error getting documents.", task.getException());
|
Log.w("FirestoreReceptiond", "Error getting documents.", task.getException());
|
||||||
}
|
}
|
||||||
|
Log.i("FirestoreReceptiond", "data: " + myDataList.size());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//Dataのリストのサイズを返す
|
||||||
public int getMyDataListSize() {
|
public int getMyDataListSize(){
|
||||||
return myDataList.size();
|
return myDataList.size();
|
||||||
}
|
}
|
||||||
|
//Dataのリストを返す
|
||||||
public List<MyDataClass> getMyDataList() {
|
public List<MyDataClass> getMyDataList(){
|
||||||
return myDataList;
|
return myDataList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,12 +11,16 @@ import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.room.Room;
|
||||||
|
|
||||||
import com.google.firebase.firestore.FirebaseFirestore;
|
import com.google.firebase.firestore.FirebaseFirestore;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
|
||||||
|
|
||||||
// ID作成のTextViewとImageView
|
// ID作成のTextViewとImageView
|
||||||
private TextView creatUUID;
|
private TextView creatUUID;
|
||||||
|
@ -69,41 +73,77 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
|
|
||||||
firestoreReception.getDocumentsByClassId(100);
|
firestoreReception.getDocumentsByClassId(100);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// クリック処理
|
// クリック処理
|
||||||
@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を表示するかのダイアログ
|
||||||
|
|
||||||
}
|
}
|
||||||
// セットアップのクリック処理
|
// セットアップのクリック処理
|
||||||
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
// ルート作成のクリック処理
|
// ルート作成のクリック処理
|
||||||
if (view == root) {
|
if(view == root){
|
||||||
imageRoot.setImageResource(R.drawable.pin);
|
imageRoot.setImageResource(R.drawable.pin);
|
||||||
List<MyDataClass> myDataList = firestoreReception.getMyDataList();
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
CreateRoot createRoot = new CreateRoot(MainActivity.this);
|
|
||||||
createRoot.receiveData(myDataList);
|
|
||||||
|
|
||||||
|
CountDownLatch latch = new CountDownLatch(2);
|
||||||
|
|
||||||
|
executor.execute(() -> {
|
||||||
|
AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build();
|
||||||
|
SetUpTableDao setUpTableDao = db.setUpTableDao();
|
||||||
|
|
||||||
|
Log.d("MainActivity", "db" + setUpTableDao.getAll());
|
||||||
|
|
||||||
|
int totalStudent = setUpTableDao.getTotalStudent();
|
||||||
|
int myDataListSize = firestoreReception.getMyDataListSize();
|
||||||
|
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
if (totalStudent != myDataListSize) {
|
||||||
|
showRouteCreationDialog(latch);
|
||||||
|
} else {
|
||||||
|
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) {
|
if(view == submission){
|
||||||
Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class);
|
Intent toSubmission = new Intent(MainActivity.this,SubmissionActivity.class);
|
||||||
startActivity(toSubmission);
|
startActivity(toSubmission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showUUIDYesNoDialog() {
|
private void showUUIDYesNoDialog() {
|
||||||
//ダイアログの表示
|
//ダイアログの表示
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
@ -122,9 +162,28 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
Log.d("DialogNO", "DialogでNoが選ばれました");
|
Log.d("DialogNO","DialogでNoが選ばれました");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
|
//ルート作成のダイアログ
|
||||||
|
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) {
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.show();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -178,6 +178,8 @@ public class SetUpActivity extends FragmentActivity
|
||||||
showTimePickerDialog();
|
showTimePickerDialog();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//リセットボタンの処理
|
||||||
|
|
||||||
reset.setOnClickListener(v -> { //テキストとラジオボタンの選択を消去
|
reset.setOnClickListener(v -> { //テキストとラジオボタンの選択を消去
|
||||||
setTeacherName.setText("");
|
setTeacherName.setText("");
|
||||||
setStartPoint.setText("");
|
setStartPoint.setText("");
|
||||||
|
@ -189,6 +191,13 @@ public class SetUpActivity extends FragmentActivity
|
||||||
setStartBreakTime.setText("");
|
setStartBreakTime.setText("");
|
||||||
setEndBreakTime.setText("");
|
setEndBreakTime.setText("");
|
||||||
setTotalStudent.setText("");
|
setTotalStudent.setText("");
|
||||||
|
|
||||||
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
|
executor.execute(() -> {
|
||||||
|
AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build();
|
||||||
|
SetUpTableDao setUpTableDao = db.setUpTableDao();
|
||||||
|
setUpTableDao.deleteAll();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package com.example.oplogy;
|
package com.example.oplogy;
|
||||||
|
|
||||||
import androidx.room.Dao;
|
import androidx.room.Dao;
|
||||||
import androidx.room.Insert;
|
import androidx.room.Insert;
|
||||||
import androidx.room.Query;
|
import androidx.room.Query;
|
||||||
import androidx.room.Update;
|
import androidx.room.Update;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
public interface SetUpTableDao {
|
public interface SetUpTableDao {
|
||||||
@Insert
|
@Insert
|
||||||
|
@ -13,20 +14,22 @@ public interface SetUpTableDao {
|
||||||
@Update
|
@Update
|
||||||
void update(SetUpTable setUpTable);
|
void update(SetUpTable setUpTable);
|
||||||
//名前が一致しているかの確認
|
//名前が一致しているかの確認
|
||||||
|
|
||||||
|
//削除処理
|
||||||
|
@Query("DELETE FROM SetUpTable")
|
||||||
|
void deleteAll();
|
||||||
|
//全件取得
|
||||||
|
@Query("SELECT * FROM SetUpTable")
|
||||||
|
List<SetUpTable> getAll();
|
||||||
|
|
||||||
@Query("SELECT * FROM SetUpTable WHERE teacherName = :name LIMIT 1")
|
@Query("SELECT * FROM SetUpTable WHERE teacherName = :name LIMIT 1")
|
||||||
SetUpTable findByName(String name);
|
SetUpTable findByName(String name);
|
||||||
|
|
||||||
|
@Query("SELECT totalStudent FROM SetUpTable")
|
||||||
|
int getTotalStudent();
|
||||||
//開始時間と終了時間の取得
|
//開始時間と終了時間の取得
|
||||||
@Query("SELECT startTime FROM SetUpTable")
|
@Query("SELECT startTime FROM SetUpTable")
|
||||||
String getStartTime();
|
String getStartTime();
|
||||||
@Query("SELECT endTime FROM SetUpTable")
|
@Query("SELECT endTime FROM SetUpTable")
|
||||||
String getEndTime();
|
String getEndTime();
|
||||||
//インターバル時間の取得
|
|
||||||
@Query("SELECT intervalTime FROM SetUpTable")
|
|
||||||
String getIntervalTime();
|
|
||||||
//休憩開始時間の取得
|
|
||||||
@Query("SELECT startBreakTime FROM SetUpTable")
|
|
||||||
String getStartBreakTime();
|
|
||||||
//休憩終了時間の取得
|
|
||||||
@Query("SELECT endBreakTime FROM SetUpTable")
|
|
||||||
String getEndBreakTime();
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user