diff --git a/.gitignore b/.gitignore index 8906afc..a1345d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,46 +1,45 @@ -# Miscellaneous -*.class -*.log -*.pyc -*.swp -.DS_Store -.atom/ -.buildlog/ -.history -.svn/ - -# IntelliJ related -*.iml -*.ipr -*.iws -.idea/ - -# The .vscode folder contains launch configuration and tasks you configure in -# VS Code which you may wish to be included in version control, so this line -# is commented out by default. -#.vscode/ - -# Flutter/Dart/Pub related -**/doc/api/ -**/ios/Flutter/.last_build_id -.dart_tool/ -.flutter-plugins -.flutter-plugins-dependencies -.packages -.pub-cache/ -.pub/ -/build/ - -# Web related -lib/generated_plugin_registrant.dart - -# Symbolication related -app.*.symbols - -# Obfuscation related -app.*.map.json - -# Android Studio will place build artifacts here -/android/app/debug -/android/app/profile -/android/app/release +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Web related + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/assets/images/basic-walking.gif b/assets/images/basic-walking.gif new file mode 100644 index 0000000..88259e4 Binary files /dev/null and b/assets/images/basic-walking.gif differ diff --git a/lib/main.dart b/lib/main.dart index 5ed8858..34c07a2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -20,6 +20,7 @@ class MyApp extends StatelessWidget { return GetMaterialApp( translations: StringValues(), locale: const Locale('ja', 'JP'), + //locale: const Locale('en', 'US'), fallbackLocale: const Locale('en', 'US'), title: 'ROGAINING', theme: ThemeData( diff --git a/lib/model/destination.dart b/lib/model/destination.dart index 5266cec..ae8347f 100644 --- a/lib/model/destination.dart +++ b/lib/model/destination.dart @@ -21,6 +21,7 @@ class Destination { double? cp; double? checkin_point; double? buy_point; + int? hidden_location; Destination({ this.name, @@ -42,7 +43,8 @@ class Destination { this.checkedin, this.cp, this.checkin_point, - this.buy_point + this.buy_point, + this.hidden_location }); factory Destination.fromMap(Map json) { @@ -70,7 +72,8 @@ class Destination { checkedin: checkin, cp: json['cp'], checkin_point: json['checkin_point'], - buy_point: json['buy_point'] + buy_point: json['buy_point'], + hidden_location: json['hidden_location'] ); } @@ -97,7 +100,8 @@ class Destination { 'checkedin': check, 'cp' : cp, 'checkin_point' : checkin_point, - 'buy_point' : buy_point + 'buy_point' : buy_point, + 'hidden_location' : hidden_location }; } diff --git a/lib/pages/camera/camera_page.dart b/lib/pages/camera/camera_page.dart index 6917780..b3146f0 100644 --- a/lib/pages/camera/camera_page.dart +++ b/lib/pages/camera/camera_page.dart @@ -19,38 +19,9 @@ class CameraPage extends StatelessWidget { } } - // void finishRog(){ - // destinationController.addToRogaining(destinationController.current_lat, destinationController.current_lon, destination_id) - // } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text("finishing_rogaining".tr), - ), - body: Column( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - Padding( - padding: EdgeInsets.all(8.0), - child: Center( - child: Obx(() => - Container( - width: MediaQuery.of(context).size.width, - height: 370, - decoration: BoxDecoration( - image: - DecorationImage( - image: getFinishImage(), - fit: BoxFit.cover - ) - ), - ), - ), - ), - ), - Row( + Widget getAction(BuildContext context){ + if(destinationController.is_at_goal.value && destinationController.is_in_rog.value){ + return Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ ElevatedButton( @@ -81,9 +52,12 @@ class CameraPage extends StatelessWidget { print("---called ext api ${value['status']} ------"); if(value['status'] == 'OK'){ Get.back(); + destinationController.skip_gps = false; Get.snackbar("goal_saved", "goal_added_successfuly"); + destinationController.resetRogaining(); } else{ + print("---- status ${value['status']} ---- "); Get.snackbar("goal_not_added", "please_try_again"); } }); @@ -93,9 +67,127 @@ class CameraPage extends StatelessWidget { Container() ) ], - ) - ], + ); + } + else{ + return ElevatedButton( + child: Text("Checking image"), + onPressed: (){ + Get.back(); + }, + ); + } + } + + // void finishRog(){ + // destinationController.addToRogaining(destinationController.current_lat, destinationController.current_lon, destination_id) + // } + + @override + Widget build(BuildContext context) { + if(destinationController.is_at_goal.value){ + return Scaffold( + appBar: AppBar( + title: Text("finishing_rogaining".tr), ), + body: Column( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + Padding( + padding: EdgeInsets.all(8.0), + child: Center( + child: Obx(() => + Container( + width: MediaQuery.of(context).size.width, + height: 370, + decoration: BoxDecoration( + image: + DecorationImage( + image: getFinishImage(), + fit: BoxFit.cover + ) + ), + ), + ), + ), + ), + getAction(context), + ], + ), + ); + } + else if(destinationController.rogaining_counted.value == true) { + return NotAtGoal(); + } + else { + return StartRogaining(); + } + + } +} + +class StartRogaining extends StatelessWidget { + StartRogaining({Key? key}) : super(key: key); + + DestinationController destinationController = Get.find(); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text("Not started yet".tr,), + ), + body: Container( + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text("You have not started rogaining yet.".tr, style: TextStyle(fontSize: 24)), + SizedBox(height: 40.0,), + ElevatedButton( + onPressed: (){ + Get.back(); + destinationController.skip_gps = false; + }, + child: Text("Back"), + ), + ], + ), + ), + ), + ); + } +} + +class NotAtGoal extends StatelessWidget { + NotAtGoal({Key? key}) : super(key: key); + + DestinationController destinationController = Get.find(); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text("Not reached the goal yet".tr,), + ), + body: Container( + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text("You have not reached the goal yet.".tr, style: TextStyle(fontSize: 24)), + SizedBox(height: 40.0,), + ElevatedButton( + onPressed: (){ + Get.back(); + destinationController.skip_gps = false; + }, + child: Text("Back"), + ), + ], + ), + ), + ), ); } } \ No newline at end of file diff --git a/lib/pages/destination/destination_controller.dart b/lib/pages/destination/destination_controller.dart index ca160af..e247e0f 100644 --- a/lib/pages/destination/destination_controller.dart +++ b/lib/pages/destination/destination_controller.dart @@ -12,6 +12,7 @@ import 'package:get/get.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'; @@ -20,6 +21,7 @@ import 'package:rogapp/services/external_service.dart'; import 'package:rogapp/services/maxtrix_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'; @@ -31,17 +33,19 @@ class DestinationController extends GetxController { var destinationCount = 0.obs; List destinations = [].obs; - List> destination_index_data = >[].obs; double current_lat = 0.0; double current_lon = 0.0; - List currentSelectedDestinations = [].obs; + List currentSelectedDestinations = [].obs; + var is_in_checkin = false.obs; var is_in_rog = false.obs; - List rogainings = [].obs; + var is_at_start = false.obs; + var is_at_goal = false.obs; + //List rogainings = [].obs; bool checking_in = false; - var isSelected = false.obs; + var is_gps_selected = true.obs; BuildContext? context; List gps = ["-- stating --"].obs; @@ -49,6 +53,8 @@ class DestinationController extends GetxController { var travelMode = 0.obs; + bool skip_gps = false; + Map matrix = {}; @@ -57,34 +63,284 @@ class DestinationController extends GetxController { final IndexController indexController = Get.find(); Timer? _timer; - int _start = 1; + int _start = 0; + int _chekcs = 0; var rogaining_counted = false.obs; - void startTimer(Destination d, double distance) { + Destination festuretoDestination(GeoJsonFeature fs){ + GeoJsonMultiPoint mp = fs.geometry as GeoJsonMultiPoint; + LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude, mp.geoSerie!.geoPoints[0].longitude); + + //print("----- ${indexController.currentFeature[0].properties} -----"); + + return Destination( + name: fs.properties!["location_name"], + address: fs.properties!["address"], + phone: fs.properties!["phone"], + email: fs.properties!["email"], + webcontents: fs.properties!["webcontents"], + videos: fs.properties!["videos"], + category: fs.properties!["category"], + series: 1, + lat: pt.latitude, + lon: pt.longitude, + location_id: fs.properties!["location_id"], + list_order: 1, + photos: fs.properties!["photos"], + checkin_radious: fs.properties!["checkin_radius"], + auto_checkin: fs.properties!["auto_checkin"] == true ? 1 : 0, + cp: fs.properties!["cp"], + checkin_point: fs.properties!["checkin_point"], + buy_point: fs.properties!["buy_point"], + selected: false, + checkedin: false, + hidden_location: fs.properties!["hidden_location"] == true ?1 : 0 + ); + } + + void startTimerLocation(GeoJsonFeature fs, double distance) { + print("---- in startTimer ----"); + double checkin_radious = fs.properties!['checkin_radius'] ?? double.infinity; + if(checkin_radious >= distance){ + indexController.currentDestinationFeature.clear(); + Destination d = festuretoDestination(fs); + indexController.currentDestinationFeature.add(d); + print("---- before calling startTimer ----"); + startTimer(d, distance); + } + } + + void startTimer(Destination d, double distance) async { + 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; + //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()} ----"); + } + else { + skip_gps = false; + return; + } + + DatabaseHelper db = DatabaseHelper.instance; + List ds = await db.getDestinationByLatLon(d.lat!, d.lon!); + if(ds.isEmpty){ + print("----- in location popup cp - ${d.cp}----"); + if(d.cp == -1){ + _chekcs = 1; + //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; + }); + } + else + { + print("----- in location popup checkin cp - ${d.cp}----"); + _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("---- location checkin radious ${d.checkin_radious} ----"); + print("---- already checked in ${location_already_checked_in} ----"); + if(checkin_radious >= distance && location_already_checked_in == 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 + if(d.hidden_location != null && d.hidden_location ==true && is_in_rog.value == true){ + _chekcs = 1; + is_in_checkin.value = true; + showModalBottomSheet(context: Get.context!, isScrollControlled: true, + builder:((context) => CameraPage()) + ).whenComplete((){ + skip_gps = false; + _chekcs = 0; + is_in_checkin.value = false; + }); + } + else if(is_in_rog.value == true){ + _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_in){ + //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) => CameraPage()) + ).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; + }); + } + } + print("---- _chekcs ${_chekcs} ----"); + if(_chekcs == 0){ + 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); + + print("---- checked in as ${indexController.currentDestinationFeature[0].checkedin.toString()} ----"); + } const oneSec = const Duration(seconds: 1); _timer = Timer.periodic( oneSec, (Timer timer) { if (_start == 0) { - if(is_in_rog.value == false){ - is_in_rog.value = true; - addToRogaining(current_lat, current_lon, d.location_id!); - Get.snackbar("Rogaining Started ", "Rogaining session started"); + //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; + }); + } } - else{ - //finish rogiain - if (rogaining_counted.value && distance <=250){ - Get.toNamed(AppPages.CAMERA_PAGE); + + 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; + is_in_rog.value = false; + is_at_start.value = false; + is_at_goal.value = false; + + _start = 0; + _chekcs = 0; + rogaining_counted.value = false; + } + void openCamera(BuildContext context) { photos.clear(); Navigator.push( @@ -110,10 +366,8 @@ class DestinationController extends GetxController { }); } - Future getDEstinationForLatLong(double lat, double long)async { + Future getDestinationForLatLong(double lat, double long)async { - String jjjj = '{"id":1,"type":"Feature","geometry":{"type":"MultiPoint","coordinates":[[136.731357,35.370094]]},"properties":{"location_id":915101,"location_name":"柳津","category":"買い物","zip":"〒501-6100","address":"柳津町字仙右城7696-1"}}'; - for(final d in destinations){ if(lat == d.lat && long == d.lon){ return d; @@ -121,90 +375,67 @@ class DestinationController extends GetxController { } } - // void addToRogaining(Rogaining rog){ - // DatabaseHelper db = DatabaseHelper.instance; - // db.insertRogaining(rog); - // } + void checkForCheckin(double la, double ln){ - checkForCheckin(double la, double ln){ + print("--- skip_gps ---- ${skip_gps}----"); for(final d in destinations){ - print("-----loc_id- ${d.location_id}----"); + print("--- check checkin for--loc_id- ${d.location_id}----"); - if(!checking_in) - { - checking_in = true; double lat = d.lat!; double lon = d.lon!; LatLng p = LatLng(lat, lon); - getDEstinationForLatLong(lat, lon).then((value){ + getDestinationForLatLong(lat, lon).then((value){ var distance = Distance(); double dist = distance.as(LengthUnit.Meter, LatLng(lat, lon), LatLng(la, ln)); - double rad = value!.checkin_radious ?? double.infinity; - bool auto_checkin = value.auto_checkin == 0 ? false : true; + //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("-----rogaining_counted---${rogaining_counted.value}-----"); + // print("-----is_in_rog---${is_in_rog}-----"); + // print("-----dist is ---${dist}-----"); + //print("----- ${indexController.currentUser} ----"); - if(d.cp != -1 && is_in_rog == true){ - rogaining_counted.value == true; - } - - if(d.cp == -1 && dist <= 250 && rogaining_counted.value == false){ + if(dist <= 250 && skip_gps == false){ + //near a destination + print("---- time with ${d.location_id} ----"); startTimer(d, dist); } - - indexController.currentDestinationFeature.add(value); - //indexController.getAction(); - - - if(rad >= dist){ - if(auto_checkin){ - makeCheckin(value, true); - } - else{ - // showModalBottomSheet(context: Get.context!, isScrollControlled: true, - // builder:((context) => BottomSheetWidget()) - // ).whenComplete((){ - // checking_in = false; - // }); - } - } - - // if(!checking_in){ - // checking_in = true; - // if(rad >= dist){ - // if(auto_checkin){ - // if(indexController.currentAction.isNotEmpty){ - // print(indexController.currentAction[0]); - // indexController.currentAction[0][0]["checkin"] = true; - // Map temp = Map.from(indexController.currentAction[0][0]); - // indexController.currentAction.clear(); - // print("---temp---${temp}"); - // indexController.currentAction.add([temp]); - // } - // indexController.makeAction(Get.context!); - // } - // else{ - // showModalBottomSheet(context: Get.context!, isScrollControlled: true, - // builder:((context) => BottomSheetWidget()) - // ).whenComplete((){ - // checking_in = false; - // }); - // } - // } - // } }); - } + } + //check for location in bounds + for(GeoJsonFeature fs in indexController.locations[0].collection){ + + 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)); + + if(dist_fs <= 250 && skip_gps == false){ + //near a location + print("---- before call startTimerLocation ----"); + startTimerLocation(fs, dist_fs); + } } } - void addToRogaining(double lat, double lon, int destination_id){ + 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]); + makeCheckin(df, true); + } + Rogaining rog = Rogaining( rog_id: null, course_id: 1, @@ -214,7 +445,6 @@ class DestinationController extends GetxController { lon:lon, time_stamp: DateTime.now().toUtc().microsecondsSinceEpoch ); - DatabaseHelper db = DatabaseHelper.instance; db.insertRogaining(rog).then((value){ print("----- inserted value ${value} ---------"); }); @@ -224,15 +454,17 @@ class DestinationController extends GetxController { // print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${action}@@@@@@@@@@@"); DatabaseHelper db = DatabaseHelper.instance; int res = await db.updateAction(destination, action); - List ddd = await db.getDestinationByLatLon(destination.lat!, destination.lon!); - // print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ddddd ${ddd[0].checkedin} @@@@@@@@@@@"); + if(ddd.isEmpty){ + await db.insertDestination(destination); + } + print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ddddd ${ddd[0].checkedin} @@@@@@@@@@@"); // print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${res}@@@@@@@@@@@"); - PopulateDestinations(); // 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()); @@ -252,14 +484,12 @@ class DestinationController extends GetxController { //print("------ in iniit"); - - if (defaultTargetPlatform == TargetPlatform.android) { locationSettings = AndroidSettings( accuracy: LocationAccuracy.bestForNavigation, distanceFilter: 00, forceLocationManager: true, - intervalDuration: const Duration(seconds: 1), + intervalDuration: const Duration(seconds: 10), //(Optional) Set foreground notification config to keep the app alive //when going to the background foregroundNotificationConfig: const ForegroundNotificationConfig( @@ -273,7 +503,7 @@ class DestinationController extends GetxController { locationSettings = AppleSettings( accuracy: LocationAccuracy.bestForNavigation, activityType: ActivityType.fitness, - distanceFilter: 1, + distanceFilter: 30, pauseLocationUpdatesAutomatically: false, // Only set to true if our app will be started up in the background. showBackgroundLocationIndicator: true @@ -293,7 +523,7 @@ class DestinationController extends GetxController { current_lat = position != null ? position.latitude : 0; current_lon = position != null ? position.longitude : 0; - if(isSelected.value){ + if(is_gps_selected.value){ double czoom = indexController.rogMapController!.zoom; indexController.rogMapController!.move(LatLng(position!.latitude, position!.longitude), czoom); //String user_id = indexController.currentUser[0]["user"]["id"].toString(); @@ -302,6 +532,8 @@ class DestinationController extends GetxController { gps.clear(); gps.add("-- lat : ${position.latitude}, lon : ${position.longitude} --"); checkForCheckin(position!.latitude, position.longitude); + print("--- call check checkin"); + print("---- skip gps is ${skip_gps.toString()} ----"); //}); } @@ -342,9 +574,9 @@ class DestinationController extends GetxController { void deleteDestination(Destination d){ //int id = destinations[index].location_id!; //print("---- index ${destinations[index].location_id!}-----"); - for(Destination ss in currentSelectedDestinations){ + for(Destination ss in destinations){ if(ss.location_id == d.location_id){ - currentSelectedDestinations.remove(ss); + destinations.remove(ss); break; } } @@ -365,7 +597,7 @@ class DestinationController extends GetxController { void addDestinations(Destination dest){ - print('------ destination controller in add destination ${dest.name} ---- :::::'); + print('------ destination controller in add destination ${dest.checkin_radious} ---- :::::'); DatabaseHelper db = DatabaseHelper.instance; db.getDestinationByLatLon(dest.lat!, dest.lon!).then((value){ @@ -395,12 +627,12 @@ class DestinationController extends GetxController { db.getDestinations().then((value){ destinationCount.value = 0; for(Destination d in value){ - for(Destination s in currentSelectedDestinations){ + for(Destination s in destinations){ if(d.location_id == s.location_id){ d.selected = !d.selected!; } } - + print("------ destination controller populating destination-------- ${d.checkedin}-------- :::::"); destinations.add(d); } // destinationCount.value = 0; diff --git a/lib/pages/destination/destination_page.dart b/lib/pages/destination/destination_page.dart index e21e527..96ad280 100644 --- a/lib/pages/destination/destination_page.dart +++ b/lib/pages/destination/destination_page.dart @@ -160,14 +160,32 @@ class DestnationPage extends StatelessWidget { automaticallyImplyLeading: true, title: Text("app_title".tr), actions: [ - TextButton( - onPressed: (){ - //ExternalService().StartRogaining('team_name', "2222"); - //destinationController.openCamera(context); + InkWell( + onTap: (){ Get.toNamed(AppPages.CAMERA_PAGE); - }, - child: Icon(Icons.ac_unit), + }, + child: destinationController.is_in_rog == true ? + Image.asset("assets/images/basic-walking.gif",height: 10.0,) + : + destinationController.is_at_goal == true ? + IconButton( + onPressed:(){Get.toNamed(AppPages.CAMERA_PAGE);}, + icon: Icon(Icons.assistant_photo), + ) + : + IconButton( + onPressed:(){Get.toNamed(AppPages.CAMERA_PAGE);}, + icon: Icon(Icons.accessibility), + ), ), + // TextButton( + // onPressed: (){ + // //ExternalService().StartRogaining('team_name', "2222"); + // //destinationController.openCamera(context); + // Get.toNamed(AppPages.CAMERA_PAGE); + // }, + // child: Icon(Icons.ac_unit), + // ), Obx(() => ToggleButtons( disabledColor: Colors.grey.shade200, @@ -176,9 +194,12 @@ class DestnationPage extends StatelessWidget { Icon(Icons.explore, size: 35.0, )], onPressed: (int index) { - destinationController.isSelected.value = !destinationController.isSelected.value; + destinationController.is_gps_selected.value = !destinationController.is_gps_selected.value; + if(destinationController.is_gps_selected.value){ + destinationController.skip_gps = false; + } }, - isSelected: [destinationController.isSelected.value], + isSelected: [destinationController.is_gps_selected.value], ), ), // IconButton(onPressed: (){ diff --git a/lib/pages/destination_map/destination_map_page.dart b/lib/pages/destination_map/destination_map_page.dart index 7189080..6357f6e 100644 --- a/lib/pages/destination_map/destination_map_page.dart +++ b/lib/pages/destination_map/destination_map_page.dart @@ -131,7 +131,12 @@ class DestinationMapPage extends StatelessWidget { if (mapEvent is MapEventMoveStart) { } if (mapEvent is MapEventMoveEnd) { - destinationController.isSelected.value = false; + //destinationController.is_gps_selected.value = true; + //indexController.mapController!.move(c.center, c.zoom); + LatLngBounds bounds = c.bounds!; + indexController.currentBound.clear(); + indexController.currentBound.add(bounds); + indexController.loadLocationsBound(); } }); }); diff --git a/lib/pages/index/index_controller.dart b/lib/pages/index/index_controller.dart index 4339e16..565bfb9 100644 --- a/lib/pages/index/index_controller.dart +++ b/lib/pages/index/index_controller.dart @@ -113,13 +113,6 @@ class IndexController extends GetxController { @override void onInit() { - // if(locations.length == 0){ - // LocationService.loadLocations().then((value){ - // locations.add(value!); - // //print(value); - // }); - // } - _ever = ever(rog_mode, (_) => print("$_ has been changed (ever)")); if(perfectures.length == 0){ @@ -215,7 +208,6 @@ void login(String email, String password, BuildContext context){ else{ switchPage(AppPages.INITIAL); } - //Get.toNamed(AppPages.INITIAL); }else{ Get.snackbar( 'failed'.tr, @@ -587,7 +579,6 @@ void login(String email, String password, BuildContext context){ if(rog_mode == 1){ DestinationController destinationController = Get.find(); - print("---- destination index--- ${destinationController.destination_index_data} --------"); } else { GeoJsonFeature pt = fs as GeoJsonFeature; @@ -620,7 +611,6 @@ void login(String email, String password, BuildContext context){ if(rog_mode == 1){ DestinationController destinationController = Get.find(); - print("---- destination index--- ${destinationController.destination_index_data} --------"); } else { diff --git a/lib/pages/index/index_page.dart b/lib/pages/index/index_page.dart index 6e0bfcb..515c993 100644 --- a/lib/pages/index/index_page.dart +++ b/lib/pages/index/index_page.dart @@ -68,19 +68,23 @@ class IndexPage extends GetView { child: InkWell( child: Obx(() => - destinationController.isSelected == true ? + destinationController.is_gps_selected == true ? Padding( padding: const EdgeInsets.only(right: 10.0, top: 4.0, bottom: 4.0), child: InkWell( child: Image(image: AssetImage('assets/images/route3_off.png'), width: 35, height: 35,), - onTap: (){Get.toNamed(AppPages.DESTINATION_MAP);}, + onTap: (){ + indexController.switchPage(AppPages.TRAVEL); + }, ), ) : Padding( padding: const EdgeInsets.only(right: 10.0, top: 4.0, bottom: 4.0), child: InkWell( child: Image(image: AssetImage('assets/images/route2_on.png'),width: 35, height: 35,), - onTap: (){Get.toNamed(AppPages.DESTINATION_MAP);}, + onTap: (){ + indexController.switchPage(AppPages.TRAVEL); + }, ), ) ) diff --git a/lib/services/location_service.dart b/lib/services/location_service.dart index b645bd0..cf28504 100644 --- a/lib/services/location_service.dart +++ b/lib/services/location_service.dart @@ -164,6 +164,7 @@ class LocationService{ return null; } else{ + //print("---- feature got from server is ${cc.collection[0].properties} ------"); return cc; } } diff --git a/lib/utils/const.dart b/lib/utils/const.dart index bacb16a..865290c 100644 --- a/lib/utils/const.dart +++ b/lib/utils/const.dart @@ -2,9 +2,10 @@ class ConstValues{ - static const server_uri = "http://container.intranet.sumasen.net:8100"; + static const container_svr = "http://container.intranet.sumasen.net:8100"; + static const server_uri = "https://rogaining.sumasen.net"; static const dev_server = "http://localhost:8100"; - static const dev_ip_server = "http://192.168.8.100:8100"; + static const dev_ip_server = "http://192.168.1.10:8100"; static const dev_home_ip_server = "http://172.20.10.9:8100"; static String currentServer(){ diff --git a/lib/utils/database_helper.dart b/lib/utils/database_helper.dart index dde5bd4..9c9e429 100644 --- a/lib/utils/database_helper.dart +++ b/lib/utils/database_helper.dart @@ -45,7 +45,8 @@ class DatabaseHelper{ checkedin INTEGER, cp REAL, checkin_point REAL, - buy_point REAL + buy_point REAL, + hidden_location INTEGER ) '''); @@ -82,6 +83,14 @@ class DatabaseHelper{ return roglist; } + 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]; + } + Future deleteRogaining(int rog_id) async { Database db = await instance.database; @@ -195,7 +204,7 @@ class DatabaseHelper{ dest.toMap(), conflictAlgorithm: ConflictAlgorithm.replace, ); - print("------ database helper insert ${res}-----------::::::::"); + print("------ database helper insert ${dest.toMap()}-----------::::::::"); return res; } diff --git a/lib/utils/string_values.dart b/lib/utils/string_values.dart index b7e865f..85fbe57 100644 --- a/lib/utils/string_values.dart +++ b/lib/utils/string_values.dart @@ -58,7 +58,16 @@ class StringValues extends Translations{ 'goal_saved': "Goal Saved", 'goal_added_successfuly' : 'Goal added successfully', 'goal_not_added' : 'Goal not added', - 'please_try_again' : 'Please try again' + 'please_try_again' : 'Please try again', + "Click start to start rogaining":"Click start to start rogaining", + "you are at roganing point, start rogaining":"you are at roganing point, start rogaining", + "Start":"Start", + "Rogaining Started":"Rogaining Started", + "Rogaining session started":"Rogaining session started", + "Not started yet":"Not started yet", + "You have not started rogaining yet.":"You have not started rogaining yet.", + "Not reached the goal yet": "Not reached the goal yet", + "You have not reached the goal yet.":"You have not reached the goal yet." }, 'ja_JP': { 'drawer_title':'ロゲイニング参加者はログイン するとチェックポイントが参照 できます', @@ -117,7 +126,16 @@ class StringValues extends Translations{ 'goal_saved': "目標を保存しました", 'goal_added_successfuly' : '目標が正常に追加されました', 'goal_not_added' : '目標が追加されていません', - 'please_try_again' : 'もう一度お試しください' + 'please_try_again' : 'もう一度お試しください', + "Click start to start rogaining":"開始をクリックして、ロゲイニングを開始します", + "you are at roganing point, start rogaining":"あなたはロガニングポイントにいます、ロガニングを始めてください", + "Start":"始める", + "Rogaining Started":"ロゲイニング開始", + "Rogaining session started":"ロゲイニングセッション開始", + "Not started yet":"まだ開始されていません", + "You have not started rogaining yet.":"あなたはまだロゲイニングを始めていません。", + "Not reached the goal yet": "まだ目標に達していない", + "You have not reached the goal yet.":"あなたはまだゴールに達していません。" }, }; } \ No newline at end of file diff --git a/lib/widgets/bottom_sheet_new.dart b/lib/widgets/bottom_sheet_new.dart index a9afd07..ab90b9e 100644 --- a/lib/widgets/bottom_sheet_new.dart +++ b/lib/widgets/bottom_sheet_new.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:geojson/geojson.dart'; import 'package:get/get.dart'; import 'package:get/get_state_manager/get_state_manager.dart'; @@ -8,6 +9,7 @@ import 'package:rogapp/model/destination.dart'; import 'package:rogapp/pages/destination/destination_controller.dart'; import 'package:rogapp/pages/index/index_controller.dart'; import 'package:rogapp/routes/app_pages.dart'; +import 'package:rogapp/utils/const.dart'; import 'package:rogapp/utils/database_helper.dart'; import 'package:rogapp/utils/text_util.dart'; import 'package:rogapp/widgets/bottom_sheet_controller.dart'; @@ -21,6 +23,7 @@ class BottomSheetNew extends GetView { Image getImage(){ + String server_url = ConstValues.currentServer(); if(indexController.rog_mode == 1){ //print("----- rogaining mode 1"); if(indexController.currentDestinationFeature.length <= 0 || indexController.currentDestinationFeature[0].photos! == ""){ @@ -40,7 +43,7 @@ class BottomSheetNew extends GetView { } else { return Image(image: NetworkImage( - 'http://container.intranet.sumasen.net:8100/media/' + indexController.currentDestinationFeature[0].photos!, + '${server_url}/media/compressed/' + indexController.currentDestinationFeature[0].photos!, ), errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) { return Image.asset("assets/images/empty_image.png"); @@ -67,7 +70,7 @@ class BottomSheetNew extends GetView { } else { return Image(image: NetworkImage( - 'http://container.intranet.sumasen.net:8100/media/' + gf.properties!["photos"], + '${server_url}/media/compressed/' + gf.properties!["photos"], ), errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) { return Image.asset("assets/images/empty_image.png"); @@ -96,11 +99,15 @@ class BottomSheetNew extends GetView { @override Widget build(BuildContext context) { + print('---- rog_mode ----- ${indexController.rog_mode} -----'); return indexController.rog_mode == 0 ? detailsSheet(context) : destinationSheet(context); } // Show destination detais SingleChildScrollView destinationSheet(BuildContext context) { + + print('---- currentDestinationFeature ----- ${indexController.currentDestinationFeature[0].name} -----'); + return SingleChildScrollView( child: Column( children: [ @@ -156,6 +163,77 @@ class BottomSheetNew extends GetView { ), ], ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + Obx(() => + indexController.currentDestinationFeature.isNotEmpty && destinationController.is_in_checkin.value == true ? + Row( + children: [ + ElevatedButton( + onPressed: (){ + if(indexController.currentDestinationFeature[0].checkedin == null || indexController.currentDestinationFeature[0].checkedin == false){ + destinationController.makeCheckin(indexController.currentDestinationFeature[0], true); + if(indexController.currentDestinationFeature[0].cp != -1){ + destinationController.rogaining_counted.value =true; + } + } + else{ + destinationController.makeCheckin(indexController.currentDestinationFeature[0], false); + } + Get.back(); + }, + child: Text( + indexController.currentDestinationFeature[0].checkedin == null || indexController.currentDestinationFeature[0].checkedin == false ? + "Chekin" + : + "Checkput" + ) + ), + ], + ) + : + Container(), + ), + Obx(() => + destinationController.is_at_start.value == true ? + ElevatedButton( + onPressed: (){ + destinationController.is_in_rog.value = true; + destinationController.addToRogaining(destinationController.current_lat, destinationController.current_lon, indexController.currentDestinationFeature[0].location_id!); + Get.back(); + }, + child: Text( + indexController.currentDestinationFeature[0].checkedin != null || indexController.currentDestinationFeature[0].checkedin == true ? + "Start Rogaining" + : + "Wrong destination ..." + ) + ) + : + Container(), + + ), + Obx(() => + destinationController.is_at_goal.value == true && destinationController.rogaining_counted ==true ? + ElevatedButton( + onPressed: (){ + Get.toNamed(AppPages.CAMERA_PAGE); + Get.back(); + }, + child: Text( + indexController.currentDestinationFeature[0].checkedin != null || indexController.currentDestinationFeature[0].checkedin == true ? + "Finish Rogaining" + : + "Wrong destination ..." + ) + ) + : + Container(), + + ), + ], + ), Obx(() => indexController.currentDestinationFeature[0].address != null && indexController.currentDestinationFeature[0].address!.isNotEmpty ? getDetails(context, "address".tr, indexController.currentDestinationFeature[0].address! ?? '') @@ -187,19 +265,19 @@ class BottomSheetNew extends GetView { Container(width: 0.0, height: 0,), ), SizedBox(height: 20.0,), - Obx(() => - //wantToGo(context), + // Obx(() => + // //wantToGo(context), - FutureBuilder( - future: wantToGo(context), - builder: (context, snapshot) { - return Container( - child: snapshot.data, - ); - }, - ), + // FutureBuilder( + // future: wantToGo(context), + // builder: (context, snapshot) { + // return Container( + // child: snapshot.data, + // ); + // }, + // ), - ), + // ), SizedBox(height: 60.0,) ], ), @@ -440,6 +518,8 @@ class BottomSheetNew extends GetView { GeoJsonMultiPoint mp = indexController.currentFeature[0].geometry as GeoJsonMultiPoint; LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude, mp.geoSerie!.geoPoints[0].longitude); + //print("----- ${indexController.currentFeature[0].properties} -----"); + Destination dest = Destination( name: indexController.currentFeature[0].properties!["location_name"], address: indexController.currentFeature[0].properties!["address"], @@ -454,13 +534,14 @@ class BottomSheetNew extends GetView { location_id: indexController.currentFeature[0].properties!["location_id"], list_order: 1, photos: indexController.currentFeature[0].properties!["photos"], - checkin_radious: indexController.currentFeature[0].properties!["checkin_radious"], + checkin_radious: indexController.currentFeature[0].properties!["checkin_radius"], auto_checkin: indexController.currentFeature[0].properties!["auto_checkin"] == true ? 1 : 0, cp: indexController.currentFeature[0].properties!["cp"], checkin_point: indexController.currentFeature[0].properties!["checkin_point"], buy_point: indexController.currentFeature[0].properties!["buy_point"], selected: false, - checkedin: false + checkedin: false, + hidden_location: indexController.currentFeature[0].properties!["hidden_location"] == true ?1 : 0 ); destinationController.addDestinations(dest); Get.back(); @@ -589,13 +670,11 @@ class BottomSheetNew extends GetView { }, child: Container( width: MediaQuery.of(context).size.width - 160, - child: Expanded( - child: Text(text, - style: TextStyle( - color: isurl ? Colors.blue : Colors.black, - ), + child: Text(text, + style: TextStyle( + color: isurl ? Colors.blue : Colors.black, ), - ), + ), ), ), ], diff --git a/lib/widgets/destination_widget.dart b/lib/widgets/destination_widget.dart index 28ee9bf..c57cb51 100644 --- a/lib/widgets/destination_widget.dart +++ b/lib/widgets/destination_widget.dart @@ -46,22 +46,23 @@ class DestinationWidget extends StatelessWidget { } } - bool getSelection(int index){ - bool ret = false; - destinationController.destination_index_data.forEach((element) { - if(index == element["index"]){ - if(element["selected"] == true){ - ret = true; - return; - } - } - }); - return ret; - } + // bool getSelection(int index){ + // bool ret = false; + // destinationController.destination_index_data.forEach((element) { + // if(index == element["index"]){ + // if(element["selected"] == true){ + // ret = true; + // return; + // } + // } + // }); + // return ret; + // } void doDelete() { destinationController.currentSelectedDestinations.forEach((element) { destinationController.deleteDestination(element); + destinationController.resetRogaining(); }); // destinationController.destination_index_data.forEach((element) { // //print(element["index"]); @@ -174,13 +175,14 @@ class DestinationWidget extends StatelessWidget { onTap: () async { { Destination? fs = destinationController.destinations[index]; - print("----fsf-----${fs}"); + print("----fsf-----${fs.location_id}"); if(fs != null){ - if(indexController.currentDestinationFeature.length > 0) { + if(indexController.currentDestinationFeature.isNotEmpty) { indexController.currentDestinationFeature.clear(); } indexController.currentDestinationFeature.add(fs); + print("--- ndexController.currentDestinationFeature ----- ${ indexController.currentDestinationFeature[0].name} ----"); //indexController.getAction(); showModalBottomSheet(context: context, isScrollControlled: true, @@ -196,7 +198,7 @@ class DestinationWidget extends StatelessWidget { if(destinationController.currentSelectedDestinations.length > 0){ if(destinationController.currentSelectedDestinations[0].location_id == destinationController.destinations[index].location_id){ destinationController.currentSelectedDestinations.clear(); - print("---- fount ----"); + print("---- found ----"); destinationController.PopulateDestinations(); return; } diff --git a/lib/widgets/map_widget.dart b/lib/widgets/map_widget.dart index 8c601b5..8dd9791 100644 --- a/lib/widgets/map_widget.dart +++ b/lib/widgets/map_widget.dart @@ -85,6 +85,7 @@ class MapWidget extends StatelessWidget { if (mapEvent is MapEventMoveEnd) { //print(DateTime.now().toString() + ' [MapEventMoveStart] END'); indexController.loadLocationsBound(); + //indexController.rogMapController!.move(c.center, c.zoom); } }); });