Support gif

This commit is contained in:
Ming Ming 2021-06-22 13:24:37 +08:00
parent 4079ba39f2
commit e1a5dbb843
6 changed files with 58 additions and 27 deletions

View file

@ -30,6 +30,7 @@ const _supportedFormatMimes = [
"image/png",
"image/webp",
"image/heic",
"image/gif",
// video player currently doesn't work on web
if (!platform_k.isWeb) "video/mp4",
];

View file

@ -300,6 +300,7 @@ class _AlbumViewerState extends State<AlbumViewer>
width: _thumbSize, height: _thumbSize);
if (file_util.isSupportedImageFormat(f)) {
yield _ImageListItem(
file: f,
account: widget.account,
previewUrl: previewUrl,
onTap: () => _onItemTap(i),
@ -368,6 +369,7 @@ class _AlbumViewerState extends State<AlbumViewer>
class _ImageListItem extends SelectableItemStreamListItem {
_ImageListItem({
@required this.file,
@required this.account,
@required this.previewUrl,
VoidCallback onTap,
@ -378,9 +380,11 @@ class _ImageListItem extends SelectableItemStreamListItem {
return PhotoListImage(
account: account,
previewUrl: previewUrl,
isGif: file.contentType == "image/gif",
);
}
final File file;
final Account account;
final String previewUrl;
}

View file

@ -341,6 +341,7 @@ class _ImageListItem extends _FileListItem {
return PhotoListImage(
account: account,
previewUrl: previewUrl,
isGif: file.contentType == "image/gif",
);
}

View file

@ -639,6 +639,7 @@ class _ImageListItem extends _FileListItem {
return PhotoListImage(
account: account,
previewUrl: previewUrl,
isGif: file.contentType == "image/gif",
);
}

View file

@ -210,10 +210,16 @@ class _ImageViewerState extends State<ImageViewer>
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,
file,
width: 1080,
height: 1080,
a: true,
);
}
}

View file

@ -10,6 +10,7 @@ class PhotoListImage extends StatelessWidget {
Key key,
@required this.account,
@required this.previewUrl,
this.isGif = false,
}) : super(key: key);
@override
@ -17,39 +18,56 @@ class PhotoListImage extends StatelessWidget {
return FittedBox(
clipBehavior: Clip.hardEdge,
fit: BoxFit.cover,
child: Container(
// arbitrary size here
constraints: BoxConstraints.tight(const Size(128, 128)),
color: AppTheme.getListItemBackgroundColor(context),
child: CachedNetworkImage(
imageUrl: previewUrl,
httpHeaders: {
"Authorization": Api.getAuthorizationHeaderValue(account),
},
fadeInDuration: const Duration(),
filterQuality: FilterQuality.high,
errorWidget: (context, url, error) {
// won't work on web because the image is downloaded by the cache
// manager instead
// where's the preview???
return Container(
child: Center(
child: Icon(
Icons.image_not_supported,
size: 64,
color: Colors.white.withOpacity(.8),
),
child: Stack(
children: [
Container(
// arbitrary size here
constraints: BoxConstraints.tight(const Size(128, 128)),
color: AppTheme.getListItemBackgroundColor(context),
child: CachedNetworkImage(
imageUrl: previewUrl,
httpHeaders: {
"Authorization": Api.getAuthorizationHeaderValue(account),
},
fadeInDuration: const Duration(),
filterQuality: FilterQuality.high,
errorWidget: (context, url, error) {
// won't work on web because the image is downloaded by the cache
// manager instead
// where's the preview???
return Container(
child: Center(
child: Icon(
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 String previewUrl;
final bool isGif;
}
class PhotoListVideo extends StatelessWidget {