Skip to content

Commit

Permalink
Added magnification to reader and Fixed category bug (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
DattatreyaReddy authored Mar 7, 2023
1 parent 84f0fe8 commit 86eeeac
Show file tree
Hide file tree
Showing 19 changed files with 445 additions and 131 deletions.
20 changes: 17 additions & 3 deletions lib/src/constants/app_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,21 @@

import 'package:flutter/material.dart';

Duration kDuration = const Duration(milliseconds: 500);
Duration kLongDuration = const Duration(seconds: 2);
const Duration kDuration = Duration(milliseconds: 500);
const Duration kLongDuration = Duration(seconds: 2);

Curve kCurve = Curves.easeIn;
const Curve kCurve = Curves.easeIn;
const Size kMagnifierSize = Size(77.37, 37.9);
const MagnifierDecoration kMagnifierDecoration = MagnifierDecoration(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(40))),
shadows: <BoxShadow>[
BoxShadow(
blurRadius: 1.5,
offset: Offset(0, 2),
spreadRadius: 0.75,
color: Color.fromARGB(25, 0, 0, 0))
],
);

const kDebounceDuration = Duration(milliseconds: 500);
28 changes: 28 additions & 0 deletions lib/src/constants/app_sizes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

import 'dart:math';

import 'package:flutter/material.dart';

import '../utils/extensions/custom_extensions.dart';
import 'app_constants.dart';
import 'db_keys.dart';

const kTabSize = Size.fromHeight(kAppBarBottomHeight);
Expand All @@ -19,6 +22,31 @@ Size kCalculateAppBarBottomSize(List<bool> checks) {
return Size.fromHeight(kAppBarBottomHeight * multiplier);
}

Offset kMagnifierPosition(Offset position, Size size, double multiplier) =>
Offset(
max(
min(
position.dx - (kMagnifierSize.width * multiplier * .5),
size.width - (kMagnifierSize.width * multiplier * .5),
),
-(kMagnifierSize.width * multiplier * .5),
),
max(
min(
position.dy - (kMagnifierSize.height * multiplier),
size.height - (kMagnifierSize.height * multiplier * 1.25),
),
-(kMagnifierSize.height * multiplier * .5),
),
);

Offset kMagnifierOffset(Offset position, Size size, double multiplier) {
return Offset(
0,
max(0, min(position.dy, (kMagnifierSize.height * multiplier))) * .5,
);
}

/// Constant sizes to be used in the app (paddings, gaps, rounded corners etc.)
enum KEdgeInsets {
a8(EdgeInsets.all(8)),
Expand Down
1 change: 1 addition & 0 deletions lib/src/constants/db_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum DBKeys {
basicCredentials(null),
readerMode(ReaderMode.webtoon),
readerPadding(0.0),
readerMagnifierSize(1.0),
readerNavigationLayout(ReaderNavigationLayout.disabled),
invertTap(false),
showNSFW(true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class EditCategoryScreen extends HookConsumerWidget {
body: categoryList.showUiWhenData(
context,
(data) {
if (data.isBlank || data.isSingletonList) {
if (data.isBlank ||
(data.isSingletonList && data?.firstOrNull?.id == 0)) {
return Emoticons(
text: context.l10n!.noCategoriesFound,
button: TextButton(
Expand All @@ -49,18 +50,20 @@ class EditCategoryScreen extends HookConsumerWidget {
),
);
} else {
final isDefaultInCategoryList = data!.first.id == 0;
return RefreshIndicator(
child: ListView.builder(
itemCount: data!.length,
itemCount: data.length,
itemBuilder: (context, index) {
final category = data[index];
if (category.id == 0) {
return const SizedBox.shrink();
} else {
return CategoryTile(
key: ValueKey(category.id),
minOrderIndex: 1,
maxOrderIndex: data.length - 1,
maxOrderIndex: isDefaultInCategoryList
? data.length - 1
: data.length,
category: category,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ class CategoryTile extends HookConsumerWidget {
const CategoryTile({
super.key,
required this.category,
required this.minOrderIndex,
required this.maxOrderIndex,
});

final Category category;
final int minOrderIndex;
final int maxOrderIndex;
@override
Widget build(BuildContext context, WidgetRef ref) {
Expand All @@ -44,7 +42,7 @@ class CategoryTile extends HookConsumerWidget {
children: [
IconButton(
visualDensity: VisualDensity.compact,
onPressed: order <= minOrderIndex
onPressed: order <= 1
? null
: () => ref
.read(categoryControllerProvider.notifier)
Expand Down
6 changes: 6 additions & 0 deletions lib/src/features/manga_book/domain/manga/manga_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class MangaMeta with _$MangaMeta {
fromJson: MangaMeta.fromJsonToDouble,
)
double? readerPadding,
@JsonKey(
name: "flutter_readerMagnifierSize",
fromJson: MangaMeta.fromJsonToDouble,
)
double? readerMagnifierSize,
}) = _MangaMeta;

static bool? fromJsonToBool(dynamic val) => val != null && val is String
Expand All @@ -80,6 +85,7 @@ enum MangaMetaKeys {
readerNavigationLayout("flutter_readerNavigationLayout"),
readerMode("flutter_readerMode"),
readerPadding("flutter_readerPadding"),
readerMagnifierSize("flutter_readerMagnifierSize"),
;

const MangaMetaKeys(this.key);
Expand Down
45 changes: 38 additions & 7 deletions lib/src/features/manga_book/domain/manga/manga_model.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,9 @@ mixin _$MangaMeta {
ReaderMode? get readerMode => throw _privateConstructorUsedError;
@JsonKey(name: "flutter_readerPadding", fromJson: MangaMeta.fromJsonToDouble)
double? get readerPadding => throw _privateConstructorUsedError;
@JsonKey(
name: "flutter_readerMagnifierSize", fromJson: MangaMeta.fromJsonToDouble)
double? get readerMagnifierSize => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
Expand All @@ -747,7 +750,9 @@ abstract class $MangaMetaCopyWith<$Res> {
@JsonKey(name: "flutter_readerMode")
ReaderMode? readerMode,
@JsonKey(name: "flutter_readerPadding", fromJson: MangaMeta.fromJsonToDouble)
double? readerPadding});
double? readerPadding,
@JsonKey(name: "flutter_readerMagnifierSize", fromJson: MangaMeta.fromJsonToDouble)
double? readerMagnifierSize});
}

/// @nodoc
Expand All @@ -767,6 +772,7 @@ class _$MangaMetaCopyWithImpl<$Res, $Val extends MangaMeta>
Object? readerNavigationLayout = freezed,
Object? readerMode = freezed,
Object? readerPadding = freezed,
Object? readerMagnifierSize = freezed,
}) {
return _then(_value.copyWith(
invertTap: freezed == invertTap
Expand All @@ -785,6 +791,10 @@ class _$MangaMetaCopyWithImpl<$Res, $Val extends MangaMeta>
? _value.readerPadding
: readerPadding // ignore: cast_nullable_to_non_nullable
as double?,
readerMagnifierSize: freezed == readerMagnifierSize
? _value.readerMagnifierSize
: readerMagnifierSize // ignore: cast_nullable_to_non_nullable
as double?,
) as $Val);
}
}
Expand All @@ -804,7 +814,9 @@ abstract class _$$_MangaMetaCopyWith<$Res> implements $MangaMetaCopyWith<$Res> {
@JsonKey(name: "flutter_readerMode")
ReaderMode? readerMode,
@JsonKey(name: "flutter_readerPadding", fromJson: MangaMeta.fromJsonToDouble)
double? readerPadding});
double? readerPadding,
@JsonKey(name: "flutter_readerMagnifierSize", fromJson: MangaMeta.fromJsonToDouble)
double? readerMagnifierSize});
}

/// @nodoc
Expand All @@ -822,6 +834,7 @@ class __$$_MangaMetaCopyWithImpl<$Res>
Object? readerNavigationLayout = freezed,
Object? readerMode = freezed,
Object? readerPadding = freezed,
Object? readerMagnifierSize = freezed,
}) {
return _then(_$_MangaMeta(
invertTap: freezed == invertTap
Expand All @@ -840,6 +853,10 @@ class __$$_MangaMetaCopyWithImpl<$Res>
? _value.readerPadding
: readerPadding // ignore: cast_nullable_to_non_nullable
as double?,
readerMagnifierSize: freezed == readerMagnifierSize
? _value.readerMagnifierSize
: readerMagnifierSize // ignore: cast_nullable_to_non_nullable
as double?,
));
}
}
Expand All @@ -855,7 +872,9 @@ class _$_MangaMeta implements _MangaMeta {
@JsonKey(name: "flutter_readerMode")
this.readerMode,
@JsonKey(name: "flutter_readerPadding", fromJson: MangaMeta.fromJsonToDouble)
this.readerPadding});
this.readerPadding,
@JsonKey(name: "flutter_readerMagnifierSize", fromJson: MangaMeta.fromJsonToDouble)
this.readerMagnifierSize});

factory _$_MangaMeta.fromJson(Map<String, dynamic> json) =>
_$$_MangaMetaFromJson(json);
Expand All @@ -874,10 +893,14 @@ class _$_MangaMeta implements _MangaMeta {
@override
@JsonKey(name: "flutter_readerPadding", fromJson: MangaMeta.fromJsonToDouble)
final double? readerPadding;
@override
@JsonKey(
name: "flutter_readerMagnifierSize", fromJson: MangaMeta.fromJsonToDouble)
final double? readerMagnifierSize;

@override
String toString() {
return 'MangaMeta(invertTap: $invertTap, readerNavigationLayout: $readerNavigationLayout, readerMode: $readerMode, readerPadding: $readerPadding)';
return 'MangaMeta(invertTap: $invertTap, readerNavigationLayout: $readerNavigationLayout, readerMode: $readerMode, readerPadding: $readerPadding, readerMagnifierSize: $readerMagnifierSize)';
}

@override
Expand All @@ -892,13 +915,15 @@ class _$_MangaMeta implements _MangaMeta {
(identical(other.readerMode, readerMode) ||
other.readerMode == readerMode) &&
(identical(other.readerPadding, readerPadding) ||
other.readerPadding == readerPadding));
other.readerPadding == readerPadding) &&
(identical(other.readerMagnifierSize, readerMagnifierSize) ||
other.readerMagnifierSize == readerMagnifierSize));
}

@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, invertTap,
readerNavigationLayout, readerMode, readerPadding);
readerNavigationLayout, readerMode, readerPadding, readerMagnifierSize);

@JsonKey(ignore: true)
@override
Expand All @@ -923,7 +948,9 @@ abstract class _MangaMeta implements MangaMeta {
@JsonKey(name: "flutter_readerMode")
final ReaderMode? readerMode,
@JsonKey(name: "flutter_readerPadding", fromJson: MangaMeta.fromJsonToDouble)
final double? readerPadding}) = _$_MangaMeta;
final double? readerPadding,
@JsonKey(name: "flutter_readerMagnifierSize", fromJson: MangaMeta.fromJsonToDouble)
final double? readerMagnifierSize}) = _$_MangaMeta;

factory _MangaMeta.fromJson(Map<String, dynamic> json) =
_$_MangaMeta.fromJson;
Expand All @@ -943,6 +970,10 @@ abstract class _MangaMeta implements MangaMeta {
@JsonKey(name: "flutter_readerPadding", fromJson: MangaMeta.fromJsonToDouble)
double? get readerPadding;
@override
@JsonKey(
name: "flutter_readerMagnifierSize", fromJson: MangaMeta.fromJsonToDouble)
double? get readerMagnifierSize;
@override
@JsonKey(ignore: true)
_$$_MangaMetaCopyWith<_$_MangaMeta> get copyWith =>
throw _privateConstructorUsedError;
Expand Down
3 changes: 3 additions & 0 deletions lib/src/features/manga_book/domain/manga/manga_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import '../../../../../constants/app_sizes.dart';
import '../../../../../utils/extensions/custom_extensions.dart';
import '../../../../../widgets/async_buttons/async_checkbox_list_tile.dart';
import '../../../../../widgets/pop_button.dart';
import '../../../../library/domain/category/category_model.dart';
import '../../../../library/presentation/category/controller/edit_category_controller.dart';
import '../../../data/manga_book_repository.dart';
import '../controller/manga_details_controller.dart';
Expand Down Expand Up @@ -58,10 +59,8 @@ class EditMangaCategoryDialog extends HookConsumerWidget {
context,
(selectedCategoryList) => Column(
children: [
for (int index = 1; index < data!.length; index++)
if (data[index].id == 0)
const SizedBox.shrink()
else
for (Category category in data!)
if (category.id != 0)
AsyncCheckboxListTile(
onChanged: (value) async {
await AsyncValue.guard(
Expand All @@ -70,22 +69,22 @@ class EditMangaCategoryDialog extends HookConsumerWidget {
.read(mangaBookRepositoryProvider)
.addMangaToCategory(
mangaId,
"${data[index].id!}",
"${category.id!}",
)
: ref
.read(mangaBookRepositoryProvider)
.removeMangaFromCategory(
mangaId,
"${data[index].id!}",
"${category.id!}",
),
);
await ref.read(provider.notifier).refresh();
},
value: selectedCategoryList?.containsKey(
"${data[index].id}",
"${category.id}",
) ??
false,
title: Text(data[index].name ?? ""),
title: Text(category.name ?? ""),
),
],
),
Expand Down
Loading

0 comments on commit 86eeeac

Please sign in to comment.