ルート作成画面の遷移時にformに送られた人数が足りてない場合、警告のダイアログを出すように変更 #9
|
@ -69,8 +69,17 @@ public class FirestoreReception {
|
|||
} 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,9 +11,13 @@ 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.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
|
||||
|
||||
// ID作成のTextViewとImageView
|
||||
|
@ -67,9 +71,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
|
||||
firestoreReception.getDocumentsByClassId(100);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -92,9 +93,44 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
// ルート作成のクリック処理
|
||||
if(view == root){
|
||||
imageRoot.setImageResource(R.drawable.pin);
|
||||
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
|
||||
executor.execute(() -> {
|
||||
AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build();
|
||||
SetUpTableDao setUpTableDao = db.setUpTableDao();
|
||||
|
||||
// データベースに登録されている生徒の数、formにデータを送信した生徒の合計数をを取得
|
||||
int totalStudent = setUpTableDao.getTotalStudent();
|
||||
int myDataListSize = firestoreReception.myDataList.size();
|
||||
|
||||
runOnUiThread(() -> {
|
||||
if (totalStudent != myDataListSize) {
|
||||
// 値が一致しない場合、ダイアログを表示
|
||||
new AlertDialog.Builder(MainActivity.this)
|
||||
.setTitle("警告")
|
||||
.setMessage("人数が足りてませんがそれでもルート作成を行いますか?")
|
||||
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent toRoot = new Intent(MainActivity.this,Maps.class);
|
||||
startActivity(toRoot);
|
||||
}
|
||||
})
|
||||
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
} else {
|
||||
Intent toRoot = new Intent(MainActivity.this,Maps.class);
|
||||
startActivity(toRoot);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
// 提出状況のクリック処理
|
||||
if(view == submission){
|
||||
Intent toSubmission = new Intent(MainActivity.this,SubmissionActivity.class);
|
||||
|
|
|
@ -16,4 +16,7 @@ public interface SetUpTableDao {
|
|||
//名前が一致しているかの確認
|
||||
@Query("SELECT * FROM SetUpTable WHERE teacherName = :name LIMIT 1")
|
||||
SetUpTable findByName(String name);
|
||||
|
||||
@Query("SELECT totalStudent FROM SetUpTable")
|
||||
int getTotalStudent();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user