From 34b642b2b54b7cab0cae92ae9db087ac9a047e9f Mon Sep 17 00:00:00 2001 From: Mohamed Nouffer Date: Tue, 31 Jan 2023 10:14:23 +0530 Subject: [PATCH] update to fix start after goal --- .../destination/destination_controller.dart | 16 ++++++++++++---- lib/services/external_service.dart | 12 ++++++++---- lib/utils/database_helper.dart | 6 ++++++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/pages/destination/destination_controller.dart b/lib/pages/destination/destination_controller.dart index a427815..094284b 100644 --- a/lib/pages/destination/destination_controller.dart +++ b/lib/pages/destination/destination_controller.dart @@ -51,6 +51,7 @@ class DestinationController extends GetxController { var is_at_start = false.obs; var is_at_goal = false.obs; var is_photo_shoot = false.obs; + DateTime last_goal_at = DateTime.now().subtract(Duration(days:1)); //List rogainings = [].obs; bool checking_in = false; @@ -169,7 +170,7 @@ class DestinationController extends GetxController { List ds = await db.getDestinationByLatLon(d.lat!, d.lon!); if(ds.isEmpty){ print("----- in location popup cp - ${d.cp}----"); - if(d.cp == -1){ + if(d.cp == -1 && DateTime.now().difference(last_goal_at).inHours >= 24){ chekcs = 1; //start print("---- in start -----"); @@ -256,6 +257,7 @@ class DestinationController extends GetxController { print("--- at goal ${is_at_goal} ---"); print("--- rog counted ${rogaining_counted} ---"); print("--- loc already checked in ${location_already_checked_in} ---"); + print("==== date diff is ${DateTime.now().difference(last_goal_at).inHours} ===="); if(isUser_logged_in && d.cp == -1 && location_already_checked_in && skip_10s == false){ //check for rogaining if(is_at_goal.value == false && rogaining_counted.value){ @@ -272,7 +274,7 @@ class DestinationController extends GetxController { is_at_goal.value = false; }); } - else if(is_in_rog.value == false && indexController.rog_mode == 1){ + else if(is_in_rog.value == false && indexController.rog_mode == 1 && DateTime.now().difference(last_goal_at).inHours >= 24){ //start print("---- in start -----"); chekcs = 6; @@ -293,7 +295,7 @@ class DestinationController extends GetxController { } } - void resetRogaining(){ + void resetRogaining() async { print("----- resetting --------"); is_in_checkin.value = false; @@ -309,8 +311,14 @@ class DestinationController extends GetxController { chekcs = 0; rogaining_counted.value = false; - DatabaseHelper db = DatabaseHelper.instance; + int? _latgoal = await db.latestGoal(); + if(_latgoal != null){ + last_goal_at = DateTime.fromMicrosecondsSinceEpoch(_latgoal); + print("===== last goal : ${last_goal_at} ====="); + } + + db.deleteAllDestinations().then((value){ PopulateDestinations(); initGPS(); diff --git a/lib/services/external_service.dart b/lib/services/external_service.dart index 9edda03..3b28d2e 100644 --- a/lib/services/external_service.dart +++ b/lib/services/external_service.dart @@ -2,7 +2,9 @@ import 'dart:io'; import 'package:get/get.dart'; import 'package:http/http.dart' as http; import 'package:intl/intl.dart'; +import 'package:rogapp/model/destination.dart'; import 'package:rogapp/model/rog.dart'; +import 'package:rogapp/pages/destination/destination_controller.dart'; import 'package:rogapp/pages/index/index_controller.dart'; import 'package:rogapp/utils/database_helper.dart'; import 'package:sqflite/sqlite_api.dart'; @@ -190,8 +192,9 @@ class ExternalService { Map _res2 = {}; final IndexController indexController = Get.find(); + final DestinationController destinationController = Get.find(); - if(indexController.connectionStatusName != "wifi" && indexController.connectionStatusName != "mobile"){ + //if(indexController.connectionStatusName != "wifi" && indexController.connectionStatusName != "mobile"){ DatabaseHelper db = DatabaseHelper.instance; Rog _rog = Rog( id:1, @@ -204,8 +207,8 @@ class ExternalService { rog_action_type: 1, ); db.insertRogaining(_rog); - } - else{ + // } + // else{ String server_url = ConstValues.currentServer(); String url1 = "${server_url}/api/goalimage/"; final im1Bytes = File(image!).readAsBytesSync(); @@ -252,7 +255,8 @@ class ExternalService { _res2 = json.decode(utf8.decode(response2.bodyBytes)); } } - } + //} + destinationController.resetRogaining(); return _res2; } diff --git a/lib/utils/database_helper.dart b/lib/utils/database_helper.dart index f963ace..13cd840 100644 --- a/lib/utils/database_helper.dart +++ b/lib/utils/database_helper.dart @@ -149,6 +149,12 @@ class DatabaseHelper{ return rog.length > 0 ? true : false; } + FuturelatestGoal() async{ + Database db = await instance.database; + return Sqflite.firstIntValue(await db.rawQuery('SELECT MAX(checkintime) FROM rog')); + + } + Future insertRogaining(Rog rog) async { Database db = await instance.database; int? next_order = Sqflite.firstIntValue(await db.rawQuery('SELECT MAX(id) FROM rog'));