From 09ae80266bdadd45a9bb3c73faab03736108a0ee Mon Sep 17 00:00:00 2001 From: Fransolet Thomas Date: Thu, 12 Jan 2023 17:47:13 +0100 Subject: [PATCH] Handle audio new format in mobile app --- README.md | 11 +++++++--- assets/images/ar.svg | 26 ++++++++++++++++++++++++ assets/images/{ => old}/DE.png | Bin assets/images/{ => old}/EN.png | Bin assets/images/{ => old}/FR.png | Bin assets/images/{ => old}/NL.png | Bin assets/images/uk.svg | 6 ++++++ lib/Components/LanguageSelection.dart | 4 ++++ lib/Components/SliderImages.dart | 2 +- lib/Screens/Article/article.dart | 13 +++++------- lib/Services/apiService.dart | 2 +- lib/Services/downloadConfiguration.dart | 12 ++++++++--- lib/constants.dart | 2 +- 13 files changed, 61 insertions(+), 17 deletions(-) create mode 100644 assets/images/ar.svg rename assets/images/{ => old}/DE.png (100%) rename assets/images/{ => old}/EN.png (100%) rename assets/images/{ => old}/FR.png (100%) rename assets/images/{ => old}/NL.png (100%) create mode 100644 assets/images/uk.svg diff --git a/README.md b/README.md index a8f4159..08fe67b 100644 --- a/README.md +++ b/README.md @@ -28,11 +28,15 @@ This README would normally document whatever steps are necessary to get your app * Repo owner or admin * Other community or team contact -# OPENAPI Generation cmd +# OPENAPI Generation cmd + +flutter pub run build_runner build --delete-conflicting-outputs Le fichier est dans le projet. -flutter pub run build_runner build --delete-conflicting-outputs +# Assets + +Les svg de drapeaux viennent de là https://flagicons.lipis.dev/ # Publication sur le Google PlayStore @@ -42,4 +46,5 @@ Puis : flutter build appbundle -Faut pas oublier d'aller changer la version avant chaque upload de version (Puis mettre l'app bundle dans le dossier du PC, peut-être mettre sur le repos aussi ?) \ No newline at end of file +Faut pas oublier d'aller changer la version avant chaque upload de version (Puis mettre l'app bundle dans le dossier du PC, peut-être mettre sur le repos aussi ?) + diff --git a/assets/images/ar.svg b/assets/images/ar.svg new file mode 100644 index 0000000..63d2fbf --- /dev/null +++ b/assets/images/ar.svg @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/assets/images/DE.png b/assets/images/old/DE.png similarity index 100% rename from assets/images/DE.png rename to assets/images/old/DE.png diff --git a/assets/images/EN.png b/assets/images/old/EN.png similarity index 100% rename from assets/images/EN.png rename to assets/images/old/EN.png diff --git a/assets/images/FR.png b/assets/images/old/FR.png similarity index 100% rename from assets/images/FR.png rename to assets/images/old/FR.png diff --git a/assets/images/NL.png b/assets/images/old/NL.png similarity index 100% rename from assets/images/NL.png rename to assets/images/old/NL.png diff --git a/assets/images/uk.svg b/assets/images/uk.svg new file mode 100644 index 0000000..7c55d48 --- /dev/null +++ b/assets/images/uk.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lib/Components/LanguageSelection.dart b/lib/Components/LanguageSelection.dart index 958f1f2..fa30f9e 100644 --- a/lib/Components/LanguageSelection.dart +++ b/lib/Components/LanguageSelection.dart @@ -30,6 +30,10 @@ class _LanguageSelection extends State with TickerProviderSta languagesEnable = configurationLanguages ?? languages; selectedLanguage = visitAppContext.language; + if(visitAppContext.configuration != null && visitAppContext.configuration!.isOffline!) { + languagesEnable = [configurationLanguages!.firstWhere((element) => element == visitAppContext.language)]; + } + if(!languagesEnable!.any((lg) => lg == selectedLanguage)) { selectedLanguage = defaultLanguage; } diff --git a/lib/Components/SliderImages.dart b/lib/Components/SliderImages.dart index dada49c..40af43c 100644 --- a/lib/Components/SliderImages.dart +++ b/lib/Components/SliderImages.dart @@ -65,7 +65,7 @@ class _SliderImagesWidget extends State { items: resourcesInWidget.map((i) { return Builder( builder: (BuildContext context) { - print(widget.imagesDTO[currentIndex-1]); + //print(widget.imagesDTO[currentIndex-1]); return InkWell( onTap: () { showImagePopup(widget.imagesDTO[currentIndex-1]!, i!, appContext, context, size); diff --git a/lib/Screens/Article/article.dart b/lib/Screens/Article/article.dart index 368175e..2be8dfb 100644 --- a/lib/Screens/Article/article.dart +++ b/lib/Screens/Article/article.dart @@ -231,7 +231,6 @@ class _ArticlePageState extends State { Future getArticle(AppContext appContext, Client client, String articleId) async { try { if(sectionDTO == null || articleDTO == null) { - print("ARTCILE DTO GET ARTICLE"); bool isConfigOffline = (appContext.getContext() as VisitAppContext).configuration!.isOffline!; if(isConfigOffline) @@ -256,19 +255,17 @@ class _ArticlePageState extends State { } if(sectionDTO!.type == SectionType.Article) { - print("set article __ !!"); - print(sectionDTO!.data!); articleDTO = ArticleDTO.fromJson(jsonDecode(sectionDTO!.data!)); } - if(articleDTO != null) { - if(articleDTO!.audioId != null) { + var audioIdArticle = articleDTO!.audioIds!.where((audioId) => audioId.language == (appContext.getContext() as VisitAppContext).language); + if(audioIdArticle.isNotEmpty && audioIdArticle.first.value != null) { if(isConfigOffline) { // OFFLINE List> ressourceTest = await DatabaseHelper .instance.queryWithColumnId( - DatabaseTableType.resources, articleDTO!.audioId!); + DatabaseTableType.resources, audioIdArticle.first.value!); if (ressourceTest.isNotEmpty) { audioResourceModel = DatabaseHelper.instance.getResourceFromDB(ressourceTest.first); Uint8List base64String = base64Decode(audioResourceModel!.data!); @@ -280,7 +277,7 @@ class _ArticlePageState extends State { else { // ONLINE - ResourceModel? resourceAudioOnline = await ApiService.downloadAudio(client, articleDTO!.audioId!); + ResourceModel? resourceAudioOnline = await ApiService.downloadAudio(client, audioIdArticle.first.value!); if(resourceAudioOnline != null) { audioResourceModel = resourceAudioOnline; Uint8List base64String = base64Decode(resourceAudioOnline.data!); @@ -321,7 +318,7 @@ class _ArticlePageState extends State { } setState(() { - print(sectionDTO!.title); + //print(sectionDTO!.title); }); } else { return null; // TODO return local list.. diff --git a/lib/Services/apiService.dart b/lib/Services/apiService.dart index 3560370..968bb5e 100644 --- a/lib/Services/apiService.dart +++ b/lib/Services/apiService.dart @@ -136,7 +136,7 @@ class ApiService { HttpClientResponse response = await request.close(); await for(dynamic d in response) { _downloadData.addAll(d); } final base64Str = base64.encode(_downloadData); - ResourceModel resourceModel = ResourceModel(id: audioId, data: base64Str, type: ResourceType.Audio); + ResourceModel resourceModel = ResourceModel(id: audioId, data: base64Str, type: ResourceType.Audio, source: ""); return resourceModel; } diff --git a/lib/Services/downloadConfiguration.dart b/lib/Services/downloadConfiguration.dart index 1249315..eb2a1db 100644 --- a/lib/Services/downloadConfiguration.dart +++ b/lib/Services/downloadConfiguration.dart @@ -4,6 +4,7 @@ import 'package:manager_api/api.dart'; import 'package:mymuseum_visitapp/Helpers/DatabaseHelper.dart'; import 'package:mymuseum_visitapp/Helpers/modelsHelper.dart'; import 'package:mymuseum_visitapp/Models/resourceModel.dart'; +import 'package:mymuseum_visitapp/Models/visitContext.dart'; import 'package:mymuseum_visitapp/Services/apiService.dart'; import 'package:mymuseum_visitapp/app_context.dart'; @@ -14,6 +15,8 @@ class DownloadConfiguration { await DatabaseHelper.instance.insert(DatabaseTableType.configurations, ModelsHelper.configurationToMap(configuration)); List usedImageOrAudioIds = []; + var currentLanguage = (appContext.getContext() as VisitAppContext).language; + if(configuration.imageId != null) { ImageDTO image = ImageDTO(resourceId: configuration.imageId, source_: configuration.imageSource); usedImageOrAudioIds.add(configuration.imageId!); @@ -49,9 +52,12 @@ class DownloadConfiguration { usedImageOrAudioIds.add(image.resourceId!); await ApiService.downloadAndPushLocalImage(appContext.clientAPI, image); } - if(articleDTO.audioId != null) { - usedImageOrAudioIds.add(articleDTO.audioId!); - await ApiService.downloadAndPushLocalAudio(appContext.clientAPI, articleDTO.audioId!); + + var audioIdArticle = articleDTO.audioIds!.where((audioId) => audioId.language == currentLanguage); + if(audioIdArticle.isNotEmpty && audioIdArticle.first.value != null) + { + usedImageOrAudioIds.add(audioIdArticle.first.value!); + await ApiService.downloadAndPushLocalAudio(appContext.clientAPI, audioIdArticle.first.value!); } } newOrder = newOrder + 1; diff --git a/lib/constants.dart b/lib/constants.dart index 278aeaf..7b45f9f 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -10,7 +10,7 @@ const kArticleTitleSize = 25.0; const kArticleDescriptionSize = 12.5; const kArticleContentSize = 16.0; -const List languages = ["FR", "NL", "EN", "DE", "IT", "ES", "PL", "CN"]; // hmmmm depends on config.. +const List languages = ["FR", "NL", "EN", "DE", "IT", "ES", "PL", "CN", "AR", "UK"]; // hmmmm depends on config.. const String defaultLanguage = "EN"; // Text Style