Skip to content
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
3 changes: 3 additions & 0 deletions assets/icons/change_cover.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"today": "today",
"shortMin": "{count}m",
"library": "Library",
"partOf": "Part {currentPart} of {partCount}"
"partOf": "Part {currentPart} of {partCount}",
"addCustomCover": "Add custom cover"
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ abstract class BookRepositoryBase with Store {
return book;
}

Future<void> updateBookCover(Book book) async {
try {
final files = [
http.MultipartFile.fromBytes(
'cover',
book.cover!,
filename: 'cover',
)
];
await pb.client.collection(_book).update(book.id, files: files);
} catch (e, stacktrace) {
log("${e.toString()}\n${stacktrace.toString()}");
}
}

void putBook(Book book) async {
try {
final body = book.toJson()..["user"] = pb.user?.id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// 🐦 Flutter imports:
import 'dart:typed_data';

import 'package:flutter/material.dart';

// 📦 Package imports:
Expand All @@ -16,6 +18,7 @@ import 'package:edokuri/src/pages/home_page/screens/library_screen/widgets/book_
import 'package:edokuri/src/pages/home_page/screens/library_screen/widgets/book_card/book_card_dialog.dart';
import 'package:edokuri/src/pages/reader/reader_page.dart';
import 'package:edokuri/src/pages/set_page/set_page.dart';
import 'package:image_picker/image_picker.dart';

class BookCard extends StatelessWidget {
final Book book;
Expand Down Expand Up @@ -50,6 +53,16 @@ class BookCard extends StatelessWidget {
);
}

void _addCustomCover(BuildContext context) async {
Navigator.pop(context);
final imagePicker = ImagePicker();
final file = await imagePicker.pickImage(source: ImageSource.gallery);
final Uint8List bytes = await file!.readAsBytes();
book.cover = bytes;
await getIt<BookRepository>().updateBookCover(book);
getIt<ToastController>().showDefaultTost("Cover is changed");
}

void _longPressHandler(BuildContext context) {
showModalBottomSheet<void>(
barrierColor: Colors.black26,
Expand All @@ -59,6 +72,7 @@ class BookCard extends StatelessWidget {
openBook: () => _openBook(context),
removeBook: () => _removeBook(context),
openBookSet: () => _openBookSet(context),
addCustomCover: () => _addCustomCover(context),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ class BookCardDialog extends StatelessWidget {
final VoidCallback? openBook;
final VoidCallback? openBookSet;
final VoidCallback? removeBook;
final VoidCallback? addCustomCover;

const BookCardDialog(
{super.key, this.openBook, this.removeBook, this.openBookSet});
{super.key,
this.openBook,
this.removeBook,
this.openBookSet,
this.addCustomCover});

@override
Widget build(BuildContext context) {
Expand All @@ -28,6 +33,10 @@ class BookCardDialog extends StatelessWidget {
svg: goToSetSvg,
onTap: openBookSet,
),
ButtonWithIcon(
text: LocaleKeys.addCustomCover.tr(),
svg: changeCoverSvg,
onTap: addCustomCover),
ButtonWithIcon(
text: LocaleKeys.delete.tr(),
svg: deleteSvg,
Expand Down
1 change: 1 addition & 0 deletions lib/src/theme/svgs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const googleLogoSvg = "assets/icons/google_logo.svg";
const addRecordSvg = "assets/icons/add_record.svg";
const translateSvg = "assets/icons/translate.svg";
const backArrowSvg = "assets/icons/back_arrow.svg";
const changeCoverSvg = "assets/icons/change_cover.svg";

const translatedByGoogleSvg = "assets/images/translated_by_google.svg";
const waveSvg = "assets/images/wave.svg";
90 changes: 69 additions & 21 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
url: "https://pub.dev"
source: hosted
version: "1.17.0"
version: "1.17.1"
connectivity_plus:
dependency: "direct main"
description:
Expand Down Expand Up @@ -265,6 +265,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.6.3"
cross_file:
dependency: transitive
description:
name: cross_file
sha256: "0b0036e8cccbfbe0555fd83c1d31a6f30b77a96b598b35a5d36dd41f718695e9"
url: "https://pub.dev"
source: hosted
version: "0.3.3+4"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -365,10 +373,10 @@ packages:
dependency: "direct main"
description:
name: easy_localization
sha256: "6a2e99fa0bfe5765bf4c6ca9b137d5de2c75593007178c5e4cd2ae985f870080"
sha256: f30e9b20ed4d1b890171c30241d9b9c43efe21fee55dee7bd68f94daf269ea75
url: "https://pub.dev"
source: hosted
version: "3.0.1"
version: "3.0.2-dev.2"
easy_logger:
dependency: transitive
description:
Expand Down Expand Up @@ -710,6 +718,46 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.3.0"
image_picker:
dependency: "direct main"
description:
name: image_picker
sha256: "64b21d9f0e065f9ab0e4dde458076226c97382cc0c6949144cb874c62bf8e9f8"
url: "https://pub.dev"
source: hosted
version: "0.8.7"
image_picker_android:
dependency: transitive
description:
name: image_picker_android
sha256: b81db5f5ed8a69d54d5f0932c2af8120e8c0518a037d8beee494eec671da4d4c
url: "https://pub.dev"
source: hosted
version: "0.8.6+5"
image_picker_for_web:
dependency: transitive
description:
name: image_picker_for_web
sha256: "98f50d6b9f294c8ba35e25cc0d13b04bfddd25dbc8d32fa9d566a6572f2c081c"
url: "https://pub.dev"
source: hosted
version: "2.1.12"
image_picker_ios:
dependency: transitive
description:
name: image_picker_ios
sha256: "50e882fe0a06bf0c8f7f5bce78d30975f279213293afc9471dc35f05617c50ff"
url: "https://pub.dev"
source: hosted
version: "0.8.7+1"
image_picker_platform_interface:
dependency: transitive
description:
name: image_picker_platform_interface
sha256: "1991219d9dbc42a99aff77e663af8ca51ced592cd6685c9485e3458302d3d4f8"
url: "https://pub.dev"
source: hosted
version: "2.6.3"
import_sorter:
dependency: "direct dev"
description:
Expand All @@ -730,10 +778,10 @@ packages:
dependency: transitive
description:
name: intl
sha256: "910f85bce16fb5c6f614e117efa303e85a1731bb0081edf3604a2ae6e9a3cc91"
sha256: a3715e3bc90294e971cb7dc063fbf3cd9ee0ebf8604ffeafabd9e6f16abbdbe6
url: "https://pub.dev"
source: hosted
version: "0.17.0"
version: "0.18.0"
io:
dependency: transitive
description:
Expand All @@ -746,10 +794,10 @@ packages:
dependency: transitive
description:
name: js
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.5"
version: "0.6.7"
json_annotation:
dependency: "direct main"
description:
Expand Down Expand Up @@ -818,10 +866,10 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
sha256: c94db23593b89766cda57aab9ac311e3616cf87c6fa4e9749df032f66f30dcb8
url: "https://pub.dev"
source: hosted
version: "0.12.13"
version: "0.12.14"
material_color_utilities:
dependency: transitive
description:
Expand All @@ -834,10 +882,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
sha256: "12307e7f0605ce3da64cf0db90e5fcab0869f3ca03f76be6bb2991ce0a55e82b"
url: "https://pub.dev"
source: hosted
version: "1.8.0"
version: "1.9.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -922,10 +970,10 @@ packages:
dependency: "direct main"
description:
name: path
sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
url: "https://pub.dev"
source: hosted
version: "1.8.2"
version: "1.8.3"
path_drawing:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1360,26 +1408,26 @@ packages:
dependency: transitive
description:
name: test
sha256: a5fcd2d25eeadbb6589e80198a47d6a464ba3e2049da473943b8af9797900c2d
sha256: "5301f54eb6fe945daa99bc8df6ece3f88b5ceaa6f996f250efdaaf63e22886be"
url: "https://pub.dev"
source: hosted
version: "1.22.0"
version: "1.23.1"
test_api:
dependency: transitive
description:
name: test_api
sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
sha256: "6182294da5abf431177fccc1ee02401f6df30f766bc6130a0852c6b6d7ee6b2d"
url: "https://pub.dev"
source: hosted
version: "0.4.16"
version: "0.4.18"
test_core:
dependency: transitive
description:
name: test_core
sha256: "0ef9755ec6d746951ba0aabe62f874b707690b5ede0fecc818b138fcc9b14888"
sha256: d2e9240594b409565524802b84b7b39341da36dd6fd8e1660b53ad928ec3e9af
url: "https://pub.dev"
source: hosted
version: "0.4.20"
version: "0.4.24"
text_to_speech:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1637,5 +1685,5 @@ packages:
source: hosted
version: "1.0.3"
sdks:
dart: ">=2.19.0 <3.0.0"
dart: ">=2.19.0 <4.0.0"
flutter: ">=3.7.0-0"
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ dependencies:
html: ^0.15.2
http: ^0.13.5
image: ^3.0.2
image_picker: ^0.8.7
json_annotation: ^4.8.0
mobx: ^2.1.4
mobx_codegen: ^2.1.1
Expand Down