Commit d5be7e7f authored by Administrator's avatar Administrator

code cleanup

parent 8f0440ac
......@@ -27,6 +27,18 @@ class Activity extends Model {
type = activity.type,
distance = activity.distance.toInt();
Activity.fromDb(DbActivity dbActivity)
: id = dbActivity.id,
stravaId = dbActivity.stravaId,
name = dbActivity.name,
movingTime = Duration(seconds: dbActivity.movingTime),
type = dbActivity.type,
distance = dbActivity.distance;
download() {
// TODO
}
persist() async {
await Db.create().connect();
......@@ -52,16 +64,14 @@ class Activity extends Model {
secret,
prompt);
final now = DateTime
.now()
.millisecondsSinceEpoch ~/ 1000;
final now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
final startDate = now - 2 * 86400;
List<SummaryActivity> summaryActivities = await strava
.getLoggedInAthleteActivities(now, startDate);
List<SummaryActivity> summaryActivities =
await strava.getLoggedInAthleteActivities(now, startDate);
for(SummaryActivity summaryActivity in summaryActivities) {
for (SummaryActivity summaryActivity in summaryActivities) {
Activity activity = Activity.fromStrava(summaryActivity);
activity.persist();
}
......@@ -69,4 +79,3 @@ class Activity extends Model {
print("Hello");
}
}
......@@ -32,6 +32,7 @@ class _ListActivitiesScreenState extends State<ListActivitiesScreen> {
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done &&
snapshot.data.length > 0) {
final activities = snapshot.data.map((dbActivity) => Activity.fromDb(dbActivity));
return ListView(
padding: EdgeInsets.all(20),
children: <Widget>[
......@@ -42,13 +43,13 @@ class _ListActivitiesScreenState extends State<ListActivitiesScreen> {
Activity.queryStrava();
},
),
for (DbActivity activity in snapshot.data)
for (Activity activity in activities)
ListTile(
leading: Icon(Icons.person),
leading: Icon(Icons.directions_run),
title: Text("${activity.type} "
"${activity.stravaId}"),
subtitle: Text(activity.name),
trailing: Text(activity.state),
trailing: stateIcon(activity),
)
],
);
......@@ -70,4 +71,17 @@ class _ListActivitiesScreenState extends State<ListActivitiesScreen> {
),
);
}
static stateIcon(Activity activity) {
switch (activity.state) {
case "new":
return IconButton(
icon: Icon(Icons.cloud_download),
onPressed: () => activity.download,
);
break;
default:
return Text(activity.state);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment