From c196399c2403466bfccaea831195507fe6505318 Mon Sep 17 00:00:00 2001 From: it232115 Date: Fri, 19 Jan 2024 01:46:33 +0900 Subject: [PATCH] =?UTF-8?q?=E4=B9=97=E8=BB=8A=E7=8A=B6=E6=85=8B=E3=81=AE?= =?UTF-8?q?=E3=81=A8=E3=81=8D=E3=81=AB=E7=AC=AC=E4=B8=89=E8=80=85=E9=80=9A?= =?UTF-8?q?=E5=A0=B1=E3=82=92=E8=A1=8C=E3=81=86=E3=81=A8=E3=80=81FireBase?= =?UTF-8?q?=E3=81=A8=E3=81=AE=E5=90=8C=E6=9C=9F=E3=81=8C=E3=82=BA=E3=83=AC?= =?UTF-8?q?=E3=82=8B=E3=83=90=E3=82=B0=E3=82=92=E8=A7=A3=E6=B6=88=E3=81=97?= =?UTF-8?q?=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/MainActivity.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index 3379dbd..4e358f3 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -146,6 +146,7 @@ public class MainActivity extends AppCompatActivity { @Override protected void onResume() { super.onResume(); + changessituation(); Log.d("onResume", "called"); Log.d("onResume", "mDocRef is null"); SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE); @@ -178,10 +179,9 @@ public class MainActivity extends AppCompatActivity { Log.d("nt", "レスポンスを検知しました1"); if (documentSnapshot.getBoolean("isReported")==false ) { if (fragment instanceof HomeFragment) { - ((HomeFragment) fragment).onEvent(isInCar); + changessituation(); } }else if(isInCar){ - ResetReported(); int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel("CHANNEL_ID", "通報通知", importance); channel.setDescription("第3者からの通報を検知しました"); @@ -189,6 +189,7 @@ public class MainActivity extends AppCompatActivity { notificationManager.createNotificationChannel(channel); Log.d("nt", "レスポンスを検知しました2"); notifyMain(); + ResetReported(); } else{ ResetReported(); Log.d("nt", "何もなし" ); @@ -274,7 +275,6 @@ public class MainActivity extends AppCompatActivity { db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ DocumentReference isReported = db.collection("status").document(IdPref); Map DEFAULT_ITEM = new HashMap<>();//mapの宣言 - DEFAULT_ITEM.put("isReported", false); isReported.update("isReported",false).addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(Void unused) { @@ -287,11 +287,22 @@ public class MainActivity extends AppCompatActivity { } }); } + + + public void changessituation(){ + SharedPreferences sharedPreferences = getSharedPreferences("app_situation",MODE_PRIVATE); + //共有プリファレンス 書き込みの準備 + SharedPreferences.Editor E = sharedPreferences.edit(); + Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragmentContainerView); + Boolean isInCar = sharedPreferences.getBoolean("isInCarPref", false);//現在の乗降状態を保存する共有プリファレンス + ((HomeFragment) fragment).onEvent(!isInCar); + } @Override public void onStop() { super.onStop(); Intent intent = new Intent(getApplication(), TestService.class); startService(intent); + } }