WT 1.1.14 Tutorial, Sports, New goals

This commit is contained in:
bossanyit
2021-05-02 17:12:42 +02:00
parent 5fe8f76f48
commit c901b07bf8
65 changed files with 2472 additions and 620 deletions
+57 -39
View File
@@ -1,6 +1,7 @@
import 'dart:collection';
import 'dart:convert';
import 'package:aitrainer_app/model/customer.dart';
import 'package:aitrainer_app/model/customer_activity.dart';
import 'package:aitrainer_app/model/evaluation.dart';
import 'package:aitrainer_app/model/exercise_plan.dart';
import 'package:aitrainer_app/model/exercise_plan_detail.dart';
@@ -13,6 +14,8 @@ import 'package:aitrainer_app/model/product.dart';
import 'package:aitrainer_app/model/product_test.dart';
import 'package:aitrainer_app/model/property.dart';
import 'package:aitrainer_app/model/purchase.dart';
import 'package:aitrainer_app/model/sport.dart';
import 'package:aitrainer_app/model/tutorial.dart';
import 'package:aitrainer_app/model/workout_menu_tree.dart';
import 'package:aitrainer_app/repository/customer_repository.dart';
import 'package:aitrainer_app/service/firebase_api.dart';
@@ -24,11 +27,11 @@ import 'package:aitrainer_app/util/env.dart';
import 'package:aitrainer_app/util/track.dart';
import 'package:flurry/flurry.dart';
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
import 'package:flutter_uxcam/flutter_uxcam.dart';
import 'package:package_info/package_info.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:aitrainer_app/model/exercise_type.dart';
import 'package:intl/intl.dart';
import 'package:smartlook/smartlook.dart';
import 'customer_exercise_device.dart';
import 'exercise_device.dart';
@@ -55,6 +58,24 @@ enum SharePrefsChange {
- is_logged_in
*/
enum ActivityDone { tutorialBasic, tutorialDevelopment, isExerciseLogSeen, isMuscleDevelopmentSeen }
extension ActivityDoneExt on ActivityDone {
String toStr() => this.toString().split(".").last;
bool equalsTo(ActivityDone value) => this.toString() == value.toString();
bool equalsStringTo(String value) => this.toStr() == value;
ActivityDone? searchByString(String activityString) {
ActivityDone? activity;
ActivityDone.values.forEach((element) {
if (element.equalsStringTo(activityString)) {
activity = element;
}
});
return activity;
}
}
class Cache with Logging {
static final Cache _singleton = Cache._internal();
@@ -73,8 +94,6 @@ class Cache with Logging {
static final String activeExercisePlanKey = "active_exercise_plan";
static final String activeExercisePlanDateKey = "active_exercise_plan_date";
static final String activeExercisePlanDetailsKey = "active_exercise_details_plan";
static final String exerciseLogSeenKey = "exercise_log_seen";
static final String muscleDevelopmentSeenKey = "muscle_development_seen_key";
static String baseUrl = 'http://aitrainer.info:8888/api/';
static final String mediaUrl = 'https://aitrainer.info:4343/media/';
@@ -99,6 +118,7 @@ class Cache with Logging {
List<Exercise>? _exercises;
ExercisePlan? _myExercisePlan;
List<Property>? _properties;
List<Sport>? _sports;
List<wt_product.Product>? _products;
List<Purchase> _purchases = [];
List<ProductTest>? _productTests;
@@ -109,6 +129,8 @@ class Cache with Logging {
List<ExerciseDevice>? _devices;
List<CustomerExerciseDevice>? _customerDevices;
List<CustomerActivity>? _customerActivities;
List<Tutorial>? _tutorials;
LinkedHashMap<int, ExercisePlanDetail> _myExercisesPlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
@@ -126,8 +148,8 @@ class Cache with Logging {
late String testEnvironment;
bool liveServer = true;
bool? hasHardware = false;
bool? isExerciseLogSeen = false;
bool? isMuscleDevelopmentSeen = false;
HashMap<String, bool> activitiesDone = HashMap();
factory Cache() {
return _singleton;
@@ -140,6 +162,10 @@ class Cache with Logging {
baseUrl = 'http://aitrainer.app:8899/api/';
liveServer = false;
}
ActivityDone.values.forEach((element) {
activitiesDone[element.toStr()] = false;
});
}
void setTestBaseUrl() {
@@ -461,9 +487,11 @@ class Cache with Logging {
}
void setProperties(List<Property> properties) => this._properties = properties;
List<Property>? getProperties() => _properties;
List<Sport>? getSports() => _sports;
void setSports(List<Sport> sports) => this._sports = sports;
void setDevices(List<ExerciseDevice> devices) => this._devices = devices;
List<ExerciseDevice>? getDevices() => this._devices;
@@ -559,11 +587,11 @@ class Cache with Logging {
setBadge("account", true);
}
if (this._exercises != null && this._exercises!.isNotEmpty) {
if (!isExerciseLogSeen!) {
if (!activitiesDone[ActivityDone.isExerciseLogSeen.toStr()]!) {
setBadge("exerciseLog", true);
setBadge("development", true);
}
if (!isMuscleDevelopmentSeen!) {
if (!activitiesDone[ActivityDone.isMuscleDevelopmentSeen.toStr()]!) {
setBadge("muscleDevelopment", true);
setBadge("development", true);
}
@@ -589,14 +617,16 @@ class Cache with Logging {
if (!isInDebugMode) {
Flurry.setUserId(customerId.toString());
Smartlook.setUserIdentifier(customerId.toString());
//Smartlook.setUserIdentifier(customerId.toString());
FlutterUxcam.setUserProperty("username", customerId.toString());
Track().track(TrackingEvent.enter);
}
await setLoginTypeFromPrefs();
await getActiveExercisePlan();
await isExerciseLogSeenPrefs();
await isMuscleDevelopmentSeenPrefs();
await Future.forEach(ActivityDone.values, (element) async {
ActivityDone activity = element as ActivityDone;
await isActivityDonePrefs(activity);
});
Cache().startPage = "home";
}
@@ -609,41 +639,29 @@ class Cache with Logging {
List get exercisePlanTemplates => this._exercisePlanTemplates;
setExercisePlanTemplates(value) => this._exercisePlanTemplates = value;
setExerciseLogSeen() async {
isActivityDonePrefs(ActivityDone activity) async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences = await prefs;
isExerciseLogSeen = true;
sharedPreferences.setBool(Cache.exerciseLogSeenKey, true);
}
Future<bool> isExerciseLogSeenPrefs() async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences = await prefs;
isExerciseLogSeen = sharedPreferences.getBool(Cache.exerciseLogSeenKey);
if (isExerciseLogSeen == null) {
isExerciseLogSeen = false;
if (sharedPreferences.getBool(activity.toStr()) != null) {
activitiesDone[activity.toStr()] = sharedPreferences.getBool(activity.toStr())!;
}
//print("ExerciseLogSeen $isExerciseLogSeen");
return isExerciseLogSeen!;
return activitiesDone[activity.toStr()]!;
}
setMuscleDevelopmentSeen() async {
setActivityDonePrefs(ActivityDone activity) async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences = await prefs;
isMuscleDevelopmentSeen = true;
sharedPreferences.setBool(Cache.muscleDevelopmentSeenKey, true);
}
Future<bool> isMuscleDevelopmentSeenPrefs() async {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
SharedPreferences sharedPreferences = await prefs;
isMuscleDevelopmentSeen = sharedPreferences.getBool(Cache.muscleDevelopmentSeenKey);
if (isMuscleDevelopmentSeen == null) {
isMuscleDevelopmentSeen = false;
}
return isMuscleDevelopmentSeen!;
activitiesDone[activity.toStr()] = true;
sharedPreferences.setBool(activity.toStr(), true);
}
List<Evaluation>? get evaluations => this._evaluations;
set evaluations(List<Evaluation>? value) => this._evaluations = value;
List<CustomerActivity>? get customerActivities => this._customerActivities;
setCustomerActivities(List<CustomerActivity>? value) => this._customerActivities = value;
List<Tutorial>? get tutorials => this._tutorials;
setTutorials(List<Tutorial>? value) => this._tutorials = value;
}
+8
View File
@@ -22,6 +22,8 @@ class Customer {
String? firebaseUid;
DateTime? dateAdd;
DateTime? dateChange;
int? emailSubscription;
int? sportId;
LinkedHashMap<String, CustomerProperty> properties = LinkedHashMap();
@@ -65,6 +67,10 @@ class Customer {
this.trainer = json['trainer'];
this.firebaseUid = json['firebaseUid'];
this.dataPolicyAllowed = json['dataPolicyAllowed'];
this.emailSubscription = json['emailSubscription'];
this.sportId = json['sportId'];
this.dateAdd = json['dateAdd'] == null ? DateTime.parse("0000-00-00") : DateTime.parse(json['dateAdd']);
this.dateChange = json['dateChange'] == null ? DateTime.parse("0000-00-00") : DateTime.parse(json['dateChange']);
}
@@ -86,6 +92,8 @@ class Customer {
"dataPolicyAllowed": dataPolicyAllowed,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!),
"dateChange": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateChange!),
"emailSubscription": this.emailSubscription,
"sportId": this.sportId
};
double getProperty(String propertyName) {
+30
View File
@@ -0,0 +1,30 @@
import 'package:intl/intl.dart';
class CustomerActivity {
late int activityId;
late int customerId;
late String type;
late DateTime? dateAdd;
bool? skipped;
CustomerActivity.fromJson(Map json) {
activityId = json['activityId'];
customerId = json['custoemrId'];
type = json['type'];
skipped = json['skipped'];
this.dateAdd = DateTime.parse(json['dateAdd']);
}
Map<String, dynamic> toJson() => {
'activityId': this.activityId,
'customerId': this.customerId,
'type': this.type,
'skipped': this.skipped,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!),
};
@override
String toString() {
return this.toJson().toString();
}
}
-20
View File
@@ -1,23 +1,3 @@
enum Sport { football, fitness, footgolf }
extension SportExt on Sport {
String toStr() => this.toString().split(".").last;
bool equalsTo(Sport sport) => this.toString() == sport.toString();
bool equalsStringTo(String sport) => this.toStr() == sport;
String description(Sport sport) {
if (Sport.football.equalsTo(sport)) {
return "Football";
} else if (Sport.fitness.equalsTo(sport)) {
return "Fitness / Body Building";
} else if (Sport.footgolf.equalsTo(sport)) {
return "Footgolf";
} else {
return "Sport";
}
}
}
class FitnessState {
late final String value;
late final String stateText;
+22
View File
@@ -0,0 +1,22 @@
class Sport {
late int sportId;
late String name;
late String sportNameTranslation;
Sport.fromJson(Map json) {
this.sportId = json['sportId'];
this.name = json['name'];
this.sportNameTranslation =
json['translations'] != null && (json['translations']).length > 0 ? json['translations'][0]['sportName'] : this.name;
}
Map<String, dynamic> toJson() => {
"sportId": sportId,
"name": name,
};
@override
String toString() {
return this.toJson().toString();
}
}
+24
View File
@@ -0,0 +1,24 @@
import 'package:aitrainer_app/model/tutorial_step.dart';
enum TutorialEnum { basic, development, training }
class Tutorial {
late int tutorialId;
late String name;
List<TutorialStep>? steps;
Tutorial.fromJson(Map<String, dynamic> json) {
this.tutorialId = json['tutorialId'];
this.name = json['name'];
if (json['steps'] != null && json['steps'].length > 0) {
steps = json['steps'].map<TutorialStep>((step) => TutorialStep.fromJson(step)).toList();
}
}
Map<String, dynamic> toJson() => {'tutorialId': this.tutorialId, 'name': this.name, 'steps': steps.toString()};
@override
String toString() => this.toJson().toString();
}
+99
View File
@@ -0,0 +1,99 @@
import 'dart:ui';
import 'dart:convert';
import 'package:aitrainer_app/util/app_language.dart';
enum TutorialEnum { basic, development, training }
class TutorialStepAction {
late String direction;
late int top;
late int left;
late bool showBubble;
late int bubbleX;
late int bubbleY;
late int bubbleWidth;
late int bubbleHeight;
late bool showCheckText;
late int parent;
TutorialStepAction.fromJson(Map json) {
this.direction = json['direction'];
this.top = json['top'];
this.left = json['left'];
this.showBubble = json['show_bubble'];
this.bubbleX = json['bubble_x'];
this.bubbleY = json['bubble_y'];
this.bubbleWidth = json['bubble_width'];
this.bubbleHeight = json['bubble_height'];
this.showCheckText = json['show_check_text'];
this.parent = json['parent'];
}
Map<String, dynamic> toJson() => {
"direction": this.direction,
"top": this.top,
"left": this.left,
"showBubble": this.showBubble,
"bubbleX": this.bubbleX,
"bubbleY": this.bubbleY,
"bubbleWidth": this.bubbleWidth,
"bubbleHeight": this.bubbleHeight,
"showCheckText": this.showCheckText,
"parent": this.parent,
};
@override
String toString() => this.toJson().toString();
}
class TutorialStep {
int? tutorialStepId;
int? tutorialId;
int? step;
String? tutorialText;
String? direction;
String? checkText;
String? condition;
String? branch;
int? parentId;
TutorialStepAction? action;
String? tutorialTextTranslation;
String? errorTextTranslation;
TutorialStep.fromJson(Map json) {
this.tutorialStepId = json['tutorialStepId'];
this.tutorialId = json['tutorialId'];
this.step = json['step'];
this.tutorialText = json['tutorialText'];
this.checkText = json['checkText'];
this.condition = json['condition'];
if (this.condition != null) {
this.condition = condition!.replaceAll(r'\\', "replace");
print("Json condition $condition");
this.action = TutorialStepAction.fromJson(jsonDecode(condition!));
}
if (json['translations'] != null && json['translations'].length > 0) {
this.tutorialTextTranslation =
AppLanguage().appLocal == Locale('hu') ? json['translations'][0]['tutorialText'] : json['tutorialText'];
this.errorTextTranslation = AppLanguage().appLocal == Locale('hu') ? json['translations'][0]['errorText'] : json['errorText'];
}
}
Map<String, dynamic> toJson() => {
"tutorialStepId": this.tutorialStepId,
"tutorialId": this.tutorialId,
"step": this.step,
"tutorialText": this.tutorialText,
"checkText": this.checkText,
"tutorialTextTranslation": this.tutorialTextTranslation,
"errorTextTranslation": this.errorTextTranslation,
"condition": this.condition,
"action": this.action != null ? this.action!.toJson() : ""
};
@override
String toString() => this.toJson().toString();
}