Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Subtitle is fetched for editions #474

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 56 additions & 52 deletions lib/model/ol_edition_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class OLEditionResult {
this.classifications,
this.sourceRecords,
this.title,
this.subtitle,
this.identifiers,
this.isbn13,
this.localId,
Expand All @@ -41,6 +42,7 @@ class OLEditionResult {
final Classifications? classifications;
final List<String>? sourceRecords;
final String? title;
final String? subtitle;
final Identifiers? identifiers;
final List<String>? isbn13;
final List<String>? localId;
Expand All @@ -52,58 +54,60 @@ class OLEditionResult {
final Created? created;
final Created? lastModified;

factory OLEditionResult.fromJson(Map<String, dynamic> json) =>
OLEditionResult(
publishers: json["publishers"] == null
? null
: List<String>.from(json["publishers"].map((x) => x)),
numberOfPages: json["number_of_pages"],
isbn10: json["isbn_10"] == null
? null
: List<String>.from(json["isbn_10"].map((x) => x)),
covers: json["covers"] == null
? null
: List<int?>.from(json["covers"].map((x) => x)),
key: json["key"],
authors: json["authors"] == null
? null
: List<Type>.from(json["authors"].map((x) => Type.fromJson(x))),
ocaid: json["ocaid"],
contributions: json["contributions"] == null
? null
: List<String>.from(json["contributions"].map((x) => x)),
languages: json["languages"] == null
? null
: List<Type>.from(json["languages"].map((x) => Type.fromJson(x))),
classifications: json["classifications"] == null
? null
: Classifications.fromJson(json["classifications"]),
sourceRecords: json["source_records"] == null
? null
: List<String>.from(json["source_records"].map((x) => x)),
title: json["title"],
identifiers: json["identifiers"] == null
? null
: Identifiers.fromJson(json["identifiers"]),
isbn13: json["isbn_13"] == null
? null
: List<String>.from(json["isbn_13"].map((x) => x)),
localId: json["local_id"] == null
? null
: List<String>.from(json["local_id"].map((x) => x)),
publishDate: json["publish_date"],
works: json["works"] == null
? null
: List<Type>.from(json["works"].map((x) => Type.fromJson(x))),
type: json["type"] == null ? null : Type.fromJson(json["type"]),
latestRevision: json["latest_revision"],
revision: json["revision"],
created:
json["created"] == null ? null : Created.fromJson(json["created"]),
lastModified: json["last_modified"] == null
? null
: Created.fromJson(json["last_modified"]),
);
factory OLEditionResult.fromJson(Map<String, dynamic> json) {
return OLEditionResult(
publishers: json["publishers"] == null
? null
: List<String>.from(json["publishers"].map((x) => x)),
numberOfPages: json["number_of_pages"],
isbn10: json["isbn_10"] == null
? null
: List<String>.from(json["isbn_10"].map((x) => x)),
covers: json["covers"] == null
? null
: List<int?>.from(json["covers"].map((x) => x)),
key: json["key"],
authors: json["authors"] == null
? null
: List<Type>.from(json["authors"].map((x) => Type.fromJson(x))),
ocaid: json["ocaid"],
contributions: json["contributions"] == null
? null
: List<String>.from(json["contributions"].map((x) => x)),
languages: json["languages"] == null
? null
: List<Type>.from(json["languages"].map((x) => Type.fromJson(x))),
classifications: json["classifications"] == null
? null
: Classifications.fromJson(json["classifications"]),
sourceRecords: json["source_records"] == null
? null
: List<String>.from(json["source_records"].map((x) => x)),
title: json["title"],
subtitle: json["subtitle"],
identifiers: json["identifiers"] == null
? null
: Identifiers.fromJson(json["identifiers"]),
isbn13: json["isbn_13"] == null
? null
: List<String>.from(json["isbn_13"].map((x) => x)),
localId: json["local_id"] == null
? null
: List<String>.from(json["local_id"].map((x) => x)),
publishDate: json["publish_date"],
works: json["works"] == null
? null
: List<Type>.from(json["works"].map((x) => Type.fromJson(x))),
type: json["type"] == null ? null : Type.fromJson(json["type"]),
latestRevision: json["latest_revision"],
revision: json["revision"],
created:
json["created"] == null ? null : Created.fromJson(json["created"]),
lastModified: json["last_modified"] == null
? null
: Created.fromJson(json["last_modified"]),
);
}
}

class Type {
Expand Down
6 changes: 3 additions & 3 deletions lib/model/ol_search_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class OLSearchResultDoc {
this.publishDate,
this.publishYear,
this.firstPublishYear,
this.numberOfPagesMedian,
this.medianPages,
this.lccn,
this.publishPlace,
this.oclc,
Expand Down Expand Up @@ -125,7 +125,7 @@ class OLSearchResultDoc {
final List<String>? publishDate;
final List<int>? publishYear;
final int? firstPublishYear;
final int? numberOfPagesMedian;
final int? medianPages;
final List<String>? lccn;
final List<String>? publishPlace;
final List<String>? oclc;
Expand Down Expand Up @@ -213,7 +213,7 @@ class OLSearchResultDoc {
? null
: List<int>.from(json["publish_year"].map((x) => x)),
firstPublishYear: json["first_publish_year"],
numberOfPagesMedian: json["number_of_pages_median"],
medianPages: json["number_of_pages_median"],
lccn: json["lccn"] == null
? null
: List<String>.from(json["lccn"].map((x) => x)),
Expand Down
25 changes: 14 additions & 11 deletions lib/resources/open_library_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class OpenLibraryService {
required int limit,
required OLSearchType searchType,
}) async {
final searchTypeKey = searchType == OLSearchType.general
final searchTypeParam = searchType == OLSearchType.general
? 'q'
: searchType == OLSearchType.author
? 'author'
Expand All @@ -24,26 +24,29 @@ class OpenLibraryService {
: searchType == OLSearchType.isbn
? 'isbn'
: 'q';
const modeParam = '&mode=everything';
const fieldsParam =
'&fields=key,title,subtitle,author_key,author_name,editions,number_of_pages_median,first_publish_year,isbn,edition_key,cover_edition_key,cover_i';
final offsetParam = '&offset=$offset';
final limitParam = '&limit=$limit';

final response = await get(
Uri.parse(
'${baseUrl}search.json?$searchTypeKey=$query&limit=$limit&offset=$offset',
),
final uri = Uri.parse(
'${baseUrl}search.json?$searchTypeParam=$query$limitParam$offsetParam$modeParam$fieldsParam',
);

final response = await get(uri);
return openLibrarySearchResultFromJson(response.body);
}

Future<OLEditionResult> getEdition(String edition) async {
final response = await get(
Uri.parse('$baseUrl/books/$edition.json'),
);
final uri = Uri.parse('$baseUrl/works/$edition.json');
final response = await get(uri);
return openLibraryEditionResultFromJson(response.body);
}

Future<OLWorkResult> getWork(String work) async {
final response = await get(
Uri.parse('$baseUrl$work.json'),
);
final uri = Uri.parse('$baseUrl$work.json');
final response = await get(uri);
return openLibraryWorkResultFromJson(response.body);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class _SearchOLEditionsScreenState extends State<SearchOLEditionsScreen> {
}) {
final book = Book(
title: result.title!,
subtitle: widget.subtitle,
subtitle: result.subtitle,
author: widget.author,
pages: result.numberOfPages,
status: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class OLEditionsGrid extends StatelessWidget {
itemBuilder: (context, item, index) => BookCardOLEdition(
publishers: item.publishers,
publicationDate: item.publishDate,
title: item.title!,
title: item.title ?? '',
pages: item.numberOfPages,
cover: item.covers != null && item.covers!.isNotEmpty
? item.covers![0]
Expand Down
87 changes: 45 additions & 42 deletions lib/ui/search_ol_screen/search_ol_screen.dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -397,55 +397,58 @@ class _SearchOLScreenState extends State<SearchOLScreen>
],
),
),
itemBuilder: (context, item, index) => BookCardOL(
title: item.title!,
subtitle: item.subtitle,
author: (item.authorName != null &&
item.authorName!.isNotEmpty)
? item.authorName![0]
: '',
openLibraryKey: item.coverEditionKey,
doc: item,
editions: item.editionKey,
pagesMedian: item.numberOfPagesMedian,
firstPublishYear: item.firstPublishYear,
onAddBookPressed: () => _saveNoEdition(
editions: item.editionKey!,
title: item.title!,
itemBuilder: (context, item, index) =>
Builder(builder: (context) {
return BookCardOL(
title: item.title ?? '',
subtitle: item.subtitle,
author: (item.authorName != null &&
item.authorName!.isNotEmpty)
? item.authorName![0]
: '',
pagesMedian: item.numberOfPagesMedian,
isbn: item.isbn,
olid: item.key,
coverKey: item.coverEditionKey,
editions: item.editionKey,
pagesMedian: item.medianPages,
firstPublishYear: item.firstPublishYear,
cover: item.coverI,
),
onChooseEditionPressed: () {
FocusManager.instance.primaryFocus?.unfocus();

Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SearchOLEditionsScreen(
editions: item.editionKey!,
title: item.title!,
subtitle: item.subtitle,
author: (item.authorName != null &&
item.authorName!.isNotEmpty)
? item.authorName![0]
: '',
pagesMedian: item.numberOfPagesMedian,
isbn: item.isbn,
olid: item.key,
firstPublishYear: item.firstPublishYear,
onAddBookPressed: () => _saveNoEdition(
editions: item.editionKey!,
title: item.title ?? '',
subtitle: item.subtitle,
author: (item.authorName != null &&
item.authorName!.isNotEmpty)
? item.authorName![0]
: '',
pagesMedian: item.medianPages,
isbn: item.isbn,
olid: item.key,
firstPublishYear: item.firstPublishYear,
cover: item.coverI,
),
onChooseEditionPressed: () {
FocusManager.instance.primaryFocus?.unfocus();

Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
SearchOLEditionsScreen(
editions: item.editionKey!,
title: item.title!,
subtitle: item.subtitle,
author: (item.authorName != null &&
item.authorName!.isNotEmpty)
? item.authorName![0]
: '',
pagesMedian: item.medianPages,
isbn: item.isbn,
olid: item.key,
firstPublishYear: item.firstPublishYear,
),
),
),
);
},
),
);
},
);
}),
),
),
),
Expand Down
15 changes: 6 additions & 9 deletions lib/ui/search_ol_screen/widgets/book_card_ol.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,33 @@ import 'package:flutter/material.dart';
import 'package:loading_animation_widget/loading_animation_widget.dart';
import 'package:openreads/core/themes/app_theme.dart';
import 'package:openreads/generated/locale_keys.g.dart';
import 'package:openreads/model/ol_search_result.dart';

class BookCardOL extends StatelessWidget {
BookCardOL({
Key? key,
super.key,
required this.title,
required this.subtitle,
required this.author,
required this.openLibraryKey,
required this.coverKey,
required this.onChooseEditionPressed,
required this.onAddBookPressed,
required this.doc,
required this.editions,
required this.pagesMedian,
required this.firstPublishYear,
}) : super(key: key);
});

final String title;
final String? subtitle;
final String author;
final String? openLibraryKey;
final OLSearchResultDoc doc;
final String? coverKey;
final Function() onChooseEditionPressed;
final Function() onAddBookPressed;
final List<String>? editions;
final int? pagesMedian;
final int? firstPublishYear;

static const String coverBaseUrl = 'https://covers.openlibrary.org/';
late final String coverUrl = '${coverBaseUrl}b/olid/$openLibraryKey-M.jpg';
late final String coverUrl = '${coverBaseUrl}b/olid/$coverKey-M.jpg';

@override
Widget build(BuildContext context) {
Expand All @@ -51,7 +48,7 @@ class BookCardOL extends StatelessWidget {
children: [
SizedBox(
width: 120,
child: (openLibraryKey != null)
child: (coverKey != null)
? ClipRRect(
borderRadius: BorderRadius.circular(2),
child: CachedNetworkImage(
Expand Down
Loading