From d86fe65b03c87d42c180af94b3a7a708b4e406d5 Mon Sep 17 00:00:00 2001 From: nyne Date: Tue, 29 Oct 2024 11:35:31 +0800 Subject: [PATCH 1/4] switch chapter button --- lib/pages/reader/images.dart | 30 ++++++++++- lib/pages/reader/scaffold.dart | 96 ++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) diff --git a/lib/pages/reader/images.dart b/lib/pages/reader/images.dart index dbe3575..6e7c91c 100644 --- a/lib/pages/reader/images.dart +++ b/lib/pages/reader/images.dart @@ -323,6 +323,13 @@ class _ContinuousModeState extends State<_ContinuousMode> void smoothTo(double offset) { futurePosition ??= scrollController.offset; + if (futurePosition! > scrollController.position.maxScrollExtent && + offset > 0) { + return; + } else if (futurePosition! < scrollController.position.minScrollExtent && + offset < 0) { + return; + } futurePosition = futurePosition! + offset * 1.2; futurePosition = futurePosition!.clamp( scrollController.position.minScrollExtent, @@ -435,6 +442,27 @@ class _ContinuousModeState extends State<_ContinuousMode> child: widget, ); + widget = NotificationListener( + onNotification: (notification) { + var length = reader.maxChapter; + if (!scrollController.hasClients) return false; + if (scrollController.position.pixels <= + scrollController.position.minScrollExtent && + reader.chapter != 1) { + context.readerScaffold.setFloatingButton(-1); + } else if (scrollController.position.pixels >= + scrollController.position.maxScrollExtent && + reader.chapter < length) { + context.readerScaffold.setFloatingButton(1); + } else { + context.readerScaffold.setFloatingButton(0); + } + + return true; + }, + child: widget, + ); + return PhotoView.customChild( backgroundDecoration: BoxDecoration( color: context.colorScheme.surface, @@ -510,7 +538,7 @@ class _ContinuousModeState extends State<_ContinuousMode> } }); } - if(event is KeyUpEvent) { + if (event is KeyUpEvent) { return; } bool? forward; diff --git a/lib/pages/reader/scaffold.dart b/lib/pages/reader/scaffold.dart index a2429f8..87739ae 100644 --- a/lib/pages/reader/scaffold.dart +++ b/lib/pages/reader/scaffold.dart @@ -18,6 +18,27 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> { bool get isOpen => _isOpen; + int showFloatingButtonValue = 0; + + double fABValue = 0; + + void setFloatingButton(int value) { + if (value == 0) { + if (showFloatingButtonValue != 0) { + showFloatingButtonValue = 0; + fABValue = 0; + update(); + } + } + if (value == 1 && showFloatingButtonValue == 0) { + showFloatingButtonValue = 1; + update(); + } else if (value == -1 && showFloatingButtonValue == 0) { + showFloatingButtonValue = -1; + update(); + } + } + @override void initState() { sliderFocus.canRequestFocus = false; @@ -71,6 +92,12 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> { height: kBottomBarHeight + context.padding.bottom, child: buildBottom(), ), + AnimatedPositioned( + duration: const Duration(milliseconds: 180), + right: 16, + bottom: showFloatingButtonValue == 0 ? -58 : 16, + child: buildEpChangeButton(), + ), ], ); } @@ -371,6 +398,75 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> { width: 400, ); } + + Widget buildEpChangeButton() { + if (context.reader.widget.chapters == null) return const SizedBox(); + switch (showFloatingButtonValue) { + case -1: + return FloatingActionButton( + onPressed: () => context.reader.toPrevChapter(), + child: const Icon(Icons.arrow_back_ios_outlined), + ); + case 0: + return Container( + width: 58, + height: 58, + clipBehavior: Clip.antiAlias, + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.primaryContainer, + borderRadius: BorderRadius.circular(16), + ), + child: Icon( + Icons.arrow_forward_ios, + size: 24, + color: Theme.of(context).colorScheme.onPrimaryContainer, + ), + ); + case 1: + return Container( + width: 58, + height: 58, + clipBehavior: Clip.antiAlias, + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.primaryContainer, + borderRadius: BorderRadius.circular(16), + ), + child: Stack( + children: [ + Positioned.fill( + child: Material( + color: Colors.transparent, + child: InkWell( + onTap: () => context.reader.toNextChapter(), + borderRadius: BorderRadius.circular(16), + child: Center( + child: Icon( + Icons.arrow_forward_ios, + size: 24, + color: Theme.of(context).colorScheme.onPrimaryContainer, + )), + ), + ), + ), + Positioned( + bottom: 0, + left: 0, + right: 0, + height: fABValue, + child: ColoredBox( + color: Theme.of(context) + .colorScheme + .surfaceTint + .withOpacity(0.2), + child: const SizedBox.expand(), + ), + ) + ], + ), + ); + } + return const SizedBox(); + } } class _ChaptersView extends StatefulWidget { From 4c1d4bda9a683b1442defd1c5775dd6858f2eac4 Mon Sep 17 00:00:00 2001 From: nyne Date: Tue, 29 Oct 2024 11:35:47 +0800 Subject: [PATCH 2/4] show language on comic tile --- lib/components/comic.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/components/comic.dart b/lib/components/comic.dart index f3e88af..ca766b6 100644 --- a/lib/components/comic.dart +++ b/lib/components/comic.dart @@ -202,7 +202,7 @@ class ComicTile extends StatelessWidget { : "[${comic.maxPage}P]${comic.title.replaceAll("\n", "")}", subtitle: comic.subtitle ?? '', description: comic.description, - badge: badge, + badge: badge ?? comic.language, tags: comic.tags, maxLines: 2, enableTranslate: ComicSource.find(comic.sourceKey) From 836226fbb5763bd321520be1e77b5c91aa7ac68d Mon Sep 17 00:00:00 2001 From: nyne Date: Tue, 29 Oct 2024 11:55:27 +0800 Subject: [PATCH 3/4] improve cache --- lib/foundation/log.dart | 1 + lib/network/cache.dart | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/lib/foundation/log.dart b/lib/foundation/log.dart index efdda91..5839e0c 100644 --- a/lib/foundation/log.dart +++ b/lib/foundation/log.dart @@ -41,6 +41,7 @@ class Log { static void addLog(LogLevel level, String title, String content) { if (!ignoreLimitation && content.length > maxLogLength) { + File("D://debug.txt").writeAsString(content); content = "${content.substring(0, maxLogLength)}..."; } diff --git a/lib/network/cache.dart b/lib/network/cache.dart index c47d923..7beea4f 100644 --- a/lib/network/cache.dart +++ b/lib/network/cache.dart @@ -160,6 +160,9 @@ class NetworkCacheManager implements Interceptor { if (response.requestOptions.method != "GET") { return handler.next(response); } + if(response.statusCode != null && response.statusCode! >= 400){ + return handler.next(response); + } var size = _calculateSize(response.data); if(size != null && size < 1024 * 1024 && size > 0) { var cache = NetworkCache( @@ -190,6 +193,9 @@ class NetworkCacheManager implements Interceptor { if(data.trim().isEmpty){ return 0; } + if(data.length < 512 && data.contains("IP address")){ + return 0; + } return data.length * 4; } if(data is Map) { From 014d0390bc9d1ad63f2c4814a5761510ae471a1d Mon Sep 17 00:00:00 2001 From: nyne Date: Tue, 29 Oct 2024 11:59:01 +0800 Subject: [PATCH 4/4] fix share image --- lib/pages/reader/scaffold.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pages/reader/scaffold.dart b/lib/pages/reader/scaffold.dart index 87739ae..fd37bf9 100644 --- a/lib/pages/reader/scaffold.dart +++ b/lib/pages/reader/scaffold.dart @@ -360,7 +360,7 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> { return await File(imageKey.substring(7)).readAsBytes(); } else { return (await CacheManager() - .findCache("$imageKey@${context.reader.type.comicSource!.key}"))! + .findCache("$imageKey@${context.reader.type.sourceKey}@${context.reader.cid}@${context.reader.eid}"))! .readAsBytes(); } }