diff --git a/Sources/dafl_project_flutter/assets/images/alpha_sort_icon.png b/Sources/dafl_project_flutter/assets/images/alpha_sort_icon.png new file mode 100644 index 0000000..398416a Binary files /dev/null and b/Sources/dafl_project_flutter/assets/images/alpha_sort_icon.png differ diff --git a/Sources/dafl_project_flutter/assets/images/date_sort_icon.png b/Sources/dafl_project_flutter/assets/images/date_sort_icon.png new file mode 100644 index 0000000..d1eb728 Binary files /dev/null and b/Sources/dafl_project_flutter/assets/images/date_sort_icon.png differ diff --git a/Sources/dafl_project_flutter/lib/main.dart b/Sources/dafl_project_flutter/lib/main.dart index 69a4c6d..4de3350 100644 --- a/Sources/dafl_project_flutter/lib/main.dart +++ b/Sources/dafl_project_flutter/lib/main.dart @@ -223,6 +223,7 @@ class CardProvider extends ChangeNotifier { ); if (!MyApp.controller.currentUser.discovery .contains(MyApp.controller.currentUser.spots.last.music)) { + MyApp.controller.currentUser.spots.last.music.defineDate(); MyApp.controller.currentUser .addDiscovery(MyApp.controller.currentUser.spots.last.music); notifyListeners(); diff --git a/Sources/dafl_project_flutter/lib/model/music.dart b/Sources/dafl_project_flutter/lib/model/music.dart index 74bb1ab..a7db91a 100644 --- a/Sources/dafl_project_flutter/lib/model/music.dart +++ b/Sources/dafl_project_flutter/lib/model/music.dart @@ -1,11 +1,11 @@ -class Music{ +class Music { String name; String artist; String linkCover; + late DateTime date; Music(this.name, this.artist, this.linkCover); - @override bool operator ==(Object other) => identical(this, other) || @@ -16,4 +16,8 @@ class Music{ @override int get hashCode => name.hashCode ^ artist.hashCode; -} \ No newline at end of file + + void defineDate() { + this.date = new DateTime.now(); + } +} diff --git a/Sources/dafl_project_flutter/lib/model/user.dart b/Sources/dafl_project_flutter/lib/model/user.dart index ed5e5e8..88b7ecb 100644 --- a/Sources/dafl_project_flutter/lib/model/user.dart +++ b/Sources/dafl_project_flutter/lib/model/user.dart @@ -8,7 +8,7 @@ import 'music.dart'; import 'spot.dart'; Timer? timer; -int test=0; +int test = 0; class User { //attributes from DAFL @@ -19,6 +19,7 @@ class User { //attributes with Spotify API late String _id; late Track track; + bool sortChoise = true; //constructors User(this.usernameDafl, this.passwDafl) { @@ -73,7 +74,7 @@ class User { } } - void listspots (){ + void listspots() { Future? rep; int i; rep = Location.sendCurrentLocation(); @@ -81,7 +82,7 @@ class User { List> musicId = []; rep.then((String result) { List tab = result.split(","); - if (tab.isEmpty!=true) { + if (tab.isEmpty != true) { for (i = 0; i < tab.length; i++) { musicId.add(tab[i].split("-")); } @@ -97,15 +98,16 @@ class User { */ // EN COMMENTAIRE PARCE QUE ERREUR SINON VU QUE J'AI PAS MUSIC POUR L'INSTANT } - }); + }); } - void getListSpots(){ - if (test==0){ - test=1; + void getListSpots() { + if (test == 0) { + test = 1; listspots(); - }else{ - timer = Timer.periodic(const Duration(seconds: 72), (Timer t) => listspots()); + } else { + timer = + Timer.periodic(const Duration(seconds: 72), (Timer t) => listspots()); } } diff --git a/Sources/dafl_project_flutter/lib/views/pages/main/w_discovery.dart b/Sources/dafl_project_flutter/lib/views/pages/main/w_discovery.dart index 11f6032..8029274 100644 --- a/Sources/dafl_project_flutter/lib/views/pages/main/w_discovery.dart +++ b/Sources/dafl_project_flutter/lib/views/pages/main/w_discovery.dart @@ -2,6 +2,8 @@ import 'package:dafl_project_flutter/main.dart'; import 'package:fluttericon/font_awesome5_icons.dart'; import 'package:flutter/material.dart'; +import '../../../model/music.dart'; + class DiscoveryWidget extends StatefulWidget { const DiscoveryWidget({Key? key}) : super(key: key); @@ -20,25 +22,42 @@ class _DiscoveryWidgetState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( - padding: const EdgeInsets.fromLTRB(30, 0, 30, 0), + padding: const EdgeInsets.fromLTRB(30, 0, 10, 0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row(children: const [ - Text( - 'Playlist découverte', - style: TextStyle( - color: Colors.white, - fontWeight: FontWeight.w500, - fontSize: 25), - ), - Spacer(), - Icon( - FontAwesome5.sort_amount_down, - size: 30, - color: Colors.white, - ), - ]), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + 'Playlist découverte', + style: TextStyle( + color: Colors.white, + fontWeight: FontWeight.w500, + fontSize: 25), + ), + OutlinedButton( + onPressed: () { + MyApp.controller.currentUser.sortChoise = + !MyApp.controller.currentUser.sortChoise; + setState(() {}); + }, + style: OutlinedButton.styleFrom( + shadowColor: Colors.black, + shape: CircleBorder(), + padding: EdgeInsets.all(24), + primary: Colors.grey), + child: MyApp.controller.currentUser.sortChoise + ? Image.asset( + 'assets/images/date_sort_icon.png', + height: 25, + ) + : Image.asset( + 'assets/images/alpha_sort_icon.png', + height: 25, + ), + ), + ]), const Padding(padding: EdgeInsets.fromLTRB(0, 5, 0, 0)), Text( 'Retrouvez ici vos nouvelles découvertes.', @@ -83,38 +102,46 @@ class _DiscoveryListState extends State { refreshList() async { await Future.delayed(const Duration(seconds: 1)); - setState(() { - MyApp.controller.currentUser.discovery; - }); + setState(() {}); } @override Widget build(BuildContext context) { + List listDiscovery = MyApp.controller.currentUser.discovery; + if (MyApp.controller.currentUser.sortChoise) { + listDiscovery.sort((a, b) { + return a.date.compareTo(b.date); + }); + } else { + listDiscovery.sort((a, b) { + return a.name.compareTo(b.name); + }); + } return RefreshIndicator( onRefresh: () async { refreshList(); + setState(() {}); }, key: refreshKey, child: ListView.builder( - itemCount: MyApp.controller.currentUser.discovery.length, + itemCount: listDiscovery.length, itemBuilder: (context, index) { - int itemCount = MyApp.controller.currentUser.discovery.length; + int itemCount = listDiscovery.length; int reversedIndex = itemCount - 1 - index; return Dismissible( - key: Key(MyApp - .controller.currentUser.discovery[reversedIndex].name), + movementDuration: Duration(milliseconds: 400), + key: Key(listDiscovery[index].name), confirmDismiss: (direction) async { if (direction == DismissDirection.endToStart) { + print(listDiscovery[reversedIndex].name); MyApp.controller.currentUser.discovery - .removeAt(reversedIndex); - setState(() { - itemCount -= 1; - }); - return true; + .remove(listDiscovery[reversedIndex]); + setState(() {}); } }, onDismissed: (direction) { if (direction == DismissDirection.startToEnd) { + print(listDiscovery[reversedIndex].name); print('play'); } }, @@ -184,7 +211,7 @@ class _DiscoveryListState extends State { color: Colors.white .withOpacity(0.6), fontSize: 16, - fontWeight: FontWeight.w400)) + fontWeight: FontWeight.w400)), ])) ])) ])));