Commit 0b162356 authored by Administrator's avatar Administrator

activities taggable

parent 98afc6e7
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.7/","dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.7/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+2/","dependencies":[]},{"name":"shared_preferences_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+8/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"url_launcher_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+5/","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"shared_preferences_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+5/","dependencies":[]},{"name":"url_launcher_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.1+5/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]},{"name":"uni_links","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_macos"]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-05-15 10:00:46.952193","version":"1.17.1"}
\ No newline at end of file
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.7/","dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.7/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+2/","dependencies":[]},{"name":"shared_preferences_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+8/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"url_launcher_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+5/","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"shared_preferences_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+5/","dependencies":[]},{"name":"url_launcher_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.1+5/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]},{"name":"uni_links","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_macos"]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-05-15 14:29:11.956456","version":"1.17.1"}
\ No newline at end of file
......@@ -52,7 +52,7 @@ class Activity extends ChangeNotifier {
..name = "t.b.d.";
}
String toString() => '$db.name $db.startTime';
String toString() => '< Activity | ${db.name} | ${db.startTime} >';
Duration movingDuration() => Duration(seconds: db.movingTime ?? 0);
get({ActivityAttr activityAttr}) {
......@@ -176,7 +176,7 @@ class Activity extends ChangeNotifier {
Future<List<Lap>> get laps async {
if (_laps == null) {
_laps = await Lap.by(activity: this);
_laps = await Lap.all(activity: this);
}
return _laps;
}
......
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/tag.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/model/model.dart';
class ActivityTagging extends ChangeNotifier {
DbActivityTagging db;
ActivityTagging({
@required Activity activity,
@required Tag tag,
}) {
db = DbActivityTagging()
..activitiesId = activity.db.id
..tagsId = tag.db.id
..system = false;
}
ActivityTagging.fromDb(this.db);
static createBy({
@required Activity activity,
@required Tag tag,
}) async {
var dbActivityTagging = await DbActivityTagging()
.select()
.activitiesId
.equals(activity.db.id)
.and
.tagsId
.equals(tag.db.id)
.toSingle();
if (dbActivityTagging != null)
return ActivityTagging.fromDb(dbActivityTagging);
else {
var activityTagging = ActivityTagging(
activity: activity,
tag: tag,
);
await activityTagging.db.save();
return activityTagging;
}
}
static getBy({
@required Activity activity,
@required Tag tag,
}) async {
var dbActivityTagging = await DbActivityTagging()
.select()
.activitiesId
.equals(activity.db.id)
.and
.tagsId
.equals(tag.db.id)
.toSingle();
if (dbActivityTagging != null)
return ActivityTagging.fromDb(dbActivityTagging);
}
static deleteBy({
@required Activity activity,
@required Tag tag,
}) async {
var dbActivityTagging = await DbActivityTagging()
.select()
.activitiesId
.equals(activity.db.id)
.and
.tagsId
.equals(tag.db.id)
.toSingle();
await dbActivityTagging.delete();
}
String toString() =>
'< ActivityTagging | actvityId ${db.activitiesId} | tagId ${db.tagsId} >';
delete() async {
await this.db.delete();
}
}
......@@ -21,7 +21,7 @@ class Athlete extends ChangeNotifier {
Athlete();
Athlete.fromDb(this.db);
String toString() => '$db.firstName $db.lastName ($db.stravaId)';
String toString() => '< Athlete | ${db.firstName} ${db.lastName} | ${db.stravaId} >';
updateFromStravaAthlete(DetailedAthlete athlete) {
db
......
......@@ -15,6 +15,8 @@ class Event {
Event.fromDb(this.db);
String toString() => '< Event | {$db.event} | $index >';
Event({
@required DataMessage dataMessage,
@required this.activity,
......
......@@ -29,7 +29,7 @@ class HeartRateZone extends ChangeNotifier {
}
HeartRateZone.fromDb(this.db);
String toString() => '$db.date $db.name';
String toString() => '< HeartRateZone | ${db.name} | ${db.lowerLimit} >';
delete() async {
await this.db.delete();
......
......@@ -110,7 +110,7 @@ class HeartRateZoneSchema extends ChangeNotifier {
}
String toString() => '$db.date $db.name';
String toString() => '< HeartRateZoneSchema | ${db.name} | ${db.date} >';
delete() async {
await this.db.delete();
......
......@@ -204,7 +204,7 @@ class Lap {
return db.sdevFormPower;
}
static Future<List<Lap>> by({Activity activity}) async {
static Future<List<Lap>> all({Activity activity}) async {
int counter = 1;
List<DbLap> dbLapList = await activity.db.getDbLaps().toList();
......
......@@ -3,6 +3,8 @@ class IntPlotPoint {
int measure;
IntPlotPoint({this.domain, this.measure});
String toString() => '< IntPlotPoint | $domain | $measure >';
}
class DoublePlotPoint {
......@@ -10,4 +12,6 @@ class DoublePlotPoint {
double measure;
DoublePlotPoint({this.domain, this.measure});
String toString() => '< DoublePlotPoint | $domain | $measure >';
}
......@@ -29,7 +29,7 @@ class PowerZone extends ChangeNotifier {
}
PowerZone.fromDb(this.db);
String toString() => '$db.date $db.name';
String toString() => '< PowerZone | ${db.name} | ${db.lowerLimit} >';
delete() async {
await this.db.delete();
......
......@@ -177,7 +177,7 @@ class PowerZoneSchema extends ChangeNotifier {
).db.save();
}
String toString() => '$db.date $db.name';
String toString() => '< PowerZoneSchema | ${db.name} | ${db.date} >';
delete() async {
await this.db.delete();
......
......@@ -4,6 +4,7 @@ import 'package:encrateia/models/tag_group.dart';
class Tag extends ChangeNotifier {
DbTag db;
bool selected;
Tag({
@required TagGroup tagGroup,
......@@ -17,7 +18,7 @@ class Tag extends ChangeNotifier {
}
Tag.fromDb(this.db);
String toString() => '$db.date $db.name';
String toString() => '< Tag | ${db.name} >';
delete() async {
await this.db.delete();
......
......@@ -3,9 +3,11 @@ import 'package:encrateia/utils/my_color.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/model/model.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/activity.dart';
class TagGroup extends ChangeNotifier {
DbTagGroup db;
List<Tag> cachedTags;
TagGroup({@required Athlete athlete}) {
db = DbTagGroup()
......@@ -16,7 +18,12 @@ class TagGroup extends ChangeNotifier {
}
TagGroup.fromDb(this.db);
get tags => Tag.all(tagGroup: this);
Future<List<Tag>> get tags async {
if (cachedTags == null) {
cachedTags = await Tag.all(tagGroup: this);
}
return cachedTags;
}
TagGroup.by(
{@required Athlete athlete,
......@@ -30,7 +37,7 @@ class TagGroup extends ChangeNotifier {
..name = name;
}
String toString() => '$db.name';
String toString() => '< Taggroup | ${db.name} >';
delete() async {
await this.db.delete();
......@@ -54,24 +61,37 @@ class TagGroup extends ChangeNotifier {
await autoPowerZonesTagGroup.db.save();
}
static includingActivityTaggings({
@required Athlete athlete,
@required Activity activity,
}) async {
var tagGroups = await all(athlete: athlete);
var dbActivityTaggings = await DbActivityTagging()
.select()
.activitiesId
.equals(activity.db.id)
.toList();
var selectedTagIds = dbActivityTaggings
.map((DbActivityTagging dbActivityTagging) => dbActivityTagging.id);
for (TagGroup tagGroup in tagGroups) {
var tags = await tagGroup.tags;
for (Tag tag in tags) {
tag.selected = selectedTagIds.contains(tag.db.id) ? true : false;
}
}
return tagGroups;
}
static Future<List<TagGroup>> all({@required Athlete athlete}) async {
var dbTagGroupList =
await athlete.db.getDbTagGroups().orderBy('name').toList();
var tagGroups = dbTagGroupList
.map((dbTagGroup) => TagGroup.fromDb(dbTagGroup))
.toList();
return tagGroups;
}
static getBy({
int athletesId,
}) async {
var dbTagGroups = await DbTagGroup()
.select()
.athletesId
.equals(athletesId)
.top(1)
.toList();
if (dbTagGroups.length != 0) return TagGroup.fromDb(dbTagGroups.first);
return tagGroups;
}
}
......@@ -13,7 +13,7 @@ class Weight extends ChangeNotifier {
}
Weight.fromDb(this.db);
String toString() => '$db.date $db.value';
String toString() => '< Weight | ${db.date} | ${db.value} >';
delete() async {
await this.db.delete();
......
......@@ -4,6 +4,7 @@ import 'package:encrateia/widgets/activity_widgets/activity_metadata_widget.dart
import 'package:encrateia/widgets/activity_widgets/activity_overview_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_power_ratio_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_speed_per_heart_rate_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_tag_widget.dart';
import 'package:encrateia/widgets/laps_list_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_heart_rate_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_power_widget.dart';
......@@ -216,7 +217,7 @@ class ShowActivityScreen extends StatelessWidget {
color: MyColor.tag,
icon: MyIcon.tag,
context: context,
nextWidget: ActivityMetadataWidget(
nextWidget: ActivityTagWidget(
activity: activity,
athlete: athlete,
),
......@@ -237,10 +238,7 @@ class ShowActivityScreen extends StatelessWidget {
}) {
return RaisedButton.icon(
color: color,
textColor:
(ThemeData.estimateBrightnessForColor(color) == Brightness.light)
? MyColor.black
: MyColor.white,
textColor: MyColor.textColor(backgroundColor: color),
icon: icon,
label: Text(title),
onPressed: () => Navigator.push(
......
......@@ -186,10 +186,7 @@ class _ShowAthleteScreenState extends State<ShowAthleteScreen> {
}) {
return RaisedButton.icon(
color: color ?? MyColor.primary,
textColor:
(ThemeData.estimateBrightnessForColor(color) == Brightness.light)
? MyColor.black
: MyColor.white,
textColor: MyColor.textColor(backgroundColor: color),
icon: icon,
label: Text(title),
onPressed: () => Navigator.push(
......
......@@ -141,10 +141,7 @@ class ShowLapScreen extends StatelessWidget {
}) {
return RaisedButton.icon(
color: color ?? MyColor.primary,
textColor:
(ThemeData.estimateBrightnessForColor(color) == Brightness.light)
? MyColor.black
: MyColor.white,
textColor: MyColor.textColor(backgroundColor: color),
icon: icon,
label: Text(title),
onPressed: () => Navigator.push(
......
......@@ -62,4 +62,18 @@ class MyColor {
static Color activity = aquaAccent;
static Color lap = grassAccent;
static Color tag = lavender;
static Color textColor({
@required Color backgroundColor,
bool selected: true,
}) {
if (selected) {
if (ThemeData.estimateBrightnessForColor(backgroundColor) ==
Brightness.light)
return black;
else
return white;
} else
return black;
}
}
import 'dart:ui';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/tag.dart';
import 'package:encrateia/models/activityTagging.dart';
import 'package:encrateia/models/tag_group.dart';
import 'package:encrateia/utils/my_color.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
class ActivityTagWidget extends StatefulWidget {
final Activity activity;
final Athlete athlete;
ActivityTagWidget({
@required this.activity,
@required this.athlete,
});
@override
_ActivityTagWidgetState createState() => _ActivityTagWidgetState();
}
class _ActivityTagWidgetState extends State<ActivityTagWidget> {
List<TagGroup> tagGroups;
@override
void initState() {
getData();
super.initState();
}
@override
Widget build(context) {
if (tagGroups == null)
return Center(child: Text("Loading ..."));
else
return ListTileTheme(
iconColor: MyColor.tag,
child: ListView.builder(
itemCount: tagGroups?.length ?? 0,
itemBuilder: (context, index) {
TagGroup tagGroup = tagGroups[index];
return Card(
child: ListTile(
contentPadding: EdgeInsets.all(20),
subtitle: Wrap(
spacing: 15,
children: [
for (Tag tag in tagGroup.cachedTags)
InputChip(
label: Text(
tag.db.name,
style: TextStyle(
color: MyColor.textColor(
selected: tag.selected,
backgroundColor: Color(tag.db.color),
),
),
),
avatar: CircleAvatar(
backgroundColor: Color(tag.db.color),
),
onSelected: (selected) {
setState(() {
if (selected) {
ActivityTagging.createBy(
activity: widget.activity,
tag: tag,
);
} else {
ActivityTagging.deleteBy(
activity: widget.activity,
tag: tag,
);
}
tag.selected = selected;
});
},
selected: tag.selected,
selectedColor: Color(tag.db.color),
backgroundColor: MyColor.white,
elevation: 3,
padding: EdgeInsets.all(10),
)
],
),
title: Text(tagGroup.db.name + "\n"),
),
);
},
),
);
}
getData() async {
tagGroups = await TagGroup.includingActivityTaggings(
athlete: widget.athlete,
activity: widget.activity,
);
setState(() {});
}
}
......@@ -42,7 +42,7 @@ class ActivityHeartRateChart extends StatelessWidget {
];
return FutureBuilder<List<Lap>>(
future: Lap.by(activity: activity),
future: Lap.all(activity: activity),
builder: (BuildContext context, AsyncSnapshot<List<Lap>> snapshot) {
if (snapshot.hasData) {
var laps = snapshot.data;
......
......@@ -18,7 +18,7 @@ class LapsListWidget extends StatelessWidget {
@override
Widget build(context) {
return FutureBuilder<List<Lap>>(
future: Lap.by(activity: activity),
future: Lap.all(activity: activity),
builder: (BuildContext context, AsyncSnapshot<List<Lap>> snapshot) {
if (snapshot.hasData) {
List<Lap> laps = snapshot.data;
......
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