画面遷移を原因とするFirebaseとの同期ズレを改善
This commit is contained in:
		
							parent
							
								
									0bdbc55518
								
							
						
					
					
						commit
						19a4765bf0
					
				@ -75,10 +75,12 @@ public class HomeFragment extends Fragment implements OnEventListener{
 | 
				
			|||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void onCreate(Bundle savedInstanceState) {
 | 
					    public void onCreate(Bundle savedInstanceState) {
 | 
				
			||||||
        super.onCreate(savedInstanceState);
 | 
					        super.onCreate(savedInstanceState);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (getArguments() != null) {
 | 
					        if (getArguments() != null) {
 | 
				
			||||||
            // mParam1 = getArguments().getString(ARG_PARAM1);
 | 
					            // mParam1 = getArguments().getString(ARG_PARAM1);
 | 
				
			||||||
            mParam2 = getArguments().getString(ARG_PARAM2);
 | 
					            mParam2 = getArguments().getString(ARG_PARAM2);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
 | 
				
			|||||||
@ -101,6 +101,8 @@ public class MainActivity extends AppCompatActivity {
 | 
				
			|||||||
                        .replace(findViewById(R.id.fragmentContainerView).getId(), this.homeFragment)
 | 
					                        .replace(findViewById(R.id.fragmentContainerView).getId(), this.homeFragment)
 | 
				
			||||||
                        .addToBackStack(null)
 | 
					                        .addToBackStack(null)
 | 
				
			||||||
                        .commit();
 | 
					                        .commit();
 | 
				
			||||||
 | 
					                firebaselink();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            } else if (v.getItemId() == findViewById(R.id.navigation_notification).getId()) {
 | 
					            } else if (v.getItemId() == findViewById(R.id.navigation_notification).getId()) {
 | 
				
			||||||
                findViewById(R.id.fab_scan_qr_code).setVisibility(FrameLayout.VISIBLE);
 | 
					                findViewById(R.id.fab_scan_qr_code).setVisibility(FrameLayout.VISIBLE);
 | 
				
			||||||
                getSupportFragmentManager().beginTransaction()
 | 
					                getSupportFragmentManager().beginTransaction()
 | 
				
			||||||
@ -123,6 +125,7 @@ public class MainActivity extends AppCompatActivity {
 | 
				
			|||||||
            ScanOptions options = new ScanOptions();
 | 
					            ScanOptions options = new ScanOptions();
 | 
				
			||||||
            options.setPrompt("QRコードを読み取ってください");
 | 
					            options.setPrompt("QRコードを読み取ってください");
 | 
				
			||||||
            QrLauncher.launch(options);
 | 
					            QrLauncher.launch(options);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Bluetooth検知機能
 | 
					        //Bluetooth検知機能
 | 
				
			||||||
@ -138,7 +141,7 @@ public class MainActivity extends AppCompatActivity {
 | 
				
			|||||||
            Log.d("BT", "Permission to connect bluetooth devices granted");
 | 
					            Log.d("BT", "Permission to connect bluetooth devices granted");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        registerReceiver(receiver, intentFilter);
 | 
					        registerReceiver(receiver, intentFilter);
 | 
				
			||||||
 | 
					        changessituation();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
@ -147,15 +150,7 @@ public class MainActivity extends AppCompatActivity {
 | 
				
			|||||||
        changessituation();
 | 
					        changessituation();
 | 
				
			||||||
        Log.d("onResume", "called");
 | 
					        Log.d("onResume", "called");
 | 
				
			||||||
        Log.d("onResume", "mDocRef is null");
 | 
					        Log.d("onResume", "mDocRef is null");
 | 
				
			||||||
        //共有プリファレンス全体の準備
 | 
					       firebaselink();
 | 
				
			||||||
        SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE);
 | 
					 | 
				
			||||||
        String IdPref = sharedPreferences.getString("ID", null);////アプリに記録されているIDの取得
 | 
					 | 
				
			||||||
        if (IdPref == null) {//FireBaseのIDがアプリに登録されているとき
 | 
					 | 
				
			||||||
            Log.d("onResume", "ID not initialized.");
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            mDocRef = FirebaseFirestore.getInstance().document("status/" + IdPref);//現在の位置を取得
 | 
					 | 
				
			||||||
            initNotification(mDocRef);//現在の位置を引数に initNotification()を処理
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void initNotification(DocumentReference mDocRef) {//サイト上で押されたボタンの管理
 | 
					    private void initNotification(DocumentReference mDocRef) {//サイト上で押されたボタンの管理
 | 
				
			||||||
@ -240,6 +235,19 @@ public class MainActivity extends AppCompatActivity {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void firebaselink(){//Firebaseのドキュメントの取得
 | 
				
			||||||
 | 
					        //共有プリファレンス全体の準備
 | 
				
			||||||
 | 
					        SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE);
 | 
				
			||||||
 | 
					        String IdPref = sharedPreferences.getString("ID", null);////アプリに記録されているIDの取得
 | 
				
			||||||
 | 
					        if (IdPref == null) {//FireBaseのIDがアプリに登録されているとき
 | 
				
			||||||
 | 
					            Log.d("onResume", "ID not initialized.");
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            mDocRef = FirebaseFirestore.getInstance().document("status/" + IdPref);//現在の位置を取得
 | 
				
			||||||
 | 
					            initNotification(mDocRef);//現在の位置を引数に initNotification()を処理
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    public void ResetReported(){//FireBaseのisReportedをfalseに初期化するメソッド
 | 
					    public void ResetReported(){//FireBaseのisReportedをfalseに初期化するメソッド
 | 
				
			||||||
        //共有プリファレンス全体の準備
 | 
					        //共有プリファレンス全体の準備
 | 
				
			||||||
        SharedPreferences sharedPreferences = MainActivity.this.getSharedPreferences("app_situation", MODE_PRIVATE);
 | 
					        SharedPreferences sharedPreferences = MainActivity.this.getSharedPreferences("app_situation", MODE_PRIVATE);
 | 
				
			||||||
 | 
				
			|||||||
@ -101,6 +101,7 @@ public class TestService extends Service {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void ResetReported() {//FireBaseのisReportedをfalseに初期化するメソッド
 | 
					    public void ResetReported() {//FireBaseのisReportedをfalseに初期化するメソッド
 | 
				
			||||||
        //共有プリファレンス全体の準備
 | 
					        //共有プリファレンス全体の準備
 | 
				
			||||||
        SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE);
 | 
					        SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE);
 | 
				
			||||||
@ -122,6 +123,7 @@ public class TestService extends Service {
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void NotificationSetting() {//通知に関する設定の処理を行うメソッド
 | 
					    public void NotificationSetting() {//通知に関する設定の処理を行うメソッド
 | 
				
			||||||
            int importance = NotificationManager.IMPORTANCE_DEFAULT;
 | 
					            int importance = NotificationManager.IMPORTANCE_DEFAULT;
 | 
				
			||||||
            //通知チャネルの実装
 | 
					            //通知チャネルの実装
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user