Skip to content

Commit

Permalink
M3-107 Feat : android_walking_service.dart 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
koomin1227 committed Jul 6, 2024
1 parent 0dc9984 commit e84dcbb
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 2 deletions.
26 changes: 26 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ PODS:
- Flutter (1.0.0)
- flutter_config (0.0.1):
- Flutter
- flutter_foreground_task (0.0.1):
- Flutter
- google_maps_flutter_ios (0.0.1):
- Flutter
- GoogleMaps (< 9.0, >= 8.4)
Expand All @@ -16,17 +18,29 @@ PODS:
- Flutter
- location (0.0.1):
- Flutter
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- pedometer (0.0.1):
- Flutter
- permission_handler_apple (9.3.0):
- Flutter
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS

DEPENDENCIES:
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
- Flutter (from `Flutter`)
- flutter_config (from `.symlinks/plugins/flutter_config/ios`)
- flutter_foreground_task (from `.symlinks/plugins/flutter_foreground_task/ios`)
- google_maps_flutter_ios (from `.symlinks/plugins/google_maps_flutter_ios/ios`)
- health (from `.symlinks/plugins/health/ios`)
- location (from `.symlinks/plugins/location/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- pedometer (from `.symlinks/plugins/pedometer/ios`)
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)

SPEC REPOS:
trunk:
Expand All @@ -39,24 +53,36 @@ EXTERNAL SOURCES:
:path: Flutter
flutter_config:
:path: ".symlinks/plugins/flutter_config/ios"
flutter_foreground_task:
:path: ".symlinks/plugins/flutter_foreground_task/ios"
google_maps_flutter_ios:
:path: ".symlinks/plugins/google_maps_flutter_ios/ios"
health:
:path: ".symlinks/plugins/health/ios"
location:
:path: ".symlinks/plugins/location/ios"
path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/darwin"
pedometer:
:path: ".symlinks/plugins/pedometer/ios"
permission_handler_apple:
:path: ".symlinks/plugins/permission_handler_apple/ios"
shared_preferences_foundation:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"

SPEC CHECKSUMS:
device_info_plus: 97af1d7e84681a90d0693e63169a5d50e0839a0d
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_config: f48f0d47a284f1791aacce2687eabb3309ba7a41
flutter_foreground_task: 21ef182ab0a29a3005cc72cd70e5f45cb7f7f817
google_maps_flutter_ios: c454f18e0e22df6ac0e9f2a4df340858f5a3680c
GoogleMaps: 8939898920281c649150e0af74aa291c60f2e77d
health: 5a380c0f6c4f619535845992993964293962e99e
location: d5cf8598915965547c3f36761ae9cc4f4e87d22e
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
pedometer: 381969883680ade42559782cc41a3bbd453d8234
permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78

PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796

Expand Down
71 changes: 69 additions & 2 deletions lib/service/android_walking_service.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,77 @@
import 'dart:async';

import 'package:get_storage/get_storage.dart';
import 'package:pedometer/pedometer.dart';

import '../utils/walking_service.dart';

//ToDo : 안드로이드 서비스 실제로 구현하기
class AndroidWalkingService implements WalkingService {
final GetStorage localStorage = GetStorage();

static String LOCAL_STORE_STEP_KEY = 'pastSteps';
static int checkDay = 0;

late Stream<StepCount> _stepCountStream;

int currentSteps = 0;
int totalSteps = 0;
int pastSteps = 0;

static final AndroidWalkingService _instance =
AndroidWalkingService._internal();

AndroidWalkingService._internal() {
print('생성');
initPlatformState();
init();
Timer.periodic(Duration(minutes: 5), (t) {
if (checkDay != DateTime.now().day) {
resetStepTimer();
checkDay = DateTime.now().day;
}
});
}

factory AndroidWalkingService() {
return _instance;
}

void init() async {
await GetStorage.init();
}

void initPlatformState() {
_stepCountStream = Pedometer.stepCountStream.asBroadcastStream();
_stepCountStream.listen(updateStep).onError(onStepCountError);
}

void onStepCountError(error) {
currentSteps = 0;
}

void updateStep(StepCount event) async {
totalSteps = event.steps;

int? value = localStorage.read(LOCAL_STORE_STEP_KEY);
if (value == null || value == 0) {
pastSteps = totalSteps;
localStorage.write(LOCAL_STORE_STEP_KEY, totalSteps);
} else {
pastSteps = value;
}
currentSteps = totalSteps - pastSteps;
print(currentSteps);
}

void resetStepTimer() async {
pastSteps = totalSteps;
currentSteps = 0;
localStorage.write(LOCAL_STORE_STEP_KEY, totalSteps);
}

@override
Future<int> getCurrentStep() {
return Future.value(4251);
return Future.value(currentSteps);
}

@override
Expand Down

0 comments on commit e84dcbb

Please sign in to comment.