diff --git a/lib/activity_feed.dart b/lib/activity_feed.dart new file mode 100644 index 0000000..ba4db31 --- /dev/null +++ b/lib/activity_feed.dart @@ -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 { + @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 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: [ + 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 + )) + + ], + ); + + } +} diff --git a/lib/main.dart b/lib/main.dart index 3e4902f..5351ad8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 _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 _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 _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, @@ -75,18 +80,17 @@ class Fluttergram extends StatelessWidget { return new MaterialApp( title: 'Fluttergram', theme: new ThemeData( - // This is the theme of your application. - // - // Try running your application with "flutter run". You'll see the - // application has a blue toolbar. Then, without quitting the app, try - // changing the primarySwatch below to Colors.green and then invoke - // "hot reload" (press "r" in the console where you ran "flutter run", - // or press Run > Flutter Hot Reload in IntelliJ). Notice that the - // counter didn't reset back to zero; the application is not restarted. - primarySwatch: Colors.blue, - buttonColor: Colors.pink, - primaryIconTheme: new IconThemeData(color: Colors.black) - ), + // This is the theme of your application. + // + // Try running your application with "flutter run". You'll see the + // application has a blue toolbar. Then, without quitting the app, try + // changing the primarySwatch below to Colors.green and then invoke + // "hot reload" (press "r" in the console where you ran "flutter run", + // or press Run > Flutter Hot Reload in IntelliJ). Notice that the + // counter didn't reset back to zero; the application is not restarted. + primarySwatch: Colors.blue, + buttonColor: Colors.pink, + primaryIconTheme: new IconThemeData(color: Colors.black)), home: new HomePage(title: 'Fluttergram'), ); } @@ -139,7 +143,7 @@ class _HomePageState extends State { 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 { 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( diff --git a/lib/profile_page.dart b/lib/profile_page.dart index de6e173..b1e8cfa 100644 --- a/lib/profile_page.dart +++ b/lib/profile_page.dart @@ -65,7 +65,7 @@ class _ProfilePage extends State { "ownerId": profileId, "username": currentUserModel.username, "userId": currentUserId, - "type": "like", + "type": "follow", "userProfileImg": currentUserModel.photoUrl, "timestamp": new DateTime.now().toString() }); diff --git a/lib/upload_page.dart b/lib/upload_page.dart index 6db6c8d..974e0d6 100644 --- a/lib/upload_page.dart +++ b/lib/upload_page.dart @@ -21,13 +21,22 @@ class _Uploader extends State { 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 { barrierDismissible: false, // user must tap button! child: new SimpleDialog( - title: const Text('Select assignment'), + title: const Text('Create a Post'), children: [ new SimpleDialogOption( child: const Text('Take a photo'),