diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml index cb79f3d..3dbed52 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 d1f0697..ed5e5e8 100644 --- a/Sources/dafl_project_flutter/lib/model/user.dart +++ b/Sources/dafl_project_flutter/lib/model/user.dart @@ -1,10 +1,15 @@ -import '../api/track.dart'; +import 'dart:async'; +import '../../../api/track.dart'; +import '../../../position/location.dart'; import '../exceptions/api_exception.dart'; import '../main.dart'; import 'conversation.dart'; import 'music.dart'; import 'spot.dart'; +Timer? timer; +int test=0; + class User { //attributes from DAFL late int idDafl; @@ -64,7 +69,43 @@ class User { _id = await MyApp.api.getCurrentlyPlayingTrack(); track = await MyApp.api.getTrackInfo(_id); } on ApiException { - // TODO : add notification to show that an error occured + // TODO : add notification to show that an error occurred + } + } + + void listspots (){ + Future? rep; + int i; + rep = Location.sendCurrentLocation(); + List> futureMusicList = []; + List> musicId = []; + rep.then((String result) { + List tab = result.split(","); + if (tab.isEmpty!=true) { + for (i = 0; i < tab.length; i++) { + musicId.add(tab[i].split("-")); + } + /* + for (i = 0; i < musicId.length; i++) { + // futuretracklist.add(MyApp.api.getTrackInfo(trackid[i][1])); + } + futureMusicList[i].then((Music m) { + for (i = 0; i < futureMusicList.length; i++) { + discovery.add(m); + } + }); + + */ // EN COMMENTAIRE PARCE QUE ERREUR SINON VU QUE J'AI PAS MUSIC POUR L'INSTANT + } + }); + } + + void 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 caef5b6..73e937c 100644 --- a/Sources/dafl_project_flutter/lib/position/location.dart +++ b/Sources/dafl_project_flutter/lib/position/location.dart @@ -1,12 +1,13 @@ -import 'dart:developer'; import 'package:geolocator/geolocator.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; 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(); @@ -29,13 +30,17 @@ class Location { return getData(); } - static Future getData() async { + static Future getData() async { 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.toString(), + http.Response response = await http.post(uri, body: { + "id": actualUser.toString(), }); var data = jsonDecode(response.body); return data.toString(); } + + } + + 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 5b3b0c0..326e293 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,6 +1,5 @@ -import 'dart:async'; +import 'package:dafl_project_flutter/main.dart'; import 'package:flutter/material.dart'; -import '../../../position/location.dart'; import '../../../presentation/custom_icons_icons.dart'; import './w_settings.dart'; import './w_spot.dart'; @@ -8,7 +7,8 @@ import './w_discovery.dart'; import './w_profile.dart'; import './w_messages.dart'; import 'w_top.dart'; -Timer? timer; + + class MainPage extends StatefulWidget { const MainPage({Key? key}) : super(key: key); @@ -32,8 +32,7 @@ class _MainPageState extends State { @override Widget build(BuildContext context) { - Location.sendCurrentLocation(); - timer = Timer.periodic(const Duration(seconds: 72), (Timer t) => Location.sendCurrentLocation()); + MyApp.controller.currentUser.getListSpots(); double height = MediaQuery.of(context).size.height; return Scaffold( resizeToAvoidBottomInset: false,