Commit f464a235 authored by Administrator's avatar Administrator

(my ;-) ) bugfix release for strava_flutter, download intervall as setting

parent b4e21656
......@@ -23,6 +23,7 @@ const tableAthlete = SqfEntityTable(
SqfEntityField('photoPath', DbType.text),
SqfEntityField('stravaId', DbType.integer),
SqfEntityField('geoState', DbType.text),
SqfEntityField('downloadInterval', DbType.integer),
],
);
......
......@@ -38,6 +38,7 @@ class TableDbAthlete extends SqfEntityTableBase {
SqfEntityFieldBase('photoPath', DbType.text),
SqfEntityFieldBase('stravaId', DbType.integer),
SqfEntityFieldBase('geoState', DbType.text),
SqfEntityFieldBase('downloadInterval', DbType.integer),
];
super.init();
}
......@@ -288,15 +289,31 @@ class DbAthlete {
this.stravaUsername,
this.photoPath,
this.stravaId,
this.geoState}) {
this.geoState,
this.downloadInterval}) {
_setDefaultValues();
}
DbAthlete.withFields(this.state, this.firstName, this.lastName,
this.stravaUsername, this.photoPath, this.stravaId, this.geoState) {
DbAthlete.withFields(
this.state,
this.firstName,
this.lastName,
this.stravaUsername,
this.photoPath,
this.stravaId,
this.geoState,
this.downloadInterval) {
_setDefaultValues();
}
DbAthlete.withId(this.id, this.state, this.firstName, this.lastName,
this.stravaUsername, this.photoPath, this.stravaId, this.geoState) {
DbAthlete.withId(
this.id,
this.state,
this.firstName,
this.lastName,
this.stravaUsername,
this.photoPath,
this.stravaId,
this.geoState,
this.downloadInterval) {
_setDefaultValues();
}
DbAthlete.fromMap(Map<String, dynamic> o) {
......@@ -308,6 +325,7 @@ class DbAthlete {
photoPath = o['photoPath'] as String;
stravaId = o['stravaId'] as int;
geoState = o['geoState'] as String;
downloadInterval = o['downloadInterval'] as int;
}
// FIELDS (DbAthlete)
int id;
......@@ -318,6 +336,7 @@ class DbAthlete {
String photoPath;
int stravaId;
String geoState;
int downloadInterval;
BoolResult saveResult;
// end FIELDS (DbAthlete)
......@@ -378,6 +397,10 @@ class DbAthlete {
map['geoState'] = geoState;
}
if (downloadInterval != null) {
map['downloadInterval'] = downloadInterval;
}
return map;
}
......@@ -415,6 +438,10 @@ class DbAthlete {
map['geoState'] = geoState;
}
if (downloadInterval != null) {
map['downloadInterval'] = downloadInterval;
}
// COLLECTIONS (DbAthlete)
if (!forQuery) {
map['DbActivities'] = await getDbActivities().toMapList();
......@@ -443,7 +470,8 @@ class DbAthlete {
stravaUsername,
photoPath,
stravaId,
geoState
geoState,
downloadInterval
];
}
......@@ -542,7 +570,7 @@ class DbAthlete {
/// Returns a <List<BoolResult>>
Future<List<BoolResult>> saveAll(List<DbAthlete> dbathletes) async {
final results = _mnDbAthlete.saveAll(
'INSERT OR REPLACE INTO athletes (id, state, firstName, lastName, stravaUsername, photoPath, stravaId, geoState) VALUES (?,?,?,?,?,?,?,?)',
'INSERT OR REPLACE INTO athletes (id, state, firstName, lastName, stravaUsername, photoPath, stravaId, geoState, downloadInterval) VALUES (?,?,?,?,?,?,?,?,?)',
dbathletes);
return results;
}
......@@ -553,7 +581,7 @@ class DbAthlete {
Future<int> _upsert() async {
try {
if (await _mnDbAthlete.rawInsert(
'INSERT OR REPLACE INTO athletes (id, state, firstName, lastName, stravaUsername, photoPath, stravaId, geoState) VALUES (?,?,?,?,?,?,?,?)',
'INSERT OR REPLACE INTO athletes (id, state, firstName, lastName, stravaUsername, photoPath, stravaId, geoState, downloadInterval) VALUES (?,?,?,?,?,?,?,?,?)',
[
id,
state,
......@@ -562,7 +590,8 @@ class DbAthlete {
stravaUsername,
photoPath,
stravaId,
geoState
geoState,
downloadInterval
]) ==
1) {
saveResult = BoolResult(
......@@ -586,7 +615,7 @@ class DbAthlete {
/// Returns a <List<BoolResult>>
Future<List<BoolResult>> upsertAll(List<DbAthlete> dbathletes) async {
final results = await _mnDbAthlete.rawInsertAll(
'INSERT OR REPLACE INTO athletes (id, state, firstName, lastName, stravaUsername, photoPath, stravaId, geoState) VALUES (?,?,?,?,?,?,?,?)',
'INSERT OR REPLACE INTO athletes (id, state, firstName, lastName, stravaUsername, photoPath, stravaId, geoState, downloadInterval) VALUES (?,?,?,?,?,?,?,?,?)',
dbathletes);
return results;
}
......@@ -1046,6 +1075,12 @@ class DbAthleteFilterBuilder extends SearchCriteria {
return _geoState = setField(_geoState, 'geoState', DbType.text);
}
DbAthleteField _downloadInterval;
DbAthleteField get downloadInterval {
return _downloadInterval =
setField(_downloadInterval, 'downloadInterval', DbType.integer);
}
bool _getIsDeleted;
void _buildParameters() {
......@@ -1402,6 +1437,13 @@ class DbAthleteFields {
return _fGeoState =
_fGeoState ?? SqlSyntax.setField(_fGeoState, 'geoState', DbType.text);
}
static TableField _fDownloadInterval;
static TableField get downloadInterval {
return _fDownloadInterval = _fDownloadInterval ??
SqlSyntax.setField(
_fDownloadInterval, 'downloadInterval', DbType.integer);
}
}
// endregion DbAthleteFields
......
......@@ -451,7 +451,8 @@ class Activity extends ChangeNotifier {
"${dataMessage.definitionMessage.globalMessageName} "
"are not implemented yet.");
print(dataMessage.values.map((v) => v.fieldName).toList());
debugger();
// Use this debugger to implement additional message types!
// debugger();
}
}
}
......@@ -477,7 +478,7 @@ class Activity extends ChangeNotifier {
prompt);
final now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
final startDate = now - 21 * 86400;
final startDate = now - athlete.db.downloadInterval * 86400;
List<StravaActivity.SummaryActivity> summaryActivities =
await strava.getLoggedInAthleteActivities(now, startDate);
......
......@@ -22,7 +22,8 @@ class Athlete extends ChangeNotifier {
..stravaUsername = athlete.username
..photoPath = athlete.profile
..geoState = athlete.state
..state = "fromStrava";
..state = "fromStrava"
..downloadInterval = 21;
notifyListeners();
}
......
......@@ -3,6 +3,7 @@ import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/widgets/activities_list_widget.dart';
import 'package:encrateia/widgets/athlete_widgets/athlete_power_widget.dart';
import 'package:encrateia/widgets/athlete_widgets/athlete_settings_widget.dart';
import 'package:encrateia/widgets/athlete_widgets/athlete_power_per_heart_rate_widget.dart';
import 'package:encrateia/widgets/athlete_widgets/athlete_speed_per_heart_rate_widget.dart';
import 'package:encrateia/utils/icon_utils.dart';
......@@ -32,7 +33,7 @@ class _ShowAthleteScreenState extends State<ShowAthleteScreen> {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 4,
length: 5,
child: Scaffold(
floatingActionButton: Visibility(
visible: floatingActionButtonVisible,
......@@ -46,6 +47,10 @@ class _ShowAthleteScreenState extends State<ShowAthleteScreen> {
title: Text(
widget.athlete.db.firstName + " " + widget.athlete.db.lastName),
bottom: TabBar(isScrollable: true, tabs: [
Tab(
icon: MyIcon.settings,
text: "Settings",
),
Tab(
icon: MyIcon.activities,
text: "Activities",
......@@ -65,6 +70,7 @@ class _ShowAthleteScreenState extends State<ShowAthleteScreen> {
]),
),
body: TabBarView(children: [
AthleteSettingsWidget(athlete: widget.athlete),
ActivitiesListWidget(athlete: widget.athlete),
AthletePowerWidget(athlete: widget.athlete),
AthletePowerPerHeartRateWidget(athlete: widget.athlete),
......
......@@ -65,6 +65,7 @@ class MyIcon {
static final repeats = Icon(Icons.loop);
static final running = Icon(Icons.directions_run);
// S
static final settings = Icon(Icons.settings);
static final show = Icon(Icons.remove_red_eye);
static final speed = Icon(Icons.shutter_speed);
static final sport = Icon(Icons.fitness_center);
......
import 'package:encrateia/utils/icon_utils.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/activity.dart';
class AthleteSettingsWidget extends StatefulWidget {
final Athlete athlete;
AthleteSettingsWidget({this.athlete});
@override
_AthleteSettingsWidgetState createState() => _AthleteSettingsWidgetState();
}
class _AthleteSettingsWidgetState extends State<AthleteSettingsWidget> {
List<Activity> activities = [];
String numberOfActivitiesString = "---";
@override
void initState() {
getData();
super.initState();
}
@override
Widget build(BuildContext context) {
var userDB = widget.athlete.db;
return ListView(
children: <Widget>[
ListTile(
leading: MyIcon.athlete,
title: Text("Name"),
subtitle: Text(
userDB.firstName + " " + userDB.lastName,
),
),
ListTile(
leading: MyIcon.stravaDownload,
title: Text("Strava ID / Username / Location"),
subtitle: Text(userDB.stravaId.toString() +
" / " +
userDB.stravaUsername +
" / " +
userDB.geoState),
),
ListTile(
leading: MyIcon.activities,
title: Text("Number of activities"),
subtitle: Text(numberOfActivitiesString),
),
ListTile(
leading: MyIcon.time,
title: Text("Days back in Time, activities are downloaded"),
subtitle: Row(
children: <Widget>[
Spacer(),
RaisedButton(
color: Colors.orange,
child: Text("- 7 days"),
onPressed: () => decreaseDownloadInterval(),
),
Spacer(),
Text(widget.athlete.db.downloadInterval.toString()),
Spacer(),
RaisedButton(
color: Colors.orange,
child: Text("+ 7 days"),
onPressed: () => increaseDownloadInterval(),
),
Spacer(),
],
),
),
],
);
}
getData() async {
activities = await widget.athlete.activities;
setState(() {
numberOfActivitiesString = activities.length.toString();
});
}
increaseDownloadInterval() async {
var userDB = widget.athlete.db;
userDB.downloadInterval = (userDB.downloadInterval ?? 21) + 7;
await userDB.save();
setState(() {});
}
decreaseDownloadInterval() async {
var userDB = widget.athlete.db;
userDB.downloadInterval = (userDB.downloadInterval ?? 21) - 7;
if(userDB.downloadInterval < 7) userDB.downloadInterval = 7;
await userDB.save();
setState(() {});
}
}
......@@ -9,7 +9,9 @@ class AthletePowerChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var nonZero = activities.where((value) => value.db.avgPower > 0).toList();
var nonZero = activities
.where((value) => value.db.avgPower != null && value.db.avgPower > 0)
.toList();
var data = [
new Series<Activity, DateTime>(
......@@ -26,6 +28,10 @@ class AthletePowerChart extends StatelessWidget {
child: TimeSeriesChart(
data,
animate: false,
defaultRenderer: LineRendererConfig(
includePoints: true,
dashPattern: [2, 2],
),
primaryMeasureAxis: NumericAxisSpec(
tickProviderSpec: BasicNumericTickProviderSpec(
zeroBound: false,
......
......@@ -10,7 +10,11 @@ class AthletePowerPerHeartRateChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var nonZero = activities
.where((value) => value.db.avgPower > 0 && value.db.avgHeartRate > 0)
.where((value) =>
value.db.avgPower != null &&
value.db.avgPower > 0 &&
value.db.avgHeartRate != null &&
value.db.avgHeartRate > 0)
.toList();
var data = [
......@@ -29,6 +33,10 @@ class AthletePowerPerHeartRateChart extends StatelessWidget {
child: TimeSeriesChart(
data,
animate: false,
defaultRenderer: LineRendererConfig(
includePoints: true,
dashPattern: [2, 2],
),
primaryMeasureAxis: NumericAxisSpec(
tickProviderSpec: BasicNumericTickProviderSpec(
zeroBound: false,
......
......@@ -10,7 +10,11 @@ class AthleteSpeedPerHeartRateChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var nonZero = activities
.where((value) => value.db.avgSpeed > 0 && value.db.avgHeartRate > 0)
.where((value) =>
value.db.avgSpeed != null &&
value.db.avgSpeed > 0 &&
value.db.avgHeartRate != null &&
value.db.avgHeartRate > 0)
.toList();
var data = [
......@@ -29,6 +33,10 @@ class AthleteSpeedPerHeartRateChart extends StatelessWidget {
child: TimeSeriesChart(
data,
animate: false,
defaultRenderer: LineRendererConfig(
includePoints: true,
dashPattern: [2, 2],
),
primaryMeasureAxis: NumericAxisSpec(
tickProviderSpec: BasicNumericTickProviderSpec(
zeroBound: false,
......
......@@ -608,7 +608,7 @@ packages:
name: strava_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0+44"
version: "1.2.0+45"
stream_channel:
dependency: transitive
description:
......
......@@ -11,7 +11,7 @@ dependencies:
sdk: flutter
flutter_launcher_icons: ^0.7.2
cupertino_icons: ^0.1.2
strava_flutter: ^1.2.0+44
strava_flutter: ^1.2.0+45
sqfentity: ^1.2.3+1
sqfentity_gen: ^1.2.1+13
......
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