update to add resume app from sleep

This commit is contained in:
Mohamed Nouffer
2023-08-16 14:53:32 +05:30
parent 68bf3e9ab3
commit 2ab96cc3d0
51 changed files with 748 additions and 789 deletions

View File

@ -1,6 +1,5 @@
import 'dart:convert';
import 'dart:io';
import 'package:camera_camera/camera_camera.dart';
@ -12,25 +11,19 @@ import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:latlong2/latlong.dart';
import 'package:rogapp/model/Rogaining.dart';
import 'package:rogapp/model/destination.dart';
import 'package:rogapp/pages/camera/camera_page.dart';
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/routes/app_pages.dart';
import 'package:rogapp/services/action_service.dart';
import 'package:rogapp/services/destination_service.dart';
import 'package:rogapp/services/external_service.dart';
import 'package:rogapp/services/location_line_service.dart';
import 'package:rogapp/services/location_service.dart';
import 'package:rogapp/services/maxtrix_service.dart';
import 'package:rogapp/services/perfecture_service.dart';
import 'package:rogapp/services/reacking_service.dart';
import 'package:rogapp/utils/database_helper.dart';
import 'package:rogapp/widgets/bottom_sheet_new.dart';
import 'dart:async';
import 'package:rogapp/widgets/bottom_sheet_widget.dart';
import 'package:sqflite/sqlite_api.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
class DestinationController extends GetxController {
@ -51,7 +44,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));
DateTime last_goal_at = DateTime.now().subtract(const Duration(days:1));
//List<Rogaining> rogainings = <Rogaining>[].obs;
bool checking_in = false;
@ -115,8 +108,8 @@ class DestinationController extends GetxController {
void startTimerLocation(GeoJsonFeature fs, double distance) {
print("---- in startTimer ----");
//skip_gps = true;
double checkin_radious = fs.properties!['checkin_radius'] ?? double.infinity;
if(checkin_radious >= distance){
double checkinRadious = fs.properties!['checkin_radius'] ?? double.infinity;
if(checkinRadious >= distance){
indexController.currentFeature.clear();
Destination d = festuretoDestination(fs);
for(Destination de in destinations){
@ -135,14 +128,14 @@ class DestinationController extends GetxController {
print("=== passed dest is ${d.location_id} ${d.checkedin} ====");
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_in = d.checkedin ?? false;
bool isUser_logged_in = indexController.currentUser.length > 0 ? true : false;
double checkinRadious = d.checkin_radious ?? double.infinity;
bool autoCheckin = d.auto_checkin == 0 ? false : true;
bool locationAlreadyCheckedIn = d.checkedin ?? false;
bool isuserLoggedIn = indexController.currentUser.isNotEmpty ? true : false;
//make current destination
print("---- checkin_radious ${checkin_radious} ----");
print("---- distance ${distance} ----");
if(checkin_radious >= distance){
print("---- checkin_radious $checkinRadious ----");
print("---- distance $distance ----");
if(checkinRadious >= distance){
//currentSelectedDestinations.add(d);
indexController.currentDestinationFeature.clear();
indexController.currentDestinationFeature.add(d);
@ -202,9 +195,9 @@ class DestinationController extends GetxController {
}
print("---- location checkin radious ${d.checkin_radious} ----");
print("---- already checked in ${location_already_checked_in} ----");
if(checkin_radious >= distance && location_already_checked_in == false && is_in_rog.value == true){
if(auto_checkin){
print("---- already checked in $locationAlreadyCheckedIn ----");
if(checkinRadious >= distance && locationAlreadyCheckedIn == false && is_in_rog.value == true){
if(autoCheckin){
if(!checking_in){
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ make checkin ${d.sub_loc_id}@@@@@@@@@@@");
makeCheckin(d, true,"");
@ -255,11 +248,11 @@ class DestinationController extends GetxController {
}
}
print("---- cp --- ${d.cp} -----");
print("--- at goal ${is_at_goal} ---");
print("--- rog counted ${rogaining_counted} ---");
print("--- loc already checked in ${location_already_checked_in} ---");
print("--- at goal $is_at_goal ---");
print("--- rog counted $rogaining_counted ---");
print("--- loc already checked in $locationAlreadyCheckedIn ---");
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){
if(isuserLoggedIn && d.cp == -1 && locationAlreadyCheckedIn && skip_10s == false){
//check for rogaining
if(is_at_goal.value == false && rogaining_counted.value){
//goal
@ -290,7 +283,7 @@ class DestinationController extends GetxController {
});
}
}
print("==== _chekcs ${chekcs} ====");
print("==== _chekcs $chekcs ====");
if(chekcs == 0){
skip_gps = false;
}
@ -316,7 +309,7 @@ class DestinationController extends GetxController {
int? _latgoal = await db.latestGoal();
if(_latgoal != null){
last_goal_at = DateTime.fromMicrosecondsSinceEpoch(_latgoal);
print("===== last goal : ${last_goal_at} =====");
print("===== last goal : $last_goal_at =====");
}
@ -339,7 +332,7 @@ class DestinationController extends GetxController {
onFile: (file) {
photos.add(file);
Navigator.pop(context);
print("----image file is : ${file}----");
print("----image file is : $file----");
//setState(() {});
},
)));
@ -362,11 +355,12 @@ class DestinationController extends GetxController {
return d;
}
}
return null;
}
void checkForCheckin(double la, double ln){
print("--- skip_gps ---- ${skip_gps}----");
print("--- skip_gps ---- $skip_gps----");
for(final d in destinations){
@ -376,7 +370,7 @@ class DestinationController extends GetxController {
double lon = d.lon!;
LatLng p = LatLng(lat, lon);
getDestinationForLatLong(lat, lon).then((value){
var distance = Distance();
var distance = const Distance();
double dist = distance.as(LengthUnit.Meter, LatLng(lat, lon), LatLng(la, ln));
//double checkin_radious = value!.checkin_radious ?? double.infinity;
//bool auto_checkin = value.auto_checkin == 0 ? false : true;
@ -405,23 +399,23 @@ class DestinationController extends GetxController {
GeoJsonMultiPoint mp = fs.geometry as GeoJsonMultiPoint;
LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude, mp.geoSerie!.geoPoints[0].longitude);
double lat_fs = pt.latitude;
double lon_fs = pt.longitude;
LatLng p_fs = LatLng(lat_fs, lon_fs);
var distance_fs = Distance();
double dist_fs = distance_fs.as(LengthUnit.Meter, LatLng(lat_fs, lon_fs), LatLng(la, ln));
double latFs = pt.latitude;
double lonFs = pt.longitude;
LatLng pFs = LatLng(latFs, lonFs);
var distanceFs = const Distance();
double distFs = distanceFs.as(LengthUnit.Meter, LatLng(latFs, lonFs), LatLng(la, ln));
if(dist_fs <= 250 && skip_gps == false){
if(distFs <= 250 && skip_gps == false){
//near a location
print("---- before call startTimerLocation ----");
startTimerLocation(fs, dist_fs);
startTimerLocation(fs, distFs);
}
}
}
void addToRogaining(double lat, double lon, int destination_id) async {
void addToRogaining(double lat, double lon, int destinationId) async {
DatabaseHelper db = DatabaseHelper.instance;
List<Destination> d = await db.getDestinationById(destination_id);
List<Destination> d = await db.getDestinationById(destinationId);
if(d.isEmpty){
Destination df = festuretoDestination(indexController.currentFeature[0]);
print("--- made checkin ${df.location_id} ----");
@ -443,10 +437,10 @@ class DestinationController extends GetxController {
PopulateDestinations();
/// post to NATNAT
if(indexController.currentUser.length > 0){
double cp_num = destination.cp!;
if(indexController.currentUser.isNotEmpty){
double cpNum = destination.cp!;
int user_id = indexController.currentUser[0]["user"]["id"];
int userId = indexController.currentUser[0]["user"]["id"];
//print("--- Pressed -----");
String _team = indexController.currentUser[0]["user"]['team_name'];
//print("--- _team : ${_team}-----");
@ -457,9 +451,9 @@ class DestinationController extends GetxController {
DateTime now = DateTime.now();
String formattedDate = DateFormat('yyyy-MM-dd HH:mm:ss').format(now);
print("------ checkin event ${_event_code} ------");
ExternalService().makeCheckpoint(user_id, _token, formattedDate, _team,cp_num.round(), _event_code, imageurl).then((value){
print("------Ext service check point ${value} ------");
print("------ checkin event $_event_code ------");
ExternalService().makeCheckpoint(userId, _token, formattedDate, _team,cpNum.round(), _event_code, imageurl).then((value){
print("------Ext service check point $value ------");
});
}
@ -496,7 +490,7 @@ class DestinationController extends GetxController {
showBackgroundLocationIndicator: true
);
} else {
locationSettings = LocationSettings(
locationSettings = const LocationSettings(
accuracy: LocationAccuracy.high,
distanceFilter: 0,
);
@ -513,17 +507,17 @@ class DestinationController extends GetxController {
indexController.current_lat = position != null ? position.latitude : 0;
current_lon = position != null ? position.longitude : 0;
print("==== gps skip is : ${skip_gps.toString()}, selected is ${is_gps_selected} , ${current_lat}");
print("==== gps skip is : ${skip_gps.toString()}, selected is $is_gps_selected , $current_lat");
if(is_gps_selected.value){
double czoom = indexController.rogMapController!.zoom;
indexController.rogMapController!.move(LatLng(position!.latitude, position!.longitude), czoom);
double czoom = indexController.rogMapController.zoom;
indexController.rogMapController.move(LatLng(position!.latitude, position.longitude), czoom);
//String user_id = indexController.currentUser[0]["user"]["id"].toString();
//TrackingService.addTrack(user_id, position!.latitude, position.longitude).then((val){
//print("---- postion is ${position.latitude}, ${position.longitude}");
gps.clear();
gps.add("-- lat : ${position.latitude}, lon : ${position.longitude} --");
checkForCheckin(position!.latitude, position.longitude);
checkForCheckin(position.latitude, position.longitude);
print("--- call check checkin");
print("---- skip gps is ${skip_gps.toString()} ----");
//});
@ -552,7 +546,7 @@ class DestinationController extends GetxController {
@override
void onReady() {
Get.toNamed(AppPages.LOGIN)!.then((value){
if(indexController.currentUser.length > 0) {
if(indexController.currentUser.isNotEmpty) {
fixMapBound();
}
else {
@ -560,7 +554,7 @@ class DestinationController extends GetxController {
PerfectureService.getSubExt("9").then((value){
if(value != null){
LatLngBounds bnds = LatLngBounds(LatLng(value[1], value[0]), LatLng(value[3], value[2]));
indexController.mapController!.fitBounds(bnds); //.centerZoomFitBounds(bnds);
indexController.mapController.fitBounds(bnds); //.centerZoomFitBounds(bnds);
}
});
}
@ -573,10 +567,10 @@ class DestinationController extends GetxController {
indexController.switchPage(AppPages.INITIAL);
LocationService.getLocationsExt(_token).then((value) {
if(value != null){
print("--- loc ext is - ${value} ----");
print("--- loc ext is - $value ----");
LatLngBounds bnds = LatLngBounds(LatLng(value[1], value[0]), LatLng(value[3], value[2]));
print("--- bnds is - ${bnds} ----");
indexController.mapController!.fitBounds(
print("--- bnds is - $bnds ----");
indexController.mapController.fitBounds(
bnds,
);
indexController.currentBound.clear();
@ -587,7 +581,7 @@ class DestinationController extends GetxController {
}
void connectionChanged(String val) {
print('----- %%%%%%%%%%%%%%%%%%%%% ----- ${val}');
print('----- %%%%%%%%%%%%%%%%%%%%% ----- $val');
Map<String, dynamic> _res = {};
if(val == "wifi" || val == "mobile"){
String _token = indexController.currentUser[0]["token"];
@ -598,11 +592,11 @@ class DestinationController extends GetxController {
_res = await ExternalService().StartRogaining();
}
else if(e.rog_action_type == 1){
var datetime = new DateTime.fromMicrosecondsSinceEpoch(e.checkintime!);
var datetime = DateTime.fromMicrosecondsSinceEpoch(e.checkintime!);
_res = await 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!);
var datetime = DateTime.fromMicrosecondsSinceEpoch(e.checkintime!);
_res = await ExternalService().makeGoal(e.user_id!, _token, e.team_name!, e.image!, getFormatedTime(datetime), e.event_code!);
}
@ -626,8 +620,8 @@ class DestinationController extends GetxController {
}
Destination? destinationById(int id){
Destination? d = null;
print("--- target des - ${id} ----");
Destination? d;
print("--- target des - $id ----");
for(Destination ss in destinations){
print("--- des - ${ss.location_id} ----");
if(ss.location_id == id){
@ -678,7 +672,7 @@ class DestinationController extends GetxController {
}
else {
db.insertDestination(dest).then((value){
print("----- destination controller added as new ${value}--- :::::");
print("----- destination controller added as new $value--- :::::");
PopulateDestinations();
});
}
@ -710,7 +704,7 @@ class DestinationController extends GetxController {
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return Center(
return const Center(
child: CircularProgressIndicator(),
);
});
@ -719,7 +713,7 @@ class DestinationController extends GetxController {
void destinationMatrixFromCurrentPoint(List<Destination> points){
buildShowDialog(Get.context!);
MatrixService.getDestinations(points).then((mat){
print(" matrix is ------- ${mat}");
print(" matrix is ------- $mat");
matrix = mat;
try{
@ -755,7 +749,7 @@ class DestinationController extends GetxController {
destinations.add(d);
}
// destinationCount.value = 0;
print("------ destination controller destinationcount-------- ${destinationCount}-------- :::::");
print("------ destination controller destinationcount-------- $destinationCount-------- :::::");
// MatrixService.getDestinations(value).then((mat){