mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 06:46:22 +01:00
Support gif
This commit is contained in:
parent
4079ba39f2
commit
e1a5dbb843
6 changed files with 58 additions and 27 deletions
|
@ -30,6 +30,7 @@ const _supportedFormatMimes = [
|
||||||
"image/png",
|
"image/png",
|
||||||
"image/webp",
|
"image/webp",
|
||||||
"image/heic",
|
"image/heic",
|
||||||
|
"image/gif",
|
||||||
// video player currently doesn't work on web
|
// video player currently doesn't work on web
|
||||||
if (!platform_k.isWeb) "video/mp4",
|
if (!platform_k.isWeb) "video/mp4",
|
||||||
];
|
];
|
||||||
|
|
|
@ -300,6 +300,7 @@ class _AlbumViewerState extends State<AlbumViewer>
|
||||||
width: _thumbSize, height: _thumbSize);
|
width: _thumbSize, height: _thumbSize);
|
||||||
if (file_util.isSupportedImageFormat(f)) {
|
if (file_util.isSupportedImageFormat(f)) {
|
||||||
yield _ImageListItem(
|
yield _ImageListItem(
|
||||||
|
file: f,
|
||||||
account: widget.account,
|
account: widget.account,
|
||||||
previewUrl: previewUrl,
|
previewUrl: previewUrl,
|
||||||
onTap: () => _onItemTap(i),
|
onTap: () => _onItemTap(i),
|
||||||
|
@ -368,6 +369,7 @@ class _AlbumViewerState extends State<AlbumViewer>
|
||||||
|
|
||||||
class _ImageListItem extends SelectableItemStreamListItem {
|
class _ImageListItem extends SelectableItemStreamListItem {
|
||||||
_ImageListItem({
|
_ImageListItem({
|
||||||
|
@required this.file,
|
||||||
@required this.account,
|
@required this.account,
|
||||||
@required this.previewUrl,
|
@required this.previewUrl,
|
||||||
VoidCallback onTap,
|
VoidCallback onTap,
|
||||||
|
@ -378,9 +380,11 @@ class _ImageListItem extends SelectableItemStreamListItem {
|
||||||
return PhotoListImage(
|
return PhotoListImage(
|
||||||
account: account,
|
account: account,
|
||||||
previewUrl: previewUrl,
|
previewUrl: previewUrl,
|
||||||
|
isGif: file.contentType == "image/gif",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final File file;
|
||||||
final Account account;
|
final Account account;
|
||||||
final String previewUrl;
|
final String previewUrl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -341,6 +341,7 @@ class _ImageListItem extends _FileListItem {
|
||||||
return PhotoListImage(
|
return PhotoListImage(
|
||||||
account: account,
|
account: account,
|
||||||
previewUrl: previewUrl,
|
previewUrl: previewUrl,
|
||||||
|
isGif: file.contentType == "image/gif",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -639,6 +639,7 @@ class _ImageListItem extends _FileListItem {
|
||||||
return PhotoListImage(
|
return PhotoListImage(
|
||||||
account: account,
|
account: account,
|
||||||
previewUrl: previewUrl,
|
previewUrl: previewUrl,
|
||||||
|
isGif: file.contentType == "image/gif",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -210,10 +210,16 @@ class _ImageViewerState extends State<ImageViewer>
|
||||||
static final _log = Logger("widget.image_viewer._ImageViewerState");
|
static final _log = Logger("widget.image_viewer._ImageViewerState");
|
||||||
}
|
}
|
||||||
|
|
||||||
String _getImageUrl(Account account, File file) => api_util.getFilePreviewUrl(
|
String _getImageUrl(Account account, File file) {
|
||||||
|
if (file.contentType == "image/gif") {
|
||||||
|
return api_util.getFileUrl(account, file);
|
||||||
|
} else {
|
||||||
|
return api_util.getFilePreviewUrl(
|
||||||
account,
|
account,
|
||||||
file,
|
file,
|
||||||
width: 1080,
|
width: 1080,
|
||||||
height: 1080,
|
height: 1080,
|
||||||
a: true,
|
a: true,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ class PhotoListImage extends StatelessWidget {
|
||||||
Key key,
|
Key key,
|
||||||
@required this.account,
|
@required this.account,
|
||||||
@required this.previewUrl,
|
@required this.previewUrl,
|
||||||
|
this.isGif = false,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -17,39 +18,56 @@ class PhotoListImage extends StatelessWidget {
|
||||||
return FittedBox(
|
return FittedBox(
|
||||||
clipBehavior: Clip.hardEdge,
|
clipBehavior: Clip.hardEdge,
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
child: Container(
|
child: Stack(
|
||||||
// arbitrary size here
|
children: [
|
||||||
constraints: BoxConstraints.tight(const Size(128, 128)),
|
Container(
|
||||||
color: AppTheme.getListItemBackgroundColor(context),
|
// arbitrary size here
|
||||||
child: CachedNetworkImage(
|
constraints: BoxConstraints.tight(const Size(128, 128)),
|
||||||
imageUrl: previewUrl,
|
color: AppTheme.getListItemBackgroundColor(context),
|
||||||
httpHeaders: {
|
child: CachedNetworkImage(
|
||||||
"Authorization": Api.getAuthorizationHeaderValue(account),
|
imageUrl: previewUrl,
|
||||||
},
|
httpHeaders: {
|
||||||
fadeInDuration: const Duration(),
|
"Authorization": Api.getAuthorizationHeaderValue(account),
|
||||||
filterQuality: FilterQuality.high,
|
},
|
||||||
errorWidget: (context, url, error) {
|
fadeInDuration: const Duration(),
|
||||||
// won't work on web because the image is downloaded by the cache
|
filterQuality: FilterQuality.high,
|
||||||
// manager instead
|
errorWidget: (context, url, error) {
|
||||||
// where's the preview???
|
// won't work on web because the image is downloaded by the cache
|
||||||
return Container(
|
// manager instead
|
||||||
child: Center(
|
// where's the preview???
|
||||||
child: Icon(
|
return Container(
|
||||||
Icons.image_not_supported,
|
child: Center(
|
||||||
size: 64,
|
child: Icon(
|
||||||
color: Colors.white.withOpacity(.8),
|
Icons.image_not_supported,
|
||||||
),
|
size: 64,
|
||||||
|
color: Colors.white.withOpacity(.8),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (isGif)
|
||||||
|
Container(
|
||||||
|
// arbitrary size here
|
||||||
|
constraints: BoxConstraints.tight(const Size(128, 128)),
|
||||||
|
alignment: AlignmentDirectional.topEnd,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 2),
|
||||||
|
child: const Icon(
|
||||||
|
Icons.gif,
|
||||||
|
size: 36,
|
||||||
|
color: Colors.white,
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
},
|
],
|
||||||
imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Account account;
|
final Account account;
|
||||||
final String previewUrl;
|
final String previewUrl;
|
||||||
|
final bool isGif;
|
||||||
}
|
}
|
||||||
|
|
||||||
class PhotoListVideo extends StatelessWidget {
|
class PhotoListVideo extends StatelessWidget {
|
||||||
|
|
Loading…
Reference in a new issue