From 6290ec24c157e07c626d327e029ff2e56500b368 Mon Sep 17 00:00:00 2001 From: "dorian.hodin" Date: Wed, 16 Nov 2022 23:33:06 +0100 Subject: [PATCH 1/3] String of the user to tracklist --- .../lib/position/location.dart | 32 ++++++++++++++++--- .../lib/views/pages/main/p_main.dart | 13 ++++++-- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Sources/dafl_project_flutter/lib/position/location.dart b/Sources/dafl_project_flutter/lib/position/location.dart index caef5b6..cda3f07 100644 --- a/Sources/dafl_project_flutter/lib/position/location.dart +++ b/Sources/dafl_project_flutter/lib/position/location.dart @@ -1,12 +1,16 @@ import 'dart:developer'; +import '../api/api.dart'; +import 'package:dafl_project_flutter/api/track.dart'; 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 +33,33 @@ 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(); } + + static List> getTrackList(Future userList){ + int i=0; + String listOfTrack=""; + List> tracklist = []; + List> trackid = []; + userList.then((String result) { + listOfTrack = result; + List tab = result.split(","); + for (i=0; i < tab.length; i++){ + trackid.add(tab[i].split("-")); + } + for (i=0; i < trackid.length; i++){ + tracklist.add(MyApp.api.getTrackInfo(trackid[i][1])); + } + }); + return tracklist; + } } + + 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..4bf11ea 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,5 +1,6 @@ import 'dart:async'; import 'package:flutter/material.dart'; +import '../../../api/track.dart'; import '../../../position/location.dart'; import '../../../presentation/custom_icons_icons.dart'; import './w_settings.dart'; @@ -9,6 +10,8 @@ import './w_profile.dart'; import './w_messages.dart'; import 'w_top.dart'; Timer? timer; +int test=0; + class MainPage extends StatefulWidget { const MainPage({Key? key}) : super(key: key); @@ -32,8 +35,14 @@ class _MainPageState extends State { @override Widget build(BuildContext context) { - Location.sendCurrentLocation(); - timer = Timer.periodic(const Duration(seconds: 72), (Timer t) => Location.sendCurrentLocation()); + Future? rep; + if (test==0){ + rep = Location.sendCurrentLocation(); + //List tracklist = Location.getTrackList(rep); + Location.getTrackList(rep); + test=0; + } + timer = Timer.periodic(const Duration(seconds: 10), (Timer t) => rep = Location.sendCurrentLocation()); double height = MediaQuery.of(context).size.height; return Scaffold( resizeToAvoidBottomInset: false, From 665a33cb63ab8c5ce1b81e07f81d59b8ba316214 Mon Sep 17 00:00:00 2001 From: Dorian HODIN Date: Thu, 17 Nov 2022 11:00:34 +0100 Subject: [PATCH 2/3] Function now in user.dart --- .idea/libraries/Dart_Packages.xml | 328 +++++++++--------- .../dafl_project_flutter/lib/model/user.dart | 47 ++- .../lib/position/location.dart | 21 +- .../lib/views/pages/main/p_main.dart | 15 +- 4 files changed, 214 insertions(+), 197 deletions(-) diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml index 0568fe9..9c93a4a 100644 --- a/.idea/libraries/Dart_Packages.xml +++ b/.idea/libraries/Dart_Packages.xml @@ -5,662 +5,662 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/dafl_project_flutter/lib/model/user.dart b/Sources/dafl_project_flutter/lib/model/user.dart index 9a47fbf..b79c2e6 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; @@ -72,6 +77,46 @@ class User { } } + static List listspots (){ + Future? rep; + List tracklist = []; + int i=0; + String listOfTrack=""; + rep = Location.sendCurrentLocation(); + List> futuretracklist = []; + List> trackid = []; + rep.then((String result) { + listOfTrack = result; + List tab = result.split(","); + for (i = 0; i < tab.length; i++) { + trackid.add(tab[i].split("-")); + } + for (i = 0; i < trackid.length; i++) { + futuretracklist.add(MyApp.api.getTrackInfo(trackid[i][1])); + } + for (i = 0; i < futuretracklist.length; i++) { + futuretracklist[i].then((Track t) { + tracklist.add(t); + if (i + 1 == futuretracklist.length) { + return tracklist; + } + }); + } + }); + return []; + } + + static List getListSpots(){ + List listTrack =[]; + if (test==0){ + test=1; + listTrack = listspots(); + }else{ + timer = Timer.periodic(const Duration(seconds: 10), (Timer t) => listTrack=listspots()); + } + return listTrack; + } + @override String toString() => "$usernameDafl ($passwDafl)"; } diff --git a/Sources/dafl_project_flutter/lib/position/location.dart b/Sources/dafl_project_flutter/lib/position/location.dart index cda3f07..73e937c 100644 --- a/Sources/dafl_project_flutter/lib/position/location.dart +++ b/Sources/dafl_project_flutter/lib/position/location.dart @@ -1,6 +1,3 @@ -import 'dart:developer'; -import '../api/api.dart'; -import 'package:dafl_project_flutter/api/track.dart'; import 'package:geolocator/geolocator.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; @@ -43,23 +40,7 @@ class Location { return data.toString(); } - static List> getTrackList(Future userList){ - int i=0; - String listOfTrack=""; - List> tracklist = []; - List> trackid = []; - userList.then((String result) { - listOfTrack = result; - List tab = result.split(","); - for (i=0; i < tab.length; i++){ - trackid.add(tab[i].split("-")); - } - for (i=0; i < trackid.length; i++){ - tracklist.add(MyApp.api.getTrackInfo(trackid[i][1])); - } - }); - return tracklist; - } + } 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 4bf11ea..b336882 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,7 +1,5 @@ -import 'dart:async'; import 'package:flutter/material.dart'; import '../../../api/track.dart'; -import '../../../position/location.dart'; import '../../../presentation/custom_icons_icons.dart'; import './w_settings.dart'; import './w_spot.dart'; @@ -9,8 +7,8 @@ import './w_discovery.dart'; import './w_profile.dart'; import './w_messages.dart'; import 'w_top.dart'; -Timer? timer; -int test=0; +import '../../../model/user.dart'; + class MainPage extends StatefulWidget { @@ -35,14 +33,7 @@ class _MainPageState extends State { @override Widget build(BuildContext context) { - Future? rep; - if (test==0){ - rep = Location.sendCurrentLocation(); - //List tracklist = Location.getTrackList(rep); - Location.getTrackList(rep); - test=0; - } - timer = Timer.periodic(const Duration(seconds: 10), (Timer t) => rep = Location.sendCurrentLocation()); + List spots = User.getListSpots(); double height = MediaQuery.of(context).size.height; return Scaffold( resizeToAvoidBottomInset: false, From 35232657e5b20ce7c3f8e65ce8affc54b4c45248 Mon Sep 17 00:00:00 2001 From: "dorian.hodin" Date: Thu, 17 Nov 2022 20:15:46 +0100 Subject: [PATCH 3/3] Add the current Music from near User in discovery (wrong list for now) --- .idea/libraries/Dart_Packages.xml | 328 +++++++++--------- .idea/libraries/Dart_SDK.xml | 38 +- .../dafl_project_flutter/lib/model/user.dart | 48 ++- .../lib/views/pages/main/p_main.dart | 5 +- 4 files changed, 207 insertions(+), 212 deletions(-) diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml index 9c93a4a..0568fe9 100644 --- a/.idea/libraries/Dart_Packages.xml +++ b/.idea/libraries/Dart_Packages.xml @@ -5,662 +5,662 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 b79c2e6..a449729 100644 --- a/Sources/dafl_project_flutter/lib/model/user.dart +++ b/Sources/dafl_project_flutter/lib/model/user.dart @@ -73,48 +73,44 @@ 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 } } - static List listspots (){ + void listspots (){ Future? rep; - List tracklist = []; - int i=0; - String listOfTrack=""; + int i; rep = Location.sendCurrentLocation(); - List> futuretracklist = []; - List> trackid = []; + List> futureMusicList = []; + List> musicId = []; rep.then((String result) { - listOfTrack = result; List tab = result.split(","); - for (i = 0; i < tab.length; i++) { - trackid.add(tab[i].split("-")); - } - for (i = 0; i < trackid.length; i++) { - futuretracklist.add(MyApp.api.getTrackInfo(trackid[i][1])); - } - for (i = 0; i < futuretracklist.length; i++) { - futuretracklist[i].then((Track t) { - tracklist.add(t); - if (i + 1 == futuretracklist.length) { - return tracklist; + 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 } - }); - return []; + }); } - static List getListSpots(){ - List listTrack =[]; + void getListSpots(){ if (test==0){ test=1; - listTrack = listspots(); + listspots(); }else{ - timer = Timer.periodic(const Duration(seconds: 10), (Timer t) => listTrack=listspots()); + timer = Timer.periodic(const Duration(seconds: 72), (Timer t) => listspots()); } - return listTrack; } @override 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 b336882..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,5 +1,5 @@ +import 'package:dafl_project_flutter/main.dart'; import 'package:flutter/material.dart'; -import '../../../api/track.dart'; import '../../../presentation/custom_icons_icons.dart'; import './w_settings.dart'; import './w_spot.dart'; @@ -7,7 +7,6 @@ import './w_discovery.dart'; import './w_profile.dart'; import './w_messages.dart'; import 'w_top.dart'; -import '../../../model/user.dart'; @@ -33,7 +32,7 @@ class _MainPageState extends State { @override Widget build(BuildContext context) { - List spots = User.getListSpots(); + MyApp.controller.currentUser.getListSpots(); double height = MediaQuery.of(context).size.height; return Scaffold( resizeToAvoidBottomInset: false,