2021-09-29 23:57:09 +00:00
|
|
|
import 'dart:async';
|
2021-12-07 15:53:19 +00:00
|
|
|
import 'dart:io';
|
2021-09-29 23:57:09 +00:00
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
2021-12-04 01:06:52 +00:00
|
|
|
import 'package:pikapika/basic/Common.dart';
|
2021-11-11 03:00:38 +00:00
|
|
|
import 'package:pikapika/basic/Entities.dart';
|
|
|
|
import 'package:pikapika/basic/config/AutoFullScreen.dart';
|
|
|
|
import 'package:pikapika/basic/config/FullScreenUI.dart';
|
|
|
|
import 'package:pikapika/basic/config/ReaderDirection.dart';
|
|
|
|
import 'package:pikapika/basic/config/ReaderType.dart';
|
|
|
|
import 'package:pikapika/basic/Method.dart';
|
2023-01-31 10:50:51 +00:00
|
|
|
import '../basic/config/IconLoading.dart';
|
2021-12-01 01:17:15 +00:00
|
|
|
import 'components/ContentError.dart';
|
|
|
|
import 'components/ContentLoading.dart';
|
2021-09-29 23:57:09 +00:00
|
|
|
import 'components/ImageReader.dart';
|
2022-03-25 14:57:30 +00:00
|
|
|
import 'components/RightClickPop.dart';
|
2021-09-29 23:57:09 +00:00
|
|
|
|
|
|
|
// 阅读下载的内容
|
|
|
|
class DownloadReaderScreen extends StatefulWidget {
|
|
|
|
final DownloadComic comicInfo;
|
|
|
|
final List<DownloadEp> epList;
|
|
|
|
final int currentEpOrder;
|
2021-11-30 10:49:51 +00:00
|
|
|
final int? initPicturePosition;
|
2021-11-04 05:56:25 +00:00
|
|
|
final ReaderType pagerType = currentReaderType();
|
2021-09-29 23:57:09 +00:00
|
|
|
final ReaderDirection pagerDirection = gReaderDirection;
|
|
|
|
late final bool autoFullScreen;
|
|
|
|
|
|
|
|
DownloadReaderScreen({
|
|
|
|
Key? key,
|
|
|
|
required this.comicInfo,
|
|
|
|
required this.epList,
|
|
|
|
required this.currentEpOrder,
|
2021-11-30 10:49:51 +00:00
|
|
|
this.initPicturePosition,
|
2021-09-29 23:57:09 +00:00
|
|
|
bool? autoFullScreen,
|
|
|
|
}) : super(key: key) {
|
2021-10-21 04:08:51 +00:00
|
|
|
this.autoFullScreen = autoFullScreen ?? currentAutoFullScreen();
|
2021-09-29 23:57:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _DownloadReaderScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _DownloadReaderScreenState extends State<DownloadReaderScreen> {
|
|
|
|
late DownloadEp _ep;
|
|
|
|
late bool _fullScreen = false;
|
|
|
|
late List<DownloadPicture> pictures = [];
|
|
|
|
late Future _future = _load();
|
|
|
|
int? _lastChangeRank;
|
|
|
|
bool _replacement = false;
|
|
|
|
|
|
|
|
Future _load() async {
|
2021-11-30 10:49:51 +00:00
|
|
|
if (widget.initPicturePosition == null) {
|
|
|
|
await method.storeViewEp(widget.comicInfo.id, _ep.epOrder, _ep.title, 0);
|
2021-09-29 23:57:09 +00:00
|
|
|
}
|
|
|
|
pictures.clear();
|
|
|
|
for (var ep in widget.epList) {
|
|
|
|
if (ep.epOrder == widget.currentEpOrder) {
|
|
|
|
pictures.addAll((await method.downloadPicturesByEpId(ep.id)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (widget.autoFullScreen) {
|
|
|
|
setState(() {
|
2022-04-17 05:48:09 +00:00
|
|
|
SystemChrome.setEnabledSystemUIMode(
|
|
|
|
SystemUiMode.manual,
|
|
|
|
overlays: [],
|
|
|
|
);
|
2021-09-29 23:57:09 +00:00
|
|
|
_fullScreen = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future _onPositionChange(int position) async {
|
2021-11-30 10:49:51 +00:00
|
|
|
_lastChangeRank = position;
|
2021-09-29 23:57:09 +00:00
|
|
|
return method.storeViewEp(
|
2021-11-30 10:49:51 +00:00
|
|
|
widget.comicInfo.id, _ep.epOrder, _ep.title, position);
|
2021-09-29 23:57:09 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 01:06:52 +00:00
|
|
|
FutureOr<dynamic> _onDownload() async {
|
2022-06-29 19:02:01 +00:00
|
|
|
defaultToast(context, "您阅读的是下载漫画");
|
2021-12-04 01:06:52 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 02:32:35 +00:00
|
|
|
FutureOr<dynamic> _onChangeEp(int epOrder) {
|
2022-03-17 03:31:25 +00:00
|
|
|
var orderMap = <int, DownloadEp>{};
|
|
|
|
for (var element in widget.epList) {
|
2021-09-29 23:57:09 +00:00
|
|
|
orderMap[element.epOrder] = element;
|
2022-03-17 03:31:25 +00:00
|
|
|
}
|
2021-12-02 02:32:35 +00:00
|
|
|
if (orderMap.containsKey(epOrder)) {
|
|
|
|
_replacement = true;
|
|
|
|
Navigator.of(context).pushReplacement(
|
2023-01-31 10:50:51 +00:00
|
|
|
mixRoute(
|
2021-12-02 02:32:35 +00:00
|
|
|
builder: (context) => DownloadReaderScreen(
|
|
|
|
comicInfo: widget.comicInfo,
|
|
|
|
epList: widget.epList,
|
|
|
|
currentEpOrder: epOrder,
|
|
|
|
autoFullScreen: _fullScreen,
|
2021-11-30 10:49:51 +00:00
|
|
|
),
|
2021-12-02 02:32:35 +00:00
|
|
|
),
|
|
|
|
);
|
2021-09-29 23:57:09 +00:00
|
|
|
}
|
2021-12-02 02:32:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FutureOr<dynamic> _onReloadEp() {
|
|
|
|
_replacement = true;
|
|
|
|
Navigator.of(context).pushReplacement(
|
2023-01-31 10:50:51 +00:00
|
|
|
mixRoute(
|
2021-12-02 02:32:35 +00:00
|
|
|
builder: (context) => DownloadReaderScreen(
|
|
|
|
comicInfo: widget.comicInfo,
|
|
|
|
epList: widget.epList,
|
|
|
|
currentEpOrder: widget.currentEpOrder,
|
|
|
|
initPicturePosition: _lastChangeRank ?? widget.initPicturePosition,
|
|
|
|
// maybe null
|
|
|
|
autoFullScreen: _fullScreen,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
2021-09-29 23:57:09 +00:00
|
|
|
// EP
|
2022-03-17 03:31:25 +00:00
|
|
|
for (var element in widget.epList) {
|
2021-09-29 23:57:09 +00:00
|
|
|
if (element.epOrder == widget.currentEpOrder) {
|
|
|
|
_ep = element;
|
|
|
|
}
|
2022-03-17 03:31:25 +00:00
|
|
|
}
|
2021-09-29 23:57:09 +00:00
|
|
|
// INIT
|
|
|
|
_future = _load();
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
if (!_replacement) {
|
|
|
|
switchFullScreenUI();
|
|
|
|
}
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-03-25 14:57:30 +00:00
|
|
|
Widget build(BuildContext context){
|
|
|
|
return rightClickPop(
|
|
|
|
child: buildScreen(context),
|
|
|
|
context: context,
|
|
|
|
canPop: true,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildScreen(BuildContext context) {
|
2021-09-29 23:57:09 +00:00
|
|
|
return readerKeyboardHolder(_build(context));
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _build(BuildContext context) {
|
2021-12-01 01:17:15 +00:00
|
|
|
return FutureBuilder(
|
|
|
|
future: _future,
|
|
|
|
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
|
|
|
|
if (snapshot.hasError) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: _fullScreen
|
|
|
|
? null
|
|
|
|
: AppBar(
|
|
|
|
title: Text("${_ep.title} - ${widget.comicInfo.title}"),
|
|
|
|
),
|
|
|
|
body: ContentError(
|
|
|
|
error: snapshot.error,
|
|
|
|
stackTrace: snapshot.stackTrace,
|
|
|
|
onRefresh: () async {
|
|
|
|
setState(() {
|
|
|
|
_future = _load();
|
|
|
|
});
|
|
|
|
},
|
2021-09-29 23:57:09 +00:00
|
|
|
),
|
2021-12-01 01:17:15 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if (snapshot.connectionState != ConnectionState.done) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: _fullScreen
|
|
|
|
? null
|
|
|
|
: AppBar(
|
|
|
|
title: Text("${_ep.title} - ${widget.comicInfo.title}"),
|
|
|
|
),
|
2022-03-25 14:57:30 +00:00
|
|
|
body: const ContentLoading(label: '加载中'),
|
2021-12-01 01:17:15 +00:00
|
|
|
);
|
|
|
|
}
|
2022-03-17 03:31:25 +00:00
|
|
|
var epNameMap = <int, String>{};
|
|
|
|
for (var element in widget.epList) {
|
2021-12-01 01:17:15 +00:00
|
|
|
epNameMap[element.epOrder] = element.title;
|
2022-03-17 03:31:25 +00:00
|
|
|
}
|
2021-12-01 01:17:15 +00:00
|
|
|
return Scaffold(
|
|
|
|
body: ImageReader(
|
2021-09-29 23:57:09 +00:00
|
|
|
ImageReaderStruct(
|
|
|
|
images: pictures
|
|
|
|
.map((e) => ReaderImageInfo(e.fileServer, e.path, e.localPath,
|
|
|
|
e.width, e.height, e.format, e.fileSize))
|
|
|
|
.toList(),
|
|
|
|
fullScreen: _fullScreen,
|
|
|
|
onFullScreenChange: _onFullScreenChange,
|
|
|
|
onPositionChange: _onPositionChange,
|
2021-11-30 10:49:51 +00:00
|
|
|
initPosition: widget.initPicturePosition,
|
2021-12-01 01:17:15 +00:00
|
|
|
epOrder: _ep.epOrder,
|
|
|
|
epNameMap: epNameMap,
|
|
|
|
comicTitle: widget.comicInfo.title,
|
2021-12-02 02:32:35 +00:00
|
|
|
onReloadEp: _onReloadEp,
|
|
|
|
onChangeEp: _onChangeEp,
|
2021-12-04 01:06:52 +00:00
|
|
|
onDownload: _onDownload,
|
2021-09-29 23:57:09 +00:00
|
|
|
),
|
2021-12-01 01:17:15 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2021-09-29 23:57:09 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future _onFullScreenChange(bool fullScreen) async {
|
|
|
|
setState(() {
|
2021-12-07 15:53:19 +00:00
|
|
|
if (fullScreen) {
|
|
|
|
if (Platform.isAndroid || Platform.isIOS) {
|
2022-04-17 05:48:09 +00:00
|
|
|
SystemChrome.setEnabledSystemUIMode(
|
|
|
|
SystemUiMode.manual,
|
|
|
|
overlays: [],
|
|
|
|
);
|
2021-12-07 15:53:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switchFullScreenUI();
|
|
|
|
}
|
2021-09-29 23:57:09 +00:00
|
|
|
_fullScreen = fullScreen;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|