mirror of
https://bitbucket.org/FransoletThomas/tablet-app.git
synced 2025-12-06 08:31:19 +00:00
thumbnail for youtube video
This commit is contained in:
parent
ef89b623d2
commit
1db1c78538
@ -6,14 +6,14 @@ import 'package:tablet_app/Models/tabletContext.dart';
|
||||
import 'package:tablet_app/app_context.dart';
|
||||
|
||||
class ImageCustomProvider {
|
||||
static ImageProvider<Object> getImageProvider(AppContext appContext, String imageId, String imageSource) {
|
||||
static ImageProvider<Object> 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<FileSystemEntity> 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);
|
||||
|
||||
@ -68,6 +68,9 @@ class _MainViewWidget extends State<MainViewWidget> {
|
||||
@override
|
||||
void initState() {
|
||||
final appContext = Provider.of<AppContext>(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<MainViewWidget> {
|
||||
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(
|
||||
|
||||
@ -126,9 +126,9 @@ class _MenuView extends State<MenuView> {
|
||||
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(
|
||||
@ -177,3 +177,18 @@ 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 "";
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user