From 4609237105e4854d49ca5a4cbde145b8d0412613 Mon Sep 17 00:00:00 2001 From: emkartal1 Date: Tue, 1 Aug 2023 02:02:15 +0200 Subject: [PATCH 1/2] Add function getAvailable --- .../components/editable_post_component.dart | 2 +- .../lib/components/top_nav_bar_component.dart | 10 +- .../justMUSIC/lib/screens/feed_screen.dart | 119 ++++++++++++------ .../justMUSIC/lib/services/AuthService.dart | 2 +- .../justMUSIC/lib/services/PostService.dart | 40 +++++- .../lib/view_model/PostViewModel.dart | 14 ++- 6 files changed, 141 insertions(+), 46 deletions(-) diff --git a/Sources/justMUSIC/lib/components/editable_post_component.dart b/Sources/justMUSIC/lib/components/editable_post_component.dart index 25eec5a..e028916 100644 --- a/Sources/justMUSIC/lib/components/editable_post_component.dart +++ b/Sources/justMUSIC/lib/components/editable_post_component.dart @@ -65,7 +65,7 @@ class _EditablePostComponentState extends State with Tick try { final image = await ImagePicker().pickImage( source: source, - imageQuality: 25, + imageQuality: 10 ); if (image == null) return; final imageTemp = File(image.path); diff --git a/Sources/justMUSIC/lib/components/top_nav_bar_component.dart b/Sources/justMUSIC/lib/components/top_nav_bar_component.dart index 60ce617..98717ff 100644 --- a/Sources/justMUSIC/lib/components/top_nav_bar_component.dart +++ b/Sources/justMUSIC/lib/components/top_nav_bar_component.dart @@ -31,6 +31,11 @@ class _TopNavBarComponentState extends State with TickerProv MyApp.postViewModel.getBestPosts(); } + void checkAvailable() async { + var res = await MyApp.postViewModel.getAvailable(); + showCapsuleDot(res); + } + @override void initState() { _controller = AnimationController( @@ -109,6 +114,7 @@ class _TopNavBarComponentState extends State with TickerProv @override Widget build(BuildContext context) { + checkAvailable(); return Padding( padding: const EdgeInsets.only(top: defaultPadding), child: Container( @@ -142,9 +148,7 @@ class _TopNavBarComponentState extends State with TickerProv enableLongTapRepeatEvent: false, longTapRepeatDuration: const Duration(milliseconds: 100), begin: 1.0, - onTap: () { - showCapsuleDot(true); - }, + onTap: () {}, end: 0.97, beginDuration: const Duration(milliseconds: 70), endDuration: const Duration(milliseconds: 100), diff --git a/Sources/justMUSIC/lib/screens/feed_screen.dart b/Sources/justMUSIC/lib/screens/feed_screen.dart index 82026ff..f619441 100644 --- a/Sources/justMUSIC/lib/screens/feed_screen.dart +++ b/Sources/justMUSIC/lib/screens/feed_screen.dart @@ -17,7 +17,8 @@ class FeedScreen extends StatefulWidget { State createState() => _FeedScreenState(); } -class _FeedScreenState extends State with SingleTickerProviderStateMixin { +class _FeedScreenState extends State + with SingleTickerProviderStateMixin { late AnimationController animationController; late Animation animation; late List friendFeed; @@ -85,7 +86,8 @@ class _FeedScreenState extends State with SingleTickerProviderStateM isScrollControlled: true, context: context, shape: const RoundedRectangleBorder( - borderRadius: BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20))), + borderRadius: BorderRadius.only( + topLeft: Radius.circular(20), topRight: Radius.circular(20))), builder: ((BuildContext context) { return GestureDetector( onTap: () { @@ -104,19 +106,24 @@ class _FeedScreenState extends State with SingleTickerProviderStateM child: Container( width: 60, height: 5, - decoration: - BoxDecoration(color: Colors.white.withOpacity(0.3), borderRadius: BorderRadius.circular(20))), + decoration: BoxDecoration( + color: Colors.white.withOpacity(0.3), + borderRadius: BorderRadius.circular(20))), ), const SizedBox( height: 20, ), Expanded( child: ClipRRect( - borderRadius: BorderRadius.only(topRight: Radius.circular(15), topLeft: Radius.circular(15)), + borderRadius: BorderRadius.only( + topRight: Radius.circular(15), + topLeft: Radius.circular(15)), child: Padding( - padding: EdgeInsets.only(left: defaultPadding, right: defaultPadding), + padding: EdgeInsets.only( + left: defaultPadding, right: defaultPadding), child: SingleChildScrollView( - physics: BouncingScrollPhysics(decelerationRate: ScrollDecelerationRate.fast), + physics: BouncingScrollPhysics( + decelerationRate: ScrollDecelerationRate.fast), child: Wrap( // to apply margin in the main axis of the wrap runSpacing: 10, @@ -131,21 +138,25 @@ class _FeedScreenState extends State with SingleTickerProviderStateM ? Container() : Padding( padding: const EdgeInsets.only(bottom: 20), - child: Text('${displayFeed[index].description ?? ""}', + child: Text( + '${displayFeed[index].description ?? ""}', style: GoogleFonts.plusJakartaSans( - color: Colors.white, fontWeight: FontWeight.w200)), + color: Colors.white, + fontWeight: FontWeight.w200)), ), Align( child: RichText( text: TextSpan( text: "3", - style: - GoogleFonts.plusJakartaSans(color: Colors.white, fontWeight: FontWeight.w600), + style: GoogleFonts.plusJakartaSans( + color: Colors.white, + fontWeight: FontWeight.w600), children: [ TextSpan( text: " commentaires", - style: - GoogleFonts.plusJakartaSans(color: Colors.white, fontWeight: FontWeight.w300), + style: GoogleFonts.plusJakartaSans( + color: Colors.white, + fontWeight: FontWeight.w300), ) ])), ), @@ -161,12 +172,15 @@ class _FeedScreenState extends State with SingleTickerProviderStateM ), ), Padding( - padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), + padding: EdgeInsets.only( + bottom: MediaQuery.of(context).viewInsets.bottom), child: Container( height: 70, width: double.infinity, decoration: BoxDecoration( - border: Border(top: BorderSide(color: grayColor, width: 2)), color: textFieldMessage), + border: Border( + top: BorderSide(color: grayColor, width: 2)), + color: textFieldMessage), child: Center( child: Padding( padding: const EdgeInsets.symmetric(horizontal: 20), @@ -176,7 +190,8 @@ class _FeedScreenState extends State with SingleTickerProviderStateM child: SizedBox.fromSize( // Image radius child: const Image( - image: AssetImage("assets/images/exemple_profile.png"), + image: AssetImage( + "assets/images/exemple_profile.png"), width: 45, ), ), @@ -189,7 +204,8 @@ class _FeedScreenState extends State with SingleTickerProviderStateM keyboardAppearance: Brightness.dark, cursorColor: primaryColor, keyboardType: TextInputType.emailAddress, - style: GoogleFonts.plusJakartaSans(color: Colors.white), + style: GoogleFonts.plusJakartaSans( + color: Colors.white), decoration: InputDecoration( suffixIcon: Icon( Icons.send, @@ -197,17 +213,27 @@ class _FeedScreenState extends State with SingleTickerProviderStateM size: 20, ), focusedBorder: OutlineInputBorder( - borderSide: BorderSide(width: 1, color: grayText), - borderRadius: BorderRadius.all(Radius.circular(100))), - contentPadding: EdgeInsets.only(top: 0, bottom: 0, left: 20, right: 20), + borderSide: BorderSide( + width: 1, color: grayText), + borderRadius: BorderRadius.all( + Radius.circular(100))), + contentPadding: EdgeInsets.only( + top: 0, + bottom: 0, + left: 20, + right: 20), fillColor: bgModal, filled: true, - focusColor: Color.fromRGBO(255, 255, 255, 0.30), + focusColor: + Color.fromRGBO(255, 255, 255, 0.30), enabledBorder: OutlineInputBorder( - borderSide: BorderSide(width: 1, color: grayText), - borderRadius: BorderRadius.all(Radius.circular(100))), + borderSide: BorderSide( + width: 1, color: grayText), + borderRadius: BorderRadius.all( + Radius.circular(100))), hintText: 'Ajoutez une réponse...', - hintStyle: GoogleFonts.plusJakartaSans(color: grayText)), + hintStyle: GoogleFonts.plusJakartaSans( + color: grayText)), ), ) ], @@ -238,16 +264,21 @@ class _FeedScreenState extends State with SingleTickerProviderStateM Container( decoration: const BoxDecoration( image: DecorationImage( - image: AssetImage("assets/images/empty_bg.png"), fit: BoxFit.cover, opacity: 0.3), + image: AssetImage("assets/images/empty_bg.png"), + fit: BoxFit.cover, + opacity: 0.3), ), child: Padding( - padding: EdgeInsets.only(top: 140.h, left: defaultPadding), + padding: + EdgeInsets.only(top: 140.h, left: defaultPadding), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text("Suis tes amis pour voir leurs capsules", style: GoogleFonts.plusJakartaSans( - color: Colors.white, fontSize: 23, fontWeight: FontWeight.w800)) + color: Colors.white, + fontSize: 23, + fontWeight: FontWeight.w800)) ], ), ), @@ -260,8 +291,14 @@ class _FeedScreenState extends State with SingleTickerProviderStateM decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.topRight, - stops: [0.3, 1], - colors: [bgColor.withOpacity(0.9), bgColor.withOpacity(0)])), + stops: [ + 0.3, + 1 + ], + colors: [ + bgColor.withOpacity(0.9), + bgColor.withOpacity(0) + ])), ), ), ), @@ -281,26 +318,32 @@ class _FeedScreenState extends State with SingleTickerProviderStateM fit: StackFit.expand, children: [ Align( + alignment: Alignment.topCenter, child: CircularRevealAnimation( animation: animation, centerOffset: Offset(30.w, -100), child: Container( constraints: BoxConstraints(maxWidth: 600), - padding: EdgeInsets.fromLTRB(defaultPadding, 100.h, defaultPadding, 0), + padding: EdgeInsets.fromLTRB( + defaultPadding, 100.h, defaultPadding, 0), child: RefreshIndicator( displacement: 20, triggerMode: RefreshIndicatorTriggerMode.onEdge, onRefresh: _refresh, child: ListView.builder( - physics: const BouncingScrollPhysics(decelerationRate: ScrollDecelerationRate.fast), + physics: const BouncingScrollPhysics( + decelerationRate: + ScrollDecelerationRate.fast), clipBehavior: Clip.none, shrinkWrap: true, itemCount: displayFeed.length, itemBuilder: (BuildContext context, int index) { return Padding( padding: const EdgeInsets.only(bottom: 40), - child: - PostComponent(callback: openDetailPost, post: displayFeed[index], index: index), + child: PostComponent( + callback: openDetailPost, + post: displayFeed[index], + index: index), ); }, ), @@ -315,8 +358,14 @@ class _FeedScreenState extends State with SingleTickerProviderStateM decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.topRight, - stops: [0.3, 1], - colors: [bgColor.withOpacity(0.9), bgColor.withOpacity(0)])), + stops: [ + 0.3, + 1 + ], + colors: [ + bgColor.withOpacity(0.9), + bgColor.withOpacity(0) + ])), ), ), ), diff --git a/Sources/justMUSIC/lib/services/AuthService.dart b/Sources/justMUSIC/lib/services/AuthService.dart index dd6679b..ed3ad4a 100644 --- a/Sources/justMUSIC/lib/services/AuthService.dart +++ b/Sources/justMUSIC/lib/services/AuthService.dart @@ -21,7 +21,7 @@ class AuthService { "nbCapsules": 0, "followers": 0, "picture": - "https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/defaultImage.png?alt=media&token=cff5ae0a-e29e-4845-91f7-817597962f6b", + "https://firebasestorage.googleapis.com/v0/b/justmusic-435d5.appspot.com/o/justMusicDefaultImage.png?alt=media&token=020d0fcb-b7df-4d4d-b380-e99597293fcc", "friends": [], "comments": [] }; diff --git a/Sources/justMUSIC/lib/services/PostService.dart b/Sources/justMUSIC/lib/services/PostService.dart index 205c8fa..b7f87d2 100644 --- a/Sources/justMUSIC/lib/services/PostService.dart +++ b/Sources/justMUSIC/lib/services/PostService.dart @@ -8,7 +8,8 @@ import 'package:firebase_storage/firebase_storage.dart'; import '../main.dart'; class PostService { - createPost(String? description, String idMusic, File? image, Tuple2? location) async { + createPost(String? description, String idMusic, File? image, + Tuple2? location) async { var id = MyApp.userViewModel.userCurrent.id; final post = { "user_id": id, @@ -44,9 +45,38 @@ class PostService { getPostsById(String id) {} - Future>>> getPopularPosts({int limit = 10, int offset = 0}) async { - QuerySnapshot> response = - await FirebaseFirestore.instance.collection("posts").limit(limit).orderBy("likes").get(); - return response.docs; + Future>>> getPopularPosts( + {int limit = 10, int offset = 0}) async { + DateTime twentyFourHoursAgo = DateTime.now().subtract(Duration(hours: 24)); + Timestamp twentyFourHoursAgoTimestamp = + Timestamp.fromDate(twentyFourHoursAgo); + + QuerySnapshot> response = await FirebaseFirestore + .instance + .collection("posts") + .where("date", isGreaterThan: twentyFourHoursAgoTimestamp) + .limit(limit) + .get(); + + var filteredPosts = response.docs.where((doc) { + String user = doc["user_id"]; // Assuming the field name is "date" + return user != MyApp.userViewModel.userCurrent.id; + }).toList(); + return filteredPosts; + } + + Future getAvailable(String idUser) async { + DateTime today = DateTime.now(); + today = DateTime(today.year, today.month, today.day); + + QuerySnapshot> response = await FirebaseFirestore + .instance + .collection("posts") + .where("user_id", isEqualTo: idUser) + .where("date", isGreaterThanOrEqualTo: today) + .where("date", isLessThan: today.add(Duration(days: 1))) + .get(); + + return response.docs.isNotEmpty; } } diff --git a/Sources/justMUSIC/lib/view_model/PostViewModel.dart b/Sources/justMUSIC/lib/view_model/PostViewModel.dart index 9c5aee8..2980018 100644 --- a/Sources/justMUSIC/lib/view_model/PostViewModel.dart +++ b/Sources/justMUSIC/lib/view_model/PostViewModel.dart @@ -22,7 +22,8 @@ class PostViewModel { List get bestPosts => _bestPosts; // Methods - addPost(String? description, String idMusic, File? image, Tuple2? location) async { + addPost(String? description, String idMusic, File? image, + Tuple2? location) async { await _postService.createPost(description, idMusic, image, location); } @@ -50,6 +51,7 @@ class PostViewModel { return _bestPosts; } catch (e) { print(e); + _bestPosts = []; return []; } } @@ -57,4 +59,14 @@ class PostViewModel { List getMoreBestPosts() { throw new Error(); } + + Future getAvailable() async { + try { + return await _postService + .getAvailable(MyApp.userViewModel.userCurrent.id); + } catch (e) { + print(e); + rethrow; + } + } } -- 2.36.3 From 5668d2ff36ff151be603c576857c8165ad76cfd6 Mon Sep 17 00:00:00 2001 From: Lucas Delanier Date: Tue, 1 Aug 2023 03:02:00 +0200 Subject: [PATCH 2/2] fix notif with text but still error gestion mutliple notif --- .../lib/components/top_nav_bar_component.dart | 34 +++++++++++++------ .../lib/screens/add_friend_screen.dart | 2 +- .../justMUSIC/lib/screens/profile_screen.dart | 2 +- .../justMUSIC/lib/services/PostService.dart | 31 ++++++++--------- 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/Sources/justMUSIC/lib/components/top_nav_bar_component.dart b/Sources/justMUSIC/lib/components/top_nav_bar_component.dart index 98717ff..fbc25d9 100644 --- a/Sources/justMUSIC/lib/components/top_nav_bar_component.dart +++ b/Sources/justMUSIC/lib/components/top_nav_bar_component.dart @@ -23,6 +23,7 @@ class TopNavBarComponent extends StatefulWidget { class _TopNavBarComponentState extends State with TickerProviderStateMixin { bool choice = true; late AnimationController _controller; + bool isDismissed = true; final DateTime midnight = DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day + 1); @@ -31,11 +32,6 @@ class _TopNavBarComponentState extends State with TickerProv MyApp.postViewModel.getBestPosts(); } - void checkAvailable() async { - var res = await MyApp.postViewModel.getAvailable(); - showCapsuleDot(res); - } - @override void initState() { _controller = AnimationController( @@ -112,9 +108,21 @@ class _TopNavBarComponentState extends State with TickerProv ).show(context); } + void checkAvailable() async { + print("test"); + var res = await MyApp.postViewModel.getAvailable(); + print(res); + ModalRoute? route = ModalRoute.of(context); + if (route != null) { + if (route.settings.name != '/flushbarRoute') { + print("yes"); + showCapsuleDot(res); + } + } + } + @override Widget build(BuildContext context) { - checkAvailable(); return Padding( padding: const EdgeInsets.only(top: defaultPadding), child: Container( @@ -129,8 +137,11 @@ class _TopNavBarComponentState extends State with TickerProv flex: 1, child: GestureDetector( behavior: HitTestBehavior.translucent, - onTap: () { - Navigator.of(context).push(routeAddFriend()); + onTap: () async { + bool returnFromOtherPage = await Navigator.of(context).push(routeAddFriend()); + if (returnFromOtherPage == true) { + checkAvailable(); + } }, child: const Icon( Icons.person_add_alt_1_rounded, @@ -225,8 +236,11 @@ class _TopNavBarComponentState extends State with TickerProv Flexible( flex: 1, child: GestureDetector( - onTap: () { - Navigator.of(context).push(routeProfile()); + onTap: () async { + bool returnFromOtherPage = await Navigator.of(context).push(routeProfile()); + if (returnFromOtherPage == true) { + checkAvailable(); + } }, child: ClipOval( child: SizedBox.fromSize( diff --git a/Sources/justMUSIC/lib/screens/add_friend_screen.dart b/Sources/justMUSIC/lib/screens/add_friend_screen.dart index b4024df..298caf6 100644 --- a/Sources/justMUSIC/lib/screens/add_friend_screen.dart +++ b/Sources/justMUSIC/lib/screens/add_friend_screen.dart @@ -169,7 +169,7 @@ class _AddFriendScreenState extends State { GestureDetector( behavior: HitTestBehavior.translucent, onTap: () { - Navigator.pop(context); + Navigator.pop(context, true); }, child: Transform( alignment: Alignment.center, diff --git a/Sources/justMUSIC/lib/screens/profile_screen.dart b/Sources/justMUSIC/lib/screens/profile_screen.dart index e3ff26e..3fd339c 100644 --- a/Sources/justMUSIC/lib/screens/profile_screen.dart +++ b/Sources/justMUSIC/lib/screens/profile_screen.dart @@ -32,7 +32,7 @@ class _ProfileScreenState extends State { GestureDetector( behavior: HitTestBehavior.translucent, onTap: () { - Navigator.pop(context); + Navigator.pop(context, true); }, child: Container( padding: EdgeInsets.symmetric(horizontal: 10), diff --git a/Sources/justMUSIC/lib/services/PostService.dart b/Sources/justMUSIC/lib/services/PostService.dart index b7f87d2..7b3e76a 100644 --- a/Sources/justMUSIC/lib/services/PostService.dart +++ b/Sources/justMUSIC/lib/services/PostService.dart @@ -2,14 +2,14 @@ import 'dart:convert'; import 'dart:io'; import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:intl/intl.dart'; import 'package:tuple/tuple.dart'; import 'package:firebase_storage/firebase_storage.dart'; import '../main.dart'; class PostService { - createPost(String? description, String idMusic, File? image, - Tuple2? location) async { + createPost(String? description, String idMusic, File? image, Tuple2? location) async { var id = MyApp.userViewModel.userCurrent.id; final post = { "user_id": id, @@ -45,14 +45,11 @@ class PostService { getPostsById(String id) {} - Future>>> getPopularPosts( - {int limit = 10, int offset = 0}) async { + Future>>> getPopularPosts({int limit = 10, int offset = 0}) async { DateTime twentyFourHoursAgo = DateTime.now().subtract(Duration(hours: 24)); - Timestamp twentyFourHoursAgoTimestamp = - Timestamp.fromDate(twentyFourHoursAgo); + Timestamp twentyFourHoursAgoTimestamp = Timestamp.fromDate(twentyFourHoursAgo); - QuerySnapshot> response = await FirebaseFirestore - .instance + QuerySnapshot> response = await FirebaseFirestore.instance .collection("posts") .where("date", isGreaterThan: twentyFourHoursAgoTimestamp) .limit(limit) @@ -67,16 +64,16 @@ class PostService { Future getAvailable(String idUser) async { DateTime today = DateTime.now(); - today = DateTime(today.year, today.month, today.day); - QuerySnapshot> response = await FirebaseFirestore - .instance - .collection("posts") - .where("user_id", isEqualTo: idUser) - .where("date", isGreaterThanOrEqualTo: today) - .where("date", isLessThan: today.add(Duration(days: 1))) - .get(); + QuerySnapshot> response = + await FirebaseFirestore.instance.collection("posts").where("user_id", isEqualTo: idUser).get(); + + // Utiliser any() pour vérifier s'il y a au moins un document avec la date d'aujourd'hui + bool isTodayAvailable = response.docs.any((doc) { + DateTime date = doc["date"].toDate(); // Assuming the field name is "date" + return date.day == today.day && date.month == today.month && date.year == today.year; + }); - return response.docs.isNotEmpty; + return !isTodayAvailable; } } -- 2.36.3