From 4528871a815e35430f8012dda73e4d9ab61710de Mon Sep 17 00:00:00 2001 From: Dorian HODIN Date: Mon, 21 Nov 2022 16:25:13 +0100 Subject: [PATCH] Modification of the location and user class to stop spamming the app --- .idea/libraries/Dart_Packages.xml | 340 +++++++++--------- .idea/libraries/Dart_SDK.xml | 38 +- .../dafl_project_flutter/lib/model/user.dart | 37 +- .../lib/position/location.dart | 9 +- .../lib/views/pages/main/p_main.dart | 7 +- 5 files changed, 217 insertions(+), 214 deletions(-) diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml index b25f471..f8237c9 100644 --- a/.idea/libraries/Dart_Packages.xml +++ b/.idea/libraries/Dart_Packages.xml @@ -5,686 +5,686 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml index b6e6985..cb79f3d 100644 --- a/.idea/libraries/Dart_SDK.xml +++ b/.idea/libraries/Dart_SDK.xml @@ -1,25 +1,25 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/Sources/dafl_project_flutter/lib/model/user.dart b/Sources/dafl_project_flutter/lib/model/user.dart index c8f73ce..47c44fc 100644 --- a/Sources/dafl_project_flutter/lib/model/user.dart +++ b/Sources/dafl_project_flutter/lib/model/user.dart @@ -4,7 +4,6 @@ import '../exceptions/api_exception.dart'; import '../main.dart'; import 'music.dart'; import 'spot.dart'; -import 'package:collection/collection.dart'; class User { Timer? timer; @@ -47,28 +46,24 @@ class User { } listSpots() { - print('ajout test'); - Future rep = Location.sendCurrentLocation(); - //ex : dorian-2d2s52a15d2a5,audric-2x5s2az3d1s5wx5s1,lucas-s2a5d25a2a25d - - rep.then((String result) { - List tab = result.split(","); - //ex : [dorian-2d2s52a15d2a5 , audric-2x5s2az3d1s5wx5s1 , lucas-s2a5d25a2a25d] - - for (var element in tab) { - List tab2 = element.split("-"); - spots.add(Spot(tab2[0], Music(tab2[1]))); + int verif=0; + Future> rep = Location.sendCurrentLocation(); + //ex : dorian : 2d2s52a15d2a5 , audric : 2x5s2az3d1s5wx5s1 , lucas : s2a5d25a2a25d + rep.then((Map result) { + if (result.isNotEmpty) { + result.forEach((key, value) { + for (var element in spots) { + if (element.userId==key){ + verif=1; + } + } + if (verif==0){ + spots.add(Spot(key, Music(value))); + } + verif=0; + }); } }); - } - getListSpots() { - if (test == 0) { - test = 1; - listSpots(); - } else { - timer = - Timer.periodic(const Duration(seconds: 72), (Timer t) => listSpots()); - } } } diff --git a/Sources/dafl_project_flutter/lib/position/location.dart b/Sources/dafl_project_flutter/lib/position/location.dart index 08e441d..1978152 100644 --- a/Sources/dafl_project_flutter/lib/position/location.dart +++ b/Sources/dafl_project_flutter/lib/position/location.dart @@ -5,7 +5,7 @@ import 'dart:async'; import '../main.dart'; class Location { - static Future sendCurrentLocation() async { + static Future> sendCurrentLocation() async { Uri uri = Uri.parse("http://89.83.53.34/phpmyadmin/dafldev/insert.php"); LocationPermission permission; permission = await Geolocator.checkPermission(); @@ -28,13 +28,16 @@ class Location { return getData(); } - static Future getData() async { + static Future> getData() async { + Map spot = {}; String actualUser = MyApp.controller.currentUser.usernameDafl; Uri uri = Uri.parse("http://89.83.53.34/phpmyadmin/dafldev/distance.php"); http.Response response = await http.post(uri, body: { "id": actualUser, }); var data = jsonDecode(response.body); - return data.toString(); + data.forEach((s)=> spot.putIfAbsent(s['user'], () => s['music'])); + return spot; } } + diff --git a/Sources/dafl_project_flutter/lib/views/pages/main/p_main.dart b/Sources/dafl_project_flutter/lib/views/pages/main/p_main.dart index 326e293..93cc366 100644 --- a/Sources/dafl_project_flutter/lib/views/pages/main/p_main.dart +++ b/Sources/dafl_project_flutter/lib/views/pages/main/p_main.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'package:dafl_project_flutter/main.dart'; import 'package:flutter/material.dart'; import '../../../presentation/custom_icons_icons.dart'; @@ -32,7 +33,6 @@ class _MainPageState extends State { @override Widget build(BuildContext context) { - MyApp.controller.currentUser.getListSpots(); double height = MediaQuery.of(context).size.height; return Scaffold( resizeToAvoidBottomInset: false, @@ -110,6 +110,11 @@ class _MainPageState extends State { ), ); } + @override + void initState() { + super.initState(); + Timer timer = Timer.periodic(const Duration(seconds: 10), (Timer t) => MyApp.controller.currentUser.listSpots()); + } } class GradientText extends StatelessWidget {