Skip to content

Commit

Permalink
A?
Browse files Browse the repository at this point in the history
  • Loading branch information
femalemonkeyman committed Apr 9, 2023
2 parents 8e0abae + d79b2c6 commit 334df06
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 56 deletions.
1 change: 1 addition & 0 deletions lib/anime/anime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class AniPageState extends State<AniPage> with AutomaticKeepAliveClientMixin {
page = 1;
animeData = [];
if (textController.text.isNotEmpty) {
print(textController.text);
selectedGenres = [];
search = textController.text;
} else {
Expand Down
12 changes: 7 additions & 5 deletions lib/manga/manga_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class MangaControlsState extends State<MangaControls> {

@override
Widget build(context) {
final width = MediaQuery.of(context).size.width;
final height = MediaQuery.of(context).size.height;
return SafeArea(
child: Stack(
children: [
Expand Down Expand Up @@ -132,8 +134,8 @@ class MangaControlsState extends State<MangaControls> {
Positioned(
top: 0,
left: 0,
width: MediaQuery.of(context).size.width / 2,
height: MediaQuery.of(context).size.height,
width: width / 2,
height: height,
child: GestureDetector(
onTap: () {
widget.controller.jumpToPage(
Expand All @@ -145,8 +147,8 @@ class MangaControlsState extends State<MangaControls> {
Positioned(
top: 0,
right: 0,
width: MediaQuery.of(context).size.width / 2,
height: MediaQuery.of(context).size.height,
width: width / 2,
height: height,
child: GestureDetector(
onTap: () {
widget.controller.jumpToPage(
Expand All @@ -156,7 +158,7 @@ class MangaControlsState extends State<MangaControls> {
),
),
Positioned(
height: MediaQuery.of(context).size.height / 5,
height: height / 5,
left: 0,
right: 0,
bottom: 0,
Expand Down
62 changes: 36 additions & 26 deletions lib/novel/novel.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'dart:io';
import 'dart:ui';
import 'package:anicross/novel/novel_parser.dart';
import 'package:anicross/widgets/grid.dart';
import 'package:anicross/models/info_models.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:isar/isar.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:file_picker/file_picker.dart';
Expand Down Expand Up @@ -32,39 +32,49 @@ class NovelPageState extends State<NovelPage> {

importNovel() async {
bool permission = true;
if (Platform.isIOS || Platform.isAndroid) {
if (Platform.isAndroid) {
if (await Permission.storage.isDenied) {
permission = (await Permission.storage.request()).isGranted;
permission =
(await Permission.manageExternalStorage.request()).isGranted;
print("uwu");
}
}
if (permission) {
final String? path = await FilePicker.platform.getDirectoryPath();
if (path != null) {
novels = await compute((directory) async {
DartPluginRegistrant.ensureInitialized();
final Directory directory = Directory(path);
final List epubs = await directory.list(recursive: true).toList()
..retainWhere(
(element) => element.path.endsWith(".epub"),
novels = await compute(
(stuff) async {
BackgroundIsolateBinaryMessenger.ensureInitialized(
stuff[1] as RootIsolateToken,
);
List<AniData> data = [];
for (File i in epubs) {
final Novel novel = Novel(path: i.path);
await novel.parse();
await novel.writeCover();
novel.close();
data.add(
AniData(
type: "novel",
title: novel.title!,
image: novel.cover!,
mediaId: i.path,
),
);
}
return data;
}, path);
final Directory directory = Directory(stuff[0] as String);
final List epubs = directory.listSync(recursive: true).toList()
..retainWhere(
(element) => element.path.endsWith(".epub"),
);
List<AniData> data = [];
for (File i in epubs) {
print(i);
final Novel novel = Novel(path: i.path);
await novel.parse();
await novel.writeCover();
novel.close();
data.add(
AniData(
type: "novel",
title: novel.title!,
image: novel.cover!,
mediaId: i.path,
),
);
}
return data;
},
[
path,
RootIsolateToken.instance,
],
);
updateIsar();
}
}
Expand Down
47 changes: 34 additions & 13 deletions lib/novel/novel_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import 'dart:convert';
import 'dart:io';
import 'package:archive/archive_io.dart';
import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import 'package:image/image.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:image/image.dart' as img;
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
import 'package:xml2json/xml2json.dart';

Expand Down Expand Up @@ -66,21 +67,41 @@ class Novel {
title = content?['metadata']?['dc\$title']?['\$t'];
}

List<Widget> parseChapters() {
List<Widget> parseChapters(final String extract) {
extractArchiveToDisk(archive, extract);
Directory current = Directory(
p.normalize(
p.join(extract, root, '../'),
),
);
List<Widget> chapters = [];
for (Map s in spine!['itemref']) {
for (Map c in content!['manifest']['item']) {
if (c.containsValue(s['idref'])) {
print(c);
print('${current.path}/${c['href']}');
chapters.add(
HtmlWidget(
utf8.decode(
archive.findFile("OEBPS/${c['href']}")?.content,
),
renderMode: const ListViewMode(
primary: false,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
),
Html(
data: File('${current.path}/${c['href']}').readAsStringSync(),
customRenders: {
(context) => context.tree.element?.localName == "img":
CustomRender.widget(
widget: (context, p1) {
return Image.file(
File(
p.normalize(
p.join(
current.path,
c['href'],
"../",
context.tree.element!.attributes['src']!,
),
),
),
);
},
),
},
),
);
}
Expand All @@ -98,7 +119,7 @@ class Novel {
imagePath =
'${documents.path}/.anicross/$title-${i['href'].split('/').last}';
//print(imagePath);
await (Command()
(img.Command()
..decodeImage(
(archive.findFile(
'${root?.split("/")[0]}/${i['href']}',
Expand Down
126 changes: 120 additions & 6 deletions lib/novel/novel_reader.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:io';
import 'package:anicross/models/info_models.dart';
import 'package:anicross/novel/novel_parser.dart';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';

class NovelReader extends StatefulWidget {
final AniData data;
Expand All @@ -12,23 +14,27 @@ class NovelReader extends StatefulWidget {

class NovelReaderState extends State<NovelReader> {
late final Novel novel = Novel(path: widget.data.mediaId!);
late final String extract;
List<Widget> chapters = [];

@override
void initState() {
super.initState();
Future.microtask(
() async {
extract = '${(await getTemporaryDirectory()).path}/anicross-epub';
await novel.parse();
chapters = novel.parseChapters();
setState(() {});
setState(() {
chapters = novel.parseChapters(extract);
});
},
);
}

@override
void dispose() {
novel.close();
Directory(extract).deleteSync(recursive: true);
super.dispose();
}

Expand All @@ -48,11 +54,119 @@ class NovelReaderState extends State<NovelReader> {
)
],
)
: ListView(
primary: true,
semanticChildCount: chapters.length,
children: chapters,
: Stack(
children: [
ListView(
primary: true,
semanticChildCount: chapters.length,
children: chapters,
),
NovelControls(),
],
),
);
}
}

class NovelControls extends StatefulWidget {
//final PageController controller;
const NovelControls({super.key});

@override
State createState() => NovelControlsState();
}

class NovelControlsState extends State<NovelControls> {
bool show = false;

@override
void dispose() {
//widget.controller.dispose();
super.dispose();
}

@override
Widget build(context) {
final width = MediaQuery.of(context).size.width;
final height = MediaQuery.of(context).size.height;
return SafeArea(
child: Stack(
children: [
AnimatedOpacity(
duration: const Duration(milliseconds: 300),
opacity: !show ? 0.0 : 1.0,
child: Stack(
children: [
// Positioned(
// bottom: 0,
// child: Text(
// ((widget.controller.page?.toInt() ?? 0) + 1).toString(),
// ),
// ),
Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xCC000000),
Color(0x00000000),
Color(0x00000000),
Color(0x00000000),
Color(0x00000000),
Color(0x00000000),
Color(0xCC000000),
],
),
),
),
Positioned(
top: 0,
left: 0,
width: width / 3,
height: height,
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
print("left");
// widget.controller.jumpToPage(
// (widget.controller.page! + 1).toInt(),
// );
},
),
),
Positioned(
top: 0,
right: 0,
width: width / 3,
height: height,
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
// widget.controller.jumpToPage(
// (widget.controller.page! - 1).toInt(),
// );
},
),
),
Positioned(
height: height / 5,
left: 0,
right: 0,
bottom: 0,
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () => setState(
() => (show) ? show = false : show = true,
),
),
),
const BackButton(),
],
),
)
],
),
);
}
}
4 changes: 2 additions & 2 deletions lib/widgets/grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class GridState extends State<Grid> with AutomaticKeepAliveClientMixin {
maxCrossAxisExtent: 280,
),
delegate: SliverChildBuilderDelegate(
childCount: widget.length,
childCount: widget.data.length,
(context, index) {
if (index >= widget.data.length - 5 && widget.length == null) {
if (index >= widget.data.length - 5 && widget.data.length >= 5) {
widget.paginate();
} else {
return Padding(
Expand Down
Loading

0 comments on commit 334df06

Please sign in to comment.