This commit is contained in:
Mohamed Nouffer
2022-11-01 23:47:35 +05:30
parent d16d97f64f
commit 4d40b400b1
3 changed files with 163 additions and 145 deletions

View File

@ -64,7 +64,7 @@ class DestinationController extends GetxController {
Timer? _timer; Timer? _timer;
int _start = 0; int _start = 0;
int _chekcs = 0; int chekcs = 0;
var rogaining_counted = false.obs; var rogaining_counted = false.obs;
Destination festuretoDestination(GeoJsonFeature fs){ Destination festuretoDestination(GeoJsonFeature fs){
@ -100,14 +100,25 @@ class DestinationController extends GetxController {
void startTimerLocation(GeoJsonFeature fs, double distance) { void startTimerLocation(GeoJsonFeature fs, double distance) {
print("---- in startTimer ----"); print("---- in startTimer ----");
chekcs = 0;
double checkin_radious = fs.properties!['checkin_radius'] ?? double.infinity; double checkin_radious = fs.properties!['checkin_radius'] ?? double.infinity;
if(checkin_radious >= distance){ if(checkin_radious >= distance){
indexController.currentDestinationFeature.clear(); chekcs = 1;
indexController.currentFeature.clear();
Destination d = festuretoDestination(fs); 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 ----"); print("---- before calling startTimer ----");
startTimer(d, distance); startTimer(d, distance);
} }
if(chekcs == 0){
skip_gps = false;
}
} }
void startTimer(Destination d, double distance) async { void startTimer(Destination d, double distance) async {
@ -137,36 +148,36 @@ class DestinationController extends GetxController {
if(ds.isEmpty){ if(ds.isEmpty){
print("----- in location popup cp - ${d.cp}----"); print("----- in location popup cp - ${d.cp}----");
if(d.cp == -1){ if(d.cp == -1){
_chekcs = 1; chekcs = 1;
//start //start
print("---- in start -----"); print("---- in start -----");
_chekcs = 1; chekcs = 1;
is_at_start.value = true; is_at_start.value = true;
showModalBottomSheet(context: Get.context!, isScrollControlled: true, showModalBottomSheet(context: Get.context!, isScrollControlled: true,
builder:((context) => BottomSheetNew()) builder:((context) => BottomSheetNew())
).whenComplete((){ ).whenComplete((){
skip_gps = false; skip_gps = false;
_chekcs = 0; chekcs = 0;
is_at_start.value = false; is_at_start.value = false;
}); });
} }
else else
{ {
print("----- in location popup checkin cp - ${d.cp}----"); print("----- in location popup checkin cp - ${d.cp}----");
_chekcs = 1; chekcs = 1;
//is_in_checkin.value = true; //is_in_checkin.value = true;
showModalBottomSheet(context: Get.context!, isScrollControlled: true, showModalBottomSheet(context: Get.context!, isScrollControlled: true,
builder:((context) => BottomSheetNew()) builder:((context) => BottomSheetNew())
).whenComplete((){ ).whenComplete((){
skip_gps = false; skip_gps = false;
_chekcs = 0; chekcs = 0;
is_in_checkin.value = false; is_in_checkin.value = false;
}); });
} }
} }
print("---- location checkin radious ${d.checkin_radious} ----"); 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(checkin_radious >= distance && location_already_checked_in == false){
if(auto_checkin){ if(auto_checkin){
if(!checking_in){ if(!checking_in){
@ -179,156 +190,161 @@ class DestinationController extends GetxController {
} }
else{ else{
// ask for checkin // ask for checkin
if(d.hidden_location != null && d.hidden_location ==true && is_in_rog.value == true){ if(d.hidden_location != null && d.hidden_location ==true && is_in_rog.value == true && d.cp != -1){
_chekcs = 1; chekcs = 1;
is_in_checkin.value = true; is_in_checkin.value = true;
showModalBottomSheet(context: Get.context!, isScrollControlled: true, showModalBottomSheet(context: Get.context!, isScrollControlled: true,
builder:((context) => CameraPage()) builder:((context) => CameraPage())
).whenComplete((){ ).whenComplete((){
skip_gps = false; skip_gps = false;
_chekcs = 0; chekcs = 0;
is_in_checkin.value = false; is_in_checkin.value = false;
}); });
} }
else if(is_in_rog.value == true){ else if(is_in_rog.value == true && d.cp != -1){
_chekcs = 1; chekcs = 1;
is_in_checkin.value = true; is_in_checkin.value = true;
showModalBottomSheet(context: Get.context!, isScrollControlled: true, showModalBottomSheet(context: Get.context!, isScrollControlled: true,
builder:((context) => BottomSheetNew()) builder:((context) => BottomSheetNew())
).whenComplete((){ ).whenComplete((){
skip_gps = false; skip_gps = false;
_chekcs = 0; chekcs = 0;
is_in_checkin.value = false; 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){ if(isUser_logged_in && d.cp == -1 && location_already_checked_in){
//check for rogaining //check for rogaining
if(is_at_goal.value == false && rogaining_counted.value){ if(is_at_goal.value == false && rogaining_counted.value){
//goal //goal
print("---- in goal -----"); print("---- in goal -----");
_chekcs = 1; chekcs = 1;
is_at_goal.value = true; is_at_goal.value = true;
showModalBottomSheet(context: Get.context!, isScrollControlled: true, showModalBottomSheet(context: Get.context!, isScrollControlled: true,
builder:((context) => CameraPage()) builder:((context) => CameraPage())
).whenComplete((){ ).whenComplete((){
skip_gps = false; skip_gps = false;
_chekcs = 0; chekcs = 0;
is_at_goal.value = false; is_at_goal.value = false;
}); });
} }
else if(is_in_rog.value == false){ else if(is_in_rog.value == false){
//start //start
print("---- in start -----"); print("---- in start -----");
_chekcs = 1; chekcs = 1;
is_at_start.value = true; is_at_start.value = true;
showModalBottomSheet(context: Get.context!, isScrollControlled: true, showModalBottomSheet(context: Get.context!, isScrollControlled: true,
builder:((context) => BottomSheetNew()) builder:((context) => BottomSheetNew())
).whenComplete((){ ).whenComplete((){
print("----- finished start -------");
skip_gps = false; skip_gps = false;
_chekcs = 0; chekcs = 0;
is_at_start.value = false; is_at_start.value = false;
}); });
} }
} }
print("---- _chekcs ${_chekcs} ----"); print("---- _chekcs ${chekcs} ----");
if(_chekcs == 0){ if(chekcs == 0){
skip_gps = false; skip_gps = false;
} }
skip_gps = false;
} }
void startTimer2(Destination d, double distance) { // void startTimer2(Destination d, double distance) {
skip_gps = true; // skip_gps = true;
print("---- in startTimer ----"); // print("---- in startTimer ----");
double checkin_radious = d.checkin_radious ?? double.infinity; // double checkin_radious = d.checkin_radious ?? double.infinity;
bool auto_checkin = d.auto_checkin == 0 ? false : true; // bool auto_checkin = d.auto_checkin == 0 ? false : true;
bool location_already_checked_id = d.checkedin ?? false; // bool location_already_checked_id = d.checkedin ?? false;
bool isUser_logged_in = indexController.currentUser.length > 0 ? true : false; // bool isUser_logged_in = indexController.currentUser.length > 0 ? true : false;
//make current destination // //make current destination
print("---- checkin_radious ${checkin_radious} ----"); // print("---- checkin_radious ${checkin_radious} ----");
print("---- distance ${distance} ----"); // print("---- distance ${distance} ----");
if(checkin_radious >= distance){ // if(checkin_radious >= distance){
//currentSelectedDestinations.add(d); // //currentSelectedDestinations.add(d);
indexController.currentDestinationFeature.clear(); // indexController.currentDestinationFeature.clear();
indexController.currentDestinationFeature.add(d); // indexController.currentDestinationFeature.add(d);
print("---- checked in as ${indexController.currentDestinationFeature[0].checkedin.toString()} ----"); // print("---- checked in as ${indexController.currentDestinationFeature[0].checkedin.toString()} ----");
} // }
const oneSec = const Duration(seconds: 1); // const oneSec = const Duration(seconds: 1);
_timer = Timer.periodic( // _timer = Timer.periodic(
oneSec, // oneSec,
(Timer timer) { // (Timer timer) {
if (_start == 0) { // if (_start == 0) {
//make checkin // //make checkin
print("---- location checkin radious ${d.checkin_radious} ----"); // print("---- location checkin radious ${d.checkin_radious} ----");
print("---- already checked in ${location_already_checked_id} ----"); // print("---- already checked in ${location_already_checked_id} ----");
if(checkin_radious >= distance && location_already_checked_id == false){ // if(checkin_radious >= distance && location_already_checked_id == false){
if(auto_checkin){ // if(auto_checkin){
if(!checking_in){ // if(!checking_in){
makeCheckin(d, true); // makeCheckin(d, true);
if(d.cp != -1){ // if(d.cp != -1){
rogaining_counted.value =true; // rogaining_counted.value =true;
} // }
skip_gps = false; // skip_gps = false;
} // }
} // }
else{ // else{
// ask for checkin // // ask for checkin
_chekcs = 1; // _chekcs = 1;
is_in_checkin.value = true; // is_in_checkin.value = true;
showModalBottomSheet(context: Get.context!, isScrollControlled: true, // showModalBottomSheet(context: Get.context!, isScrollControlled: true,
builder:((context) => BottomSheetNew()) // builder:((context) => BottomSheetNew())
).whenComplete((){ // ).whenComplete((){
skip_gps = false; // skip_gps = false;
_chekcs = 0; // _chekcs = 0;
is_in_checkin.value = false; // is_in_checkin.value = false;
}); // });
} // }
} // }
if(isUser_logged_in && d.cp == -1 && location_already_checked_id){ // if(isUser_logged_in && d.cp == -1 && location_already_checked_id){
//check for rogaining // //check for rogaining
if(is_at_goal.value == false && rogaining_counted.value){ // if(is_at_goal.value == false && rogaining_counted.value){
//goal // //goal
print("---- in goal -----"); // print("---- in goal -----");
_chekcs = 1; // _chekcs = 1;
is_at_goal.value = true; // is_at_goal.value = true;
showModalBottomSheet(context: Get.context!, isScrollControlled: true, // showModalBottomSheet(context: Get.context!, isScrollControlled: true,
builder:((context) => BottomSheetNew()) // builder:((context) => BottomSheetNew())
).whenComplete((){ // ).whenComplete((){
skip_gps = false; // skip_gps = false;
_chekcs = 0; // _chekcs = 0;
is_at_goal.value = false; // is_at_goal.value = false;
}); // });
} // }
else if(is_in_rog.value == false){ // else if(is_in_rog.value == false){
//start // //start
print("---- in start -----"); // print("---- in start -----");
_chekcs = 1; // _chekcs = 1;
is_at_start.value = true; // is_at_start.value = true;
showModalBottomSheet(context: Get.context!, isScrollControlled: true, // showModalBottomSheet(context: Get.context!, isScrollControlled: true,
builder:((context) => BottomSheetNew()) // builder:((context) => BottomSheetNew())
).whenComplete((){ // ).whenComplete((){
skip_gps = false; // skip_gps = false;
_chekcs = 0; // _chekcs = 0;
is_at_start.value = false; // is_at_start.value = false;
}); // });
} // }
} // }
timer.cancel(); // timer.cancel();
} else { // } else {
_start--; // _start--;
} // }
print("---- _chekcs ${_chekcs} ----"); // print("---- _chekcs ${_chekcs} ----");
if(_chekcs == 0){ // if(_chekcs == 0){
skip_gps = false; // skip_gps = false;
} // }
}, // },
); // );
} // }
void resetRogaining(){ void resetRogaining(){
is_in_checkin.value = false; is_in_checkin.value = false;
@ -337,7 +353,7 @@ class DestinationController extends GetxController {
is_at_goal.value = false; is_at_goal.value = false;
_start = 0; _start = 0;
_chekcs = 0; chekcs = 0;
rogaining_counted.value = false; rogaining_counted.value = false;
} }
@ -430,9 +446,10 @@ class DestinationController extends GetxController {
void addToRogaining(double lat, double lon, int destination_id) async { void addToRogaining(double lat, double lon, int destination_id) async {
DatabaseHelper db = DatabaseHelper.instance; DatabaseHelper db = DatabaseHelper.instance;
Destination d = await db.getDestinationById(destination_id); List<Destination> d = await db.getDestinationById(destination_id);
if(d == null){ if(d.isEmpty){
Destination df = festuretoDestination(indexController.currentFeature[0]); Destination df = festuretoDestination(indexController.currentFeature[0]);
print("--- made checkin ${df.location_id} ----");
makeCheckin(df, true); makeCheckin(df, true);
} }
@ -448,32 +465,30 @@ class DestinationController extends GetxController {
db.insertRogaining(rog).then((value){ db.insertRogaining(rog).then((value){
print("----- inserted value ${value} ---------"); print("----- inserted value ${value} ---------");
}); });
is_in_rog.value = true;
} }
void makeCheckin(Destination destination, bool action) async { void makeCheckin(Destination destination, bool action) async {
// print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${action}@@@@@@@@@@@"); // print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${action}@@@@@@@@@@@");
DatabaseHelper db = DatabaseHelper.instance; DatabaseHelper db = DatabaseHelper.instance;
int res = await db.updateAction(destination, action); List<Destination> ddd = await db.getDestinationByLatLon(destination.lat!, destination.lon!);
List<Destination> ddd = await db.getDestinationByLatLon(destination.lat!, destination.lon!);
if(ddd.isEmpty){
await db.insertDestination(destination);
}
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ddddd ${ddd[0].checkedin} @@@@@@@@@@@");
// print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${res}@@@@@@@@@@@"); if(ddd.isEmpty){
// print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ after populating ${res} @@@@@@@@@@@"); destination.checkedin = true;
// print("---- database update resulr ------ res : ${res}-------"); await db.insertDestination(destination);
}
//int res = await db.updateAction(destination, action);
PopulateDestinations(); PopulateDestinations();
/// post to NATNAT /// post to NATNAT
if(indexController.currentUser.length > 0){ if(indexController.currentUser.length > 0){
int cp_num = int.parse(destination.cp!.toString()); int cp_num = int.parse(destination.cp!.toString());
String _team = indexController.currentUser[0]["user"]["team_name"]; String _team = indexController.currentUser[0]["user"]["team_name"];
String _event_code = indexController.currentUser[0]["user"]["event_code"]; String _event_code = indexController.currentUser[0]["user"]["event_code"];
ExternalService().makeCheckpoint(_team, cp_num, _event_code).then((value){ ExternalService().makeCheckpoint(_team, cp_num, _event_code).then((value){
print("------Ext service check point ${value} ------"); print("------Ext service check point ${value} ------");
}); });
} }
} }
@ -627,12 +642,8 @@ class DestinationController extends GetxController {
db.getDestinations().then((value){ db.getDestinations().then((value){
destinationCount.value = 0; destinationCount.value = 0;
for(Destination d in value){ 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("------ destination controller populating destination-------- ${d.checkedin}-------- :::::");
print("-----populated----- ${d.toMap()}");
destinations.add(d); destinations.add(d);
} }
// destinationCount.value = 0; // destinationCount.value = 0;
@ -643,8 +654,14 @@ class DestinationController extends GetxController {
print(" matrix is ------- ${mat}"); print(" matrix is ------- ${mat}");
matrix = mat; matrix = mat;
getRoutePoints(); try{
destinationCount.value = destinations.length; getRoutePoints();
destinationCount.value = destinations.length;
}
catch(_){
skip_gps = false;
return;
}
}); });
}); });

View File

@ -196,6 +196,7 @@ class DestnationPage extends StatelessWidget {
onPressed: (int index) { onPressed: (int index) {
destinationController.is_gps_selected.value = !destinationController.is_gps_selected.value; destinationController.is_gps_selected.value = !destinationController.is_gps_selected.value;
if(destinationController.is_gps_selected.value){ if(destinationController.is_gps_selected.value){
destinationController.chekcs = 0;
destinationController.skip_gps = false; destinationController.skip_gps = false;
} }
}, },

View File

@ -83,12 +83,12 @@ class DatabaseHelper{
return roglist; return roglist;
} }
Future<Destination> getDestinationById(int id) async { Future<List<Destination>> getDestinationById(int id) async {
Database db = await instance.database; Database db = await instance.database;
var rog = await db.query('destination', where: "location_id = ${id}"); var rog = await db.query('destination', where: "location_id = ${id}");
List<Destination> deslist = rog.isNotEmpty List<Destination> deslist = rog.isNotEmpty
? rog.map((e) => Destination.fromMap(e)).toList() : []; ? rog.map((e) => Destination.fromMap(e)).toList() : [];
return deslist[0]; return deslist;
} }
@ -204,7 +204,7 @@ class DatabaseHelper{
dest.toMap(), dest.toMap(),
conflictAlgorithm: ConflictAlgorithm.replace, conflictAlgorithm: ConflictAlgorithm.replace,
); );
print("------ database helper insert ${dest.toMap()}-----------::::::::"); //print("------ database helper insert ${dest.toMap()}-----------::::::::");
return res; return res;
} }
@ -218,7 +218,7 @@ class DatabaseHelper{
"destination", "destination",
row, row,
where: 'location_id = ?', where: 'location_id = ?',
whereArgs: [destination.location_id] whereArgs: [destination.location_id!]
); );
} }