|
|
@ -1,70 +1,79 @@
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:dafl_project_flutter/controller/live_datas.dart';
|
|
|
|
import 'package:dafl_project_flutter/model/music.dart';
|
|
|
|
import 'package:dafl_project_flutter/model/music.dart';
|
|
|
|
|
|
|
|
import 'package:dafl_project_flutter/model/spot.dart';
|
|
|
|
import 'package:dafl_project_flutter/services/api/api_spotify.dart';
|
|
|
|
import 'package:dafl_project_flutter/services/api/api_spotify.dart';
|
|
|
|
import 'package:dafl_project_flutter/services/database/database_service.dart';
|
|
|
|
import 'package:dafl_project_flutter/services/database/database_service.dart';
|
|
|
|
import 'package:dafl_project_flutter/services/position/location.dart';
|
|
|
|
import 'package:dafl_project_flutter/services/position/location.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import '../model/spot.dart';
|
|
|
|
|
|
|
|
import '../model/user.dart';
|
|
|
|
import '../model/user.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class Controller {
|
|
|
|
class Controller {
|
|
|
|
ApiSpotify _api = ApiSpotify();
|
|
|
|
ApiSpotify _api = ApiSpotify();
|
|
|
|
late User _currentUser;
|
|
|
|
late User _currentUser;
|
|
|
|
final Location _location = Location();
|
|
|
|
|
|
|
|
final DataBaseService _dataBaseService = DataBaseService();
|
|
|
|
final DataBaseService _dataBaseService = DataBaseService();
|
|
|
|
bool sortChoice = false; //false = sort by name ; true = sort by date
|
|
|
|
final LiveDatas _datas = LiveDatas();
|
|
|
|
|
|
|
|
|
|
|
|
late BuildContext navigatorKey;
|
|
|
|
late BuildContext navigatorKey;
|
|
|
|
|
|
|
|
|
|
|
|
Uri getApiUrlAuthorize() {
|
|
|
|
//
|
|
|
|
return _api.identification.urlAuthorize;
|
|
|
|
// Methods to manage datas
|
|
|
|
}
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
String getApiRedirectUrl() {
|
|
|
|
// Datas that can change
|
|
|
|
return _api.identification.redirectUri;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apiAuthorization(url) {
|
|
|
|
bool getChoice() => _datas.discoveriesSortChoice;
|
|
|
|
_api.apiAuthorization(url);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String getIdSpotify() {
|
|
|
|
setChoice(bool c) {
|
|
|
|
return _currentUser.idSpotify;
|
|
|
|
_datas.discoveriesSortChoice = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<Music> getCompleteMusic(String id) async {
|
|
|
|
Music getCurrentMusic() => _datas.userCurrentMusic;
|
|
|
|
Map infos = await _api.requests.getTrackInfo(id);
|
|
|
|
|
|
|
|
return Music(id, infos['name'], infos['artist'], infos['cover']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setCurrentMusic() async {
|
|
|
|
setCurrentMusic() async {
|
|
|
|
_currentUser.currentMusic = await _api.requests.getCurrentlyPlayingTrack();
|
|
|
|
_datas.userCurrentMusic =
|
|
|
|
|
|
|
|
await getCompleteMusic(await _api.requests.getCurrentlyPlayingTrack());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String getCurrentMusic() {
|
|
|
|
List<Spot> getSpots() => _datas.spots;
|
|
|
|
return _currentUser.currentMusic;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int getIdDafl() {
|
|
|
|
setSpots() async {
|
|
|
|
return _currentUser.idDafl;
|
|
|
|
_datas.spots = await Location.sendCurrentLocation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<Spot> getSpots() {
|
|
|
|
Map<Music, DateTime> getDiscoveries() => _datas.discoveries;
|
|
|
|
return _location.spots;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getLocation() async {
|
|
|
|
setDiscoveries() async {
|
|
|
|
await _location.sendCurrentLocation();
|
|
|
|
Map<String, DateTime> tmpData = await _api.requests.getPlaylistTracks();
|
|
|
|
|
|
|
|
Map<Music, DateTime> tmpCast = {};
|
|
|
|
|
|
|
|
tmpData.forEach((key, value) async {
|
|
|
|
|
|
|
|
tmpCast[(await getCompleteMusic(key))] = value;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
_datas.discoveries = tmpCast;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
playTrack(String id) {
|
|
|
|
//Data that can not change
|
|
|
|
_api.requests.playTrack(id);
|
|
|
|
|
|
|
|
|
|
|
|
Uri getApiUrlAuthorize() => _api.identification.urlAuthorize;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String getApiRedirectUrl() => _api.identification.redirectUri;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String getIdSpotify() => _currentUser.idSpotify;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int getIdDafl() => _currentUser.idDafl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//Other methods
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apiAuthorization(url) {
|
|
|
|
|
|
|
|
_api.apiAuthorization(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<Map<String, DateTime>> getDiscoveries() async {
|
|
|
|
Future<Music> getCompleteMusic(String id) async {
|
|
|
|
_currentUser.discoveries = await _api.requests.getPlaylistTracks();
|
|
|
|
Map infos = await _api.requests.getTrackInfo(id);
|
|
|
|
return _currentUser.discoveries;
|
|
|
|
return Music(id, infos['name'], infos['artist'], infos['cover']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
removeFromPlaylist(String id) {
|
|
|
|
removeFromPlaylist(String id) {
|
|
|
@ -75,6 +84,10 @@ class Controller {
|
|
|
|
_api.requests.addToPlaylist(id);
|
|
|
|
_api.requests.addToPlaylist(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
playTrack(String id) {
|
|
|
|
|
|
|
|
_api.requests.playTrack(id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// DATABASE
|
|
|
|
// DATABASE
|
|
|
|
void save(User userToSave) {
|
|
|
|
void save(User userToSave) {
|
|
|
|
_dataBaseService.save(userToSave);
|
|
|
|
_dataBaseService.save(userToSave);
|
|
|
|