Skip to content

Commit

Permalink
Update page details
Browse files Browse the repository at this point in the history
  • Loading branch information
lockieRichter committed Feb 11, 2024
1 parent 9cca57a commit ad3ca51
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 114 deletions.
9 changes: 9 additions & 0 deletions assets/translations/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@
"my_thoughts": "",
"subtitle": "Write down your thoughts, feelings or some general remarks about {title}"
},
"book_progress": {
"current_page": "TODO",
"enter_pages": "TODO",
"error": "TODO",
"error_current_page": "TODO",
"ok": "TODO",
"page_count": "TODO",
"save": "TODO"
},
"cancel": "Zurück",
"change": "Ändern",
"change_password": "Passwort ändern",
Expand Down
9 changes: 9 additions & 0 deletions assets/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@
"my_thoughts": "My thoughts belong here...",
"subtitle": "Write down your thoughts, feelings or some general remarks about {title}"
},
"book_progress": {
"current_page": "Current page",
"enter_pages": "Enter pages",
"error": "Error",
"error_current_page": "Current page cannot be greater than page count",
"ok": "Ok",
"page_count": "Pages",
"save": "Save"
},
"cancel": "Cancel",
"change": "Change",
"change_password": "Change password",
Expand Down
24 changes: 12 additions & 12 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ PODS:
- Firebase/Storage (10.20.0):
- Firebase/CoreOnly
- FirebaseStorage (~> 10.20.0)
- firebase_analytics (10.8.4):
- firebase_analytics (10.8.5):
- Firebase/Analytics (= 10.20.0)
- firebase_core
- Flutter
- firebase_auth (4.17.3):
- firebase_auth (4.17.4):
- Firebase/Auth (= 10.20.0)
- firebase_core
- Flutter
- firebase_core (2.25.3):
- firebase_core (2.25.4):
- Firebase/CoreOnly (= 10.20.0)
- Flutter
- firebase_crashlytics (3.4.13):
- firebase_crashlytics (3.4.14):
- Firebase/Crashlytics (= 10.20.0)
- firebase_core
- Flutter
- firebase_database (10.4.4):
- firebase_database (10.4.5):
- Firebase/Database (= 10.20.0)
- firebase_core
- Flutter
- firebase_storage (11.6.4):
- firebase_storage (11.6.5):
- Firebase/Storage (= 10.20.0)
- firebase_core
- Flutter
Expand Down Expand Up @@ -275,12 +275,12 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
AppAuth: 3bb1d1cd9340bd09f5ed189fb00b1cc28e1e8570
Firebase: 10c8cb12fb7ad2ae0c09ffc86cd9c1ab392a0031
firebase_analytics: 6c4873e8164677423b57f44172fb20c202310d7a
firebase_auth: 37eb4a237d7407336d9dc3b739e81153c5077d70
firebase_core: 96a734ae596de989b81a66f8a205f54485263555
firebase_crashlytics: daf6839ff459f660d9856cd73f4b6aa6f3435725
firebase_database: 6f3eac77f7ebbdb8563dbe9032d441434e8c2e0e
firebase_storage: cab6237615be4a29f042640cc6364d54e1b6ffc4
firebase_analytics: 2e82fd84ce13f8321aa7b99336d6ee0e6cc7b984
firebase_auth: 29a10d4129d53aa690c10dbd838ed1a059ef0c9b
firebase_core: a46c312d8bae4defa3d009b2aa7b5b413aeb394e
firebase_crashlytics: 3d12285fcbd865d576b9965bd4090cd8b68e11fd
firebase_database: e6b72eeda8dadd6e3965d86b86c997d35e43d4e2
firebase_storage: 5007be227e54a46f260b6040a23b4fdc8ca1c5c5
FirebaseAnalytics: a2731bf3670747ce8f65368b118d18aa8e368246
FirebaseAppCheckInterop: e81bdb1cdb82f8e0cef353ba5018a8402682032c
FirebaseAuth: 9c5c400d2c3055d8ae3a0284944c86fa95d48dac
Expand Down
6 changes: 5 additions & 1 deletion lib/src/data/book/book_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ abstract class BookRepository {

Future<void> delete(String id);

Future<void> updateCurrentPage(String bookId, int currentPage);
Future<void> updatePageInfo({
required String bookId,
required int currentPage,
required int pageCount,
});

Stream<List<Book>> search(SearchCriteria criteria);

Expand Down
10 changes: 8 additions & 2 deletions lib/src/data/book/firebase_book_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ class FirebaseBookRepository implements BookRepository {
}

@override
Future<void> updateCurrentPage(String bookId, int currentPage) async {
Future<void> updatePageInfo({
required String bookId,
required int currentPage,
required int pageCount,
}) async {
final bookSnapshot = await _booksRef().child(bookId).get();
final bookMap = bookSnapshot.child(bookId).toMap();

Expand All @@ -120,7 +124,9 @@ class FirebaseBookRepository implements BookRepository {
}
final currentBook = Book.fromJson(bookMap);

return update(currentBook.copyWith(currentPage: currentPage));
return update(
currentBook.copyWith(currentPage: currentPage, pageCount: pageCount),
);
}

DatabaseReference _booksRef() {
Expand Down
51 changes: 2 additions & 49 deletions lib/src/ui/book/book_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import 'package:dantex/src/providers/app_router.dart';
import 'package:dantex/src/providers/book.dart';
import 'package:dantex/src/providers/repository.dart';
import 'package:dantex/src/ui/book/add_label_bottom_sheet.dart';
import 'package:dantex/src/ui/book/book_progress_indicator.dart';
import 'package:dantex/src/ui/core/generic_error_widget.dart';
import 'package:dantex/src/util/extensions.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:percent_indicator/circular_percent_indicator.dart';

class BookDetailPage extends ConsumerWidget {
final String id;
Expand Down Expand Up @@ -47,7 +47,7 @@ class BookDetailPage extends ConsumerWidget {
children: [
_BookInfo(book: book),
const SizedBox(height: 20),
_BookProgress(book: book),
BookProgress(book: book),
const SizedBox(height: 20),
_BookActions(book: book),
const SizedBox(height: 20),
Expand Down Expand Up @@ -139,53 +139,6 @@ class _BookInfo extends StatelessWidget {
}
}

class _BookProgress extends StatelessWidget {
final Book book;

const _BookProgress({required this.book});

@override
Widget build(BuildContext context) {
return Visibility(
visible: book.pageCount > 0,
child: SizedBox(
height: 140,
child: CircularPercentIndicator(
key: const ValueKey('book-detail-progress-indicator'),
radius: 70.0,
lineWidth: 2.0,
circularStrokeCap: CircularStrokeCap.round,
animation: true,
widgetIndicator: Icon(
Icons.circle,
size: 12,
color: Theme.of(context).colorScheme.secondaryContainer,
),
percent: book.currentPage / book.pageCount,
center: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.menu_book_outlined,
color: Theme.of(context).colorScheme.secondaryContainer,
),
const SizedBox(height: 8),
Text(
'${book.currentPage} / ${book.pageCount}',
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
),
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
progressColor: Theme.of(context).colorScheme.onSecondaryContainer,
),
),
);
}
}

class _BookActions extends StatelessWidget {
final Book book;

Expand Down
145 changes: 145 additions & 0 deletions lib/src/ui/book/book_progress_indicator.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import 'package:dantex/src/data/book/entity/book.dart';
import 'package:dantex/src/providers/repository.dart';
import 'package:dantex/src/ui/core/dante_components.dart';
import 'package:dantex/src/ui/core/platform_components.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:percent_indicator/circular_percent_indicator.dart';

class BookProgress extends ConsumerStatefulWidget {
final Book book;

const BookProgress({required this.book, super.key});

@override
createState() => _BookProgressState();
}

class _BookProgressState extends ConsumerState<BookProgress> {
final _currentPageController = TextEditingController();
final _pageCountController = TextEditingController();

@override
void initState() {
super.initState();
_currentPageController.text = widget.book.currentPage.toString();
_pageCountController.text = widget.book.pageCount.toString();
}

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () async => _showEditPageDialog(context),
child: SizedBox(
height: 140,
child: CircularPercentIndicator(
key: const ValueKey('book-detail-progress-indicator'),
radius: 70.0,
lineWidth: 2.0,
circularStrokeCap: CircularStrokeCap.round,
animation: true,
widgetIndicator: Icon(
Icons.circle,
size: 12,
color: Theme.of(context).colorScheme.secondaryContainer,
),
percent: widget.book.pageCount > 0
? widget.book.currentPage / widget.book.pageCount
: 0.0,
center: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.menu_book_outlined,
color: Theme.of(context).colorScheme.secondaryContainer,
),
const SizedBox(height: 8),
Text(
'${widget.book.currentPage} / ${widget.book.pageCount}',
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
),
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
progressColor: Theme.of(context).colorScheme.onSecondaryContainer,
),
),
);
}

Future<void> _showEditPageDialog(BuildContext context) async {
return showDanteDialog(
context,
title: 'book_progress.enter_pages'.tr(),
trailing: IconButton(
icon: const Icon(Icons.close),
onPressed: () {
Navigator.of(context).pop();
},
),
content: Material(
child: Column(
children: [
DanteTextField(
controller: _currentPageController,
label: Text('book_progress.current_page'.tr()),
),
const Text(
'/',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
DanteTextField(
controller: _pageCountController,
label: Text('book_progress.page_count'.tr()),
),
],
),
),
barrierDismissible: true,
actions: [
DanteDialogAction(
name: 'book_progress.save'.tr(),
action: (BuildContext context) async {
final newCurrentPage =
int.tryParse(_currentPageController.text) ?? 0;
final newPageCount = int.tryParse(_pageCountController.text) ?? 0;

if (newCurrentPage > newPageCount) {
await showPlatformDialog(
context: context,
builder: (_) => PlatformAlertDialog(
title: Text('book_progress.error'.tr()),
content: Text(
'book_progress.error_current_page'.tr(),
),
actions: [
PlatformDialogAction(
child: Text('ok'.tr()),
onPressed: () => Navigator.of(context).pop(),
),
],
),
);
return;
}
if (context.mounted) {
Navigator.of(context).pop();
}
await ref.read(bookRepositoryProvider).updatePageInfo(
bookId: widget.book.id,
currentPage: newCurrentPage,
pageCount: newPageCount,
);
},
),
],
);
}
}
3 changes: 3 additions & 0 deletions lib/src/ui/core/dante_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class DanteTextField extends StatelessWidget {
final String? initialValue;
final String? hint;
final Widget? suffixIcon;
final Widget? label;
final bool? enabled;
final void Function(String)? onChanged;
final int maxLines;
Expand All @@ -43,6 +44,7 @@ class DanteTextField extends StatelessWidget {
this.onChanged,
this.errorText,
this.formatter,
this.label,
});

@override
Expand All @@ -62,6 +64,7 @@ class DanteTextField extends StatelessWidget {
onChanged: onChanged,
inputFormatters: [if (formatter != null) formatter!],
decoration: InputDecoration(
label: label,
errorText: errorText,
hintText: hint,
suffixIcon: suffixIcon,
Expand Down
Loading

0 comments on commit ad3ca51

Please sign in to comment.