Merge pull request 'NOTIF_AVAILABLE_EKA-LDE' (#31) from NOTIF_AVAILABLE_EKA-LDE into master

Reviewed-on: #31
pull/35/head
Emre KARTAL 2 years ago
commit 99932c9e2c

@ -65,7 +65,7 @@ class _EditablePostComponentState extends State<EditablePostComponent> with Tick
try { try {
final image = await ImagePicker().pickImage( final image = await ImagePicker().pickImage(
source: source, source: source,
imageQuality: 25, imageQuality: 10
); );
if (image == null) return; if (image == null) return;
final imageTemp = File(image.path); final imageTemp = File(image.path);

@ -23,6 +23,7 @@ class TopNavBarComponent extends StatefulWidget {
class _TopNavBarComponentState extends State<TopNavBarComponent> with TickerProviderStateMixin { class _TopNavBarComponentState extends State<TopNavBarComponent> with TickerProviderStateMixin {
bool choice = true; bool choice = true;
late AnimationController _controller; late AnimationController _controller;
bool isDismissed = true;
final DateTime midnight = DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day + 1); final DateTime midnight = DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day + 1);
@ -107,6 +108,19 @@ class _TopNavBarComponentState extends State<TopNavBarComponent> with TickerProv
).show(context); ).show(context);
} }
void checkAvailable() async {
print("test");
var res = await MyApp.postViewModel.getAvailable();
print(res);
ModalRoute<dynamic>? route = ModalRoute.of(context);
if (route != null) {
if (route.settings.name != '/flushbarRoute') {
print("yes");
showCapsuleDot(res);
}
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Padding( return Padding(
@ -123,8 +137,11 @@ class _TopNavBarComponentState extends State<TopNavBarComponent> with TickerProv
flex: 1, flex: 1,
child: GestureDetector( child: GestureDetector(
behavior: HitTestBehavior.translucent, behavior: HitTestBehavior.translucent,
onTap: () { onTap: () async {
Navigator.of(context).push(routeAddFriend()); bool returnFromOtherPage = await Navigator.of(context).push(routeAddFriend());
if (returnFromOtherPage == true) {
checkAvailable();
}
}, },
child: const Icon( child: const Icon(
Icons.person_add_alt_1_rounded, Icons.person_add_alt_1_rounded,
@ -142,9 +159,7 @@ class _TopNavBarComponentState extends State<TopNavBarComponent> with TickerProv
enableLongTapRepeatEvent: false, enableLongTapRepeatEvent: false,
longTapRepeatDuration: const Duration(milliseconds: 100), longTapRepeatDuration: const Duration(milliseconds: 100),
begin: 1.0, begin: 1.0,
onTap: () { onTap: () {},
showCapsuleDot(true);
},
end: 0.97, end: 0.97,
beginDuration: const Duration(milliseconds: 70), beginDuration: const Duration(milliseconds: 70),
endDuration: const Duration(milliseconds: 100), endDuration: const Duration(milliseconds: 100),
@ -221,8 +236,11 @@ class _TopNavBarComponentState extends State<TopNavBarComponent> with TickerProv
Flexible( Flexible(
flex: 1, flex: 1,
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () async {
Navigator.of(context).push(routeProfile()); bool returnFromOtherPage = await Navigator.of(context).push(routeProfile());
if (returnFromOtherPage == true) {
checkAvailable();
}
}, },
child: ClipOval( child: ClipOval(
child: SizedBox.fromSize( child: SizedBox.fromSize(

@ -169,7 +169,7 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
GestureDetector( GestureDetector(
behavior: HitTestBehavior.translucent, behavior: HitTestBehavior.translucent,
onTap: () { onTap: () {
Navigator.pop(context); Navigator.pop(context, true);
}, },
child: Transform( child: Transform(
alignment: Alignment.center, alignment: Alignment.center,

@ -17,7 +17,8 @@ class FeedScreen extends StatefulWidget {
State<FeedScreen> createState() => _FeedScreenState(); State<FeedScreen> createState() => _FeedScreenState();
} }
class _FeedScreenState extends State<FeedScreen> with SingleTickerProviderStateMixin { class _FeedScreenState extends State<FeedScreen>
with SingleTickerProviderStateMixin {
late AnimationController animationController; late AnimationController animationController;
late Animation<double> animation; late Animation<double> animation;
late List<Post> friendFeed; late List<Post> friendFeed;
@ -85,7 +86,8 @@ class _FeedScreenState extends State<FeedScreen> with SingleTickerProviderStateM
isScrollControlled: true, isScrollControlled: true,
context: context, context: context,
shape: const RoundedRectangleBorder( 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) { builder: ((BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
@ -104,19 +106,24 @@ class _FeedScreenState extends State<FeedScreen> with SingleTickerProviderStateM
child: Container( child: Container(
width: 60, width: 60,
height: 5, height: 5,
decoration: decoration: BoxDecoration(
BoxDecoration(color: Colors.white.withOpacity(0.3), borderRadius: BorderRadius.circular(20))), color: Colors.white.withOpacity(0.3),
borderRadius: BorderRadius.circular(20))),
), ),
const SizedBox( const SizedBox(
height: 20, height: 20,
), ),
Expanded( Expanded(
child: ClipRRect( 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( child: Padding(
padding: EdgeInsets.only(left: defaultPadding, right: defaultPadding), padding: EdgeInsets.only(
left: defaultPadding, right: defaultPadding),
child: SingleChildScrollView( child: SingleChildScrollView(
physics: BouncingScrollPhysics(decelerationRate: ScrollDecelerationRate.fast), physics: BouncingScrollPhysics(
decelerationRate: ScrollDecelerationRate.fast),
child: Wrap( child: Wrap(
// to apply margin in the main axis of the wrap // to apply margin in the main axis of the wrap
runSpacing: 10, runSpacing: 10,
@ -131,21 +138,25 @@ class _FeedScreenState extends State<FeedScreen> with SingleTickerProviderStateM
? Container() ? Container()
: Padding( : Padding(
padding: const EdgeInsets.only(bottom: 20), padding: const EdgeInsets.only(bottom: 20),
child: Text('${displayFeed[index].description ?? ""}', child: Text(
'${displayFeed[index].description ?? ""}',
style: GoogleFonts.plusJakartaSans( style: GoogleFonts.plusJakartaSans(
color: Colors.white, fontWeight: FontWeight.w200)), color: Colors.white,
fontWeight: FontWeight.w200)),
), ),
Align( Align(
child: RichText( child: RichText(
text: TextSpan( text: TextSpan(
text: "3", text: "3",
style: style: GoogleFonts.plusJakartaSans(
GoogleFonts.plusJakartaSans(color: Colors.white, fontWeight: FontWeight.w600), color: Colors.white,
fontWeight: FontWeight.w600),
children: [ children: [
TextSpan( TextSpan(
text: " commentaires", text: " commentaires",
style: style: GoogleFonts.plusJakartaSans(
GoogleFonts.plusJakartaSans(color: Colors.white, fontWeight: FontWeight.w300), color: Colors.white,
fontWeight: FontWeight.w300),
) )
])), ])),
), ),
@ -161,12 +172,15 @@ class _FeedScreenState extends State<FeedScreen> with SingleTickerProviderStateM
), ),
), ),
Padding( Padding(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom),
child: Container( child: Container(
height: 70, height: 70,
width: double.infinity, width: double.infinity,
decoration: BoxDecoration( 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: Center(
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20), padding: const EdgeInsets.symmetric(horizontal: 20),
@ -176,7 +190,8 @@ class _FeedScreenState extends State<FeedScreen> with SingleTickerProviderStateM
child: SizedBox.fromSize( child: SizedBox.fromSize(
// Image radius // Image radius
child: const Image( child: const Image(
image: AssetImage("assets/images/exemple_profile.png"), image: AssetImage(
"assets/images/exemple_profile.png"),
width: 45, width: 45,
), ),
), ),
@ -189,7 +204,8 @@ class _FeedScreenState extends State<FeedScreen> with SingleTickerProviderStateM
keyboardAppearance: Brightness.dark, keyboardAppearance: Brightness.dark,
cursorColor: primaryColor, cursorColor: primaryColor,
keyboardType: TextInputType.emailAddress, keyboardType: TextInputType.emailAddress,
style: GoogleFonts.plusJakartaSans(color: Colors.white), style: GoogleFonts.plusJakartaSans(
color: Colors.white),
decoration: InputDecoration( decoration: InputDecoration(
suffixIcon: Icon( suffixIcon: Icon(
Icons.send, Icons.send,
@ -197,17 +213,27 @@ class _FeedScreenState extends State<FeedScreen> with SingleTickerProviderStateM
size: 20, size: 20,
), ),
focusedBorder: OutlineInputBorder( focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: grayText), borderSide: BorderSide(
borderRadius: BorderRadius.all(Radius.circular(100))), width: 1, color: grayText),
contentPadding: EdgeInsets.only(top: 0, bottom: 0, left: 20, right: 20), borderRadius: BorderRadius.all(
Radius.circular(100))),
contentPadding: EdgeInsets.only(
top: 0,
bottom: 0,
left: 20,
right: 20),
fillColor: bgModal, fillColor: bgModal,
filled: true, filled: true,
focusColor: Color.fromRGBO(255, 255, 255, 0.30), focusColor:
Color.fromRGBO(255, 255, 255, 0.30),
enabledBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: grayText), borderSide: BorderSide(
borderRadius: BorderRadius.all(Radius.circular(100))), width: 1, color: grayText),
borderRadius: BorderRadius.all(
Radius.circular(100))),
hintText: 'Ajoutez une réponse...', hintText: 'Ajoutez une réponse...',
hintStyle: GoogleFonts.plusJakartaSans(color: grayText)), hintStyle: GoogleFonts.plusJakartaSans(
color: grayText)),
), ),
) )
], ],
@ -238,16 +264,21 @@ class _FeedScreenState extends State<FeedScreen> with SingleTickerProviderStateM
Container( Container(
decoration: const BoxDecoration( decoration: const BoxDecoration(
image: DecorationImage( 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( child: Padding(
padding: EdgeInsets.only(top: 140.h, left: defaultPadding), padding:
EdgeInsets.only(top: 140.h, left: defaultPadding),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text("Suis tes amis pour voir leurs capsules", Text("Suis tes amis pour voir leurs capsules",
style: GoogleFonts.plusJakartaSans( 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<FeedScreen> with SingleTickerProviderStateM
decoration: BoxDecoration( decoration: BoxDecoration(
gradient: LinearGradient( gradient: LinearGradient(
begin: Alignment.topRight, begin: Alignment.topRight,
stops: [0.3, 1], stops: [
colors: [bgColor.withOpacity(0.9), bgColor.withOpacity(0)])), 0.3,
1
],
colors: [
bgColor.withOpacity(0.9),
bgColor.withOpacity(0)
])),
), ),
), ),
), ),
@ -281,26 +318,32 @@ class _FeedScreenState extends State<FeedScreen> with SingleTickerProviderStateM
fit: StackFit.expand, fit: StackFit.expand,
children: [ children: [
Align( Align(
alignment: Alignment.topCenter,
child: CircularRevealAnimation( child: CircularRevealAnimation(
animation: animation, animation: animation,
centerOffset: Offset(30.w, -100), centerOffset: Offset(30.w, -100),
child: Container( child: Container(
constraints: BoxConstraints(maxWidth: 600), constraints: BoxConstraints(maxWidth: 600),
padding: EdgeInsets.fromLTRB(defaultPadding, 100.h, defaultPadding, 0), padding: EdgeInsets.fromLTRB(
defaultPadding, 100.h, defaultPadding, 0),
child: RefreshIndicator( child: RefreshIndicator(
displacement: 20, displacement: 20,
triggerMode: RefreshIndicatorTriggerMode.onEdge, triggerMode: RefreshIndicatorTriggerMode.onEdge,
onRefresh: _refresh, onRefresh: _refresh,
child: ListView.builder( child: ListView.builder(
physics: const BouncingScrollPhysics(decelerationRate: ScrollDecelerationRate.fast), physics: const BouncingScrollPhysics(
decelerationRate:
ScrollDecelerationRate.fast),
clipBehavior: Clip.none, clipBehavior: Clip.none,
shrinkWrap: true, shrinkWrap: true,
itemCount: displayFeed.length, itemCount: displayFeed.length,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return Padding( return Padding(
padding: const EdgeInsets.only(bottom: 40), padding: const EdgeInsets.only(bottom: 40),
child: child: PostComponent(
PostComponent(callback: openDetailPost, post: displayFeed[index], index: index), callback: openDetailPost,
post: displayFeed[index],
index: index),
); );
}, },
), ),
@ -315,8 +358,14 @@ class _FeedScreenState extends State<FeedScreen> with SingleTickerProviderStateM
decoration: BoxDecoration( decoration: BoxDecoration(
gradient: LinearGradient( gradient: LinearGradient(
begin: Alignment.topRight, begin: Alignment.topRight,
stops: [0.3, 1], stops: [
colors: [bgColor.withOpacity(0.9), bgColor.withOpacity(0)])), 0.3,
1
],
colors: [
bgColor.withOpacity(0.9),
bgColor.withOpacity(0)
])),
), ),
), ),
), ),

@ -32,7 +32,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
GestureDetector( GestureDetector(
behavior: HitTestBehavior.translucent, behavior: HitTestBehavior.translucent,
onTap: () { onTap: () {
Navigator.pop(context); Navigator.pop(context, true);
}, },
child: Container( child: Container(
padding: EdgeInsets.symmetric(horizontal: 10), padding: EdgeInsets.symmetric(horizontal: 10),

@ -21,7 +21,7 @@ class AuthService {
"nbCapsules": 0, "nbCapsules": 0,
"followers": 0, "followers": 0,
"picture": "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": [], "friends": [],
"comments": [] "comments": []
}; };

@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:intl/intl.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
import 'package:firebase_storage/firebase_storage.dart'; import 'package:firebase_storage/firebase_storage.dart';
@ -45,8 +46,34 @@ class PostService {
getPostsById(String id) {} getPostsById(String id) {}
Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getPopularPosts({int limit = 10, int offset = 0}) async { Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getPopularPosts({int limit = 10, int offset = 0}) async {
DateTime twentyFourHoursAgo = DateTime.now().subtract(Duration(hours: 24));
Timestamp twentyFourHoursAgoTimestamp = Timestamp.fromDate(twentyFourHoursAgo);
QuerySnapshot<Map<String, dynamic>> 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<bool> getAvailable(String idUser) async {
DateTime today = DateTime.now();
QuerySnapshot<Map<String, dynamic>> response = QuerySnapshot<Map<String, dynamic>> response =
await FirebaseFirestore.instance.collection("posts").limit(limit).orderBy("likes").get(); await FirebaseFirestore.instance.collection("posts").where("user_id", isEqualTo: idUser).get();
return response.docs;
// 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 !isTodayAvailable;
} }
} }

@ -22,7 +22,8 @@ class PostViewModel {
List<Post> get bestPosts => _bestPosts; List<Post> get bestPosts => _bestPosts;
// Methods // Methods
addPost(String? description, String idMusic, File? image, Tuple2<String, String>? location) async { addPost(String? description, String idMusic, File? image,
Tuple2<String, String>? location) async {
await _postService.createPost(description, idMusic, image, location); await _postService.createPost(description, idMusic, image, location);
} }
@ -50,6 +51,7 @@ class PostViewModel {
return _bestPosts; return _bestPosts;
} catch (e) { } catch (e) {
print(e); print(e);
_bestPosts = [];
return []; return [];
} }
} }
@ -57,4 +59,14 @@ class PostViewModel {
List<Post> getMoreBestPosts() { List<Post> getMoreBestPosts() {
throw new Error(); throw new Error();
} }
Future<bool> getAvailable() async {
try {
return await _postService
.getAvailable(MyApp.userViewModel.userCurrent.id);
} catch (e) {
print(e);
rethrow;
}
}
} }

Loading…
Cancel
Save