Merge pull request 'メソッド化' (#17) from murakumo_修正パッチその1 into master
Reviewed-on: #17
This commit is contained in:
commit
2e61c4c3f7
|
@ -113,55 +113,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
// ルート作成のクリック処理
|
// ルート作成のクリック処理
|
||||||
if(view == root){
|
if(view == root){
|
||||||
imageRoot.setImageResource(R.drawable.pin);
|
imageRoot.setImageResource(R.drawable.pin);
|
||||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
fetchDataAndCreateRoute();
|
||||||
|
|
||||||
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 == imageRoot){
|
if(view == imageRoot){
|
||||||
imageRoot.setImageResource(R.drawable.pin);
|
imageRoot.setImageResource(R.drawable.pin);
|
||||||
Intent toRoot = new Intent(MainActivity.this,Maps.class);
|
fetchDataAndCreateRoute();
|
||||||
startActivity(toRoot);
|
|
||||||
}
|
}
|
||||||
// 提出状況のクリック処理
|
// 提出状況のクリック処理
|
||||||
if(view == submission){
|
if(view == submission){
|
||||||
|
@ -173,6 +130,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
startActivity(toSubmission);
|
startActivity(toSubmission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//UUIDを表示するかのダイアログ
|
||||||
private void showUUIDYesNoDialog() {
|
private void showUUIDYesNoDialog() {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this); // この 'this' が問題でないか確認
|
AlertDialog.Builder builder = new AlertDialog.Builder(this); // この 'this' が問題でないか確認
|
||||||
builder.setTitle("クラスID");
|
builder.setTitle("クラスID");
|
||||||
|
@ -196,8 +154,54 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
alertDialog.show();
|
alertDialog.show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//ルート作成の非同期処理
|
||||||
|
private void fetchDataAndCreateRoute() {
|
||||||
|
//非同期処理の開始
|
||||||
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
|
CountDownLatch latch = new CountDownLatch(2);
|
||||||
|
|
||||||
|
// タスク1: ローカルDBから生徒数を取得
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// タスク2: Firestoreからデータを取得
|
||||||
|
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();
|
||||||
|
}
|
||||||
//ルート作成のダイアログ
|
//ルート作成のダイアログ
|
||||||
private void showRouteCreationDialog(CountDownLatch latch) {
|
private void showRouteCreationDialog(CountDownLatch latch) {
|
||||||
new AlertDialog.Builder(MainActivity.this)
|
new AlertDialog.Builder(MainActivity.this)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user