Skip to content

Commit

Permalink
geez..state is starting to work and fail
Browse files Browse the repository at this point in the history
  • Loading branch information
Desync-o-tron committed Sep 19, 2024
1 parent 271c83b commit a650384
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 33 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ If you're interested in collaborating, please reach out.
- [x] Create a basic UI for searching exercises, and adding them to a training session.
- [x] (in progress) Add history and permanant state
- [x] (in progress) Add the ability to ingest training data from other apps
- [x] (in progress) Add charts for tracking progress
- [ ] Reach out for help to prettify the UI
- [ ] Add the ability to upload custom exercises so they can be added to the database for all users
- [ ] Add the ability to store photos & videos? in a training session notes data
- [ ] Add the ability to log & view bodyweight
- [ ] Add charts for tracking progress
- [ ] Add history for a muscle group
- [ ] Add a full body fatigue tracker
- Look into video analysis for muscle activation. see [this paper](https://musclesinaction.cs.columbia.edu/) and things like it
- [ ] Add import/export csv or json for training history
- [ ] Add the ability to view other user's workouts so trainers and users can share workouts
- [ ] (Optional?) Add a recommendation engine for exercises that you want prioritized
- [ ] Create a basic backend for saving anonimized training so we can get stats for models later
- [ ] Add import/export for openfitnesstracker training history


## Attributions
Expand Down
7 changes: 5 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ dependencies {
implementation 'androidx.multidex:multidex:2.0.1'

// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:32.8.0')
implementation platform('com.google.firebase:firebase-bom:33.3.0')
// implementation platform('com.google.firebase:firebase-bom:32.8.0')

// Add the dependency for the Firebase SDK for Google Analytics
implementation("com.google.firebase:firebase-analytics")
Expand All @@ -82,6 +83,8 @@ dependencies {

implementation("com.google.firebase:firebase-firestore")

// Also add the dependency for the Google Play services library and dont? specify its version
implementation("com.google.android.gms:play-services-auth")
// Also add the dependency for the Google Play services library and specify its version
implementation("com.google.android.gms:play-services-auth:21.0.0")
// implementation("com.google.android.gms:play-services-auth:21.0.0")
}
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ buildscript {

plugins {
// Add the dependency for the Google services Gradle plugin
id 'com.google.gms.google-services' version '4.3.15' apply false
// id 'com.google.gms.google-services' version '4.4.1' apply false
// id 'com.google.gms.google-services' version '4.3.15' apply false
id 'com.google.gms.google-services' version '4.4.2' apply false

}

Expand Down
3 changes: 2 additions & 1 deletion android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
// START: FlutterFire Configuration
id "com.google.gms.google-services" version "4.3.15" apply false
id "com.google.gms.google-services" version "4.4.2" apply false
// id "com.google.gms.google-services" version "4.3.15" apply false
// END: FlutterFire Configuration
}

Expand Down
29 changes: 15 additions & 14 deletions lib/cloud_io/firestore_sync.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// ignore_for_file: curly_braces_in_flow_control_structures

import 'dart:async';
import 'dart:async';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
Expand All @@ -15,7 +12,7 @@ MyStorage myStorage = MyStorage();
class MyStorage {
static const _historyKey = 'TrainingHistory';
final FirebaseFirestore firestore = FirebaseFirestore.instance;
var _historyCacheClock = CollectionCacheUpdateClock(_historyKey);
final _historyCacheClock = CollectionCacheUpdateClock(_historyKey);

Future<void> addTrainingSessionToHistory(TrainingSession session) async {
CollectionReference users = firestore.collection('users');
Expand Down Expand Up @@ -48,7 +45,6 @@ class MyStorage {

return query.snapshots().map((snapshot) {
return snapshot.docs.map((doc) {
// print(doc.data());
return TrainingSession.fromJson(doc.data() as Map<String, dynamic>)..id = doc.id;
}).toList();
});
Expand All @@ -62,19 +58,25 @@ class MyStorage {

Future<List<TrainingSession>> getEntireUserTrainingHistory(
{required bool useCache}) async {
if (FirebaseAuth.instance.currentUser == null) return Future.error("please sign in");
if (!FirebaseAuth.instance.currentUser!.emailVerified)
return Future.error("please verify email");
if (FirebaseAuth.instance.currentUser == null) return [];
if (!FirebaseAuth.instance.currentUser!.emailVerified) return [];

final FirebaseFirestore firestore = FirebaseFirestore.instance;
CollectionReference users = firestore.collection('users');
DocumentReference userDoc = users.doc(FirebaseAuth.instance.currentUser!.uid);

QuerySnapshot<Object?> cloudTrainingHistory;
if (useCache) {
cloudTrainingHistory = await userDoc.collection(_historyKey).getSavy();
cloudTrainingHistory = await userDoc
.collection(_historyKey)
.get(const GetOptions(source: Source.cache));
print('cache had ${cloudTrainingHistory.docs.length} items');
} else {
cloudTrainingHistory = await userDoc.collection(_historyKey).get();
cloudTrainingHistory = await userDoc
.collection(_historyKey)
.get(const GetOptions(source: Source.server));
// cloudTrainingHistory = await userDoc.collection(_historyKey).get();
print('server had ${cloudTrainingHistory.docs.length} items');
_historyCacheClock.resetClock();
}

Expand Down Expand Up @@ -103,13 +105,12 @@ class MyStorage {
}
}

//todo I should be selective about how I call this...gets esp. to server can fail!
class CollectionCacheUpdateClock {
// static const String shared_prefs_label = 'last_true_time';
final String _collectionName;
final String _sharedPrefsLabel;
late final Future<SharedPreferences> _prefs;
CollectionCacheUpdateClock(this._collectionName)
: _sharedPrefsLabel = 'last_set_$_collectionName' {
CollectionCacheUpdateClock(String collectionName)
: _sharedPrefsLabel = 'last_set_$collectionName' {
_prefs = SharedPreferences.getInstance();
}

Expand Down
1 change: 1 addition & 0 deletions lib/community/charts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class _CoolChartState extends State<CoolChart> {
void _loadData() async {
List<TrainingSession> trainHist =
await myStorage.getEntireUserTrainingHistory(useCache: true);
if (trainHist.isEmpty) return;

for (var trainSesh in trainHist) {
for (var setsOfAnExercise in trainSesh.trainingData) {
Expand Down
31 changes: 19 additions & 12 deletions lib/history/history_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class HistoryPage extends StatefulWidget {
class _HistoryPageState extends State<HistoryPage> {
final int _pageSize = 10; // Number of items per page
final List<TrainingSession> _sessions = [];
var numSessions = 0;
bool _isLoading = false;
bool _hasMore = true;
DateTime? _lastTimestamp;
Expand Down Expand Up @@ -49,7 +50,7 @@ class _HistoryPageState extends State<HistoryPage> {
super.dispose();
}

void _loadMoreData() {
void _loadMoreData() async {
setState(() {
_isLoading = true;
});
Expand Down Expand Up @@ -84,19 +85,25 @@ class _HistoryPageState extends State<HistoryPage> {
//todo error handling?
}
});
numSessions = (await myStorage.getEntireUserTrainingHistory(useCache: true)).length;
setState(() {
//numSessions
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('History'),
actions: [
_hamburgerMenuActions(context),
],
),
body: _buildBody(),
);
return Builder(builder: (context) {
return Scaffold(
appBar: AppBar(
title: Text('History ($numSessions)'),
actions: [
_hamburgerMenuActions(context),
],
),
body: _buildBody(),
);
});
}

Widget _buildBody() {
Expand All @@ -107,7 +114,7 @@ class _HistoryPageState extends State<HistoryPage> {
} else {
return ListView.builder(
controller: _scrollController,
itemCount: _sessions.length + 1, // (_hasMore ? 1 : 0),
itemCount: _sessions.length + 1,
itemBuilder: (context, index) {
if (index < _sessions.length) {
return TrainingSessionHistoryCard(session: _sessions[index]);
Expand Down Expand Up @@ -143,7 +150,7 @@ class _HistoryPageState extends State<HistoryPage> {
});
}
if (result == 'refresh training history') {
myStorage.getEntireUserTrainingHistory(useCache: true);
myStorage.getEntireUserTrainingHistory(useCache: false);
}
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
Expand Down

0 comments on commit a650384

Please sign in to comment.