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 {
final image = await ImagePicker().pickImage(
source: source,
imageQuality: 25,
imageQuality: 10
);
if (image == null) return;
final imageTemp = File(image.path);

@ -23,6 +23,7 @@ class TopNavBarComponent extends StatefulWidget {
class _TopNavBarComponentState extends State<TopNavBarComponent> 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);
@ -107,6 +108,19 @@ class _TopNavBarComponentState extends State<TopNavBarComponent> with TickerProv
).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
Widget build(BuildContext context) {
return Padding(
@ -123,8 +137,11 @@ class _TopNavBarComponentState extends State<TopNavBarComponent> 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,
@ -142,9 +159,7 @@ class _TopNavBarComponentState extends State<TopNavBarComponent> 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),
@ -221,8 +236,11 @@ class _TopNavBarComponentState extends State<TopNavBarComponent> 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(

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

@ -17,7 +17,8 @@ class FeedScreen extends StatefulWidget {
State<FeedScreen> createState() => _FeedScreenState();
}
class _FeedScreenState extends State<FeedScreen> with SingleTickerProviderStateMixin {
class _FeedScreenState extends State<FeedScreen>
with SingleTickerProviderStateMixin {
late AnimationController animationController;
late Animation<double> animation;
late List<Post> friendFeed;
@ -85,7 +86,8 @@ class _FeedScreenState extends State<FeedScreen> 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<FeedScreen> 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<FeedScreen> 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<FeedScreen> 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<FeedScreen> 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<FeedScreen> 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<FeedScreen> 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<FeedScreen> 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<FeedScreen> 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<FeedScreen> 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<FeedScreen> 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)
])),
),
),
),

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

@ -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": []
};

@ -2,6 +2,7 @@ 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';
@ -45,8 +46,34 @@ class PostService {
getPostsById(String id) {}
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 =
await FirebaseFirestore.instance.collection("posts").limit(limit).orderBy("likes").get();
return response.docs;
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 !isTodayAvailable;
}
}

@ -22,7 +22,8 @@ class PostViewModel {
List<Post> get bestPosts => _bestPosts;
// 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);
}
@ -50,6 +51,7 @@ class PostViewModel {
return _bestPosts;
} catch (e) {
print(e);
_bestPosts = [];
return [];
}
}
@ -57,4 +59,14 @@ class PostViewModel {
List<Post> getMoreBestPosts() {
throw new Error();
}
Future<bool> getAvailable() async {
try {
return await _postService
.getAvailable(MyApp.userViewModel.userCurrent.id);
} catch (e) {
print(e);
rethrow;
}
}
}

Loading…
Cancel
Save