Skip to content

Commit

Permalink
added video icon on thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
ReightI committed Feb 13, 2023
1 parent 88e0a6a commit 75238a6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
24 changes: 17 additions & 7 deletions lib/components/cards/image_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,21 @@ class ImageCard extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (image.favorite)
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (image.isVideo)
Padding(
padding: const EdgeInsets.all(2.0),
child: Icon(
Icons.local_movies,
color: Color(0xFFFFFFFF),
size: 12,
shadows: AppShadows.icon,
),
),
if (image.favorite)
Padding(
padding: const EdgeInsets.all(2.0),
child: Icon(
Expand All @@ -86,8 +96,8 @@ class ImageCard extends StatelessWidget {
shadows: AppShadows.icon,
),
),
],
),
],
),
if (Preferences.getShowThumbnailTitle)
Container(
padding: const EdgeInsets.all(2.0),
Expand Down
7 changes: 7 additions & 0 deletions lib/models/image_model.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:mime_type/mime_type.dart';

class ImageModel {
int id;
int width;
Expand Down Expand Up @@ -74,6 +76,11 @@ class ImageModel {
}
}

bool get isVideo {
String? mimeType = mime(file) ?? mime(elementUrl) ?? mime(derivatives.medium.url);
return mimeType != null && mimeType.startsWith('video');
}

@override
operator ==(other) => other is ImageModel && id == other.id;

Expand Down
12 changes: 5 additions & 7 deletions lib/views/image/image_view_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mime_type/mime_type.dart';
import 'package:photo_view/photo_view.dart';
import 'package:photo_view/photo_view_gallery.dart';
import 'package:piwigo_ng/api/api_error.dart';
Expand Down Expand Up @@ -340,10 +339,9 @@ class _ImageViewPageState extends State<ImageViewPage> {
builder: (context, index) {
final ImageModel image = _imageList[index];

/// Check mime type of file (multiple test to ensure it is not null)
String? mimeType = mime(image.file) ?? mime(image.elementUrl) ?? mime(image.derivatives.medium.url);
if (mimeType != null && mimeType.startsWith('video')) {
/// Returns video player
// Check mime type of file (multiple test to ensure it is not null)
if (image.isVideo) {
// Returns video player
return PhotoViewGalleryPageOptions.customChild(
disableGestures: true,
child: VideoView(
Expand All @@ -356,7 +354,7 @@ class _ImageViewPageState extends State<ImageViewPage> {
);
}

/// Default behavior: Zoomable image
// Default behavior: Zoomable image
return PhotoViewGalleryPageOptions(
imageProvider: NetworkImage(
image.getDerivativeFromString(Preferences.getImageFullScreenSize)?.url ?? '',
Expand All @@ -365,7 +363,7 @@ class _ImageViewPageState extends State<ImageViewPage> {
minScale: PhotoViewComputedScale.contained,
errorBuilder: (context, o, s) {
debugPrint("$o");
return Center();
return SizedBox();
},
);
},
Expand Down

0 comments on commit 75238a6

Please sign in to comment.