Skip to content

Commit

Permalink
Merge pull request #8 from softeng-feup/featured-speakers-main-page
Browse files Browse the repository at this point in the history
Featured speakers section on main screen
  • Loading branch information
daviddias99 authored Dec 8, 2019
2 parents 7d37293 + e5b8e50 commit 7cde6b7
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 28 deletions.
4 changes: 4 additions & 0 deletions AMA/lib/controller/Controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ class Controller {
return DatabaseMapper.getSession(DatabaseController().getDatabase(), sessionKey);
}

Future<List<Person.Person>> getDaySpeakers(String sessionKey) async {
return DatabaseMapper.getDaySpeakers(DatabaseController().getDatabase(), sessionKey);
}

Future<List<String>> getLocationsByOrder() async {
return DatabaseMapper.getLocationsByOrder(DatabaseController().getDatabase());
}
Expand Down
16 changes: 16 additions & 0 deletions AMA/lib/controller/database/DatabaseMapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ class DatabaseMapper {
return sessions;
}

static Future<List<Person>> getDaySpeakers(Database db, String date) async {

var results = await db.rawQuery('SELECT DISTINCT personKey FROM Session JOIN SessionChair WHERE day = ?',[date]);

List<String> keys = List<String>();

for(int i = 0; i < results.length;i++){

keys.add(results.elementAt(i)['personKey']);
}

List<Person> people = await getPeopleWithKeys(db,keys);

return people;
}


static Future<SplayTreeSet<Session>> getSessionsInLocation(Database db, String location) async {
var results = await db.rawQuery('SELECT * FROM Session WHERE location = ?', [location]);
Expand Down
216 changes: 194 additions & 22 deletions AMA/lib/view/components/DayContainer.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import 'dart:math';

import 'package:ama/constants/Dates.dart';
import 'package:ama/controller/Controller.dart';
import 'package:ama/model/Person.dart';
import 'package:ama/view/components/GenericTitle.dart';
import 'package:ama/controller/Controller.dart';
import 'package:flutter/material.dart';
import '../../constants/AppColors.dart' as AppColors;

class MainScreenPage extends StatelessWidget {
MainScreenPage({this.dayNo, this.date});
Expand All @@ -10,22 +16,176 @@ class MainScreenPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
return GestureDetector(
key: Key("Calendar page"),
onTap: () {
String routeOnTap = "/day" + dayNo.toString() + "Screen";
Navigator.pushNamed(context, routeOnTap);
},
return SingleChildScrollView(
child: Column(
children: <Widget>[
Align(
alignment: Alignment.topCenter,
child: GestureDetector(
key: Key("Calendar page"),
onTap: () {
String routeOnTap = "/day" + dayNo.toString() + "Screen";
Navigator.pushNamed(context, routeOnTap);
},
child: new SmallCalendarPage(
date: date,
dayNo: dayNo,
))),
FeaturedSpeakersPage(
date: date,
dayNo: dayNo,
)
],
),
);
}
}

class FeaturedSpeakersPage extends StatelessWidget {
final Date date;
final int dayNo;
List<Person> people = null;

FeaturedSpeakersPage({
Key key,
this.date,
this.dayNo,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(top: 15.0),
child: Container(
decoration: BoxDecoration(
borderRadius: new BorderRadius.circular(20),
color: AppColors.containerColor,
border: Border.all(width: 2),
),
child: Column(
children: <Widget>[
Align(
alignment: Alignment.topCenter,
child: new SmallCalendarPage(
date: date,
dayNo: dayNo,
)),
],
));
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: GenericTitle(
title: "Featured Speakers:",
backgroundColor: AppColors.containerColor,
padding: EdgeInsets.all(6.0),
margin: EdgeInsets.only(top: 10.0),
style: TextStyle(
color: AppColors.mainColor,
fontWeight: FontWeight.w900,
fontSize: 18)),
),
printSpeakers(),
],
),
),
);
}

Widget printSpeakers() {
return FutureBuilder(
future: Controller.instance().getDaySpeakers(this.date.toDateString()),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
List<Person> dbSpeakers = snapshot.data;

dbSpeakers = shuffle(dbSpeakers);

if (this.people == null) this.people = dbSpeakers;

Person speaker1 = this.people.elementAt(0);
Person speaker2 = this.people.elementAt(1);
Person speaker3 = this.people.elementAt(2);
Person speaker4 = this.people.elementAt(3);

return Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Flexible(flex: 1, child: printAvatar(context,speaker1)),
Padding(padding: const EdgeInsets.only(bottom: 8.0)),
Flexible(flex: 1, child: printAvatar(context,speaker2)),
],
),
Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Flexible(flex: 1, child: printAvatar(context,speaker3)),
Padding(padding: const EdgeInsets.only(bottom: 8.0)),
Flexible(flex: 1, child: printAvatar(context,speaker4)),
],
),
],
),
);
} else {
return Container();
}
});
}

printAvatar(BuildContext context, Person person) {
if (person.imageURL != null)
return Column(
children: <Widget>[
GestureDetector(
key: Key("Calendar page"),
onTap: () {
String routeOnTap = "/profileScreen";
Navigator.pushNamed(context, routeOnTap,arguments: person);
},
child: CircleAvatar(
radius: 30,
backgroundImage: NetworkImage(person.imageURL),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Text(
person.name,
style: TextStyle(color: Colors.black87),
maxLines: 1,
overflow: TextOverflow.ellipsis,
softWrap: false,
),
),
],
);
else {
return Column(
children: <Widget>[
CircleAvatar(
radius: 30,
child: Text(
getInitials(person.name),
style: TextStyle(fontSize: 10),
)),
Text(
person.name,
style: TextStyle(color: Colors.black87),
),
],
);
}
}

String getInitials(String text) {
if (text.length <= 1) return text.toUpperCase();
var words = text.split(' ');
var capitalized = words.map((word) {
var first = word.substring(0, 1).toUpperCase();
return '$first';
});
return capitalized.join(' ');
}
}

Expand All @@ -39,7 +199,6 @@ class SmallCalendarPage extends StatelessWidget {
this.dayNo,
}) : super(key: key);


@override
Widget build(BuildContext context) {
return Container(
Expand All @@ -53,9 +212,7 @@ class SmallCalendarPage extends StatelessWidget {
);
}


Widget drawCalendar(BuildContext context) {

String text = Controller.instance().getTextActivities(dayNo);

return ClipRRect(
Expand All @@ -67,8 +224,8 @@ class SmallCalendarPage extends StatelessWidget {
backgroundColor: Colors.red,
leading: Padding(
padding: const EdgeInsets.all(8.5),
child:
Text("#" + dayNo.toString(), style: TextStyle(fontSize: 30), key: Key("identifierDay")),
child: Text("#" + dayNo.toString(),
style: TextStyle(fontSize: 30), key: Key("identifierDay")),
),
),
body: Center(
Expand All @@ -86,7 +243,8 @@ class SmallCalendarPage extends StatelessWidget {
),
Padding(
padding: const EdgeInsets.only(top: 12.0),
child: Text( text,
child: Text(
text,
style: TextStyle(fontSize: 20, color: Colors.black),
key: Key("numberOfActivitiesDay"),
),
Expand All @@ -97,6 +255,20 @@ class SmallCalendarPage extends StatelessWidget {
),
);
}

}

List shuffle(List items) {
var random = new Random();

// Go through all elements.
for (var i = items.length - 1; i > 0; i--) {
// Pick a pseudorandom number according to the list length
var n = random.nextInt(i + 1);

var temp = items[i];
items[i] = items[n];
items[n] = temp;
}

return items;
}
5 changes: 3 additions & 2 deletions AMA/lib/view/components/GenericTitle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ import 'package:flutter/material.dart';
import '../../constants/AppColors.dart' as AppColors;

class GenericTitle extends StatelessWidget {
GenericTitle({this.title, this.style, this.padding, this.margin});
GenericTitle({this.title, this.style, this.padding, this.margin,this.backgroundColor = AppColors.containerColor});

final String title;
final TextStyle style;
final EdgeInsets padding;
final EdgeInsets margin;
final Color backgroundColor;

@override
Widget build(BuildContext context) {
return Container(
padding: this.padding,
margin: this.margin,
decoration: new BoxDecoration(
color: AppColors.containerColor,
color: this.backgroundColor,
borderRadius: BorderRadius.circular(10.0)),
child: Text(this.title, style: this.style));
}
Expand Down
8 changes: 4 additions & 4 deletions AMA/lib/view/screens/MainScreenPager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ class _MainScreenPagerState extends State<MainScreenPager> {
Widget build(BuildContext context) {
List<Widget> pages = [
Padding(
padding: EdgeInsets.all(40),
padding: EdgeInsets.only(top:40, right: 40, left: 40, bottom: 10),
child: MainScreenPage(dayNo: 1, date: Dates.date1)),
Padding(
padding: EdgeInsets.all(40),
padding: EdgeInsets.only(top:40, right: 40, left: 40, bottom: 10),
child: MainScreenPage(dayNo: 2, date: Dates.date2)),
Padding(
padding: EdgeInsets.all(40),
padding: EdgeInsets.only(top:40, right: 40, left: 40, bottom: 10),
child: MainScreenPage(dayNo: 3, date: Dates.date3)),
Padding(
padding: EdgeInsets.all(40),
padding: EdgeInsets.only(top:40, right: 40, left: 40, bottom: 10),
child: MainScreenPage(dayNo: 4, date: Dates.date4)),
];

Expand Down

0 comments on commit 7cde6b7

Please sign in to comment.