diff --git a/lib/main.dart b/lib/main.dart index e5fe222..3e6c841 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -25,6 +25,8 @@ void restoreGame() async { destinationController.isInRog.value = pref.getBool("is_in_rog") ?? false; destinationController.rogainingCounted.value = pref.getBool("rogaining_counted") ?? false; + print( + "--restored -- destinationController.isInRog.value ${pref.getBool("is_in_rog")} -- ${pref.getBool("rogaining_counted")}"); } void main() async { @@ -61,6 +63,9 @@ class _MyAppState extends State with WidgetsBindingObserver { @override void initState() { super.initState(); + if (context.mounted) { + restoreGame(); + } WidgetsBinding.instance.addObserver(this); } @@ -83,22 +88,22 @@ class _MyAppState extends State with WidgetsBindingObserver { Get.find(); switch (state) { case AppLifecycleState.resumed: - //print("RESUMED"); + print("RESUMED"); restoreGame(); break; case AppLifecycleState.inactive: - //print("INACTIVE"); + print("INACTIVE"); break; case AppLifecycleState.paused: - //print("PAUSED"); + print("PAUSED"); saveGameState(); break; case AppLifecycleState.detached: - //print("DETACHED"); + print("DETACHED"); saveGameState(); break; case AppLifecycleState.hidden: - //print("DETACHED"); + print("DETACHED"); saveGameState(); break; } diff --git a/lib/pages/destination/destination_controller.dart b/lib/pages/destination/destination_controller.dart index 1696e04..def4063 100644 --- a/lib/pages/destination/destination_controller.dart +++ b/lib/pages/destination/destination_controller.dart @@ -675,13 +675,13 @@ class DestinationController extends GetxController { Destination des = festuretoDestination(gfs); - //print("=== gfs == ${des.toMap()}"); + print("=== gfs == ${des.toMap()}"); double distanceToDest = double.infinity; var distance = const Distance(); distanceToDest = distance.as(LengthUnit.Meter, LatLng(currentLat, currentLon), LatLng(des.lat!, des.lon!)); - //print("==== dist==${distanceToDest}"); + print("==== dist==${distanceToDest}"); return distanceToDest; } @@ -936,6 +936,9 @@ class DestinationController extends GetxController { //print("-----populated----- ${d.toMap()}"); destinations.add(d); } + if (destinations.isEmpty) { + rogainingCounted.value = false; + } // destinationCount.value = 0; //print( // "------ destination controller destinationcount-------- $destinationCount-------- :::::"); diff --git a/lib/widgets/bottom_sheet_new.dart b/lib/widgets/bottom_sheet_new.dart index 44dc09e..93682cf 100644 --- a/lib/widgets/bottom_sheet_new.dart +++ b/lib/widgets/bottom_sheet_new.dart @@ -1,5 +1,5 @@ import 'dart:ffi'; - +import 'dart:ui' as ui; import 'package:flutter/material.dart'; import 'package:geojson/geojson.dart'; import 'package:geolocator/geolocator.dart'; @@ -8,6 +8,7 @@ import 'package:image_picker/image_picker.dart'; import 'package:latlong2/latlong.dart'; import 'package:rogapp/main.dart'; import 'package:rogapp/model/destination.dart'; +import 'package:rogapp/pages/camera/camera_page.dart'; import 'package:rogapp/pages/destination/destination_controller.dart'; import 'package:rogapp/pages/index/index_controller.dart'; import 'package:rogapp/routes/app_pages.dart'; @@ -16,15 +17,19 @@ 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'; +import 'package:sqflite/sqflite.dart'; import 'package:url_launcher/url_launcher.dart'; class BottomSheetNew extends GetView { - BottomSheetNew({Key? key, required this.destination}) : super(key: key); + BottomSheetNew( + {this.isAlreadyCheckedIn = false, Key? key, required this.destination}) + : super(key: key); final IndexController indexController = Get.find(); final DestinationController destinationController = Get.find(); - Destination destination; + final Destination destination; + final bool isAlreadyCheckedIn; Image getImage() { String serverUrl = ConstValues.currentServer(); @@ -116,258 +121,265 @@ class BottomSheetNew extends GetView { } // Show destination detais - SingleChildScrollView destinationSheet(BuildContext context) { - // print( - // '---- currentDestinationFeature ----- ${indexController.currentDestinationFeature[0].name} -----'); + // SingleChildScrollView destinationSheet(BuildContext context) { + // // print( + // // '---- currentDestinationFeature ----- ${indexController.currentDestinationFeature[0].name} -----'); - return SingleChildScrollView( - child: Column( - children: [ - Padding( - padding: const EdgeInsets.all(8.0), - child: Row( - children: [ - MaterialButton( - onPressed: () { - Get.back(); - //destinationController.makePrevious(indexController.currentDestinationFeature[0]); - }, - color: Colors.blue, - textColor: Colors.white, - padding: const EdgeInsets.all(16), - shape: const CircleBorder(), - child: const Icon( - Icons.arrow_back_ios, - size: 14, - ), - ), - Expanded( - child: Container( - alignment: Alignment.center, - child: Obx(() => indexController.currentUser.isNotEmpty - ? Text( - "${TextUtils.getDisplayText(indexController.currentDestinationFeature[0])} : ${TextUtils.getDisplayText(indexController.currentDestinationFeature[0])} : ${indexController.currentDestinationFeature[0].name!}", - style: const TextStyle( - fontSize: 15.0, - fontWeight: FontWeight.bold, - ), - ) - : Text( - indexController.currentDestinationFeature[0].name!, - style: const TextStyle( - fontSize: 15.0, - fontWeight: FontWeight.bold, - ), - )), - ), - ), - ], - ), - ), - Row( - children: [ - Expanded( - child: SizedBox( - height: 260.0, - child: Obx(() => getImage()), - )), - ], - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - Obx( - () => indexController.currentDestinationFeature.isNotEmpty && - destinationController.isInCheckin.value == true && - destinationController.isAtStart.value == false - ? Row( - children: [ - ElevatedButton( - onPressed: () { - if (indexController.currentDestinationFeature[0] - .checkedin == - null || - indexController.currentDestinationFeature[0] - .checkedin == - false) { - if (indexController - .currentDestinationFeature[0] - .hidden_location == - 0) { - destinationController.skipGps = false; - destinationController.isPhotoShoot.value = - true; - Get.back(); - } else { - destinationController.makeCheckin( - indexController - .currentDestinationFeature[0], - true, - ""); - if (indexController - .currentDestinationFeature[0].cp != - -1) { - destinationController - .rogainingCounted.value = true; - } - } - } else { - destinationController.makeCheckin( - indexController - .currentDestinationFeature[0], - false, - ""); - } - //Get.back(); - }, - child: Text( - //Checkin - indexController.currentDestinationFeature[0] - .checkedin == - null || - indexController - .currentDestinationFeature[0] - .checkedin == - false - ? "チェックイン" - : "チェックアウト")), - ], - ) - : Container(), - ), - Obx( - () => destinationController.isAtStart.value == true - ? ElevatedButton( - onPressed: () { - destinationController.isInRog.value = true; - destinationController.addToRogaining( - destinationController.currentLat, - destinationController.currentLon, - indexController - .currentDestinationFeature[0].location_id!); - saveGameState(); - ExternalService() - .startRogaining() - .then((value) => Get.back()); - }, - child: Text( - // start - indexController.currentDestinationFeature[0] - .checkedin != - null || - indexController.currentDestinationFeature[0] - .checkedin == - true - ? "ロゲイニングを開始" - : "間違った目的地...")) - : Container(), - ), - Obx( - () => destinationController.isAtGoal.value == true && - destinationController.rogainingCounted.value == true - ? ElevatedButton( - onPressed: () { - Get.toNamed(AppPages.CAMERA_PAGE); - Get.back(); - }, - child: Text( - //goal - indexController.currentDestinationFeature[0] - .checkedin != - null || - indexController.currentDestinationFeature[0] - .checkedin == - true - ? "ロゲイニングを終える" - : "間違った目的地 ...")) - : Container(), - ), - ], - ), - Obx( - () => indexController.currentDestinationFeature[0].address != - null && - indexController - .currentDestinationFeature[0].address!.isNotEmpty - ? getDetails(context, "address".tr, - indexController.currentDestinationFeature[0].address! ?? '') - : const SizedBox( - width: 0.0, - height: 0, - ), - ), - Obx( - () => indexController.currentDestinationFeature[0].phone != null && - indexController - .currentDestinationFeature[0].phone!.isNotEmpty - ? getDetails(context, "telephone".tr, - indexController.currentDestinationFeature[0].phone! ?? '') - : const SizedBox( - width: 0.0, - height: 0, - ), - ), - Obx( - () => indexController.currentDestinationFeature[0].email != null && - indexController - .currentDestinationFeature[0].email!.isNotEmpty - ? getDetails(context, "email".tr, - indexController.currentDestinationFeature[0].email! ?? '') - : const SizedBox( - width: 0.0, - height: 0, - ), - ), - Obx( - () => indexController.currentDestinationFeature[0].webcontents != - null && - indexController - .currentDestinationFeature[0].webcontents!.isNotEmpty - ? getDetails( - context, - "web".tr, - indexController.currentDestinationFeature[0].webcontents! ?? - '', - isurl: true) - : const SizedBox( - width: 0.0, - height: 0, - ), - ), - Obx( - () => indexController.currentDestinationFeature[0].videos != null && - indexController - .currentDestinationFeature[0].videos!.isNotEmpty - ? getDetails(context, "video".tr, - indexController.currentDestinationFeature[0].videos! ?? '', - isurl: true) - : const SizedBox( - width: 0.0, - height: 0, - ), - ), - const SizedBox( - height: 20.0, - ), - // Obx(() => - // //wantToGo(context), + // return SingleChildScrollView( + // child: Column( + // children: [ + // Padding( + // padding: const EdgeInsets.all(8.0), + // child: Row( + // children: [ + // MaterialButton( + // onPressed: () { + // Get.back(); + // //destinationController.makePrevious(indexController.currentDestinationFeature[0]); + // }, + // color: Colors.blue, + // textColor: Colors.white, + // padding: const EdgeInsets.all(16), + // shape: const CircleBorder(), + // child: const Icon( + // Icons.arrow_back_ios, + // size: 14, + // ), + // ), + // Expanded( + // child: Container( + // alignment: Alignment.center, + // child: Obx(() => indexController.currentUser.isNotEmpty + // ? Text( + // "${TextUtils.getDisplayText(indexController.currentDestinationFeature[0])} : ${TextUtils.getDisplayText(indexController.currentDestinationFeature[0])} : ${indexController.currentDestinationFeature[0].name!}", + // style: const TextStyle( + // fontSize: 15.0, + // fontWeight: FontWeight.bold, + // ), + // ) + // : Text( + // indexController.currentDestinationFeature[0].name!, + // style: const TextStyle( + // fontSize: 15.0, + // fontWeight: FontWeight.bold, + // ), + // )), + // ), + // ), + // ], + // ), + // ), + // Row( + // children: [ + // Expanded( + // child: SizedBox( + // height: 260.0, + // child: Obx(() => getImage()), + // )), + // ], + // ), + // Row( + // mainAxisAlignment: MainAxisAlignment.spaceAround, + // children: [ + // Obx( + // () => indexController.currentDestinationFeature.isNotEmpty && + // destinationController.isInCheckin.value == true && + // destinationController.isAtStart.value == false + // ? Row( + // children: [ + // ElevatedButton( + // onPressed: () { + // if (indexController.currentDestinationFeature[0] + // .checkedin == + // null || + // indexController.currentDestinationFeature[0] + // .checkedin == + // false) { + // if (indexController + // .currentDestinationFeature[0] + // .hidden_location == + // 0) { + // destinationController.skipGps = false; + // destinationController.isPhotoShoot.value = + // true; + // Get.back(); + // } else { + // destinationController.makeCheckin( + // indexController + // .currentDestinationFeature[0], + // true, + // ""); + // if (indexController + // .currentDestinationFeature[0].cp != + // -1) { + // destinationController + // .rogainingCounted.value = true; + // } + // } + // } else { + // destinationController.makeCheckin( + // indexController + // .currentDestinationFeature[0], + // false, + // ""); + // } + // //Get.back(); + // }, + // child: Text( + // //Checkin + // indexController.currentDestinationFeature[0] + // .checkedin == + // null || + // indexController + // .currentDestinationFeature[0] + // .checkedin == + // false + // ? "チェックイン" + // : "チェックアウト")), + // ], + // ) + // : Container(), + // ), + // Obx( + // () => destinationController.isAtStart.value == true + // ? ElevatedButton( + // onPressed: () { + // destinationController.isInRog.value = true; + // destinationController.addToRogaining( + // destinationController.currentLat, + // destinationController.currentLon, + // indexController + // .currentDestinationFeature[0].location_id!); + // saveGameState(); + // ExternalService() + // .startRogaining() + // .then((value) => Get.back()); + // }, + // child: Text( + // // start + // indexController.currentDestinationFeature[0] + // .checkedin != + // null || + // indexController.currentDestinationFeature[0] + // .checkedin == + // true + // ? "ロゲイニングを開始" + // : "間違った目的地...")) + // : Container(), + // ), + // Obx( + // () => destinationController.isAtGoal.value == true && + // destinationController.rogainingCounted.value == true + // ? ElevatedButton( + // onPressed: () { + // Get.toNamed(AppPages.CAMERA_PAGE); + // Get.back(); + // }, + // child: Text( + // //goal + // indexController.currentDestinationFeature[0] + // .checkedin != + // null || + // indexController.currentDestinationFeature[0] + // .checkedin == + // true + // ? "ロゲイニングを終える" + // : "間違った目的地 ...")) + // : Container(), + // ), + // ], + // ), + // Obx( + // () => indexController.currentDestinationFeature[0].address != + // null && + // indexController + // .currentDestinationFeature[0].address!.isNotEmpty + // ? getDetails(context, "address".tr, + // indexController.currentDestinationFeature[0].address! ?? '') + // : const SizedBox( + // width: 0.0, + // height: 0, + // ), + // ), + // Obx( + // () => indexController.currentDestinationFeature[0].phone != null && + // indexController + // .currentDestinationFeature[0].phone!.isNotEmpty + // ? getDetails(context, "telephone".tr, + // indexController.currentDestinationFeature[0].phone! ?? '') + // : const SizedBox( + // width: 0.0, + // height: 0, + // ), + // ), + // Obx( + // () => indexController.currentDestinationFeature[0].email != null && + // indexController + // .currentDestinationFeature[0].email!.isNotEmpty + // ? getDetails(context, "email".tr, + // indexController.currentDestinationFeature[0].email! ?? '') + // : const SizedBox( + // width: 0.0, + // height: 0, + // ), + // ), + // Obx( + // () => indexController.currentDestinationFeature[0].webcontents != + // null && + // indexController + // .currentDestinationFeature[0].webcontents!.isNotEmpty + // ? getDetails( + // context, + // "web".tr, + // indexController.currentDestinationFeature[0].webcontents! ?? + // '', + // isurl: true) + // : const SizedBox( + // width: 0.0, + // height: 0, + // ), + // ), + // Obx( + // () => indexController.currentDestinationFeature[0].videos != null && + // indexController + // .currentDestinationFeature[0].videos!.isNotEmpty + // ? getDetails(context, "video".tr, + // indexController.currentDestinationFeature[0].videos! ?? '', + // isurl: true) + // : const SizedBox( + // width: 0.0, + // height: 0, + // ), + // ), + // const SizedBox( + // height: 20.0, + // ), + // // 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, + // // ); + // // }, + // // ), - // ), - const SizedBox( - height: 60.0, - ) - ], - ), - ); + // // ), + // const SizedBox( + // height: 60.0, + // ) + // ], + // ), + // ); + // } + + Future isDestinationCheckedIn(Destination d) async { + DatabaseHelper db = DatabaseHelper.instance; + List ds = await db.getDestinationByLatLon(d.lat!, d.lon!); + + return ds.isNotEmpty; } // show add location details @@ -486,12 +498,35 @@ class BottomSheetNew extends GetView { destination.cp == -1 && destinationController.distanceToStart() <= 500 ? ElevatedButton( - onPressed: () { - Get.toNamed(AppPages.CAMERA_PAGE); - Get.back(); + onPressed: () async { + destinationController.isAtGoal.value = true; + destinationController.photos.clear(); + await showModalBottomSheet( + constraints: BoxConstraints.loose(ui.Size( + Get.width, Get.height * 0.75)), + context: Get.context!, + isScrollControlled: true, + builder: ((context) => CameraPage( + destination: destination, + ))).whenComplete(() { + destinationController.skipGps = false; + destinationController.chekcs = 0; + destinationController.isAtGoal.value = + false; + }); }, child: Text("ロゲイニングを終える")) : Container(), + //remove checkin + isAlreadyCheckedIn == true && destination.cp != -1 + ? ElevatedButton( + onPressed: () async { + destinationController + .deleteDestination(destination); + Get.back(); + }, + child: const Text("チェックイン取消")) + : Container(), // Obx( // () => destinationController.rogainingCounted.value == @@ -568,6 +603,7 @@ class BottomSheetNew extends GetView { distanceToDest <= destinationController .getForcedChckinDistance(destination) && + destinationController.isInRog.value == false && // destinationController.isInCheckin.value == // true && destinationController.rogainingCounted.value == @@ -607,7 +643,8 @@ class BottomSheetNew extends GetView { color: Theme.of(context) .colorScheme .onSecondary))) - : Container(), + : ElevatedButton( + onPressed: () {}, child: const Text("ゲーム中")), ], ), Row( diff --git a/lib/widgets/map_widget.dart b/lib/widgets/map_widget.dart index 8cfbe41..97078b9 100644 --- a/lib/widgets/map_widget.dart +++ b/lib/widgets/map_widget.dart @@ -10,6 +10,7 @@ import 'package:latlong2/latlong.dart'; 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/utils/database_helper.dart'; import 'package:rogapp/utils/text_util.dart'; import 'package:rogapp/widgets/base_layer_widget.dart'; import 'package:rogapp/widgets/bottom_sheet_new.dart'; @@ -43,18 +44,20 @@ class MapWidget extends StatelessWidget { Destination des = destinationController.festuretoDestination(fs); - showModalBottomSheet( - constraints: - BoxConstraints.loose(Size(Get.width, Get.height * 0.85)), - context: context, - isScrollControlled: true, - isDismissible: true, - builder: ((context) => BottomSheetNew( - destination: des, - )) - //builder:((context) => BottomSheetWidget()) - ).whenComplete(() { - destinationController.skipGps = false; + DatabaseHelper db = DatabaseHelper.instance; + db.getDestinationByLatLon(des.lat!, des.lon!).then((value) { + showModalBottomSheet( + constraints: BoxConstraints.loose( + Size(Get.width, Get.height * 0.85)), + context: context, + isScrollControlled: true, + isDismissible: true, + builder: ((context) => BottomSheetNew( + destination: des, isAlreadyCheckedIn: value.isNotEmpty)) + //builder:((context) => BottomSheetWidget()) + ).whenComplete(() { + destinationController.skipGps = false; + }); }); } }, diff --git a/pubspec.yaml b/pubspec.yaml index c7e0a8f..3f48580 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.24+24 +version: 1.0.25+25 environment: sdk: ">=3.1.0 <4.0.0"