diff --git a/lib/logic/met_api_logic.dart b/lib/logic/artifact_api_logic.dart similarity index 59% rename from lib/logic/met_api_logic.dart rename to lib/logic/artifact_api_logic.dart index a083eecc..692ec5ea 100644 --- a/lib/logic/met_api_logic.dart +++ b/lib/logic/artifact_api_logic.dart @@ -3,17 +3,18 @@ import 'dart:collection'; import 'package:wonders/common_libs.dart'; import 'package:wonders/logic/common/http_client.dart'; import 'package:wonders/logic/data/artifact_data.dart'; -import 'package:wonders/logic/met_api_service.dart'; +import 'package:wonders/logic/artifact_api_service.dart'; -class MetAPILogic { +class ArtifactAPILogic { final HashMap _artifactCache = HashMap(); - MetAPIService get service => GetIt.I.get(); + ArtifactAPIService get service => GetIt.I.get(); /// Returns artifact data by ID. Returns null if artifact cannot be found. */ - Future getArtifactByID(String id) async { + Future getArtifactByID(String id, {bool selfHosted = false}) async { if (_artifactCache.containsKey(id)) return _artifactCache[id]; - ServiceResult result = (await service.getObjectByID(id)); + ServiceResult result = + (await (selfHosted ? service.getSelfHostedObjectByID(id) : service.getMetObjectByID(id))); if (!result.success) throw $strings.artifactDetailsErrorNotFound(id); ArtifactData? artifact = result.content; return _artifactCache[id] = artifact; diff --git a/lib/logic/met_api_service.dart b/lib/logic/artifact_api_service.dart similarity index 72% rename from lib/logic/met_api_service.dart rename to lib/logic/artifact_api_service.dart index c8cb9a3e..c14c1aec 100644 --- a/lib/logic/met_api_service.dart +++ b/lib/logic/artifact_api_service.dart @@ -1,14 +1,20 @@ import 'package:wonders/logic/common/http_client.dart'; import 'package:wonders/logic/data/artifact_data.dart'; -class MetAPIService { +class ArtifactAPIService { final String _baseMETUrl = 'https://collectionapi.metmuseum.org/public/collection/v1'; + final String _baseSelfHostedUrl = 'https://www.wonderous.info/met'; - Future> getObjectByID(String id) async { + Future> getMetObjectByID(String id) async { HttpResponse? response = await HttpClient.send('$_baseMETUrl/objects/$id'); return ServiceResult(response, _parseArtifactData); } + Future> getSelfHostedObjectByID(String id) async { + HttpResponse? response = await HttpClient.send('$_baseSelfHostedUrl/$id.json'); + return ServiceResult(response, _parseArtifactData); + } + ArtifactData? _parseArtifactData(Map content) { // Source: https://metmuseum.github.io/ return ArtifactData( diff --git a/lib/ui/screens/artifact/artifact_details/artifact_details_screen.dart b/lib/ui/screens/artifact/artifact_details/artifact_details_screen.dart index 2b3df379..f9ef8c04 100644 --- a/lib/ui/screens/artifact/artifact_details/artifact_details_screen.dart +++ b/lib/ui/screens/artifact/artifact_details/artifact_details_screen.dart @@ -7,7 +7,7 @@ import 'package:wonders/ui/common/gradient_container.dart'; import 'package:wonders/ui/common/modals/fullscreen_url_img_viewer.dart'; part 'widgets/_info_column.dart'; -part 'widgets/_image_btn.dart'; +part 'widgets/_artifact_image_btn.dart'; class ArtifactDetailsScreen extends StatefulWidget { const ArtifactDetailsScreen({Key? key, required this.artifactId}) : super(key: key); @@ -18,7 +18,7 @@ class ArtifactDetailsScreen extends StatefulWidget { } class _ArtifactDetailsScreenState extends State { - late final _future = metAPILogic.getArtifactByID(widget.artifactId); + late final _future = metAPILogic.getArtifactByID(widget.artifactId, selfHosted: true); @override Widget build(BuildContext context) { @@ -37,7 +37,7 @@ class _ArtifactDetailsScreenState extends State { } else { content = hzMode ? Row(children: [ - Expanded(child: _ImageBtn(data: data!)), + Expanded(child: _ArtifactImageBtn(data: data!)), Expanded(child: Center(child: SizedBox(width: 600, child: _InfoColumn(data: data)))), ]) : CustomScrollView( @@ -48,7 +48,7 @@ class _ArtifactDetailsScreenState extends State { leading: SizedBox.shrink(), expandedHeight: context.heightPx * .5, collapsedHeight: context.heightPx * .35, - flexibleSpace: _ImageBtn(data: data!), + flexibleSpace: _ArtifactImageBtn(data: data!), ), SliverToBoxAdapter(child: _InfoColumn(data: data)), ], diff --git a/lib/ui/screens/artifact/artifact_details/widgets/_image_btn.dart b/lib/ui/screens/artifact/artifact_details/widgets/_artifact_image_btn.dart similarity index 82% rename from lib/ui/screens/artifact/artifact_details/widgets/_image_btn.dart rename to lib/ui/screens/artifact/artifact_details/widgets/_artifact_image_btn.dart index 2ae8f924..c7e25a1e 100644 --- a/lib/ui/screens/artifact/artifact_details/widgets/_image_btn.dart +++ b/lib/ui/screens/artifact/artifact_details/widgets/_artifact_image_btn.dart @@ -1,7 +1,7 @@ part of '../artifact_details_screen.dart'; -class _ImageBtn extends StatelessWidget { - const _ImageBtn({Key? key, required this.data}) : super(key: key); +class _ArtifactImageBtn extends StatelessWidget { + const _ArtifactImageBtn({Key? key, required this.data}) : super(key: key); final ArtifactData data; @override @@ -28,9 +28,9 @@ class _ImageBtn extends StatelessWidget { bottom: false, minimum: EdgeInsets.symmetric(vertical: $styles.insets.sm), child: Hero( - tag: data.image, + tag: data.selfHostedImageUrl, child: AppImage( - image: NetworkImage(data.image), + image: NetworkImage(data.selfHostedImageUrl), fit: BoxFit.contain, distractor: true, scale: FullscreenUrlImgViewer.imageScale, // so the image isn't reloaded @@ -44,6 +44,6 @@ class _ImageBtn extends StatelessWidget { } void _handleImagePressed(BuildContext context) { - appLogic.showFullscreenDialogRoute(context, FullscreenUrlImgViewer(urls: [data.image])); + appLogic.showFullscreenDialogRoute(context, FullscreenUrlImgViewer(urls: [data.selfHostedImageUrl])); } }