added rog local data

This commit is contained in:
Mohamed Nouffer
2022-11-14 22:22:41 +05:30
parent 78970ef5c3
commit 22a17e108c
10 changed files with 369 additions and 239 deletions

View File

@ -70,6 +70,10 @@ class DestinationController extends GetxController {
int chekcs = 0;
var rogaining_counted = false.obs;
String getFormatedTime(DateTime datetime){
return DateFormat('yyyy-MM-dd HH:mm:ss').format(datetime);
}
Destination festuretoDestination(GeoJsonFeature fs){
GeoJsonMultiPoint mp = fs.geometry as GeoJsonMultiPoint;
LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude, mp.geoSerie!.geoPoints[0].longitude);
@ -278,96 +282,6 @@ class DestinationController extends GetxController {
}
}
// 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;
// });
// }
// }
// 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(){
currentSelectedDestinations.forEach((element) {
deleteDestination(element);
@ -479,19 +393,6 @@ class DestinationController extends GetxController {
print("--- made checkin ${df.location_id} ----");
makeCheckin(df, true, "");
}
Rogaining rog = Rogaining(
rog_id: null,
course_id: 1,
user_id: indexController.currentUser[0]['user']['id'],
location_id: destination_id,
lat: lat,
lon:lon,
time_stamp: DateTime.now().toUtc().microsecondsSinceEpoch
);
db.insertRogaining(rog).then((value){
print("----- inserted value ${value} ---------");
});
is_in_rog.value = true;
}
@ -598,10 +499,35 @@ class DestinationController extends GetxController {
locationPermission.add(err.toString());
}
ever(indexController.connectionStatusName, connectionChanged);
super.onInit();
}
void connectionChanged(String val) {
print('----- %%%%%%%%%%%%%%%%%%%%% ----- ${val}');
if(val == "wifi" || val == "mobile"){
String _token = indexController.currentUser[0]["token"];
DatabaseHelper db = DatabaseHelper.instance;
db.allRogianing().then((value){
value.forEach((e) {
if(e.rog_action_type == 0){
ExternalService().StartRogaining();
}
else if(e.rog_action_type == 1){
var datetime = new DateTime.fromMicrosecondsSinceEpoch(e.checkintime!);
ExternalService().makeCheckpoint(e.user_id!, _token, getFormatedTime(datetime), e.team_name!, e.cp_number!, e.event_code!, e.image!);
}
else if(e.rog_action_type == 2){
var datetime = new DateTime.fromMicrosecondsSinceEpoch(e.checkintime!);
ExternalService().makeGoal(e.user_id!, _token, e.team_name!, e.image!, getFormatedTime(datetime), e.event_code!);
}
});
});
}
}
void checkPermission() async {
LocationPermission permission = await Geolocator.checkPermission();
if (permission != LocationPermission.whileInUse ||