diff --git a/lib/main.dart b/lib/main.dart index 19e5779..4f4d70a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,5 @@ import 'dart:developer'; import 'dart:io'; - import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:media_kit/media_kit.dart'; diff --git a/lib/models/metadata/metadata_movie_model.dart b/lib/models/metadata/metadata_movie_model.dart index 4644ae7..1598977 100644 --- a/lib/models/metadata/metadata_movie_model.dart +++ b/lib/models/metadata/metadata_movie_model.dart @@ -28,36 +28,37 @@ class MetadataMovieModel { final String? website; MetadataMovieModel({ - required this.year, - required this.rated, - required this.released, - required this.runtime, - required this.genre, - required this.director, - required this.writer, - required this.actors, - required this.plot, - required this.language, - required this.country, - required this.awards, - required this.poster, - required this.logo, - required this.backdrop, - required this.ratings, - required this.metascore, - required this.imdbRating, - required this.imdbVotes, - required this.imdbID, - required this.type, - required this.dvd, - required this.boxOffice, - required this.production, - required this.website, + this.year, + this.rated, + this.released, + this.runtime, + this.genre, + this.director, + this.writer, + this.actors, + this.plot, + this.language, + this.country, + this.awards, + this.poster, + this.logo, + this.backdrop, + this.ratings, + this.metascore, + this.imdbRating, + this.imdbVotes, + this.imdbID, + this.type, + this.dvd, + this.boxOffice, + this.production, + this.website, }); factory MetadataMovieModel.fromJson(Map json) { var ratingsList = json['ratings'] as List?; - List? ratings = ratingsList?.map((ratingJson) => Rating.fromJson(ratingJson)).toList(); + List? ratings = + ratingsList?.map((ratingJson) => Rating.fromJson(ratingJson)).toList(); var poster = (json['poster'] as String?); @@ -123,4 +124,4 @@ class MetadataMovieModel { 'website': website, }; } -} \ No newline at end of file +} diff --git a/lib/views/gallery.dart b/lib/views/gallery.dart index edf6381..1d35dfa 100644 --- a/lib/views/gallery.dart +++ b/lib/views/gallery.dart @@ -1,7 +1,9 @@ import 'package:flutter/material.dart'; import 'package:open_media_server_app/apis/inventory_api.dart'; import 'package:open_media_server_app/apis/metadata_api.dart'; +import 'package:open_media_server_app/helpers/preferences.dart'; import 'package:open_media_server_app/models/internal/grid_item_model.dart'; +import 'package:open_media_server_app/models/inventory/inventory_item.dart'; import 'package:open_media_server_app/models/metadata/metadata_model.dart'; import 'package:open_media_server_app/widgets/grid_item.dart'; import 'package:open_media_server_app/views/detail_views/movie_detail.dart'; @@ -23,7 +25,7 @@ class Gallery extends StatelessWidget { return Padding( padding: const EdgeInsets.all(8.0), - child: FutureBuilder>( + child: FutureBuilder>( future: futureItems, builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { @@ -34,7 +36,7 @@ class Gallery extends StatelessWidget { return const Center(child: Text('No movies found.')); } - List items = snapshot.data!; + List items = snapshot.data!; return GridView.builder( itemCount: items.length, @@ -45,23 +47,39 @@ class Gallery extends StatelessWidget { childAspectRatio: 0.7, // Adjust for desired aspect ratio ), itemBuilder: (context, index) { + var gridItemFake = GridItemModel( + inventoryItem: items[index], + metadataModel: null, + ); + + gridItemFake.posterUrl = + "${Preferences.prefs?.getString("BaseUrl")}/images/${items[index].category}/${items[index].metadataId}/poster"; + return InkWell( child: GridItem( - item: items[index], + item: gridItemFake, desiredItemWidth: desiredItemWidth, ), - onTap: () { + onTap: () async { + GridItemModel gridItem; + + if (items[index].category == "Movie") { + gridItem = await getMovie(items[index]); + } else { + gridItem = await getShow(items[index]); + } + Navigator.push( context, MaterialPageRoute(builder: (context) { - if (items[index].inventoryItem!.category == "Movie") { + if (items[index].category == "Movie") { return MovieDetailView( - itemModel: items[index], + itemModel: gridItem, ); } - if (items[index].inventoryItem!.category == "Show") { + if (items[index].category == "Show") { return ShowDetailView( - itemModel: items[index], + itemModel: gridItem, ); } @@ -77,52 +95,53 @@ class Gallery extends StatelessWidget { ); } - Future> getGridItems() async { + Future> getGridItems() async { InventoryApi inventoryApi = InventoryApi(); - MetadataApi metadataApi = MetadataApi(); - var movies = await inventoryApi.listItems("Movie"); + var items = await inventoryApi.listItems("Movie"); var shows = await inventoryApi.listItems("Show"); - List gridItems = []; - - for (var element in movies) { - var movie = await inventoryApi.getMovie(element.id); + items.addAll(shows); - MetadataModel? metadata; + return items; + } - if (movie.metadataId != null) { - metadata = await metadataApi.getMetadata(movie.metadataId!, "Movie"); - } + Future getMovie(InventoryItem element) async { + InventoryApi inventoryApi = InventoryApi(); + MetadataApi metadataApi = MetadataApi(); - var gridItem = - GridItemModel(inventoryItem: movie, metadataModel: metadata); + var movie = await inventoryApi.getMovie(element.id); - gridItem.posterUrl = metadata?.movie?.poster; - gridItem.backdropUrl = metadata?.movie?.backdrop; + MetadataModel? metadata; - gridItems.add(gridItem); + if (movie.metadataId != null) { + metadata = await metadataApi.getMetadata(movie.metadataId!, "Movie"); } - for (var element in shows) { - var show = await inventoryApi.getShow(element.id); + var gridItem = GridItemModel(inventoryItem: movie, metadataModel: metadata); - MetadataModel? metadata; + gridItem.posterUrl = metadata?.movie?.poster; + gridItem.backdropUrl = metadata?.movie?.backdrop; + return gridItem; + } - if (show.metadataId != null) { - metadata = await metadataApi.getMetadata(show.metadataId!, "Show"); - } + Future getShow(InventoryItem element) async { + InventoryApi inventoryApi = InventoryApi(); + MetadataApi metadataApi = MetadataApi(); - var gridItem = - GridItemModel(inventoryItem: show, metadataModel: metadata); + var show = await inventoryApi.getShow(element.id); - gridItem.posterUrl = metadata?.show?.poster; - gridItem.backdropUrl = metadata?.show?.backdrop; - gridItem.childIds = show.seasonIds; + MetadataModel? metadata; - gridItems.add(gridItem); + if (show.metadataId != null) { + metadata = await metadataApi.getMetadata(show.metadataId!, "Show"); } - return gridItems; + var gridItem = GridItemModel(inventoryItem: show, metadataModel: metadata); + + gridItem.posterUrl = metadata?.show?.poster; + gridItem.backdropUrl = metadata?.show?.backdrop; + gridItem.childIds = show.seasonIds; + return gridItem; } } diff --git a/lib/widgets/custom_image.dart b/lib/widgets/custom_image.dart index 9c73afc..40fe157 100644 --- a/lib/widgets/custom_image.dart +++ b/lib/widgets/custom_image.dart @@ -1,6 +1,7 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:open_media_server_app/apis/base_api.dart'; +import 'package:open_media_server_app/globals/globals.dart'; class CustomImage extends StatelessWidget { const CustomImage({ @@ -8,7 +9,7 @@ class CustomImage extends StatelessWidget { required this.imageUrl, this.fit, this.width, - this.height, + this.height, this.disableAdaptiveImage = false, }); @@ -32,6 +33,15 @@ class CustomImage extends StatelessWidget { width: width, height: height, httpHeaders: BaseApi.getHeaders(), + errorWidget: (context, url, error) { + return CustomImage( + imageUrl: Globals.PictureNotFoundUrl, + width: width, + height: height, + fit: fit, + disableAdaptiveImage: disableAdaptiveImage, + ); + }, ); } }