Skip to content

Commit

Permalink
feat: adjust duration of open book
Browse files Browse the repository at this point in the history
  • Loading branch information
Anxcye committed Aug 10, 2024
1 parent 5bf5fac commit 46073bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
15 changes: 10 additions & 5 deletions lib/page/book_player/epub_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class EpubPlayerState extends State<EpubPlayer> with TickerProviderStateMixin {
onHideContextMenu: () {},
);
_animationController = AnimationController(
duration: const Duration(milliseconds: 600),
duration: const Duration(milliseconds: 400),
vsync: this,
);
_animation =
Expand All @@ -275,15 +275,20 @@ class EpubPlayerState extends State<EpubPlayer> with TickerProviderStateMixin {
super.didChangeDependencies();
}

Future<void> saveReadingProgress() async {
if (cfi == '') return;
Book book = widget.book;
book.lastReadPosition = cfi;
book.readingPercentage = percentage;
await updateBook(book);
}

@override
void dispose() {
super.dispose();
_animationController.dispose();
InAppWebViewController.clearAllCache();
Book book = widget.book;
book.lastReadPosition = cfi;
book.readingPercentage = percentage;
updateBook(book);
saveReadingProgress();
removeOverlay();
}

Expand Down
8 changes: 4 additions & 4 deletions lib/service/book.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,20 @@ Future<Book> importBook(File file) async {
void openBook(BuildContext context, Book book, Function updateBookList) {
book.updateTime = DateTime.now();
updateBook(book);
Future.delayed(const Duration(seconds: 1), () {
Future.delayed(const Duration(milliseconds: 500), () {
updateBookList();
});

Navigator.push(
context,
PageRouteBuilder(
transitionDuration: const Duration(milliseconds: 1000),
reverseTransitionDuration: const Duration(milliseconds: 1000),
transitionDuration: const Duration(milliseconds: 500),
reverseTransitionDuration: const Duration(milliseconds: 500),
pageBuilder: (context, animation, secondaryAnimation) =>
ReadingPage(key: readingPageKey, book: book),
)).then((value) {
// wait 1s to update book which is read
Future.delayed(const Duration(seconds: 1), () {
Future.delayed(const Duration(milliseconds: 500), () {
updateBookList();
});
});
Expand Down

0 comments on commit 46073bf

Please sign in to comment.