From f17dcc954f452dc73f545e2575c704346d9f27cd Mon Sep 17 00:00:00 2001 From: femalemonkeyman Date: Tue, 30 Jul 2024 12:45:39 -0400 Subject: [PATCH] --- lib/media/providers/anime/anitaku.dart | 6 +- lib/viewers/Anime/media_anime.dart | 25 +++--- lib/viewers/Novel/media_novel.dart | 7 +- lib/viewers/Novel/novel_controller.dart | 101 +++++++++--------------- pubspec.yaml | 56 ++++++------- 5 files changed, 84 insertions(+), 111 deletions(-) diff --git a/lib/media/providers/anime/anitaku.dart b/lib/media/providers/anime/anitaku.dart index 72136b7..e606193 100644 --- a/lib/media/providers/anime/anitaku.dart +++ b/lib/media/providers/anime/anitaku.dart @@ -6,7 +6,7 @@ import 'package:encrypt/encrypt.dart'; import 'package:html/parser.dart'; import 'package:tokuwari_models/info_models.dart'; -const String gogo = 'https://anitaku.so'; +const String gogo = 'https://anitaku.pe'; Provider gogoList(final AniData data) async { try { @@ -59,9 +59,9 @@ Anime gogoInfo(final String id) async { ); final response = await Dio() .get( - 'https://playtaku.online/encrypt-ajax.php?id=$updatedParams&alias=$encrypt', + 'https://s3taku.com/encrypt-ajax.php?id=$updatedParams&alias=$encrypt', options: Options( - headers: {'referer': episode, 'host': 'playtaku.online', 'x-requested-with': 'XMLHttpRequest'}, + headers: {'referer': episode, 'host': 's3taku.com', 'x-requested-with': 'XMLHttpRequest'}, ), ) .then((value) => jsonDecode(value.data)['data']); diff --git a/lib/viewers/Anime/media_anime.dart b/lib/viewers/Anime/media_anime.dart index 91c5f8d..2d1d782 100644 --- a/lib/viewers/Anime/media_anime.dart +++ b/lib/viewers/Anime/media_anime.dart @@ -21,21 +21,22 @@ extension DurationExtension on Duration { /// Returns a [String] representation of [Duration]. String label({Duration? reference}) { reference ??= this; + int days = inDays; + int hours = inHours - (days * 24); + int minutes = inMinutes - (inHours * 60); + int seconds = inSeconds - (inMinutes * 60); if (reference > const Duration(days: 1)) { - final days = inDays.toString().padLeft(3, '0'); - final hours = (inHours - (inDays * 24)).toString().padLeft(2, '0'); - final minutes = (inMinutes - (inHours * 60)).toString().padLeft(2, '0'); - final seconds = (inSeconds - (inMinutes * 60)).toString().padLeft(2, '0'); - return '$days:$hours:$minutes:$seconds'; + return '${days.toString().padLeft(3, '0')}:' + '${hours.toString().padLeft(2, '0')}:' + '${minutes.toString().padLeft(2, '0')}:' + '${seconds.toString().padLeft(2, '0')}'; } else if (reference > const Duration(hours: 1)) { - final hours = inHours.toString().padLeft(2, '0'); - final minutes = (inMinutes - (inHours * 60)).toString().padLeft(2, '0'); - final seconds = (inSeconds - (inMinutes * 60)).toString().padLeft(2, '0'); - return '$hours:$minutes:$seconds'; + return '${hours.toString().padLeft(2, '0')}:' + '${minutes.toString().padLeft(2, '0')}:' + '${seconds.toString().padLeft(2, '0')}'; } else { - final minutes = inMinutes.toString().padLeft(2, '0'); - final seconds = (inSeconds - (inMinutes * 60)).toString().padLeft(2, '0'); - return '$minutes:$seconds'; + return '${minutes.toString().padLeft(2, '0')}:' + '${seconds.toString().padLeft(2, '0')}'; } } } diff --git a/lib/viewers/Novel/media_novel.dart b/lib/viewers/Novel/media_novel.dart index c724535..cfba13d 100644 --- a/lib/viewers/Novel/media_novel.dart +++ b/lib/viewers/Novel/media_novel.dart @@ -40,7 +40,10 @@ class NovelViewerState extends State with AutomaticKeepAliveClientM child: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(20), - child: controller.chapters[index], + child: RichText( + text: controller.chapters[index], + textScaler: TextScaler.linear(controller.fontScale), + ), ), ), ); @@ -50,7 +53,7 @@ class NovelViewerState extends State with AutomaticKeepAliveClientM behavior: HitTestBehavior.translucent, onTap: () => setState(() { print('yes'); - controller.setFontScale(20); + controller.setFontScale(16); }), ), const BackButton(), diff --git a/lib/viewers/Novel/novel_controller.dart b/lib/viewers/Novel/novel_controller.dart index 5eedcc1..9c61c49 100644 --- a/lib/viewers/Novel/novel_controller.dart +++ b/lib/viewers/Novel/novel_controller.dart @@ -2,19 +2,16 @@ import 'dart:io'; import 'package:epubx/epubx.dart'; import 'package:extended_image/extended_image.dart'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:csslib/parser.dart' as cs; import 'package:csslib/visitor.dart' as csv; -import 'package:flutter/rendering.dart'; -import 'package:flutter/widgets.dart'; import 'package:path/path.dart' as p; import 'package:xml/xml.dart'; class NovelController { final EpubBook epub; - final List chapters; + final List chapters; double fontScale = Platform.isAndroid || Platform.isIOS ? 1 : 1.14285714; NovelController._(this.epub, this.chapters); @@ -83,8 +80,8 @@ class ChapterParser { _ => const TextStyle(), }; - List parseChapters() { - final List chapters = []; + List parseChapters() { + final List chapters = []; for (final chapter in epub.Chapters) { final List children = []; currentChapterFile = chapter.ContentFileName; @@ -101,15 +98,16 @@ class ChapterParser { if (htmlBody == null) { throw Exception('Chapter parsing error: HTML body not found'); } - _parseElements(htmlBody, children, const TextStyle()); - chapters.add(ChapterElement(text: TextSpan(children: children))); + _parseElements(htmlBody, children); + chapters.add(TextSpan(children: children)); } return chapters; } - void _parseElements(XmlElement node, List children, TextStyle style) { + void _parseElements(XmlElement node, List children) { if (node.getAttribute('hidden') != null) return; final name = node.localName.toLowerCase(); + final textWidgets = _buildWidgets(node); switch (node.localName.toLowerCase()) { // Inline Elements case 'image': @@ -119,11 +117,13 @@ class ChapterParser { .path; children.add( WidgetSpan( - child: ExtendedImage.memory( - epub.images[location]!.Content!, - fit: BoxFit.cover, - enableMemoryCache: false, - clearMemoryCacheWhenDispose: true, + child: Center( + child: ExtendedImage.memory( + epub.images[location]!.Content!, + fit: BoxFit.cover, + enableMemoryCache: false, + clearMemoryCacheWhenDispose: true, + ), ), ), ); @@ -140,29 +140,47 @@ class ChapterParser { case 'body': case 'section': case 'p': - children.addAll(_buildWidgets(node, style)); + children.add(const TextSpan(text: '\n', style: TextStyle(fontSize: 0))); + children.addAll(textWidgets); case 'br': - print('no'); children.add(const TextSpan(text: '\n')); + // Inline case 'em': case 'i': + children.add( + TextSpan( + children: textWidgets, + style: const TextStyle(fontStyle: FontStyle.italic), + ), + ); case 'b': - case 'span': case 'strong': + children.add( + TextSpan( + children: textWidgets, + style: const TextStyle(fontWeight: FontWeight.bold), + ), + ); case 'a': - children.addAll(_buildWidgets(node, style)); + children.add( + TextSpan( + children: textWidgets, + style: const TextStyle(color: Colors.blue), + ), + ); default: + children.addAll(textWidgets); } } - List _buildWidgets(XmlElement node, TextStyle style) { + List _buildWidgets(XmlElement node) { final List children = []; for (final child in node.children) { if (child case XmlText(:final value)) { if (value.trim().isEmpty) continue; children.add(TextSpan(text: value)); } else if (child is XmlElement) { - _parseElements(child, children, style); + _parseElements(child, children); } else { print(child); } @@ -170,46 +188,3 @@ class ChapterParser { return children; } } - -class ChapterElement extends MultiChildRenderObjectWidget { - final InlineSpan text; - final ElementRenderType renderType; - ChapterElement({ - super.key, - required this.text, - this.renderType = ElementRenderType.block, - }) : super(children: WidgetSpan.extractFromInlineSpan(text, TextScaler.noScaling)); - - @override - ChapterElementRenderObject createRenderObject(BuildContext context) { - return ChapterElementRenderObject(text, textDirection: TextDirection.ltr); - } - - @override - void updateRenderObject(BuildContext context, covariant ChapterElementRenderObject renderObject) { - // TODO: implement updateRenderObject - //renderObject.markNeedsPaint(); - } -} - -class TextNode extends TextSpan { - final ElementRenderType renderType; - const TextNode({super.text, super.style, this.renderType = ElementRenderType.block, super.children}); -} - -class ChapterElementRenderObject extends RenderParagraph { - ChapterElementRenderObject( - super.text, { - super.textDirection = TextDirection.ltr, - }); - @override - void performLayout() { - // For non-block elements, perform default layout - super.performLayout(); - } -} - -enum ElementRenderType { - block, - inline, -} diff --git a/pubspec.yaml b/pubspec.yaml index 265b38c..c17de3b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,28 +5,28 @@ description: Something I guess # pub.dev using `pub publish`. This is preferred for private packages. publish_to: 'none' # Remove this line if you wish to publish to pub.dev -version: 0.5.1 +version: 0.5.2 environment: - sdk: ">=3.2.0" + sdk: ">=3.4.0" dependencies: flutter: sdk: flutter - sliver_tools: - path: - dio: - async: - graphql: - flex_color_scheme: + sliver_tools: ^0.2.12 + path: ^1.9.0 + dio: ^5.5.0+1 + async: ^2.11.0 + graphql: ^5.2.0-beta.8 + flex_color_scheme: ^7.3.1 # For novels epubx: git: url: https://github.com/femalemonkeyman/epubx #path: /mnt/Storage/HomeStuff/Documents/epubx - html: - file_picker: - permission_handler: + html: ^0.15.4 + file_picker: ^8.0.6 + permission_handler: ^11.3.1 # Media kit media_kit: git: @@ -43,20 +43,18 @@ dependencies: url: https://github.com/media-kit/media-kit.git ref: main path: ./libs/universal/media_kit_libs_video - path_provider: - window_manager: - encrypt: + path_provider: ^2.1.3 + window_manager: ^0.3.9 + encrypt: ^5.0.3 isar: ^4.0.0-dev.14 isar_flutter_libs: ^4.0.0-dev.14 - xml: - expandable_text: - string_similarity: - go_router: - extended_image: - collection: - expandable_page_view: - csslib: - + xml: ^6.5.0 + expandable_text: ^2.3.0 + string_similarity: ^2.0.0 + go_router: ^14.2.1 + extended_image: ^8.2.1 + expandable_page_view: ^1.0.17 + csslib: ^1.0.0 #Model tokuwari_models: @@ -71,18 +69,14 @@ dependencies: # url: https://github.com/femalemonkeyman/key dependency_overrides: - graphql: ^5.2.0-beta.6 + graphql: ^5.2.0-beta.8 + screen_brightness: ">=1.0.1" media_kit: git: url: https://github.com/media-kit/media-kit.git ref: main path: ./media_kit - media_kit_video: - git: - url: https://github.com/media-kit/media-kit.git - ref: main - path: ./media_kit_video media_kit_native_event_loop: git: url: https://github.com/media-kit/media-kit.git @@ -99,5 +93,5 @@ flutter: # the material Icons class. uses-material-design: true dev_dependencies: - build_runner: - flutter_lints: + build_runner: ^2.4.11 + flutter_lints: ^4.0.0