mirror of
https://github.com/mdanics/fluttergram.git
synced 2025-08-06 13:19:53 +08:00
added initial activity feed
This commit is contained in:
145
lib/activity_feed.dart
Normal file
145
lib/activity_feed.dart
Normal file
@ -0,0 +1,145 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
|
||||
class ActivityFeedPage extends StatefulWidget {
|
||||
@override
|
||||
_ActivityFeedPageState createState() => new _ActivityFeedPageState();
|
||||
}
|
||||
|
||||
class _ActivityFeedPageState extends State<ActivityFeedPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new Scaffold(
|
||||
appBar: new AppBar(
|
||||
title: new Text(
|
||||
"Activity Feed",
|
||||
style: new TextStyle(color: Colors.black),
|
||||
),
|
||||
backgroundColor: Colors.white,
|
||||
),
|
||||
body: buildActivityFeed(),
|
||||
);
|
||||
}
|
||||
|
||||
buildActivityFeed() {
|
||||
return new Container(
|
||||
child: new FutureBuilder(
|
||||
future: getFeed(),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData)
|
||||
return new Container(
|
||||
alignment: FractionalOffset.center,
|
||||
padding: const EdgeInsets.only(top: 10.0),
|
||||
child: new CircularProgressIndicator());
|
||||
else {
|
||||
return new ListView(children: snapshot.data);
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
getFeed() async {
|
||||
List<ActivityFeedItem> items = [];
|
||||
var snap = await Firestore.instance
|
||||
.collection('insta_a_feed')
|
||||
.document("xnnP5qKOw10S8hRyhG0B" /*currentUserModel.id*/)
|
||||
.getCollection("items")
|
||||
.orderBy("timestamp")
|
||||
.getDocuments();
|
||||
|
||||
for (var doc in snap.documents) {
|
||||
items.add(new ActivityFeedItem.fromDocument(doc));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
class ActivityFeedItem extends StatelessWidget {
|
||||
final String username;
|
||||
final String userId;
|
||||
final String
|
||||
type; // potetial types include liked photo, follow user, comment on photo
|
||||
final String mediaUrl;
|
||||
final String userProfileImg;
|
||||
final String commentData;
|
||||
|
||||
ActivityFeedItem(
|
||||
{this.username,
|
||||
this.userId,
|
||||
this.type,
|
||||
this.mediaUrl,
|
||||
this.userProfileImg,
|
||||
this.commentData});
|
||||
|
||||
factory ActivityFeedItem.fromDocument(DocumentSnapshot document) {
|
||||
return new ActivityFeedItem(
|
||||
username: document['username'],
|
||||
userId: document['userId'],
|
||||
type: document['type'],
|
||||
mediaUrl: document['mediaUrl'],
|
||||
userProfileImg: document['userProfileImg'],
|
||||
commentData: document["commentData"],
|
||||
);
|
||||
}
|
||||
|
||||
Widget mediaPreview = new Container();
|
||||
String actionText;
|
||||
|
||||
void configureItem() {
|
||||
if (type == "like") {
|
||||
actionText = "$username liked your post.";
|
||||
|
||||
mediaPreview = // new Image.network(mediaUrl, height: 100.0, fit: BoxFit.cover);
|
||||
|
||||
new Container(
|
||||
height: 45.0,
|
||||
width: 45.0,
|
||||
child: new AspectRatio(
|
||||
aspectRatio: 487 / 451,
|
||||
child: new Container(
|
||||
decoration: new BoxDecoration(
|
||||
image: new DecorationImage(
|
||||
fit: BoxFit.fill,
|
||||
alignment: FractionalOffset.topCenter,
|
||||
image: new NetworkImage(mediaUrl),
|
||||
)),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else if (type == "follow") {
|
||||
actionText = "$username starting following you.";
|
||||
} else if (type == "comment") {
|
||||
actionText = "$username commented: $commentData";
|
||||
|
||||
mediaPreview = new Image.network(mediaUrl);
|
||||
} else {
|
||||
actionText = "Error - invalid activityFeed type: $type";
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
configureItem();
|
||||
return new Row(
|
||||
children: <Widget>[
|
||||
new Padding(
|
||||
padding: const EdgeInsets.only(left: 20.0, right: 15.0),
|
||||
child: new CircleAvatar(
|
||||
radius: 23.0,
|
||||
backgroundImage: new NetworkImage(userProfileImg),
|
||||
),
|
||||
),
|
||||
new Text(actionText),
|
||||
new Expanded(child: new Align(
|
||||
child: new Padding(
|
||||
child: mediaPreview,
|
||||
padding: new EdgeInsets.all(15.0),
|
||||
),
|
||||
alignment: AlignmentDirectional.bottomEnd
|
||||
))
|
||||
|
||||
],
|
||||
);
|
||||
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'profile_page.dart';
|
||||
import 'search_page.dart';
|
||||
import 'activity_feed.dart';
|
||||
|
||||
final auth = FirebaseAuth.instance;
|
||||
final googleSignIn = new GoogleSignIn();
|
||||
@ -20,7 +21,9 @@ Future<Null> _ensureLoggedIn() async {
|
||||
user = await googleSignIn.signInSilently();
|
||||
}
|
||||
if (user == null) {
|
||||
await googleSignIn.signIn().then((_) {tryCreateUserRecord();});
|
||||
await googleSignIn.signIn().then((_) {
|
||||
tryCreateUserRecord();
|
||||
});
|
||||
}
|
||||
|
||||
if (await auth.currentUser() == null) {
|
||||
@ -35,7 +38,9 @@ Future<Null> _silentLogin() async {
|
||||
GoogleSignInAccount user = googleSignIn.currentUser;
|
||||
|
||||
if (user == null) {
|
||||
user = await googleSignIn.signInSilently().then((_) {tryCreateUserRecord();});
|
||||
user = await googleSignIn.signInSilently().then((_) {
|
||||
tryCreateUserRecord();
|
||||
});
|
||||
}
|
||||
|
||||
if (await auth.currentUser() == null && user != null) {
|
||||
@ -48,11 +53,11 @@ Future<Null> _silentLogin() async {
|
||||
|
||||
tryCreateUserRecord() async {
|
||||
GoogleSignInAccount user = googleSignIn.currentUser;
|
||||
if (user == null ){
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
DocumentSnapshot userRecord = await ref.document(user.id).get();
|
||||
if (userRecord.data == null ) {
|
||||
if (userRecord.data == null) {
|
||||
ref.document(user.id).setData({
|
||||
"id": user.id,
|
||||
"username": user.displayName,
|
||||
@ -85,8 +90,7 @@ class Fluttergram extends StatelessWidget {
|
||||
// counter didn't reset back to zero; the application is not restarted.
|
||||
primarySwatch: Colors.blue,
|
||||
buttonColor: Colors.pink,
|
||||
primaryIconTheme: new IconThemeData(color: Colors.black)
|
||||
),
|
||||
primaryIconTheme: new IconThemeData(color: Colors.black)),
|
||||
home: new HomePage(title: 'Fluttergram'),
|
||||
);
|
||||
}
|
||||
@ -139,7 +143,7 @@ class _HomePageState extends State<HomePage> {
|
||||
Widget build(BuildContext context) {
|
||||
if (triedSilentLogin == false) {
|
||||
silentLogin();
|
||||
} // might cause performance issues?
|
||||
}
|
||||
return googleSignIn.currentUser == null
|
||||
? buildLoginPage()
|
||||
: new Scaffold(
|
||||
@ -149,12 +153,13 @@ class _HomePageState extends State<HomePage> {
|
||||
color: Colors.white,
|
||||
child: new Feed(),
|
||||
),
|
||||
new Container(color: Colors.white, child: new SearchPage()),
|
||||
|
||||
new Container(
|
||||
color: Colors.green,
|
||||
child: new SearchPage(),
|
||||
child: new Uploader(),
|
||||
),
|
||||
new Container(color: Colors.white, child: new Uploader()),
|
||||
new Container(color: Colors.amber),
|
||||
new Container(color: Colors.white, child: new ActivityFeedPage()),
|
||||
new Container(
|
||||
color: Colors.white,
|
||||
child: new ProfilePage(
|
||||
|
@ -65,7 +65,7 @@ class _ProfilePage extends State<ProfilePage> {
|
||||
"ownerId": profileId,
|
||||
"username": currentUserModel.username,
|
||||
"userId": currentUserId,
|
||||
"type": "like",
|
||||
"type": "follow",
|
||||
"userProfileImg": currentUserModel.photoUrl,
|
||||
"timestamp": new DateTime.now().toString()
|
||||
});
|
||||
|
@ -21,13 +21,22 @@ class _Uploader extends State<Uploader> {
|
||||
bool uploading = false;
|
||||
bool promted = false;
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
@override
|
||||
initState(){
|
||||
|
||||
|
||||
if (file == null && promted == false) {
|
||||
_selectImage();
|
||||
setState(() {
|
||||
promted = true;
|
||||
});
|
||||
}
|
||||
print("ss");
|
||||
super.initState();
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
|
||||
return file == null
|
||||
? new IconButton(
|
||||
@ -72,7 +81,7 @@ class _Uploader extends State<Uploader> {
|
||||
barrierDismissible: false, // user must tap button!
|
||||
|
||||
child: new SimpleDialog(
|
||||
title: const Text('Select assignment'),
|
||||
title: const Text('Create a Post'),
|
||||
children: <Widget>[
|
||||
new SimpleDialogOption(
|
||||
child: const Text('Take a photo'),
|
||||
|
Reference in New Issue
Block a user