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 {
|
2022-12-29 05:24:44 +00:00
|
|
|
static const thumbnailDimension = 350.0;
|
2022-12-14 02:06:10 +00:00
|
|
|
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),
|
2022-12-29 05:24:44 +00:00
|
|
|
child: GestureDetector(
|
|
|
|
onDoubleTap: () {
|
2022-12-14 02:14:42 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|