Commit 20dbeb2f authored by Administrator's avatar Administrator

fixed non updating state after download of new episodes, download only new...

fixed non updating state after download of new episodes, download only new episodes, rename Duration.string() to Duration.asString()
parent 5c4b8997
......@@ -30,10 +30,7 @@ class Activity extends ChangeNotifier {
..distance = summaryActivity.distance.toInt()
..stravaId = summaryActivity.id
..startTime = summaryActivity.startDate
..movingTime = summaryActivity.movingTime
..save();
notifyListeners();
..movingTime = summaryActivity.movingTime;
}
String toString() => '$db.name $db.startTime';
......@@ -132,7 +129,8 @@ class Activity extends ChangeNotifier {
..startTime = dateTimeFromStrava(dataMessage.get('start_time'))
..startPositionLat = dataMessage.get('start_position_lat')
..startPositionLong = dataMessage.get('start_position_long')
..totalElapsedTime = dataMessage.get('total_elapsed_time')?.round()
..totalElapsedTime =
dataMessage.get('total_elapsed_time')?.round()
..totalTimerTime = dataMessage.get('total_timer_time')?.round()
..totalDistance = dataMessage.get('total_distance')?.round()
..totalStrides = dataMessage.get('total_strides')?.round()
......@@ -200,6 +198,10 @@ class Activity extends ChangeNotifier {
print("Persisted activity ${db.stravaId} to database.");
}
delete() {
this.db.delete();
}
static queryStrava({Athlete athlete}) async {
var strava = Strava(true, secret);
final prompt = 'auto';
......@@ -217,15 +219,25 @@ class Activity extends ChangeNotifier {
await strava.getLoggedInAthleteActivities(now, startDate);
for (StravaActivity.SummaryActivity summaryActivity in summaryActivities) {
Activity.fromStrava(
var activity = Activity.fromStrava(
summaryActivity: summaryActivity,
athlete: athlete,
);
var existingAlready = await DbActivity()
.select()
.stravaId
.equals(activity.db.stravaId)
.toList();
if (existingAlready.length == 0) {
activity.db.save();
}
}
}
static Future<List<Activity>> all() async {
List<DbActivity> dbActivityList = await DbActivity().select().toList();
List<DbActivity> dbActivityList =
await DbActivity().select().orderByDesc('stravaId').toList();
return dbActivityList
.map((dbActivity) => Activity.fromDb(dbActivity))
.toList();
......
......@@ -21,12 +21,14 @@ class _ListActivitiesScreenState extends State<ListActivitiesScreen> {
@override
Widget build(BuildContext context) {
activities = Activity.all();
return Scaffold(
appBar: AppBar(
title: Text('Activities'),
),
body: FutureBuilder<List<Activity>>(
future: Activity.all(),
future: activities,
builder: (context, snapshot) {
return ListView(
padding: EdgeInsets.all(20),
......@@ -34,10 +36,9 @@ class _ListActivitiesScreenState extends State<ListActivitiesScreen> {
if (widget.athlete.email != null &&
widget.athlete.password != null)
ListTile(
leading: Icon(Icons.cloud_download),
title: Text("Download Activities from Strava"),
onTap: () => Activity.queryStrava(athlete: widget.athlete),
),
leading: Icon(Icons.cloud_download),
title: Text("Download Activities from Strava"),
onTap: () => queryStrava()),
if (widget.athlete.password == null)
ListTile(
leading: Icon(Icons.error),
......@@ -59,7 +60,7 @@ class _ListActivitiesScreenState extends State<ListActivitiesScreen> {
value: activity,
child: Consumer<Activity>(
builder: (context, activity, _child) =>
stateIcon(activity, widget.athlete),
stateIcon(activity: activity),
),
),
),
......@@ -70,13 +71,33 @@ class _ListActivitiesScreenState extends State<ListActivitiesScreen> {
);
}
stateIcon(Activity activity, Athlete athlete) {
Future queryStrava() async {
await Activity.queryStrava(athlete: widget.athlete);
setState(() => {});
}
Future delete({Activity activity}) async {
await activity.delete();
setState(() => {});
}
stateIcon({Activity activity}) {
switch (activity.db.state) {
case "new":
return IconButton(
icon: Icon(Icons.cloud_download),
onPressed: () => activity.download(athlete: athlete),
tooltip: 'Download',
return Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
icon: Icon(Icons.cloud_download),
onPressed: () => activity.download(athlete: widget.athlete),
tooltip: 'Download',
),
IconButton(
icon: Icon(Icons.delete),
onPressed: () => delete(activity: activity),
tooltip: 'Delete',
),
],
);
break;
case "downloaded":
......@@ -85,12 +106,12 @@ class _ListActivitiesScreenState extends State<ListActivitiesScreen> {
children: <Widget>[
IconButton(
icon: Icon(Icons.build),
onPressed: () => activity.parse(athlete: athlete),
onPressed: () => activity.parse(athlete: widget.athlete),
tooltip: 'Parse .fit-file',
),
IconButton(
icon: Icon(Icons.cloud_download),
onPressed: () => activity.download(athlete: athlete),
onPressed: () => activity.download(athlete: widget.athlete),
tooltip: 'Download',
),
],
......@@ -116,7 +137,7 @@ class _ListActivitiesScreenState extends State<ListActivitiesScreen> {
),
IconButton(
icon: Icon(Icons.build),
onPressed: () => activity.parse(athlete: athlete),
onPressed: () => activity.parse(athlete: widget.athlete),
tooltip: 'Parse .fit-file',
),
],
......
......@@ -7,7 +7,7 @@ dateTimeFromStrava(double dateTime) {
}
extension DurationFormatters on Duration {
String print() {
String asString() {
return inHours.toString() +
"h " +
inMinutes.remainder(60).toString() +
......
......@@ -62,12 +62,12 @@ class ActivityMetadataWidget extends StatelessWidget {
ListTile(
leading: Icon(Icons.timer),
title:
Text(Duration(seconds: activity.db.totalElapsedTime).print()),
Text(Duration(seconds: activity.db.totalElapsedTime).asString()),
subtitle: Text('total elapsed time'),
),
ListTile(
leading: Icon(Icons.timer),
title: Text(Duration(seconds: activity.db.totalTimerTime).print()),
title: Text(Duration(seconds: activity.db.totalTimerTime).asString()),
subtitle: Text('total timer time'),
),
ListTile(
......
......@@ -23,7 +23,7 @@ class ActivityOverviewWidget extends StatelessWidget {
),
ListTile(
leading: Icon(Icons.timer),
title: Text(Duration(seconds: activity.db.movingTime).print()),
title: Text(Duration(seconds: activity.db.movingTime).asString()),
subtitle: Text('moving time'),
),
ListTile(
......
......@@ -48,12 +48,12 @@ class LapMetadataWidget extends StatelessWidget {
),
ListTile(
leading: Icon(Icons.timer),
title: Text(Duration(seconds: lap.db.totalElapsedTime).print()),
title: Text(Duration(seconds: lap.db.totalElapsedTime).asString()),
subtitle: Text('total elapsed time'),
),
ListTile(
leading: Icon(Icons.timer),
title: Text(Duration(seconds: lap.db.totalTimerTime).print()),
title: Text(Duration(seconds: lap.db.totalTimerTime).asString()),
subtitle: Text('total timer time'),
),
ListTile(
......
......@@ -3,8 +3,6 @@ import 'package:charts_flutter/flutter.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/event.dart';
import 'package:encrateia/models/plot_point.dart';
import 'package:encrateia/models/power_duration.dart';
class PowerDurationChart extends StatelessWidget {
final List<Event> records;
......@@ -36,6 +34,21 @@ class PowerDurationChart extends StatelessWidget {
TickSpec(PowerDuration.scaled(seconds: 3600), label: '1h'),
];
final chartTitles = [
ChartTitle(
'Power (W)',
titleStyleSpec: TextStyleSpec(fontSize: 13),
behaviorPosition: BehaviorPosition.start,
titleOutsideJustification: OutsideJustification.end,
),
ChartTitle(
'Time',
titleStyleSpec: TextStyleSpec(fontSize: 13),
behaviorPosition: BehaviorPosition.bottom,
titleOutsideJustification: OutsideJustification.end,
),
];
return new Container(
height: 300,
padding: EdgeInsets.all(2),
......@@ -49,26 +62,10 @@ class PowerDurationChart extends StatelessWidget {
desiredMinTickCount: 6),
),
domainAxis: NumericAxisSpec(
tickProviderSpec:
StaticNumericTickProviderSpec(staticTicks)),
tickProviderSpec: StaticNumericTickProviderSpec(staticTicks)),
animate: false,
behaviors: [
ChartTitle(
'Power (W)',
titleStyleSpec: TextStyleSpec(fontSize: 13),
behaviorPosition: BehaviorPosition.start,
titleOutsideJustification: OutsideJustification.end,
),
ChartTitle(
'Time',
titleStyleSpec: TextStyleSpec(fontSize: 13),
behaviorPosition: BehaviorPosition.bottom,
titleOutsideJustification: OutsideJustification.end,
),
],
behaviors: chartTitles,
),
);
}
}
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