ルート作成画面の遷移時にformに送られた人数が足りてない場合、警告のダイアログを出すように変更 #9
|
@ -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;
|
||||
|
||||
|
@ -63,19 +64,19 @@ public class FirestoreReception {
|
|||
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());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//Dataのリストのサイズを返す
|
||||
public int getMyDataListSize(){
|
||||
return myDataList.size();
|
||||
}
|
||||
|
||||
//Dataのリストを返す
|
||||
public List<MyDataClass> getMyDataList(){
|
||||
return myDataList;
|
||||
}
|
||||
|
|
|
@ -11,10 +11,14 @@ 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{
|
||||
|
||||
|
@ -69,7 +73,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
|
||||
firestoreReception.getDocumentsByClassId(100);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -92,10 +95,48 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
// ルート作成のクリック処理
|
||||
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){
|
||||
|
@ -103,7 +144,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
startActivity(toSubmission);
|
||||
}
|
||||
}
|
||||
|
||||
private void showUUIDYesNoDialog() {
|
||||
//ダイアログの表示
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
|
@ -127,4 +167,23 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
});
|
||||
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