update status

This commit is contained in:
Mohamed Nouffer
2023-09-08 21:19:12 +05:30
parent 720dd149a9
commit 6f3249631f
8 changed files with 135 additions and 36 deletions

View File

@ -6,6 +6,7 @@ import 'package:rogapp/pages/index/index_binding.dart';
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/routes/app_pages.dart';
import 'package:rogapp/utils/string_values.dart';
import 'package:shared_preferences/shared_preferences.dart';
// import 'package:is_lock_screen/is_lock_screen.dart';
void main() async {
@ -54,11 +55,27 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
super.dispose();
}
void saveGameState() async {
DestinationController destinationController = Get.find<DestinationController>();
SharedPreferences pref = await SharedPreferences.getInstance();
pref.setBool("is_in_rog", destinationController.is_in_rog.value);
pref.setBool("rogaining_counted", destinationController.rogaining_counted.value);
}
void restoreGame() async{
SharedPreferences pref = await SharedPreferences.getInstance();
DestinationController destinationController = Get.find<DestinationController>();
destinationController.skip_gps = false;
destinationController.is_in_rog.value = pref.getBool("is_in_rog") ?? false;
destinationController.rogaining_counted.value = pref.getBool("rogaining_counted") ?? false;
}
void didChangeAppLifecycleState(AppLifecycleState state) {
DestinationController destinationController = Get.find<DestinationController>();
switch (state) {
case AppLifecycleState.resumed:
print("RESUMED");
DestinationController destinationController = Get.find<DestinationController>();
restoreGame();
if(destinationController.positionStream == null){
destinationController.startGPSTimer();
}
@ -68,12 +85,15 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
break;
case AppLifecycleState.paused:
print("PAUSED");
saveGameState();
break;
case AppLifecycleState.detached:
print("DETACHED");
saveGameState();
break;
case AppLifecycleState.hidden:
print("DETACHED");
saveGameState();
break;
}
}

View File

@ -0,0 +1,18 @@
enum LocationState {
noGps,
notInCheckin,
withinCheckin
}
enum GameState {
notStarted,
startedNotCounted,
startedCounted,
nodeGoal
}
class GameInstanceState{
LocationState locationState = LocationState.noGps;
GameState gameState = GameState.notStarted;
}

View File

@ -114,12 +114,13 @@ class DestinationController extends GetxController {
if (checkinRadious >= distance) {
indexController.currentFeature.clear();
Destination d = festuretoDestination(fs);
for (Destination de in destinations) {
if (de.location_id == d.location_id) {
d = de;
break;
}
}
print("----- destination lenght is ${destinations.length} -----");
// 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);
@ -130,9 +131,13 @@ class DestinationController extends GetxController {
print("=== passed dest is ${d.location_id} ${d.checkedin} ====");
skip_gps = true;
print("---- in startTimer ----");
DatabaseHelper db = DatabaseHelper.instance;
List<Destination> ds = await db.getDestinationByLatLon(d.lat!, d.lon!);
double checkinRadious = d.checkin_radious ?? double.infinity;
bool autoCheckin = d.auto_checkin == 0 ? false : true;
bool locationAlreadyCheckedIn = d.checkedin ?? false;
bool locationAlreadyCheckedIn = ds.length > 0 && ds[0].checkedin == true ? true : false;
bool isuserLoggedIn = indexController.currentUser.isNotEmpty ? true : false;
//make current destination
print("---- checkin_radious $checkinRadious ----");
@ -165,8 +170,6 @@ class DestinationController extends GetxController {
return;
}
DatabaseHelper db = DatabaseHelper.instance;
List<Destination> ds = await db.getDestinationByLatLon(d.lat!, d.lon!);
if (ds.isEmpty) {
print("----- in location popup cp - ${d.cp}----");
if (d.cp == -1 && DateTime.now().difference(last_goal_at).inHours >= 24) {
@ -435,32 +438,32 @@ class DestinationController extends GetxController {
void checkForCheckin(double la, double ln) {
print("--- skip_gps ---- $skip_gps----");
for (final d in destinations) {
print("--- check checkin for--loc_id- ${d.sub_loc_id}----");
// for (final d in destinations) {
// print("--- check checkin for--loc_id- ${d.sub_loc_id}----");
double lat = d.lat!;
double lon = d.lon!;
LatLng p = LatLng(lat, lon);
getDestinationForLatLong(lat, lon).then((value) {
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;
//bool location_already_checked_id = d.checkedin ?? false;
// double lat = d.lat!;
// double lon = d.lon!;
// LatLng p = LatLng(lat, lon);
// getDestinationForLatLong(lat, lon).then((value) {
// 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;
// //bool location_already_checked_id = d.checkedin ?? false;
// print("-----rogaining_counted---${rogaining_counted.value}-----");
// print("-----is_in_rog---${is_in_rog}-----");
// print("-----dist is ---${dist}-----");
//print("----- ${indexController.currentUser} ----");
// // print("-----rogaining_counted---${rogaining_counted.value}-----");
// // print("-----is_in_rog---${is_in_rog}-----");
// // print("-----dist is ---${dist}-----");
// //print("----- ${indexController.currentUser} ----");
if (dist <= 250 && skip_gps == false) {
//near a destination
print("---- time with ${d.location_id} ----");
startTimer(d, dist);
}
});
}
// if (dist <= 250 && skip_gps == false) {
// //near a destination
// print("---- time with ${d.location_id} ----");
// startTimer(d, dist);
// }
// });
// }
if (indexController.locations.isEmpty) return;

View File

@ -0,0 +1,27 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:rogapp/model/game_instance_state.dart';
final gameStateNotifierProvider = StateNotifierProvider<GameStaticState, GameInstanceState>((ref) {
return GameStaticState();
});
class GameStaticState extends StateNotifier<GameInstanceState>{
GameStaticState(): super(GameInstanceState());
@override
GameInstanceState get state => super.state;
void startGame(GameInstanceState gi){
state = gi;
}
void doCheckin(){
}
void makeGoal(){
}
}