diff --git a/lib/Helpers/ImageCustomProvider.dart b/lib/Helpers/ImageCustomProvider.dart index 0b130a0..aa97b71 100644 --- a/lib/Helpers/ImageCustomProvider.dart +++ b/lib/Helpers/ImageCustomProvider.dart @@ -6,14 +6,14 @@ import 'package:tablet_app/Models/tabletContext.dart'; import 'package:tablet_app/app_context.dart'; class ImageCustomProvider { - static ImageProvider getImageProvider(AppContext appContext, String imageId, String imageSource) { + static ImageProvider getImageProvider(AppContext appContext, String? imageId, String imageSource) { TabletAppContext tabletAppContext = appContext.getContext(); try { if(appContext.getContext().localPath != null && tabletAppContext.configuration != null) { Directory configurationDirectory = Directory('${tabletAppContext.localPath!}/${tabletAppContext.configuration!.id!}'); List fileList = configurationDirectory.listSync(); - if(fileList.any((fileL) => fileL.uri.pathSegments.last.contains(imageId))) { + if(imageId != null && fileList.any((fileL) => fileL.uri.pathSegments.last.contains(imageId))) { File file = File(fileList.firstWhere((fileL) => fileL.uri.pathSegments.last.contains(imageId)).path); print("FILE EXISTT"); return FileImage(file); diff --git a/lib/Screens/MainView/main_view.dart b/lib/Screens/MainView/main_view.dart index 129d365..359a665 100644 --- a/lib/Screens/MainView/main_view.dart +++ b/lib/Screens/MainView/main_view.dart @@ -68,6 +68,9 @@ class _MainViewWidget extends State { @override void initState() { final appContext = Provider.of(context, listen: false); + + + configurationDTO = appContext.getContext().configuration; if(configurationDTO.isHour != null && configurationDTO.isHour!) { Timer.periodic(Duration(seconds: 1), (Timer t) => _getTime(currentHourDate)); @@ -344,9 +347,9 @@ class _MainViewWidget extends State { decoration: BoxDecoration( color: sectionsLocal![index].imageSource == null ? kBackgroundLight : null, // default color if no image shape: BoxShape.rectangle, - image: sectionsLocal![index].imageSource != null ? new DecorationImage( + image: sectionsLocal![index].imageSource != null || sectionsLocal![index].type == SectionType.Video ? new DecorationImage( fit: BoxFit.cover, - image: ImageCustomProvider.getImageProvider(appContext, sectionsLocal![index].imageId!, sectionsLocal![index].imageSource!), + image: ImageCustomProvider.getImageProvider(appContext, sectionsLocal![index].imageId, sectionsLocal![index].type == SectionType.Video ? getYoutubeThumbnailUrl(sectionsLocal![index]) : sectionsLocal![index].imageSource!), ): null, ), ) @@ -386,10 +389,10 @@ boxDecoration(AppContext appContext, SectionDTO section, bool isSelected) { color: !isSelected ? kBackgroundLight : section.imageSource == null ? kBackgroundLight : null, shape: BoxShape.rectangle, borderRadius: BorderRadius.circular(tabletAppContext.configuration!.roundedValue?.toDouble() ?? 30.0), - image: section.imageSource != null ? new DecorationImage( + image: section.imageSource != null || section.type == SectionType.Video ? new DecorationImage( fit: BoxFit.cover, colorFilter: !isSelected? new ColorFilter.mode(kBackgroundLight.withOpacity(0.2), BlendMode.dstATop) : null, - image: ImageCustomProvider.getImageProvider(appContext, section.imageId!, section.imageSource!), + image: ImageCustomProvider.getImageProvider(appContext, section.imageId, section.type == SectionType.Video ? getYoutubeThumbnailUrl(section) : section.imageSource!), ): null, boxShadow: [ BoxShadow( diff --git a/lib/Screens/Menu/menu_view.dart b/lib/Screens/Menu/menu_view.dart index 7463b6e..870f037 100644 --- a/lib/Screens/Menu/menu_view.dart +++ b/lib/Screens/Menu/menu_view.dart @@ -126,9 +126,9 @@ class _MenuView extends State { decoration: BoxDecoration( color: menuDTO.sections![index].imageSource == null ? kBackgroundColor : null, // default color if no image shape: BoxShape.rectangle, - image: menuDTO.sections![index].imageSource != null ? new DecorationImage( + image: menuDTO.sections![index].imageSource != null || menuDTO.sections![index].type == SectionType.Video ? new DecorationImage( fit: BoxFit.cover, - image: ImageCustomProvider.getImageProvider(appContext, menuDTO.sections![index].imageId!, menuDTO.sections![index].imageSource!), + image: ImageCustomProvider.getImageProvider(appContext, menuDTO.sections![index].imageId, menuDTO.sections![index].type == SectionType.Video ? getYoutubeThumbnailUrl(menuDTO.sections![index]) : menuDTO.sections![index].imageSource!), ): null, ), ) @@ -162,10 +162,10 @@ boxDecoration(AppContext appContext, SectionDTO section, bool isSelected) { color: kBackgroundLight, shape: BoxShape.rectangle, borderRadius: BorderRadius.circular(tabletAppContext.configuration!.roundedValue?.toDouble() ?? 20.0), - image: section.imageSource != null ? new DecorationImage( + image: section.imageSource != null || section.type == SectionType.Video ? new DecorationImage( fit: BoxFit.cover, - colorFilter: !isSelected? new ColorFilter.mode(kBackgroundLight.withOpacity(0.2), BlendMode.dstATop) : null, - image: ImageCustomProvider.getImageProvider(appContext, section.imageId!, section.imageSource!), + colorFilter: !isSelected? new ColorFilter.mode(kBackgroundLight.withOpacity(0.35), BlendMode.dstATop) : null, + image: ImageCustomProvider.getImageProvider(appContext, section.imageId, section.type == SectionType.Video ? getYoutubeThumbnailUrl(section) : section.imageSource!), ): null, boxShadow: [ BoxShadow( @@ -176,4 +176,19 @@ boxDecoration(AppContext appContext, SectionDTO section, bool isSelected) { ), ], ); +} + +String getYoutubeThumbnailUrl(SectionDTO sectionDTO) { + try{ + VideoDTO? videoDTO = VideoDTO.fromJson(jsonDecode(sectionDTO.data!)); + Uri uri = Uri.parse(videoDTO!.source_!); + String videoId = uri.queryParameters['v']!; + // Construire l'URL du thumbnail en utilisant l'identifiant de la vidéo YouTube + String thumbnailUrl = 'https://img.youtube.com/vi/$videoId/0.jpg'; + + return thumbnailUrl; + + } catch(e) { + return ""; + } } \ No newline at end of file