diff --git a/lib/pages/destination/destination_controller.dart b/lib/pages/destination/destination_controller.dart index 2ea0e5f..6525746 100644 --- a/lib/pages/destination/destination_controller.dart +++ b/lib/pages/destination/destination_controller.dart @@ -36,6 +36,7 @@ class DestinationController extends GetxController { List destinations = [].obs; double currentLat = 0.0; double currentLon = 0.0; + DateTime lastGPSCollectedTime = DateTime.now(); static bool gps_push_started = false; static bool game_started = false; @@ -524,9 +525,10 @@ class DestinationController extends GetxController { try { //print("--- 000 ---- $skip_gps----"); - await Future.delayed(const Duration(milliseconds: 2500)); + await Future.delayed(const Duration(milliseconds: 3000)); Position position = await Geolocator.getCurrentPosition( desiredAccuracy: LocationAccuracy.bestForNavigation); + currentLat = position.latitude; currentLon = position.longitude; final la = position.latitude; @@ -535,7 +537,22 @@ class DestinationController extends GetxController { //print("--- gps is ${la}, ${ln}"); //add gps to database - await addGPStoDB(la, ln); + //check distance to previous point + var distance = const Distance(); + double distanceToDest = distance.as( + LengthUnit.Meter, + LatLng(position.latitude, position.longitude), + LatLng(currentLat, currentLon)); + Duration difference = + lastGPSCollectedTime.difference(DateTime.now()).abs(); + if (difference.inSeconds >= 10 || distanceToDest >= 10) { + print( + "^^^^^^^^ GPS data collected ${DateFormat('kk:mm:ss \n EEE d MMM').format(DateTime.now())}, ^^^ ${position.latitude}, ${position.longitude}"); + + await addGPStoDB(la, ln); + lastGPSCollectedTime = DateTime.now(); + } + // GpsDatabaseHelper db = GpsDatabaseHelper.instance; // final team_name = indexController.currentUser[0]["user"]['team_name']; // final event_code = indexController.currentUser[0]["user"]["event_code"]; diff --git a/lib/widgets/bottom_sheet_new.dart b/lib/widgets/bottom_sheet_new.dart index b405bbe..8689381 100644 --- a/lib/widgets/bottom_sheet_new.dart +++ b/lib/widgets/bottom_sheet_new.dart @@ -498,6 +498,8 @@ class BottomSheetNew extends GetView { // ), destinationController.rogainingCounted.value == true && + destinationController.distanceToStart() <= + 500 && destination.cp == -1 ? ElevatedButton( onPressed: () async { @@ -604,57 +606,61 @@ class BottomSheetNew extends GetView { ), // forced start / checkin - Obx(() => ElevatedButton( - style: ElevatedButton.styleFrom( - backgroundColor: - Theme.of(context).colorScheme.secondary), - onPressed: () async { - //print("~~~~ manual checkin button ~~~~"); - if (destination.cp == -1 && - destinationController.isInRog.value == - false && - destinationController - .rogainingCounted.value == - false) { - destinationController.isInRog.value = true; - destinationController.addToRogaining( - destinationController.currentLat, - destinationController.currentLon, - destination.location_id!); - saveGameState(); - ExternalService() - .startRogaining() - .then((value) => Get.back()); - } else { - if (destination.cp == -1) { - return; - } - Get.back(); - await destinationController - .callforCheckin(destination); - } - }, - child: Text( - destination.cp == -1 && - destinationController.isInRog.value == - false && - destinationController - .rogainingCounted.value == - false - ? "ロゲ開始" - : destinationController.isInRog.value == - true && - destination.cp == -1 - ? "ゲーム中" - : isAlreadyCheckedIn == true - ? "ゲーム中" - : "チェックイン", - style: TextStyle( - color: Theme.of(context) + distanceToDest <= + destinationController + .getForcedChckinDistance(destination) + ? Obx(() => ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: Theme.of(context) .colorScheme - .onSecondary)))) - // ElevatedButton( - // onPressed: () {}, child: const Text("ゲーム中")), + .secondary), + onPressed: () async { + //print("~~~~ manual checkin button ~~~~"); + if (destination.cp == -1 && + destinationController.isInRog.value == + false && + destinationController + .rogainingCounted.value == + false) { + destinationController.isInRog.value = true; + destinationController.addToRogaining( + destinationController.currentLat, + destinationController.currentLon, + destination.location_id!); + saveGameState(); + ExternalService() + .startRogaining() + .then((value) => Get.back()); + } else { + if (destination.cp == -1) { + return; + } + Get.back(); + await destinationController + .callforCheckin(destination); + } + }, + child: Text( + destination.cp == -1 && + destinationController + .isInRog.value == + false && + destinationController + .rogainingCounted.value == + false + ? "ロゲ開始" + : destinationController.isInRog.value == + true && + destination.cp == -1 + ? "ゲーム中" + : isAlreadyCheckedIn == true + ? "ゲーム中" + : "チェックイン", + style: TextStyle( + color: Theme.of(context) + .colorScheme + .onSecondary)))) + : Container(), ], ), Row(