From 4d40b400b12fd7b03f354f248bfb84c2a31d578c Mon Sep 17 00:00:00 2001 From: Mohamed Nouffer Date: Tue, 1 Nov 2022 23:47:35 +0530 Subject: [PATCH] update --- .../destination/destination_controller.dart | 299 +++++++++--------- lib/pages/destination/destination_page.dart | 1 + lib/utils/database_helper.dart | 8 +- 3 files changed, 163 insertions(+), 145 deletions(-) diff --git a/lib/pages/destination/destination_controller.dart b/lib/pages/destination/destination_controller.dart index e247e0f..2df14a7 100644 --- a/lib/pages/destination/destination_controller.dart +++ b/lib/pages/destination/destination_controller.dart @@ -64,7 +64,7 @@ class DestinationController extends GetxController { Timer? _timer; int _start = 0; - int _chekcs = 0; + int chekcs = 0; var rogaining_counted = false.obs; Destination festuretoDestination(GeoJsonFeature fs){ @@ -100,14 +100,25 @@ class DestinationController extends GetxController { void startTimerLocation(GeoJsonFeature fs, double distance) { print("---- in startTimer ----"); + chekcs = 0; double checkin_radious = fs.properties!['checkin_radius'] ?? double.infinity; if(checkin_radious >= distance){ - indexController.currentDestinationFeature.clear(); + chekcs = 1; + indexController.currentFeature.clear(); Destination d = festuretoDestination(fs); - indexController.currentDestinationFeature.add(d); + for(Destination de in destinations){ + if(de.location_id == d.location_id){ + d = de; + break; + } + } + indexController.currentFeature.add(fs); print("---- before calling startTimer ----"); startTimer(d, distance); } + if(chekcs == 0){ + skip_gps = false; + } } void startTimer(Destination d, double distance) async { @@ -137,36 +148,36 @@ class DestinationController extends GetxController { if(ds.isEmpty){ print("----- in location popup cp - ${d.cp}----"); if(d.cp == -1){ - _chekcs = 1; + chekcs = 1; //start print("---- in start -----"); - _chekcs = 1; + chekcs = 1; is_at_start.value = true; showModalBottomSheet(context: Get.context!, isScrollControlled: true, builder:((context) => BottomSheetNew()) ).whenComplete((){ skip_gps = false; - _chekcs = 0; + chekcs = 0; is_at_start.value = false; }); } else { print("----- in location popup checkin cp - ${d.cp}----"); - _chekcs = 1; + chekcs = 1; //is_in_checkin.value = true; showModalBottomSheet(context: Get.context!, isScrollControlled: true, builder:((context) => BottomSheetNew()) ).whenComplete((){ skip_gps = false; - _chekcs = 0; + chekcs = 0; is_in_checkin.value = false; }); } } print("---- location checkin radious ${d.checkin_radious} ----"); - print("---- already checked in ${location_already_checked_in} ----"); + print("---- already checked in ${location_already_checked_in} ----"); if(checkin_radious >= distance && location_already_checked_in == false){ if(auto_checkin){ if(!checking_in){ @@ -179,156 +190,161 @@ class DestinationController extends GetxController { } else{ // ask for checkin - if(d.hidden_location != null && d.hidden_location ==true && is_in_rog.value == true){ - _chekcs = 1; + if(d.hidden_location != null && d.hidden_location ==true && is_in_rog.value == true && d.cp != -1){ + chekcs = 1; is_in_checkin.value = true; showModalBottomSheet(context: Get.context!, isScrollControlled: true, builder:((context) => CameraPage()) ).whenComplete((){ skip_gps = false; - _chekcs = 0; + chekcs = 0; is_in_checkin.value = false; }); } - else if(is_in_rog.value == true){ - _chekcs = 1; + else if(is_in_rog.value == true && d.cp != -1){ + chekcs = 1; is_in_checkin.value = true; showModalBottomSheet(context: Get.context!, isScrollControlled: true, builder:((context) => BottomSheetNew()) ).whenComplete((){ skip_gps = false; - _chekcs = 0; + chekcs = 0; is_in_checkin.value = false; }); } } } - + print("---- cp --- ${d.cp} -----"); + print("--- at goal ${is_at_goal} ---"); + print("--- rog counted ${rogaining_counted} ---"); + print("--- loc already checked in ${location_already_checked_in} ---"); if(isUser_logged_in && d.cp == -1 && location_already_checked_in){ //check for rogaining if(is_at_goal.value == false && rogaining_counted.value){ //goal print("---- in goal -----"); - _chekcs = 1; + chekcs = 1; is_at_goal.value = true; showModalBottomSheet(context: Get.context!, isScrollControlled: true, builder:((context) => CameraPage()) ).whenComplete((){ skip_gps = false; - _chekcs = 0; + chekcs = 0; is_at_goal.value = false; }); } else if(is_in_rog.value == false){ //start print("---- in start -----"); - _chekcs = 1; + chekcs = 1; is_at_start.value = true; showModalBottomSheet(context: Get.context!, isScrollControlled: true, builder:((context) => BottomSheetNew()) ).whenComplete((){ + print("----- finished start -------"); skip_gps = false; - _chekcs = 0; + chekcs = 0; is_at_start.value = false; }); } } - print("---- _chekcs ${_chekcs} ----"); - if(_chekcs == 0){ + print("---- _chekcs ${chekcs} ----"); + if(chekcs == 0){ skip_gps = false; } + skip_gps = false; } - void startTimer2(Destination d, double distance) { - skip_gps = true; - print("---- in startTimer ----"); - double checkin_radious = d.checkin_radious ?? double.infinity; - bool auto_checkin = d.auto_checkin == 0 ? false : true; - bool location_already_checked_id = d.checkedin ?? false; - bool isUser_logged_in = indexController.currentUser.length > 0 ? true : false; - //make current destination - print("---- checkin_radious ${checkin_radious} ----"); - print("---- distance ${distance} ----"); - if(checkin_radious >= distance){ - //currentSelectedDestinations.add(d); - indexController.currentDestinationFeature.clear(); - indexController.currentDestinationFeature.add(d); + // void startTimer2(Destination d, double distance) { + // skip_gps = true; + // print("---- in startTimer ----"); + // double checkin_radious = d.checkin_radious ?? double.infinity; + // bool auto_checkin = d.auto_checkin == 0 ? false : true; + // bool location_already_checked_id = d.checkedin ?? false; + // bool isUser_logged_in = indexController.currentUser.length > 0 ? true : false; + // //make current destination + // print("---- checkin_radious ${checkin_radious} ----"); + // print("---- distance ${distance} ----"); + // if(checkin_radious >= distance){ + // //currentSelectedDestinations.add(d); + // indexController.currentDestinationFeature.clear(); + // indexController.currentDestinationFeature.add(d); - print("---- checked in as ${indexController.currentDestinationFeature[0].checkedin.toString()} ----"); - } - const oneSec = const Duration(seconds: 1); - _timer = Timer.periodic( - oneSec, - (Timer timer) { - if (_start == 0) { - //make checkin - print("---- location checkin radious ${d.checkin_radious} ----"); - print("---- already checked in ${location_already_checked_id} ----"); - if(checkin_radious >= distance && location_already_checked_id == false){ - if(auto_checkin){ - if(!checking_in){ - makeCheckin(d, true); - if(d.cp != -1){ - rogaining_counted.value =true; - } - skip_gps = false; - } - } - else{ - // ask for checkin - _chekcs = 1; - is_in_checkin.value = true; - showModalBottomSheet(context: Get.context!, isScrollControlled: true, - builder:((context) => BottomSheetNew()) - ).whenComplete((){ - skip_gps = false; - _chekcs = 0; - is_in_checkin.value = false; - }); - } - } + // print("---- checked in as ${indexController.currentDestinationFeature[0].checkedin.toString()} ----"); + // } + // const oneSec = const Duration(seconds: 1); + // _timer = Timer.periodic( + // oneSec, + // (Timer timer) { + // if (_start == 0) { + // //make checkin + // print("---- location checkin radious ${d.checkin_radious} ----"); + // print("---- already checked in ${location_already_checked_id} ----"); + // if(checkin_radious >= distance && location_already_checked_id == false){ + // if(auto_checkin){ + // if(!checking_in){ + // makeCheckin(d, true); + // if(d.cp != -1){ + // rogaining_counted.value =true; + // } + // skip_gps = false; + // } + // } + // else{ + // // ask for checkin + // _chekcs = 1; + // is_in_checkin.value = true; + // showModalBottomSheet(context: Get.context!, isScrollControlled: true, + // builder:((context) => BottomSheetNew()) + // ).whenComplete((){ + // skip_gps = false; + // _chekcs = 0; + // is_in_checkin.value = false; + // }); + // } + // } - if(isUser_logged_in && d.cp == -1 && location_already_checked_id){ - //check for rogaining - if(is_at_goal.value == false && rogaining_counted.value){ - //goal - print("---- in goal -----"); - _chekcs = 1; - is_at_goal.value = true; - showModalBottomSheet(context: Get.context!, isScrollControlled: true, - builder:((context) => BottomSheetNew()) - ).whenComplete((){ - skip_gps = false; - _chekcs = 0; - is_at_goal.value = false; - }); - } - else if(is_in_rog.value == false){ - //start - print("---- in start -----"); - _chekcs = 1; - is_at_start.value = true; - showModalBottomSheet(context: Get.context!, isScrollControlled: true, - builder:((context) => BottomSheetNew()) - ).whenComplete((){ - skip_gps = false; - _chekcs = 0; - is_at_start.value = false; - }); - } - } - timer.cancel(); - } else { - _start--; - } - print("---- _chekcs ${_chekcs} ----"); - if(_chekcs == 0){ - skip_gps = false; - } - }, - ); - } + // if(isUser_logged_in && d.cp == -1 && location_already_checked_id){ + // //check for rogaining + // if(is_at_goal.value == false && rogaining_counted.value){ + // //goal + // print("---- in goal -----"); + // _chekcs = 1; + // is_at_goal.value = true; + // showModalBottomSheet(context: Get.context!, isScrollControlled: true, + // builder:((context) => BottomSheetNew()) + // ).whenComplete((){ + // skip_gps = false; + // _chekcs = 0; + // is_at_goal.value = false; + // }); + // } + // else if(is_in_rog.value == false){ + // //start + // print("---- in start -----"); + // _chekcs = 1; + // is_at_start.value = true; + // showModalBottomSheet(context: Get.context!, isScrollControlled: true, + // builder:((context) => BottomSheetNew()) + // ).whenComplete((){ + // skip_gps = false; + // _chekcs = 0; + // is_at_start.value = false; + // }); + // } + // } + // timer.cancel(); + // } else { + // _start--; + // } + // print("---- _chekcs ${_chekcs} ----"); + // if(_chekcs == 0){ + // skip_gps = false; + // } + // }, + // ); + // } void resetRogaining(){ is_in_checkin.value = false; @@ -337,7 +353,7 @@ class DestinationController extends GetxController { is_at_goal.value = false; _start = 0; - _chekcs = 0; + chekcs = 0; rogaining_counted.value = false; } @@ -430,9 +446,10 @@ class DestinationController extends GetxController { void addToRogaining(double lat, double lon, int destination_id) async { DatabaseHelper db = DatabaseHelper.instance; - Destination d = await db.getDestinationById(destination_id); - if(d == null){ - Destination df = festuretoDestination(indexController.currentFeature[0]); + List d = await db.getDestinationById(destination_id); + if(d.isEmpty){ + Destination df = festuretoDestination(indexController.currentFeature[0]); + print("--- made checkin ${df.location_id} ----"); makeCheckin(df, true); } @@ -448,32 +465,30 @@ class DestinationController extends GetxController { db.insertRogaining(rog).then((value){ print("----- inserted value ${value} ---------"); }); + is_in_rog.value = true; } void makeCheckin(Destination destination, bool action) async { // print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${action}@@@@@@@@@@@"); - DatabaseHelper db = DatabaseHelper.instance; - int res = await db.updateAction(destination, action); - List ddd = await db.getDestinationByLatLon(destination.lat!, destination.lon!); - if(ddd.isEmpty){ - await db.insertDestination(destination); - } - print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ddddd ${ddd[0].checkedin} @@@@@@@@@@@"); + DatabaseHelper db = DatabaseHelper.instance; + List ddd = await db.getDestinationByLatLon(destination.lat!, destination.lon!); + + if(ddd.isEmpty){ + destination.checkedin = true; + await db.insertDestination(destination); + } + //int res = await db.updateAction(destination, action); - // print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${res}@@@@@@@@@@@"); - // print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ after populating ${res} @@@@@@@@@@@"); - // print("---- database update resulr ------ res : ${res}-------"); - - PopulateDestinations(); - /// post to NATNAT - if(indexController.currentUser.length > 0){ - int cp_num = int.parse(destination.cp!.toString()); - String _team = indexController.currentUser[0]["user"]["team_name"]; - String _event_code = indexController.currentUser[0]["user"]["event_code"]; - ExternalService().makeCheckpoint(_team, cp_num, _event_code).then((value){ - print("------Ext service check point ${value} ------"); - }); - } + PopulateDestinations(); + /// post to NATNAT + if(indexController.currentUser.length > 0){ + int cp_num = int.parse(destination.cp!.toString()); + String _team = indexController.currentUser[0]["user"]["team_name"]; + String _event_code = indexController.currentUser[0]["user"]["event_code"]; + ExternalService().makeCheckpoint(_team, cp_num, _event_code).then((value){ + print("------Ext service check point ${value} ------"); + }); + } } @@ -627,12 +642,8 @@ class DestinationController extends GetxController { db.getDestinations().then((value){ destinationCount.value = 0; for(Destination d in value){ - for(Destination s in destinations){ - if(d.location_id == s.location_id){ - d.selected = !d.selected!; - } - } print("------ destination controller populating destination-------- ${d.checkedin}-------- :::::"); + print("-----populated----- ${d.toMap()}"); destinations.add(d); } // destinationCount.value = 0; @@ -643,8 +654,14 @@ class DestinationController extends GetxController { print(" matrix is ------- ${mat}"); matrix = mat; - getRoutePoints(); - destinationCount.value = destinations.length; + try{ + getRoutePoints(); + destinationCount.value = destinations.length; + } + catch(_){ + skip_gps = false; + return; + } }); }); diff --git a/lib/pages/destination/destination_page.dart b/lib/pages/destination/destination_page.dart index 96ad280..f6cdd99 100644 --- a/lib/pages/destination/destination_page.dart +++ b/lib/pages/destination/destination_page.dart @@ -196,6 +196,7 @@ class DestnationPage extends StatelessWidget { onPressed: (int index) { destinationController.is_gps_selected.value = !destinationController.is_gps_selected.value; if(destinationController.is_gps_selected.value){ + destinationController.chekcs = 0; destinationController.skip_gps = false; } }, diff --git a/lib/utils/database_helper.dart b/lib/utils/database_helper.dart index 9c9e429..2251dc7 100644 --- a/lib/utils/database_helper.dart +++ b/lib/utils/database_helper.dart @@ -83,12 +83,12 @@ class DatabaseHelper{ return roglist; } - Future getDestinationById(int id) async { + Future> getDestinationById(int id) async { Database db = await instance.database; var rog = await db.query('destination', where: "location_id = ${id}"); List deslist = rog.isNotEmpty ? rog.map((e) => Destination.fromMap(e)).toList() : []; - return deslist[0]; + return deslist; } @@ -204,7 +204,7 @@ class DatabaseHelper{ dest.toMap(), conflictAlgorithm: ConflictAlgorithm.replace, ); - print("------ database helper insert ${dest.toMap()}-----------::::::::"); + //print("------ database helper insert ${dest.toMap()}-----------::::::::"); return res; } @@ -218,7 +218,7 @@ class DatabaseHelper{ "destination", row, where: 'location_id = ?', - whereArgs: [destination.location_id] + whereArgs: [destination.location_id!] ); }