Skip to content

Commit

Permalink
M3-107 Feat : 안드로이드 만보계 정각에 걸음수 초기화 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
koomin1227 committed Jul 6, 2024
1 parent 317cb44 commit f94ef34
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 142 deletions.
94 changes: 0 additions & 94 deletions lib/controllers/android_walking_controller.dart

This file was deleted.

14 changes: 8 additions & 6 deletions lib/utils/android_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ Future<void> initForegroundTask() async {

@pragma('vm:entry-point')
void startCallback() {
FlutterForegroundTask.setTaskHandler(FirstTaskHandler());
FlutterForegroundTask.setTaskHandler(AndroidWalkingHandler());
}

class FirstTaskHandler extends TaskHandler {
class AndroidWalkingHandler extends TaskHandler {
SendPort? _sendPort;
late Stream<StepCount> _stepCountStream;
final GetStorage _localStorage = GetStorage();
Expand All @@ -60,7 +60,7 @@ class FirstTaskHandler extends TaskHandler {
@override
void onStart(DateTime timestamp, SendPort? sendPort) async {
_sendPort = sendPort;
currentSteps = (await _localStorage.read(todayStepKey)) ?? 0;
currentSteps = _localStorage.read(todayStepKey) ?? 0;
_stepCountStream = Pedometer.stepCountStream.asBroadcastStream();
_stepCountStream.listen(updateStep).onError(onStepCountError);
_initializeMidnightReset();
Expand All @@ -74,16 +74,18 @@ class FirstTaskHandler extends TaskHandler {
DateTime now = DateTime.now();
DateTime midnight = DateTime(now.year, now.month, now.day + 1);
Duration timeUntilMidnight = midnight.difference(now);

_midnightTimer?.cancel();
_midnightTimer = Timer(timeUntilMidnight, () {
_resetStepsAtMidnight();
_midnightTimer?.cancel();
_midnightTimer = Timer.periodic(Duration(days: 1), (timer) {
_resetStepsAtMidnight();
});
});
}

void _resetStepsAtMidnight() {
// TODO : 서버에 걸음수 저장하는 로직 추가
currentSteps = 0;
_localStorage.write(todayStepKey, 0);

Expand All @@ -97,8 +99,8 @@ class FirstTaskHandler extends TaskHandler {
updateStep(StepCount event) async {
int currentTotalStep = event.steps;

int lastSavedStepCount = await _localStorage.read(lastSavedStepKey);
int todaySteps = await _localStorage.read(todayStepKey) ?? 0;
int? lastSavedStepCount = _localStorage.read(lastSavedStepKey);
int todaySteps = _localStorage.read(todayStepKey) ?? 0;

if (lastSavedStepCount == null) {
_localStorage.write(lastSavedStepKey, currentTotalStep);
Expand Down
42 changes: 0 additions & 42 deletions lib/widgets/map/android_step_stats.dart

This file was deleted.

0 comments on commit f94ef34

Please sign in to comment.