Commit 4dc336bd authored by Stefan Haslinger's avatar Stefan Haslinger

move parse .fit-file into ShowActivityScreen

parent dc21eaf9
......@@ -158,7 +158,7 @@ class Activity extends ChangeNotifier {
String averagePowerString() {
return (db.avgPower == null || db.avgPower == -1)
? '- - -'
? '-'
: db.avgPower.toStringAsFixed(1) + ' W';
}
......
......@@ -242,7 +242,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
color: MyColor.add,
icon: MyIcon.settings,
textColor: MyColor.textColor(backgroundColor: MyColor.add),
label: const Flexible(
label: const Expanded(
child: Text('Rerun Autotagging'),
),
onPressed: () => autoTagger(),
......@@ -253,18 +253,29 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
color: MyColor.add,
icon: MyIcon.download,
textColor: MyColor.textColor(backgroundColor: MyColor.add),
label: const Flexible(
child: Text('Redownload .fit'),
label: const Expanded(
child: Text('Download fit file'),
),
onPressed: () => download(),
),
if (<String>['downloaded', 'persisted'].contains(widget.activity.db.state))
RaisedButton.icon(
color: MyColor.add,
icon: MyIcon.parse,
textColor: MyColor.textColor(backgroundColor: MyColor.add),
label: const Expanded(
child: Text('Parse fit file'),
),
onPressed: () => parse(),
),
if (<String>['new', 'downloaded', 'persisted'].contains(widget.activity.db.state))
RaisedButton.icon(
color: MyColor.delete,
icon: MyIcon.delete,
textColor: MyColor.textColor(backgroundColor: MyColor.delete),
label: const Flexible(
label: const Expanded(
child: Text('Delete Activity'),
),
onPressed: () => delete(),
......@@ -343,12 +354,12 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
setState(() {});
}
Future<void> delete({Activity activity}) async {
Future<void> delete() async {
await widget.activity.delete();
Navigator.of(context).pop();
}
Future<void> download({Activity activity}) async {
Future<void> download() async {
flushbar = Flushbar<Object>(
message: 'Download .fit-File for »${widget.activity.db.name}«',
duration: const Duration(seconds: 10),
......@@ -366,4 +377,26 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
setState(() {});
}
Future<void> parse() async {
Flushbar<Object> flushbar = Flushbar<Object>(
message: '0% of storing »${widget.activity.db.name}«',
duration: const Duration(seconds: 10),
animationDuration: const Duration(milliseconds: 1),
titleText: const LinearProgressIndicator(value: 0),
)..show(context);
final Stream<int> percentageStream =
widget.activity.parse(athlete: widget.athlete);
await for (final int value in percentageStream) {
flushbar.dismiss();
flushbar = Flushbar<Object>(
titleText: LinearProgressIndicator(value: value / 100),
message: '$value% of storing »${widget.activity.db.name}«',
duration: const Duration(seconds: 3),
animationDuration: const Duration(milliseconds: 1),
)..show(context);
}
setState(() {});
}
}
......@@ -16,10 +16,6 @@ enum LapDoubleAttr {
ecor,
}
enum ActivityAction {
parse,
}
enum ActivityAttr {
avgPower,
avgPowerPerHeartRate,
......
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:encrateia/screens/show_activity_screen.dart';
import 'package:encrateia/utils/icon_utils.dart';
import 'package:flushbar/flushbar.dart';
import 'package:encrateia/utils/enums.dart';
class ActivitiesFeedWidget extends StatefulWidget {
const ActivitiesFeedWidget({Key key, this.athlete}) : super(key: key);
......@@ -39,36 +37,25 @@ class _ActivitiesFeedWidgetState extends State<ActivitiesFeedWidget> {
separatorBuilder: (BuildContext context, int index) => Divider(
color: Colors.black,
),
padding: const EdgeInsets.only(top: 20),
padding: const EdgeInsets.only(top: 10),
itemCount: activities.length,
itemBuilder: (BuildContext context, int index) {
final Activity activity = activities[index];
return ListTile(
leading: sportsIcon(sport: activity.db.sport),
title: Text(activity.db.name ?? 'Activity'),
subtitle: SingleChildScrollView(
scrollDirection: Axis.horizontal,
subtitle: Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text(activity.dateString() + '\n' + activity.distanceString()),
const SizedBox(width: 20),
Text(activity.paceString()),
Text(activity.paceString() + "\n" + activity.heartRateString()),
const SizedBox(width: 20),
Text(activity.heartRateString() +
'\n' +
activity.averagePowerString()),
Text(activity.averagePowerString()),
],
),
),
trailing: ChangeNotifierProvider<Activity>.value(
value: activity,
child: Consumer<Activity>(
builder:
(BuildContext context, Activity activity, Widget _child) =>
popupMenuButton(activity: activity),
),
),
onTap: () async {
if (activity.db.state == 'persisted') {
await Navigator.push(
......@@ -99,67 +86,11 @@ class _ActivitiesFeedWidgetState extends State<ActivitiesFeedWidget> {
}
}
Future<void> parse({Activity activity}) async {
Flushbar<Object> flushbar = Flushbar<Object>(
message: '0% of storing »${activity.db.name}«',
duration: const Duration(seconds: 10),
animationDuration: const Duration(milliseconds: 1),
titleText: const LinearProgressIndicator(value: 0),
)..show(context);
final Stream<int> percentageStream =
activity.parse(athlete: widget.athlete);
await for (final int value in percentageStream) {
flushbar.dismiss();
flushbar = Flushbar<Object>(
titleText: LinearProgressIndicator(value: value / 100),
message: '$value% of storing »${activity.db.name}«',
duration: const Duration(seconds: 3),
animationDuration: const Duration(milliseconds: 1),
)..show(context);
}
activities = await Activity.all(athlete: widget.athlete);
setState(() {});
}
Future<void> getActivities() async {
activities = await Activity.all(athlete: widget.athlete);
setState(() {});
}
PopupMenuButton<ActivityAction> popupMenuButton({Activity activity}) {
List<String> actions;
switch (activity.db.state) {
case 'downloaded':
case 'persisted':
actions = <String>['parse'];
break;
}
return PopupMenuButton<ActivityAction>(
onSelected: (ActivityAction action) {
switch (action) {
case ActivityAction.parse:
parse(activity: activity);
break;
}
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<ActivityAction>>[
if (actions.contains('parse'))
PopupMenuItem<ActivityAction>(
value: ActivityAction.parse,
child: Row(
children: <Widget>[
MyIcon.parse,
const Text(' Parse .fit-file'),
],
),
),
],
);
}
void showMyFlushbar() {
if (widget.athlete.email == null) {
flushbar = Flushbar<Object>(
......
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