mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
Always use preview when showing image
This commit is contained in:
parent
5143f86751
commit
f47fbb11ef
4 changed files with 56 additions and 29 deletions
|
@ -113,6 +113,12 @@ class AppTheme extends StatelessWidget {
|
|||
return Colors.white.withOpacity(.5);
|
||||
}
|
||||
|
||||
static Color getListItemBackgroundColor(BuildContext context) {
|
||||
return Theme.of(context).brightness == Brightness.light
|
||||
? Colors.black26
|
||||
: Colors.white12;
|
||||
}
|
||||
|
||||
static const primarySwatchLight = Colors.blue;
|
||||
static const primarySwatchDark = Colors.cyan;
|
||||
|
||||
|
|
|
@ -77,13 +77,10 @@ class _AlbumViewerState extends State<AlbumViewer>
|
|||
|
||||
void _initCover() {
|
||||
try {
|
||||
final coverFile = _backingFiles.first;
|
||||
if (coverFile.hasPreview) {
|
||||
_coverPreviewUrl = api_util.getFilePreviewUrl(widget.account, coverFile,
|
||||
width: 1024, height: 600);
|
||||
} else {
|
||||
_coverPreviewUrl = api_util.getFileUrl(widget.account, coverFile);
|
||||
}
|
||||
final coverFile =
|
||||
_backingFiles.firstWhere((element) => element.hasPreview);
|
||||
_coverPreviewUrl = api_util.getFilePreviewUrl(widget.account, coverFile,
|
||||
width: 1024, height: 600);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
|
@ -164,6 +161,10 @@ class _AlbumViewerState extends State<AlbumViewer>
|
|||
Api.getAuthorizationHeaderValue(widget.account),
|
||||
},
|
||||
filterQuality: FilterQuality.high,
|
||||
errorWidget: (context, url, error) {
|
||||
// just leave it empty
|
||||
return Container();
|
||||
},
|
||||
imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet,
|
||||
),
|
||||
),
|
||||
|
@ -262,13 +263,8 @@ class _AlbumViewerState extends State<AlbumViewer>
|
|||
.sorted(compareFileDateTimeDescending);
|
||||
|
||||
itemStreamListItems = _backingFiles.mapWithIndex((i, e) {
|
||||
var previewUrl;
|
||||
if (e.hasPreview) {
|
||||
previewUrl = api_util.getFilePreviewUrl(widget.account, e,
|
||||
width: _thumbSize, height: _thumbSize);
|
||||
} else {
|
||||
previewUrl = api_util.getFileUrl(widget.account, e);
|
||||
}
|
||||
final previewUrl = api_util.getFilePreviewUrl(widget.account, e,
|
||||
width: _thumbSize, height: _thumbSize);
|
||||
return _ImageListItem(
|
||||
account: widget.account,
|
||||
previewUrl: previewUrl,
|
||||
|
@ -319,6 +315,21 @@ class _ImageListItem extends SelectableItemStreamListItem {
|
|||
},
|
||||
fadeInDuration: const Duration(),
|
||||
filterQuality: FilterQuality.high,
|
||||
errorWidget: (context, url, error) {
|
||||
// where's the preview???
|
||||
return Container(
|
||||
color: AppTheme.getListItemBackgroundColor(context),
|
||||
width: 128,
|
||||
height: 128,
|
||||
child: Center(
|
||||
child: Icon(
|
||||
Icons.image_not_supported,
|
||||
size: 56,
|
||||
color: Colors.white.withOpacity(.8),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet,
|
||||
),
|
||||
);
|
||||
|
|
|
@ -188,17 +188,13 @@ class _HomeAlbumsState extends State<HomeAlbums> {
|
|||
final latestFile = album.items
|
||||
.whereType<AlbumFileItem>()
|
||||
.map((e) => e.file)
|
||||
.where((element) => file_util.isSupportedFormat(element))
|
||||
.where((element) =>
|
||||
file_util.isSupportedFormat(element) && element.hasPreview)
|
||||
.sorted(compareFileDateTimeDescending)
|
||||
.first;
|
||||
|
||||
String previewUrl;
|
||||
if (latestFile.hasPreview) {
|
||||
previewUrl = api_util.getFilePreviewUrl(widget.account, latestFile,
|
||||
width: 512, height: 512);
|
||||
} else {
|
||||
previewUrl = api_util.getFileUrl(widget.account, latestFile);
|
||||
}
|
||||
final previewUrl = api_util.getFilePreviewUrl(widget.account, latestFile,
|
||||
width: 512, height: 512);
|
||||
cover = FittedBox(
|
||||
clipBehavior: Clip.hardEdge,
|
||||
fit: BoxFit.cover,
|
||||
|
@ -209,6 +205,10 @@ class _HomeAlbumsState extends State<HomeAlbums> {
|
|||
},
|
||||
fadeInDuration: const Duration(),
|
||||
filterQuality: FilterQuality.high,
|
||||
errorWidget: (context, url, error) {
|
||||
// just leave it empty
|
||||
return Container();
|
||||
},
|
||||
imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet,
|
||||
),
|
||||
);
|
||||
|
|
|
@ -360,13 +360,8 @@ class _HomePhotosState extends State<HomePhotos>
|
|||
currentDateStr = newDateStr;
|
||||
}
|
||||
|
||||
var previewUrl;
|
||||
if (f.hasPreview) {
|
||||
previewUrl = api_util.getFilePreviewUrl(widget.account, f,
|
||||
width: _thumbSize, height: _thumbSize);
|
||||
} else {
|
||||
previewUrl = api_util.getFileUrl(widget.account, f);
|
||||
}
|
||||
final previewUrl = api_util.getFilePreviewUrl(widget.account, f,
|
||||
width: _thumbSize, height: _thumbSize);
|
||||
yield _ImageListItem(
|
||||
file: f,
|
||||
account: widget.account,
|
||||
|
@ -491,6 +486,21 @@ class _ImageListItem extends _FileListItem {
|
|||
},
|
||||
fadeInDuration: const Duration(),
|
||||
filterQuality: FilterQuality.high,
|
||||
errorWidget: (context, url, error) {
|
||||
// where's the preview???
|
||||
return Container(
|
||||
color: AppTheme.getListItemBackgroundColor(context),
|
||||
width: 128,
|
||||
height: 128,
|
||||
child: Center(
|
||||
child: Icon(
|
||||
Icons.image_not_supported,
|
||||
size: 56,
|
||||
color: Colors.white.withOpacity(.8),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet,
|
||||
),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue