Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: Add a description field #250

Merged
merged 1 commit into from
Apr 12, 2023
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
11 changes: 8 additions & 3 deletions lib/database/database_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ class DatabaseProvider {

return await openDatabase(
path,
version: 1,
version: 2,
onCreate: (Database db, int version) async {
await db.execute("CREATE TABLE booksTable ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"title TEXT, "
"subtitle TEXT, "
"author TEXT, "
"description TEXT, "
"status INTEGER, "
"rating INTEGER, "
"favourite INTEGER, "
Expand All @@ -41,8 +42,12 @@ class DatabaseProvider {
"blur_hash TEXT "
")");
},
onUpgrade: (Database db, int oldVersion, int newVersion) {
if (newVersion > oldVersion) {}
onUpgrade: (Database db, int oldVersion, int newVersion) async {
if (newVersion > oldVersion) {
if (oldVersion == 1) {
await db.execute("ALTER TABLE booksTable ADD description TEXT");
}
}
},
);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"enter_author": "Enter the author",
"enter_pages": "Number of pages",
"enter_publication_year": "Publication year",
"enter_description": "Enter the description",
"isbn": "ISBN",
"open_library_ID": "Open Library ID",
"enter_tags": "Tags",
Expand All @@ -61,6 +62,7 @@
"title": "Title",
"author": "Author",
"rating": "Rating",
"description": "Description",

"sort_by": "Sort by",
"only_favourite": "Only favourite",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"enter_author": "Entrez l'auteur",
"enter_pages": "Nombre de pages",
"enter_publication_year": "Année de publication",
"enter_description": "Entrez la description",
"isbn": "ISBN",
"open_library_ID": "ID de Open Library",
"enter_tags": "Étiquettes",
Expand All @@ -55,6 +56,7 @@
"title": "Titre",
"author": "Auteur",
"rating": "Note",
"description": "Description",
"sort_by": "Trier par",
"only_favourite": "Seulement les favoris",
"filter_by_finish_year": "Filtrer par année d'achèvement",
Expand Down
4 changes: 4 additions & 0 deletions lib/model/book.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Book {
String title;
String? subtitle;
String author;
String? description;
int status;
bool favourite;
bool deleted;
Expand All @@ -29,6 +30,7 @@ class Book {
required this.author,
required this.status,
this.subtitle,
this.description,
this.favourite = false,
this.deleted = false,
this.rating,
Expand All @@ -50,6 +52,7 @@ class Book {
title: json['title'],
subtitle: json['subtitle'],
author: json['author'],
description: json['description'],
status: json['status'],
rating: json['rating'],
favourite: (json['favourite'] == 1) ? true : false,
Expand Down Expand Up @@ -119,6 +122,7 @@ class Book {
'title': title,
'subtitle': subtitle,
'author': author,
'description': description,
'status': status,
'rating': rating,
'favourite': favourite ? 1 : 0,
Expand Down
16 changes: 16 additions & 0 deletions lib/ui/add_book_screen/add_book_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class _AddBookScreenState extends State<AddBookScreen> {
final _authorCtrl = TextEditingController();
final _pagesCtrl = TextEditingController();
final _pubYearCtrl = TextEditingController();
final _descriptionCtrl = TextEditingController();
final _isbnCtrl = TextEditingController();
final _olidCtrl = TextEditingController();
final _tagsCtrl = TextEditingController();
Expand Down Expand Up @@ -70,6 +71,7 @@ class _AddBookScreenState extends State<AddBookScreen> {
_authorCtrl.text = widget.book?.author ?? '';
_pubYearCtrl.text = (widget.book?.publicationYear ?? '').toString();
_pagesCtrl.text = (widget.book?.pages ?? '').toString();
_descriptionCtrl.text = widget.book?.description ?? '';
_isbnCtrl.text = widget.book?.isbn ?? '';
_olidCtrl.text = widget.book?.olid ?? '';
_myReviewCtrl.text = widget.book?.myReview ?? '';
Expand Down Expand Up @@ -156,6 +158,7 @@ class _AddBookScreenState extends State<AddBookScreen> {
pages: _pagesCtrl.text.isEmpty ? null : int.parse(_pagesCtrl.text),
publicationYear:
_pubYearCtrl.text.isEmpty ? null : int.parse(_pubYearCtrl.text),
description: _descriptionCtrl.text.isEmpty ? null : _descriptionCtrl.text,
isbn: _isbnCtrl.text.isEmpty ? null : _isbnCtrl.text,
olid: _olidCtrl.text.isEmpty ? null : _olidCtrl.text,
tags: (selectedTags == null || selectedTags!.isEmpty)
Expand Down Expand Up @@ -193,6 +196,7 @@ class _AddBookScreenState extends State<AddBookScreen> {
pages: _pagesCtrl.text.isEmpty ? null : int.parse(_pagesCtrl.text),
publicationYear:
_pubYearCtrl.text.isEmpty ? null : int.parse(_pubYearCtrl.text),
description: _descriptionCtrl.text.isEmpty ? null : _descriptionCtrl.text,
isbn: _isbnCtrl.text.isEmpty ? null : _isbnCtrl.text,
olid: _olidCtrl.text.isEmpty ? null : _olidCtrl.text,
tags: (selectedTags == null || selectedTags!.isEmpty)
Expand Down Expand Up @@ -441,6 +445,7 @@ class _AddBookScreenState extends State<AddBookScreen> {
_authorCtrl.dispose();
_pagesCtrl.dispose();
_pubYearCtrl.dispose();
_descriptionCtrl.dispose();
_isbnCtrl.dispose();
_olidCtrl.dispose();
_tagsCtrl.dispose();
Expand Down Expand Up @@ -575,6 +580,17 @@ class _AddBookScreenState extends State<AddBookScreen> {
],
),
const SizedBox(height: 20),
BookTextField(
controller: _descriptionCtrl,
hint: l10n.enter_description,
icon: FontAwesomeIcons.solidKeyboard,
keyboardType: TextInputType.multiline,
maxLength: 5000,
hideCounter: false,
maxLines: 15,
textCapitalization: TextCapitalization.sentences,
),
const SizedBox(height: 20),
BookTextField(
controller: _isbnCtrl,
hint: l10n.isbn,
Expand Down
14 changes: 14 additions & 0 deletions lib/ui/book_screen/book_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class BookScreen extends StatelessWidget {
title: book!.title,
subtitle: book!.subtitle,
author: book!.author,
description: book!.description,
status: book!.status,
favourite: book?.favourite == true ? false : true,
rating: book!.rating,
Expand Down Expand Up @@ -446,6 +447,19 @@ class BookScreen extends StatelessWidget {
text: (snapshot.data!.pages ?? "").toString(),
)
: const SizedBox(),
SizedBox(
height: (snapshot.data!.description != null &&
snapshot.data!.description!.isNotEmpty)
? 5
: 0,
),
(snapshot.data!.description != null &&
snapshot.data!.description!.isNotEmpty)
? BookDetail(
title: l10n.description,
text: snapshot.data!.description!,
)
: const SizedBox(),
SizedBox(
height: (snapshot.data!.isbn != null) ? 5 : 0,
),
Expand Down