Conversation
SugyoIn-LBSTech
commented
May 29, 2020
- 디바이스 데이터 베이스에 저장할지 여부를 선택하는 storeHistory 옵션 추가.
- 디바이스 데이터 베이스에 저장하는 데이터의 걸음 주기를 정하는 resultStepsUnit 옵션 추가.
- Flutter로 보내는 데이터의 걸음 주기를 정하는 resultStepsUnit 옵션 추가.
Flutter side code를 기존 MethodChannel을 사용한 data streaming 방식에서 EventChannel로 변경.
- 디바이스 데이터 베이스에 저장할지 여부를 선택하는 storeHistory 옵션 추가. - 디바이스 데이터 베이스에 저장하는 데이터의 걸음 주기를 정하는 resultStepsUnit 옵션 추가. - Flutter로 보내는 데이터의 걸음 주기를 정하는 resultStepsUnit 옵션 추가.
- LbsPedometerPlugin.java의 static 변수들 member 변수로 전환. - Plugin의 성격상 MethodChannel 사용에서 EventChannel 사용으로 변경. - ServiceManager와 ServiceSensor가 사용하던 같은 상수들을 ServiceManager로 병합 및 공유. - Flutter에서 추가된 옵션 처리 부분 추가.
| private boolean isGPSEnable; | ||
|
|
||
| LocationHandler(Context context, Activity activity, LbsPedometerPlugin instance) { | ||
| LocationHandler(Context context, Activity activity) { |
| private Context context; | ||
| private Activity activity; | ||
| private LbsPedometerPlugin plugin; | ||
|
|
| private int resultStepsUnit; | ||
| private int storeStepsUnit; | ||
| private EventChannel.EventSink eventSink; | ||
|
|
| this.storeHistory = storeHistory; | ||
| this.resultStepsUnit = resultStepsUnit; | ||
| this.storeStepsUnit = storeStepsUnit; | ||
| this.eventSink = eventSink; |
| static final int MSG_SENSOR_TRIGGER = 0XAA2; | ||
| static final int MSG_LIFECYCLE_START = 0XAA3; | ||
| static final int MSG_LIFECYCLE_STOP = 0XAA4; | ||
|
|
There was a problem hiding this comment.
ServiceSensor와 같은 내용으로 ServiceManager에서 공유하도록 변경.
|
|
||
| private Context context; | ||
| private Activity activity; | ||
| private LbsPedometerPlugin plugin; |
|
|
||
| try { | ||
| Message msg = Message.obtain(null, what); | ||
| Message msg = Message.obtain(null, what, obj); |
| plugin.sendDataToFlutter( | ||
| sqlController.getCurrentWhereStep(ServiceSensor.currentSavedStepCnt) | ||
| ); | ||
| eventSink.success(msg.obj); |
There was a problem hiding this comment.
MethodChannel에서 EventChannel로 변경.
|
|
||
| private boolean storeHistory; | ||
| private int resultStepsUnit; | ||
| private int storeStepsUnit; |
| // ==================================== anonymous class ===================================== | ||
| // message handler - APP 으로부터의 메세지를 다루는 익명 클래스 | ||
| @SuppressLint("HandlerLeak") | ||
| private Messenger messenger = new Messenger(new Handler(){ | ||
| private Messenger messenger = new Messenger(new Handler() { | ||
| @Override | ||
| public void handleMessage(Message msg) { | ||
| int data = msg.what; | ||
| switch (data){ | ||
| case MSG_INIT: | ||
| switch (data) { | ||
| case ServiceManager.MSG_INIT: | ||
| Log.i("PEDOLOG_SS", "received msg: MSG_INIT"); | ||
| appMessenger = msg.replyTo; | ||
| Map args = (Map) msg.obj; | ||
| storeHistory = (boolean) args.get("storeHistory"); | ||
| resultStepsUnit = (int) args.get("resultStepsUnit"); | ||
| storeStepsUnit = (int) args.get("storeStepsUnit"); | ||
| sensorStart(); | ||
| break; | ||
| case MSG_LIFECYCLE_START: | ||
| case ServiceManager.MSG_LIFECYCLE_START: | ||
| Log.i("PEDOLOG_SS", "received msg: MSG_LIFECYCLE_START"); | ||
| appMessenger = msg.replyTo; | ||
| break; | ||
| case MSG_LIFECYCLE_STOP: | ||
| case ServiceManager.MSG_LIFECYCLE_STOP: | ||
| Log.i("PEDOLOG_SS", "received msg: MSG_LIFECYCLE_STOP"); | ||
| appMessenger = null; | ||
| break; |
There was a problem hiding this comment.
ServiceSensor와 같은 내용으로 ServiceManager에서 공유하도록 변경.
|
|
||
| break; | ||
| } | ||
| } |
There was a problem hiding this comment.
Flutter에 가는 알림과 디바이스 데이터 베이스에 저장하는 단위의 분할로 인해 기존 sqlController에 저장되어있던 내용을 보내는 것에서 resultStepsUnit에 맞게 들어온 위치 정보를 obj로 보내는 형식으로 변경.
| onAndroidResumed: onAndroidResume, | ||
| resultStepsUnit: 3, | ||
| storeHistory: true, | ||
| storeStepsUnit: 10, |
|
|
||
| const String _CHANNEL_NAME = 'lbstech.net.plugin/lbs_pedoemter'; No newline at end of file | ||
| const String _METHOD_CHANNEL_NAME = 'lbstech.net.plugin/lbs_pedoemter/method'; | ||
| const String _EVENT_CHANNEL_NAME = 'lbstech.net.plugin/lbs_pedoemter/event'; No newline at end of file |
There was a problem hiding this comment.
기존 MethodChannel을 MethodChannel과 EventChannel로 분리.
| final MethodChannel _channel = MethodChannel(_CHANNEL_NAME); | ||
| class _PedometerController { | ||
| final MethodChannel _channel = MethodChannel(_METHOD_CHANNEL_NAME); | ||
| final EventChannel _eventChannel = EventChannel(_EVENT_CHANNEL_NAME); |
There was a problem hiding this comment.
기존 MethodChannel을 MethodChannel과 EventChannel로 분리.
| print('종료 이후 이전 기록 가져오기의 결과가 비어 있습니다.'); | ||
| return null; | ||
| } | ||
| } |
There was a problem hiding this comment.
- call.method가 _MTD_TAKE_STEPS일 경우의 로직은 EventChannel로 변경하면서 EventChannel의 listen()함수로 넘어감.
- 또한 stop()에 있던 로직을 call.method가 "onCancel"일 때로 옮겨옴. Android 코드에서 EventChannel의 구독이 취소될때 불림.
|
|
||
| String _androidNotificationTitle = 'GPS 위치정보 추적중'; | ||
| String _androidNotificationContent = '백그라운드에서 현재 위치를 지속적으로 추적하고 있습니다'; | ||
| StreamSubscription _pedometerStream; |
There was a problem hiding this comment.
EventChannel의 broadcastStream 구독 객체.
| 'storeHistory': storeHistory ?? true, | ||
| 'resultStepsUnit': resultStepsUnit ?? storeStepsUnit ?? 10, | ||
| 'storeStepsUnit': storeStepsUnit ?? resultStepsUnit ?? 10, | ||
| }).listen((stepData) => pedometer._onTakeStep(StepData.fromMap(stepData))); |
There was a problem hiding this comment.
기존 MethodCallHandler의 _MTD_TAKE_STEPS의 경우 로직을 옮겨옴.
| } | ||
| } | ||
| void stop() => _pedometerStream?.cancel(); | ||
|
|
There was a problem hiding this comment.
MethodCallHandler의 "onCancel"의 경우로 로직 이전.
Android 코드에서 EventChannel의 구독이 취소될때 불림.
|
|
||
| const String _MTD_STOP = 'stop'; | ||
|
|
||
| const String _MTD_TAKE_STEPS = 'takeSteps'; |
| /// 안드로이드 한정으로 [onAndroidResumed]에서 onResume의 콜백 처리를 한다. | ||
| /// 마찬가지로 안드로이드 한정으로 [resultStepsUnit]과 [storeStepsUnit]는 각각 Flutter로 데이터를 보내는 걸음 단위와 디바이스 데이터 베이스에 저장하는 걸음 단위를 의미한다. | ||
| /// 예를 들어 [resultStepsUnit]이 3이고 [storeStepsUnit]가 10이면 매 3걸음 마다 [onTakeStep]이 불리며 10걸음마다 디바이스 데이터 베이스에 데이터를 저장한다. | ||
| /// [resultStepsUnit]와 [storeStepsUnit] 둘 중 하나의 값 많이 정의 되더라도 다른 값 또한 같은 값으로 정의된며 기본값은 둘 다 10이다. |
| ); | ||
| return null; | ||
| } | ||
| } |
|
|
||
| /// permission 을 요청하는 함수 | ||
| Future<void> requestPermission() async => _controller.requestPermission(); | ||
|
|
| @required String content, | ||
| }) { | ||
| if (Platform.isIOS) return; | ||
| return _controller.setAndroidNotification(title: title, content: content); |
| Future<List<StepData>> get history { | ||
| if (Platform.isIOS) return null; | ||
| return _controller.getHistory(); | ||
| } |
There was a problem hiding this comment.
getHistory 함수를 getter 함수로 변경.
| /// | ||
| /// | ||
| /// @return type : [Coordinate] | ||
| Future<Coordinate> get location => _controller.getLocation(); |
There was a problem hiding this comment.
getLocation 함수를 getter 함수로 변경.
| Future<void> start({OnTakeStep onTakeStep, OnAndroidResumed onAndroidResumed}) { | ||
| /// @return type : [AuthorizationState] | ||
| Future<AuthorizationState> get authorizationState => | ||
| _controller.getAuthorizationState(); |
There was a problem hiding this comment.
getAuthorizationState 함수를 getter 함수로 변경.
| return _controller.getLocation(); | ||
| } | ||
| @Deprecated('Effective Dart문서에 따라 getter를 쓰기로합니다. 2.x.x 이후 사라집니다.') | ||
| Future<Coordinate> getLocation() => _controller.getLocation(); |
| } | ||
| @Deprecated('Effective Dart문서에 따라 getter를 쓰기로합니다. 2.x.x 이후 사라집니다.') | ||
| Future<AuthorizationState> getAuthorizationState() async => | ||
| _controller.getAuthorizationState(); |
| } | ||
|
|
||
| } No newline at end of file | ||
| } |
| private final int MSG_INIT = 0XAA1; | ||
| private final int MSG_SENSOR_TRIGGER = 0XAA2; | ||
| private final int MSG_LIFECYCLE_START = 0XAA3; | ||
| private final int MSG_LIFECYCLE_STOP = 0XAA4; |
There was a problem hiding this comment.
ServiceSensor와 같은 내용으로 ServiceManager에서 공유하도록 변경.