WT 1.1.5+2 remote images for menu

This commit is contained in:
bossanyit
2021-01-31 12:59:52 +01:00
parent 71efd3f349
commit c1a57dd10e
88 changed files with 743 additions and 316 deletions
+10 -8
View File
@@ -3,10 +3,11 @@ import 'dart:convert';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/exercise_tree.dart';
import 'package:aitrainer_app/model/exercise_tree_parents.dart';
import 'package:aitrainer_app/service/logging.dart';
import 'package:flutter/services.dart';
import 'api.dart';
class ExerciseTreeApi {
class ExerciseTreeApi with Logging {
final APIClient _client = new APIClient();
Future<List<ExerciseTree>> getExerciseTree() async {
@@ -17,23 +18,24 @@ class ExerciseTreeApi {
exerciseTree = await getExerciseTreeParents(exerciseTree);
if (exerciseTree != null) {
exerciseTree.forEach((element) async {
element.imageUrl = await _buildImage(element.imageUrl);
await Future.forEach(exerciseTree, (element) async {
//exerciseTree.forEach((element) async {
element.imageUrl = await _buildImage(element.imageUrl, element.treeId);
});
log("ExerciseTree downloaded");
Cache().setExerciseTree(exerciseTree);
}
Cache().setExerciseTree(exerciseTree);
return exerciseTree;
}
Future<String> _buildImage(String imageUrl) async {
Future<String> _buildImage(String imageUrl, int treeId) async {
String assetImage = 'asset/menu/' + imageUrl.substring(7);
//print("Loading image " + assetImage);
return rootBundle.load(assetImage).then((value) {
return await rootBundle.load(assetImage).then((value) {
return assetImage;
}).catchError((_) {
String imagePath = assetImage.substring(10);
String url = Cache.mediaUrl + 'images' + imagePath;
//print("Exception: " + assetImage + " will be loaded from the network " + url);
return url;
});
}
+7 -4
View File
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'package:aitrainer_app/library/image_cache.dart';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/exercise_type.dart';
import 'package:aitrainer_app/service/api.dart';
@@ -14,14 +15,17 @@ class ExerciseTypeApi with Logging {
final List<ExerciseType> exerciseTypes = json.map((exerciseType) => ExerciseType.fromJson(exerciseType)).toList();
if (exerciseTypes != null) {
exerciseTypes.forEach((element) async {
element.imageUrl = await _buildImage(element.imageUrl);
element.imageUrl = await _buildImage(element.imageUrl, element.exerciseTypeId);
//ImageCache().downloadAndSaveImage(element.exerciseTypeId, element.imageUrl);
});
log("ExerciseTypes downloaded");
Cache().setExerciseTypes(exerciseTypes);
}
Cache().setExerciseTypes(exerciseTypes);
return exerciseTypes;
}
Future<String> _buildImage(String imageUrl) async {
Future<String> _buildImage(String imageUrl, int exerciseTypeId) async {
if (imageUrl.length > 8) {
String assetImage = 'asset/menu/' + imageUrl.substring(7);
return rootBundle.load(assetImage).then((value) {
@@ -29,7 +33,6 @@ class ExerciseTypeApi with Logging {
}).catchError((_) {
String imagePath = assetImage.substring(10);
String url = Cache.mediaUrl + 'images' + imagePath;
//print("Exception: " + assetImage + " will be loaded from the network " + url);
return url;
});
} else {