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

feat: Increased tag limit to 100 char, code refactor #456

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
10 changes: 7 additions & 3 deletions lib/core/constants/constants.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const defaultFormHeight = 60.0;
class Constants {
static const formHeight = 60.0;

const blurHashX = 2;
const blurHashY = 2;
static const blurHashX = 2;
static const blurHashY = 2;

static const maxTagLength = 100;
}
4 changes: 2 additions & 2 deletions lib/core/helpers/backup/backup_import.dart
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ class BackupImport {

return blurhash_dart.BlurHash.encode(
img.decodeImage(cover)!,
numCompX: blurHashX,
numCompY: blurHashY,
numCompX: Constants.blurHashX,
numCompY: Constants.blurHashY,
).hash;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/core/helpers/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import 'package:openreads/model/book.dart';
Future generateBlurHash(Uint8List bytes, BuildContext context) async {
final blurHashStringTmp = await blurhash.BlurHash.encode(
bytes,
blurHashX,
blurHashY,
Constants.blurHashX,
Constants.blurHashY,
);

if (!context.mounted) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class MigrationV1ToV2Bloc

if (v1BooksDbPath == null) {
if (event.retrigger) {
// ignore: use_build_context_synchronously
_showSnackbar(event.context, 'Migration error 1');
}

Expand All @@ -49,9 +50,11 @@ class MigrationV1ToV2Bloc
await _migrateBooksFromV1ToV2(v1BooksDbPath);

if (v1YearsDbPath != null) {
// ignore: use_build_context_synchronously
await _migrateYearsFromV1ToV2(event.context, v1YearsDbPath);
} else {
if (event.retrigger) {
// ignore: use_build_context_synchronously
_showSnackbar(event.context, 'Migration error 3');
}
}
Expand Down Expand Up @@ -117,6 +120,7 @@ class MigrationV1ToV2Bloc
final totalBooksToMigrate = books.length;
var booksMigrated = 0;

// ignore: invalid_use_of_visible_for_testing_member
emit(MigrationOnging(total: totalBooksToMigrate, done: booksMigrated));

for (var book in books) {
Expand All @@ -127,6 +131,7 @@ class MigrationV1ToV2Bloc
);
booksMigrated += 1;

// ignore: invalid_use_of_visible_for_testing_member
emit(MigrationOnging(total: totalBooksToMigrate, done: booksMigrated));
}

Expand All @@ -150,8 +155,8 @@ class MigrationV1ToV2Bloc

return blurhash_dart.BlurHash.encode(
img.decodeImage(cover)!,
numCompX: blurHashX,
numCompY: blurHashY,
numCompX: Constants.blurHashX,
numCompY: Constants.blurHashY,
).hash;
}

Expand Down Expand Up @@ -202,6 +207,7 @@ class MigrationV1ToV2Bloc
}
}

// ignore: use_build_context_synchronously
BlocProvider.of<ChallengeBloc>(context).add(
RestoreChallengesEvent(
challenges: newChallenges,
Expand Down
4 changes: 2 additions & 2 deletions lib/logic/cubit/book_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ class BookCubit extends Cubit {

return blurhash_dart.BlurHash.encode(
img.decodeImage(cover)!,
numCompX: blurHashX,
numCompY: blurHashY,
numCompX: Constants.blurHashX,
numCompY: Constants.blurHashY,
).hash;
}
}
1 change: 0 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import 'package:openreads/logic/cubit/edit_book_cubit.dart';
import 'package:openreads/resources/connectivity_service.dart';
import 'package:openreads/resources/open_library_service.dart';
import 'package:openreads/ui/books_screen/books_screen.dart';
import 'package:openreads/ui/common/keyboard_dismissable.dart';
import 'package:openreads/ui/welcome_screen/welcome_screen.dart';
import 'package:path_provider/path_provider.dart';

Expand Down
4 changes: 2 additions & 2 deletions lib/ui/add_book_screen/add_book_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ class _AddBookScreenState extends State<AddBookScreen> {
),
BookStatusRow(
animDuration: _animDuration,
defaultHeight: defaultFormHeight,
defaultHeight: Constants.formHeight,
),
const SizedBox(height: 10),
BookRatingBar(animDuration: _animDuration),
Expand Down Expand Up @@ -502,7 +502,7 @@ class _AddBookScreenState extends State<AddBookScreen> {
hint: LocaleKeys.enter_tags.tr(),
icon: FontAwesomeIcons.tags,
keyboardType: TextInputType.text,
maxLength: 20,
maxLength: Constants.maxTagLength,
onSubmitted: (_) => _addNewTag(),
onEditingComplete: () {},
unselectTag: (tag) => _unselectTag(tag),
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/add_book_screen/widgets/book_rating_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BookRatingBar extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 10),
child: AnimatedContainer(
duration: animDuration,
height: (state.status == 0) ? defaultFormHeight : 0,
height: (state.status == 0) ? Constants.formHeight : 0,
child: Container(
width: double.infinity,
clipBehavior: Clip.hardEdge,
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/add_book_screen/widgets/cover_view_edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class _CoverViewEditState extends State<CoverViewEdit> {
);
} else {
return CoverPlaceholder(
defaultHeight: defaultFormHeight,
defaultHeight: Constants.formHeight,
onPressed: () => showCoverLoadBottomSheet(context),
);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/ui/add_book_screen/widgets/reading_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class _ReadingRowState extends State<ReadingRow> {
children: [
Expanded(
child: SetDateButton(
defaultHeight: defaultFormHeight,
defaultHeight: Constants.formHeight,
icon: FontAwesomeIcons.play,
text: widget.reading.startDate != null
? dateFormat.format(widget.reading.startDate!)
Expand All @@ -131,7 +131,7 @@ class _ReadingRowState extends State<ReadingRow> {
const SizedBox(width: 10),
Expanded(
child: SetDateButton(
defaultHeight: defaultFormHeight,
defaultHeight: Constants.formHeight,
icon: FontAwesomeIcons.flagCheckered,
text: widget.reading.finishDate != null
? dateFormat.format(widget.reading.finishDate!)
Expand All @@ -152,7 +152,7 @@ class _ReadingRowState extends State<ReadingRow> {
children: [
Expanded(
child: BookReadingTimeField(
defaultHeight: defaultFormHeight,
defaultHeight: Constants.formHeight,
changeReadingTime: _changeReadingTime,
resetTime: _resetTime,
readingTime: widget.reading.customReadingTime,
Expand Down
11 changes: 9 additions & 2 deletions lib/ui/add_book_screen/widgets/tags_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ class TagsField extends StatelessWidget {
final Function(String)? unselectTag;
final List<String>? allTags;

Widget _buildTagChip(BuildContext context,
{required String tag, required bool selected}) {
Widget _buildTagChip(
BuildContext context, {
required String tag,
required bool selected,
}) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 5),
child: FilterChip(
Expand All @@ -54,7 +57,11 @@ class TagsField extends StatelessWidget {
style: TextStyle(
color: selected ? Theme.of(context).colorScheme.onSecondary : null,
),
overflow: TextOverflow.fade,
softWrap: true,
maxLines: 5,
),
clipBehavior: Clip.none,
checkmarkColor:
selected ? Theme.of(context).colorScheme.onSecondary : null,
selected: selected,
Expand Down
4 changes: 4 additions & 0 deletions lib/ui/book_screen/widgets/book_title_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ class BookTitleDetail extends StatelessWidget {
),
label: Text(
tag,
overflow: TextOverflow.fade,
softWrap: true,
maxLines: 5,
style: TextStyle(
color: Theme.of(context).colorScheme.onSecondary,
),
),
clipBehavior: Clip.none,
onSelected: (_) {
Navigator.push(
context,
Expand Down
Loading