2022-12-14 02:06:10 +00:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
import '../controls/padding.dart';
|
|
|
|
import '../serializers/friendica/image_entry_friendica_extensions.dart';
|
|
|
|
import '../services/gallery_service.dart';
|
|
|
|
import 'image_viewer_screen.dart';
|
|
|
|
|
|
|
|
class GalleryScreen extends StatelessWidget {
|
|
|
|
static const thumbnailDimension = 100.0;
|
|
|
|
static final _logger = Logger('$GalleryScreen');
|
|
|
|
final String galleryName;
|
|
|
|
|
|
|
|
const GalleryScreen({super.key, required this.galleryName});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
_logger.finest('Building');
|
|
|
|
final service = context.watch<GalleryService>();
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(galleryName),
|
|
|
|
),
|
|
|
|
body: RefreshIndicator(
|
|
|
|
onRefresh: () async {
|
|
|
|
print('Refresh $galleryName image list');
|
|
|
|
},
|
|
|
|
child: RefreshIndicator(
|
|
|
|
onRefresh: () async {
|
|
|
|
await service.updateGalleryImageList(galleryName);
|
|
|
|
},
|
|
|
|
child: buildBody(context, service)),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildBody(BuildContext context, GalleryService service) {
|
|
|
|
final imageResult = service.getGalleryImageList(galleryName);
|
|
|
|
if (imageResult.isFailure) {
|
|
|
|
return SingleChildScrollView(
|
|
|
|
child: Center(
|
|
|
|
child: Text('Error getting images for gallery: ${imageResult.error}'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
final images = imageResult.value;
|
|
|
|
if (images.isEmpty && service.loaded) {
|
|
|
|
return const SingleChildScrollView(
|
|
|
|
child: Center(
|
|
|
|
child: Text('No images'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (images.isEmpty) {
|
|
|
|
return Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: const [
|
|
|
|
Text('Loading images'),
|
|
|
|
VerticalPadding(),
|
|
|
|
CircularProgressIndicator(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-14 02:14:42 +00:00
|
|
|
return GridView.builder(
|
|
|
|
itemCount: images.length,
|
|
|
|
padding: EdgeInsets.all(5.0),
|
|
|
|
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
|
|
|
maxCrossAxisExtent: thumbnailDimension),
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
final image = images[index];
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.all(2.0),
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(context, MaterialPageRoute(builder: (context) {
|
|
|
|
return ImageViewerScreen(
|
|
|
|
attachment: image.toMediaAttachment());
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
child: CachedNetworkImage(
|
|
|
|
width: thumbnailDimension,
|
|
|
|
height: thumbnailDimension,
|
|
|
|
imageUrl: image.thumbnailUrl,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-12-14 02:06:10 +00:00
|
|
|
return ListView.separated(
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
final image = images[index];
|
|
|
|
return InkWell(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(context, MaterialPageRoute(builder: (context) {
|
|
|
|
return ImageViewerScreen(attachment: image.toMediaAttachment());
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
child: ListTile(
|
|
|
|
leading: CachedNetworkImage(
|
|
|
|
width: thumbnailDimension,
|
|
|
|
height: thumbnailDimension,
|
|
|
|
imageUrl: image.thumbnailUrl,
|
|
|
|
),
|
|
|
|
title: Text(image.filename),
|
|
|
|
subtitle: Text(
|
|
|
|
image.description,
|
|
|
|
style: Theme.of(context).textTheme.caption,
|
|
|
|
),
|
|
|
|
trailing: Text(image.created.toString()),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
separatorBuilder: (context, index) {
|
|
|
|
return const Divider();
|
|
|
|
},
|
|
|
|
itemCount: images.length,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|