Android のバックグラウンドGPSを組み込み

This commit is contained in:
2024-05-06 00:06:38 +09:00
parent 7a97127a19
commit dd9343bef7
89 changed files with 521 additions and 273 deletions

View File

@ -112,7 +112,7 @@ class DestinationController extends GetxController {
DateTime lastGPSDataReceivedTime = DateTime.now();
DateTime lastPopupShownTime = DateTime.now().subtract(Duration(minutes: 10));
bool isPopupShown = false;
bool hasReceivedGPSData = false;
bool hasReceivedGPSData = true;
var isCheckingIn = false.obs; // チェックイン操作中はtrueになり、重複してポップアップが出ないようにするもの。
@ -161,31 +161,36 @@ class DestinationController extends GetxController {
*/
void showGPSDataNotReceivedPopup() {
Get.dialog(
AlertDialog(
title: Text('GPS信号が受信できません'),
content: Text('GPS信号が受信できる場所に移動してください。'),
actions: [
TextButton(
onPressed: () => Get.back(),
child: Text('OK'),
),
],
),
);
if (Get.context != null) {
Get.dialog(
AlertDialog(
title: Text('GPS信号が受信できません'),
content: Text('GPS信号が受信できる場所に移動してください。'),
actions: [
TextButton(
onPressed: () => Get.back(),
child: Text('OK'),
),
],
),
);
} else {
// Get.contextがnullの場合の処理を追加
print('GPS signal not received, but context is null');
}
}
// 最後に有効なGPSデータを受け取ってから10分以上経過している場合にのみメッセージを表示するようにします。
//
void checkGPSDataReceived() {
if (!hasReceivedGPSData) {
// GPS信号を全く受信していない。
if (!isPopupShown) {
// ポップアップしていない。
showGPSDataNotReceivedPopup();
lastPopupShownTime = DateTime.now();
isPopupShown = true;
}
//debugPrint("GPS信号を全く受信していない。");
if (!isPopupShown) {
// ポップアップしていない。
showGPSDataNotReceivedPopup();
lastPopupShownTime = DateTime.now();
isPopupShown = true;
}
} else {
if (DateTime.now().difference(lastGPSDataReceivedTime).inSeconds >= 600) {
// 前回GPS信号を受信してから10分経過。
@ -946,7 +951,7 @@ class DestinationController extends GetxController {
is_checkin: isCheckin,
created_at: DateTime.now().millisecondsSinceEpoch);
var res = await db.insertGps(gps_data);
//debugPrint("Saved GPS data into DB...");
debugPrint("Saved GPS data into DB...:${gps_data}");
}
} catch (err) {
print("errr ready gps ${err}");
@ -1188,7 +1193,7 @@ class DestinationController extends GetxController {
// ゲームを開始する関数です。
//
Future<void> startGame() async {
//print("------ starting game ------");
debugPrint("------ starting game ------");
if (game_started == false) {
await checkForCheckin();
}
@ -1206,6 +1211,7 @@ class DestinationController extends GetxController {
//
bool inError=false;
bool isRunningBackgroundGPS=false;
int activeEngineCount = 0;
@override
void onInit() async {
@ -1215,6 +1221,8 @@ class DestinationController extends GetxController {
// MapControllerの初期化完了を待機するフラグを設定
WidgetsBinding.instance.addPostFrameCallback((_) {
//checkGPSDataReceived(); removed 2024-5-4
isMapControllerReady = true;
});
@ -1280,7 +1288,7 @@ class DestinationController extends GetxController {
startGame();
checkGPSDataReceived();
//checkGPSDataReceived();
}
void restartGPS(){
@ -1308,8 +1316,11 @@ class DestinationController extends GetxController {
//
double prevLat = 0.0; // 直前の位置
double prevLon = 0.0;
bool gpsDebugMode=false;
void handleLocationUpdate(LocationMarkerPosition? position) async {
//debugPrint("DestinationController.handleLocationUpdate");
try {
//final DestinationController destinationController = Get.find<DestinationController>();
//final signalStrength = locationController.getGpsSignalStrength();
@ -1399,7 +1410,7 @@ class DestinationController extends GetxController {
lastGPSCollectedTime = DateTime.now();
prevLat = position.latitude;
prevLon = position.longitude;
debugPrint("フロントエンドでのGPS保存(時間差:${difference.inSeconds}, 距離差:${distanceToDest}) : Time=${lastGPSCollectedTime}");
gpsDebugMode ? debugPrint("フロントエンドでのGPS保存(時間差:${difference.inSeconds}, 距離差:${distanceToDest}) : Time=${lastGPSCollectedTime}"):null;
}
}
}

View File

@ -104,7 +104,7 @@ class IndexPage extends GetView<IndexController> {
// タップすることでGPS信号の強弱をシミュレーションできるようにする
// Akira 2024-4-5
//
/*
/*
Obx(() {
if (locationController.isSimulationMode) {
return DropdownButton<String>(
@ -122,34 +122,11 @@ class IndexPage extends GetView<IndexController> {
}).toList(),
);
} else {
return InkWell(
onTap: () {
locationController.setSimulatedSignalStrength('high');
},
child: const Icon(Icons.info),
);
return Container();
}
}),
*/
*/
/*
Obx(() => locationController.isSimulationMode
? DropdownButton<String>(
value: locationController.getSimulatedSignalStrength(),
onChanged: (value) {
locationController.setSimulatedSignalStrength(value!);
},
items: ['low', 'medium', 'high','real']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
)
: Container(),
),
*/
],
),
// bottomNavigationBar: BottomAppBar(

View File

@ -25,24 +25,10 @@ class LoginPage extends StatelessWidget {
backgroundColor: Colors.white,
automaticallyImplyLeading: false,
),
/* 2024-04-03 Updated by Akira . See https://wiki.sumasen.net/issues/2796?issue_count=1&issue_position=1
appBar: AppBar(
elevation: 0,
backgroundColor: Colors.white,
leading: IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: const Icon(
Icons.arrow_back_ios,
size: 20,
color: Colors.black,
)),
),
*/
body: indexController.currentUser.isEmpty
? SizedBox(
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
@ -129,30 +115,6 @@ class LoginPage extends StatelessWidget {
emailController.text,
passwordController.text,
context);
/*
try {
bool isLoggedIn = await indexController.login(emailController.text, passwordController.text,context);
if (isLoggedIn) {
Get.offAllNamed(AppPages.INDEX);
} else {
Get.snackbar(
"Login Failed",
"Invalid email or password",
icon: const Icon(Icons.error, color: Colors.red),
snackPosition: SnackPosition.BOTTOM,
);
}
} catch (e) {
Get.snackbar(
"Error",
"An error occurred during login",
icon: const Icon(Icons.error, color: Colors.red),
snackPosition: SnackPosition.BOTTOM,
);
} finally {
indexController.isLoading.value = false;
}
*/ // ここまで
},
color: Colors.indigoAccent[400],
shape: RoundedRectangleBorder(
@ -165,16 +127,6 @@ class LoginPage extends StatelessWidget {
fontSize: 16,
color: Colors.white70),
),
/*
child: Obx(
() => indexController.isLoading.value
? const CircularProgressIndicator(color: Colors.white)
: const Text(
"ログイン",
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 16, color: Colors.white70),
),
),
*/ // ここまで
),
const SizedBox(
height: 5.0,
@ -223,7 +175,7 @@ class LoginPage extends StatelessWidget {
),
)),
const SizedBox(
height: 5,
height: 3,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
@ -280,6 +232,7 @@ class LoginPage extends StatelessWidget {
),
],
),
)
: TextButton(
onPressed: () {