Merge pull request #18 from child-guardian/hotfix-1

Hotfix 1
This commit is contained in:
ろむねこ 2024-01-19 12:56:18 +09:00 committed by GitHub
commit 3404e833e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 14 deletions

View File

@ -1,5 +1,6 @@
package com.example.childguard;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
@ -76,6 +77,12 @@ public class HomeFragment extends Fragment implements OnEventListener{
public void onResume() {
super.onResume();
Log.d("HomeFragment", "onResume: called");
this.updateUiState(getIsInCarLocal());
}
private boolean getIsInCarLocal() {
SharedPreferences pref = requireActivity().getSharedPreferences("app_situation", requireActivity().MODE_PRIVATE);
return pref.getBoolean("isInCar", false);
}
//画面遷移メソッド

View File

@ -131,13 +131,11 @@ public class MainActivity extends AppCompatActivity {
Log.d("BT", "Permission to connect bluetooth devices granted");
}
registerReceiver(receiver, intentFilter);
changessituation();
}
@Override
protected void onResume() {
super.onResume();
changessituation();
Log.d("onResume", "called");
Log.d("onResume", "mDocRef is null");
firebaselink();
@ -162,7 +160,8 @@ public class MainActivity extends AppCompatActivity {
//FireBaseで更新された情報の判定
if (documentSnapshot.getBoolean("isReported") == false) {//isReportedがfalseのとき=サイト上で保護者ボタンが押されたとき
if (fragment instanceof HomeFragment) {//fragementがHomeFragmentのインスタンスかの判定
changessituation();// changessituation()メソッドを処理アプリ側の乗降状態を変化
// changessituation();// changessituation()メソッドを処理アプリ側の乗降状態を変化
((HomeFragment) fragment).onEvent(!isInCar);
}
} else if (isInCar) {//第三者ボタンが押されたときにisInCarがtrueのとき乗車状態のときいたずら防止
int importance = NotificationManager.IMPORTANCE_DEFAULT;
@ -302,17 +301,6 @@ public class MainActivity extends AppCompatActivity {
notificationManager.notify(R.string.app_name, builder.build());//通知の表示
}
public void changessituation() {//乗降状態の管理をするためにHomeFramgentを呼び出すメソッド
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();