Merge pull request 'ルート作成画面の遷移時にformに送られた人数が足りてない場合、警告のダイアログを出すように変更' (#9) from murakumo_setupの情報をroomに保存し隊 into master
Reviewed-on: #9
This commit is contained in:
commit
fc25e35a77
|
@ -11,6 +11,7 @@ import com.google.firebase.firestore.QueryDocumentSnapshot;
|
|||
import com.google.firebase.firestore.QuerySnapshot;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -23,7 +24,7 @@ public class FirestoreReception {
|
|||
}
|
||||
|
||||
//firestoreから受け取ったデータを束ねるためのマップ
|
||||
public List<MyDataClass> myDataList = new ArrayList<>();
|
||||
public List<MyDataClass>myDataList = new ArrayList<>();
|
||||
|
||||
//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());
|
||||
}
|
||||
|
||||
} else {
|
||||
Log.w("FirestoreReceptiond", "Error getting documents.", task.getException());
|
||||
}
|
||||
Log.i("FirestoreReceptiond", "data: " + myDataList.size());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public int getMyDataListSize() {
|
||||
//Dataのリストのサイズを返す
|
||||
public int getMyDataListSize(){
|
||||
return myDataList.size();
|
||||
}
|
||||
|
||||
public List<MyDataClass> getMyDataList() {
|
||||
//Dataのリストを返す
|
||||
public List<MyDataClass> getMyDataList(){
|
||||
return myDataList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,12 +11,16 @@ import android.widget.Toast;
|
|||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
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;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
||||
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
|
||||
|
||||
// ID作成のTextViewとImageView
|
||||
private TextView creatUUID;
|
||||
|
@ -69,41 +73,77 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
|
||||
firestoreReception.getDocumentsByClassId(100);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// クリック処理
|
||||
// クリック処理
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// ID作成のクリック処理
|
||||
if (view == creatUUID) {
|
||||
if(view == creatUUID){
|
||||
imageUuid.setImageResource(R.drawable.ischecked_uuid);
|
||||
showUUIDYesNoDialog();//UUIDを表示するかのダイアログ
|
||||
|
||||
}
|
||||
// セットアップのクリック処理
|
||||
if (view == setUp) {
|
||||
if(view == setUp){
|
||||
imageSetup.setImageResource(R.drawable.ischecked_uuid);
|
||||
Intent toSetup = new Intent(MainActivity.this, SetUpActivity.class);
|
||||
Intent toSetup = new Intent(MainActivity.this,SetUpActivity.class);
|
||||
startActivity(toSetup);
|
||||
|
||||
}
|
||||
// ルート作成のクリック処理
|
||||
if (view == root) {
|
||||
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();
|
||||
|
||||
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) {
|
||||
Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class);
|
||||
if(view == submission){
|
||||
Intent toSubmission = new Intent(MainActivity.this,SubmissionActivity.class);
|
||||
startActivity(toSubmission);
|
||||
}
|
||||
}
|
||||
|
||||
private void showUUIDYesNoDialog() {
|
||||
//ダイアログの表示
|
||||
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() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Log.d("DialogNO", "DialogでNoが選ばれました");
|
||||
Log.d("DialogNO","DialogでNoが選ばれました");
|
||||
}
|
||||
});
|
||||
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();
|
||||
});
|
||||
|
||||
//リセットボタンの処理
|
||||
|
||||
reset.setOnClickListener(v -> { //テキストとラジオボタンの選択を消去
|
||||
setTeacherName.setText("");
|
||||
setStartPoint.setText("");
|
||||
|
@ -189,6 +191,13 @@ public class SetUpActivity extends FragmentActivity
|
|||
setStartBreakTime.setText("");
|
||||
setEndBreakTime.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;
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface SetUpTableDao {
|
||||
@Insert
|
||||
|
@ -13,20 +14,22 @@ public interface SetUpTableDao {
|
|||
@Update
|
||||
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")
|
||||
SetUpTable findByName(String name);
|
||||
|
||||
@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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user