ID,セットアップが終わっていない場合にtoast表示を行う
This commit is contained in:
parent
d96f67b09b
commit
356021beae
|
@ -5,12 +5,12 @@ import java.util.List;
|
||||||
|
|
||||||
public class CreateUUID {
|
public class CreateUUID {
|
||||||
|
|
||||||
public static int generateUUID(List<Integer> classIdList ){
|
public static int generateUUID(List<Integer> classIdList) {
|
||||||
while (true){
|
while (true) {
|
||||||
int uuidInt = (int)(Math.random() * 1000000);
|
int uuidInt = (int) (Math.random() * 1000000);
|
||||||
boolean isDuplicate = false;
|
boolean isDuplicate = false;
|
||||||
for(int classIdInt : classIdList){
|
for (int classIdInt : classIdList) {
|
||||||
if(classIdInt==uuidInt){
|
if (classIdInt == uuidInt) {
|
||||||
//重複があればフラグを立て、ループを抜ける
|
//重複があればフラグを立て、ループを抜ける
|
||||||
isDuplicate = true;
|
isDuplicate = true;
|
||||||
break;
|
break;
|
||||||
|
@ -22,7 +22,7 @@ public class CreateUUID {
|
||||||
InsertClassIdforFirebase insertClassIdforFirebase = new InsertClassIdforFirebase();
|
InsertClassIdforFirebase insertClassIdforFirebase = new InsertClassIdforFirebase();
|
||||||
insertClassIdforFirebase.insertClassId(uuidInt);
|
insertClassIdforFirebase.insertClassId(uuidInt);
|
||||||
//テスト用
|
//テスト用
|
||||||
uuidInt=100;
|
uuidInt = 100;
|
||||||
return uuidInt;
|
return uuidInt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,19 +16,18 @@ import java.util.Map;
|
||||||
|
|
||||||
public class FirestoreReception {
|
public class FirestoreReception {
|
||||||
|
|
||||||
|
//firestoreから受け取ったデータを束ねるためのマップ
|
||||||
|
public List<MyDataClass> myDataList = new ArrayList<>();
|
||||||
private FirebaseFirestore db;
|
private FirebaseFirestore db;
|
||||||
|
|
||||||
public FirestoreReception() {
|
public FirestoreReception() {
|
||||||
db = FirebaseFirestore.getInstance();
|
db = FirebaseFirestore.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
//firestoreから受け取ったデータを束ねるためのマップ
|
|
||||||
public List<MyDataClass> myDataList = new ArrayList<>();
|
|
||||||
|
|
||||||
//ClassIdを引数にデータの作成を行う
|
//ClassIdを引数にデータの作成を行う
|
||||||
public void getDocumentsByClassId(int classId) {
|
public void getDocumentsByClassId(int classId) {
|
||||||
myDataList.clear();
|
myDataList.clear();
|
||||||
CollectionReference collectionRef = db.collection("testAddressArray");
|
CollectionReference collectionRef = db.collection("testDistinct");
|
||||||
|
|
||||||
// classIdが引数のものを取得する
|
// classIdが引数のものを取得する
|
||||||
collectionRef.whereEqualTo("classId", classId).get()
|
collectionRef.whereEqualTo("classId", classId).get()
|
||||||
|
|
|
@ -19,6 +19,7 @@ import com.google.gson.Gson;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
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;
|
||||||
|
@ -85,7 +86,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
// firestoreの受信関連
|
// firestoreの受信関連
|
||||||
db = FirebaseFirestore.getInstance();
|
db = FirebaseFirestore.getInstance();
|
||||||
firestoreReception = new FirestoreReception();
|
firestoreReception = new FirestoreReception();
|
||||||
Log.d("MainActivity","geocodeAddress");
|
Log.d("MainActivity", "geocodeAddress");
|
||||||
|
|
||||||
|
|
||||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
|
@ -105,7 +106,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// クリック処理
|
// クリック処理
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
@ -136,51 +136,65 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
// ルート作成のクリック処理
|
// ルート作成のクリック処理
|
||||||
if (view == root) {
|
if (view == root) {
|
||||||
imageRoot.setImageResource(R.drawable.pin);
|
imageRoot.setImageResource(R.drawable.pin);
|
||||||
fetchDataAndCreateRoute();
|
checkSetupAndCreateRoute(this::fetchDataAndCreateRoute);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (view == imageRoot) {
|
if (view == imageRoot) {
|
||||||
imageRoot.setImageResource(R.drawable.pin);
|
imageRoot.setImageResource(R.drawable.pin);
|
||||||
fetchDataAndCreateRoute();
|
checkSetupAndCreateRoute(this::fetchDataAndCreateRoute);
|
||||||
}
|
}
|
||||||
// 提出状況のクリック処理
|
// 提出状況のクリック処理
|
||||||
if (view == submission) {
|
if (view == submission) {
|
||||||
|
checkSetupAndCreateRoute(() -> {
|
||||||
ArrayList<SubmissionStudent> submissionStudents = getSubmissionStudents();
|
ArrayList<SubmissionStudent> submissionStudents = getSubmissionStudents();
|
||||||
Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class);
|
Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class);
|
||||||
toSubmission.putParcelableArrayListExtra("submissionStudents", submissionStudents);
|
toSubmission.putParcelableArrayListExtra("submissionStudents", submissionStudents);
|
||||||
startActivity(toSubmission);
|
startActivity(toSubmission);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (view == imageSubmission) {
|
if (view == imageSubmission) {
|
||||||
|
checkSetupAndCreateRoute(() -> {
|
||||||
ArrayList<SubmissionStudent> submissionStudents = getSubmissionStudents();
|
ArrayList<SubmissionStudent> submissionStudents = getSubmissionStudents();
|
||||||
Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class);
|
Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class);
|
||||||
toSubmission.putParcelableArrayListExtra("submissionStudents", submissionStudents);
|
toSubmission.putParcelableArrayListExtra("submissionStudents", submissionStudents);
|
||||||
startActivity(toSubmission);
|
startActivity(toSubmission);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//UUIDを表示するかのダイアログ
|
//ID作成、表示に関する処理
|
||||||
private void showUUIDYesNoDialog() {
|
private void showUUIDYesNoDialog() {
|
||||||
firestoreReception_classIdDatabase = new FirestoreReception_classIdDatabase();
|
firestoreReception_classIdDatabase = new FirestoreReception_classIdDatabase();
|
||||||
List<Integer> classIdList = firestoreReception_classIdDatabase.getAllDocumentsFromClassIdDatabase();
|
List<Integer> classIdList = firestoreReception_classIdDatabase.getAllDocumentsFromClassIdDatabase();
|
||||||
|
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setTitle("クラスID");
|
builder.setTitle("ID");
|
||||||
builder.setMessage("あなたのクラスIDを表示しますか?");
|
builder.setMessage("あなたのIDを表示/もしくは新規で作成しますか?");
|
||||||
|
|
||||||
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
//作成処理
|
||||||
|
builder.setPositiveButton("作成", new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
classId = CreateUUID.generateUUID(classIdList);
|
classId = CreateUUID.generateUUID(classIdList);
|
||||||
Toast.makeText(MainActivity.this, "クラスID: " + classId, Toast.LENGTH_SHORT).show();
|
// 生成されたIDを表示するメソッド
|
||||||
imageUuid.setImageResource(R.drawable.checked_image);
|
showClassIdDialog("生成されたID", classId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
//表示処理
|
||||||
|
builder.setNegativeButton("表示", new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
Log.d("DialogNO", "DialogでNoが選ばれました");
|
//roomを扱うため非同期処理
|
||||||
imageUuid.setImageResource(R.drawable.checked_image);
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
|
executor.execute(() -> {
|
||||||
|
// 現在のクラスIDを取得
|
||||||
|
int currentClassId = getCurrentClassIdFromRoom();
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
// 現在のクラスIDを表示するダイアログ
|
||||||
|
showClassIdDialog("現在のID", currentClassId);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
executor.shutdown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -189,12 +203,86 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getCurrentClassIdFromRoom() {
|
||||||
|
AppDatabase db = getDatabaseInstance();
|
||||||
|
SetUpTableDao setUpTableDao = db.setUpTableDao();
|
||||||
|
|
||||||
|
// 現在のクラスIDを取得
|
||||||
|
return setUpTableDao.getClassId();
|
||||||
|
}
|
||||||
|
|
||||||
|
//クラスIDを表示するダイアログ
|
||||||
|
private void showClassIdDialog(String title, int classId) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
builder.setTitle(title);
|
||||||
|
builder.setMessage("ID: " + classId);
|
||||||
|
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
AlertDialog dialog = builder.create();
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//ルート作成、提出状況の遷移を行う前のチェックを行う処理
|
||||||
|
private void checkSetupAndCreateRoute(Runnable onSetupComplete) {
|
||||||
|
if (isClassIdSet()) {
|
||||||
|
isSetupExists(classId).thenAccept(setupExists -> {
|
||||||
|
if (setupExists) {
|
||||||
|
runOnUiThread(onSetupComplete);
|
||||||
|
} else {
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
Toast.makeText(this, "先にセットアップを済ませてください", Toast.LENGTH_LONG).show();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).exceptionally(ex -> {
|
||||||
|
ex.printStackTrace();
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
Toast.makeText(this, "エラーが発生しました", Toast.LENGTH_LONG).show();
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, "先にIDの作成を行ってください", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// クラスIDが設定されているかどうかを判定
|
||||||
|
private boolean isClassIdSet() {
|
||||||
|
// classIdが0より大きい場合、trueを返す
|
||||||
|
return classId > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// セットアップが存在するかどうかを判定
|
||||||
|
private CompletableFuture<Boolean> isSetupExists(int classId) {
|
||||||
|
final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||||
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
|
AppDatabase db = getDatabaseInstance();
|
||||||
|
SetUpTableDao setUpTableDao = db.setUpTableDao();
|
||||||
|
//データベースの値を全取得
|
||||||
|
List<SetUpTable> checkData = setUpTableDao.getAll();
|
||||||
|
for (SetUpTable setUpTable : checkData) {
|
||||||
|
//SetUpTableのclassIdと引数のclassIdが一致する場合、trueを返す
|
||||||
|
if (setUpTable.classId == classId) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
//処理完了時にexecutorServiceをシャットダウン
|
||||||
|
}, executorService).whenComplete((result, throwable) -> executorService.shutdown());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//ルート作成の非同期処理
|
//ルート作成の非同期処理
|
||||||
private void fetchDataAndCreateRoute() {
|
private void fetchDataAndCreateRoute() {
|
||||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
executor.execute(() -> {
|
executor.execute(() -> {
|
||||||
AppDatabase db = getDatabaseInstance(); SetUpTableDao setUpTableDao = db.setUpTableDao();
|
AppDatabase db = getDatabaseInstance();
|
||||||
|
SetUpTableDao setUpTableDao = db.setUpTableDao();
|
||||||
int totalStudentInt = setUpTableDao.getTotalStudent();
|
int totalStudentInt = setUpTableDao.getTotalStudent();
|
||||||
int myDataListSizeInt = firestoreReception.getMyDataListSize();
|
int myDataListSizeInt = firestoreReception.getMyDataListSize();
|
||||||
|
|
||||||
|
@ -248,7 +336,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
String startPointLatLngString = createSchedule.receiveData(myDataList, getApplicationContext());
|
String startPointLatLngString = createSchedule.receiveData(myDataList, getApplicationContext());
|
||||||
|
|
||||||
runOnUiThread(() -> {
|
runOnUiThread(() -> {
|
||||||
if ( !startPointLatLngString.equals("")) {
|
if (!startPointLatLngString.equals("")) {
|
||||||
Log.d("MainActivity", "スケジュール作成成功");
|
Log.d("MainActivity", "スケジュール作成成功");
|
||||||
saveMyDataList(finalMyDataList);
|
saveMyDataList(finalMyDataList);
|
||||||
Intent toRoot = new Intent(MainActivity.this, Maps.class);
|
Intent toRoot = new Intent(MainActivity.this, Maps.class);
|
||||||
|
@ -264,6 +352,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
executor.shutdown();
|
executor.shutdown();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveMyDataList(List<MyDataClass> myDataList) {
|
private void saveMyDataList(List<MyDataClass> myDataList) {
|
||||||
// 共有プリファレンスのインスタンスを取得
|
// 共有プリファレンスのインスタンスを取得
|
||||||
SharedPreferences sharedPreferences = getSharedPreferences("MyDataList", MODE_PRIVATE);
|
SharedPreferences sharedPreferences = getSharedPreferences("MyDataList", MODE_PRIVATE);
|
||||||
|
@ -307,7 +396,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//提出状況の取得
|
//提出状況の取得
|
||||||
private ArrayList<SubmissionStudent> getSubmissionStudents() {
|
private ArrayList<SubmissionStudent> getSubmissionStudents() {
|
||||||
ArrayList<SubmissionStudent> submissionStudents = new ArrayList<>();
|
ArrayList<SubmissionStudent> submissionStudents = new ArrayList<>();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user