fix any bugs

This commit is contained in:
niuhuan 2021-12-01 09:17:15 +08:00
parent 8ebcccfbf8
commit 20e0ee172c
4 changed files with 346 additions and 224 deletions

View File

@ -11,7 +11,8 @@ import 'package:pikapika/basic/config/Quality.dart';
import 'package:pikapika/basic/config/ReaderDirection.dart'; import 'package:pikapika/basic/config/ReaderDirection.dart';
import 'package:pikapika/basic/config/ReaderType.dart'; import 'package:pikapika/basic/config/ReaderType.dart';
import 'package:pikapika/basic/const.dart'; import 'package:pikapika/basic/const.dart';
import 'package:pikapika/screens/components/ContentBuilder.dart'; import 'package:pikapika/screens/components/ContentError.dart';
import 'package:pikapika/screens/components/ContentLoading.dart';
import 'components/ImageReader.dart'; import 'components/ImageReader.dart';
// 线 // 线
@ -151,7 +152,26 @@ class _ComicReaderScreenState extends State<ComicReaderScreen> {
return readerKeyboardHolder(_build(context)); return readerKeyboardHolder(_build(context));
} }
Future _onSelectDirection() async {
await choosePagerDirection(context);
if (widget.pagerDirection != gReaderDirection) {
_reloadReader();
}
}
Future _onSelectReaderType() async {
await choosePagerType(context);
if (widget.pagerType != currentReaderType()) {
_reloadReader();
}
}
Widget _build(BuildContext context) { Widget _build(BuildContext context) {
return FutureBuilder(
future: _future,
builder: (BuildContext context,
AsyncSnapshot<List<RemoteImageInfo>> snapshot) {
if (snapshot.hasError) {
return Scaffold( return Scaffold(
appBar: _fullScreen appBar: _fullScreen
? null ? null
@ -160,35 +180,53 @@ class _ComicReaderScreenState extends State<ComicReaderScreen> {
title: Text("${_ep.title} - ${widget.comicInfo.title}"), title: Text("${_ep.title} - ${widget.comicInfo.title}"),
actions: [ actions: [
IconButton( IconButton(
onPressed: () async { onPressed: _onSelectDirection,
await choosePagerDirection(context);
if (widget.pagerDirection != gReaderDirection) {
_reloadReader();
}
},
icon: Icon(Icons.grid_goldenratio), icon: Icon(Icons.grid_goldenratio),
), ),
IconButton( IconButton(
onPressed: () async { onPressed: _onSelectReaderType,
await choosePagerType(context);
if (widget.pagerType != currentReaderType()) {
_reloadReader();
}
},
icon: Icon(Icons.view_day_outlined), icon: Icon(Icons.view_day_outlined),
), ),
], ],
), ),
body: ContentBuilder( body: ContentError(
future: _future, error: snapshot.error,
stackTrace: snapshot.stackTrace,
onRefresh: () async { onRefresh: () async {
setState(() { setState(() {
_future = _load(); _future = _load();
}); });
}, },
successBuilder: (BuildContext context, ),
AsyncSnapshot<List<RemoteImageInfo>> snapshot) { );
return ImageReader( }
if (snapshot.connectionState != ConnectionState.done) {
return Scaffold(
appBar: _fullScreen
? null
: AppBar(
backgroundColor: readerAppbarColor,
title: Text("${_ep.title} - ${widget.comicInfo.title}"),
actions: [
IconButton(
onPressed: _onSelectDirection,
icon: Icon(Icons.grid_goldenratio),
),
IconButton(
onPressed: _onSelectReaderType,
icon: Icon(Icons.view_day_outlined),
),
],
),
body: ContentLoading(label: '加载中'),
);
}
var epNameMap = Map<int, String>();
widget.epList.forEach((element) {
epNameMap[element.order] = element.title;
});
return Scaffold(
body: ImageReader(
ImageReaderStruct( ImageReaderStruct(
images: snapshot.data! images: snapshot.data!
.map((e) => ReaderImageInfo( .map((e) => ReaderImageInfo(
@ -210,10 +248,15 @@ class _ComicReaderScreenState extends State<ComicReaderScreen> {
initPosition: widget.initPicturePosition, initPosition: widget.initPicturePosition,
pagerType: widget.pagerType, pagerType: widget.pagerType,
pagerDirection: widget.pagerDirection, pagerDirection: widget.pagerDirection,
epNameMap: epNameMap,
epOrder: _ep.order,
comicTitle: widget.comicInfo.title,
onSelectDirection: _onSelectDirection,
onSelectReaderType: _onSelectReaderType,
),
), ),
); );
}, },
),
); );
} }

View File

@ -10,6 +10,8 @@ import 'package:pikapika/basic/config/ReaderDirection.dart';
import 'package:pikapika/basic/config/ReaderType.dart'; import 'package:pikapika/basic/config/ReaderType.dart';
import 'package:pikapika/screens/components/ContentBuilder.dart'; import 'package:pikapika/screens/components/ContentBuilder.dart';
import 'package:pikapika/basic/Method.dart'; import 'package:pikapika/basic/Method.dart';
import 'components/ContentError.dart';
import 'components/ContentLoading.dart';
import 'components/ImageReader.dart'; import 'components/ImageReader.dart';
// //
@ -143,7 +145,25 @@ class _DownloadReaderScreenState extends State<DownloadReaderScreen> {
return readerKeyboardHolder(_build(context)); return readerKeyboardHolder(_build(context));
} }
Future _onSelectDirection() async {
await choosePagerDirection(context);
if (widget.pagerDirection != gReaderDirection) {
_reloadReader();
}
}
Future _onSelectReaderType() async {
await choosePagerType(context);
if (widget.pagerType != currentReaderType()) {
_reloadReader();
}
}
Widget _build(BuildContext context) { Widget _build(BuildContext context) {
return FutureBuilder(
future: _future,
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.hasError) {
return Scaffold( return Scaffold(
appBar: _fullScreen appBar: _fullScreen
? null ? null
@ -151,35 +171,52 @@ class _DownloadReaderScreenState extends State<DownloadReaderScreen> {
title: Text("${_ep.title} - ${widget.comicInfo.title}"), title: Text("${_ep.title} - ${widget.comicInfo.title}"),
actions: [ actions: [
IconButton( IconButton(
onPressed: () async { onPressed: _onSelectDirection,
await choosePagerDirection(context);
if (widget.pagerDirection != gReaderDirection) {
_reloadReader();
}
},
icon: Icon(Icons.grid_goldenratio), icon: Icon(Icons.grid_goldenratio),
), ),
IconButton( IconButton(
onPressed: () async { onPressed: _onSelectReaderType,
await choosePagerType(context);
if (widget.pagerType != currentReaderType()) {
_reloadReader();
}
},
icon: Icon(Icons.view_day_outlined), icon: Icon(Icons.view_day_outlined),
), ),
], ],
), ),
body: ContentBuilder( body: ContentError(
future: _future, error: snapshot.error,
stackTrace: snapshot.stackTrace,
onRefresh: () async { onRefresh: () async {
setState(() { setState(() {
_future = _load(); _future = _load();
}); });
}, },
successBuilder: ),
(BuildContext context, AsyncSnapshot<dynamic> snapshot) { );
return ImageReader( }
if (snapshot.connectionState != ConnectionState.done) {
return Scaffold(
appBar: _fullScreen
? null
: AppBar(
title: Text("${_ep.title} - ${widget.comicInfo.title}"),
actions: [
IconButton(
onPressed: _onSelectDirection,
icon: Icon(Icons.grid_goldenratio),
),
IconButton(
onPressed: _onSelectReaderType,
icon: Icon(Icons.view_day_outlined),
),
],
),
body: ContentLoading(label: '加载中'),
);
}
var epNameMap = Map<int, String>();
widget.epList.forEach((element) {
epNameMap[element.epOrder] = element.title;
});
return Scaffold(
body: ImageReader(
ImageReaderStruct( ImageReaderStruct(
images: pictures images: pictures
.map((e) => ReaderImageInfo(e.fileServer, e.path, e.localPath, .map((e) => ReaderImageInfo(e.fileServer, e.path, e.localPath,
@ -194,10 +231,15 @@ class _DownloadReaderScreenState extends State<DownloadReaderScreen> {
initPosition: widget.initPicturePosition, initPosition: widget.initPicturePosition,
pagerType: widget.pagerType, pagerType: widget.pagerType,
pagerDirection: widget.pagerDirection, pagerDirection: widget.pagerDirection,
epOrder: _ep.epOrder,
epNameMap: epNameMap,
comicTitle: widget.comicInfo.title,
onSelectDirection: _onSelectDirection,
onSelectReaderType: _onSelectReaderType,
),
), ),
); );
}, },
),
); );
} }

View File

@ -146,19 +146,21 @@ class _ComicInfoCard extends State<ComicInfoCard> {
iconMargin, iconMargin,
] ]
: []), : []),
info.epsCount > 0 ...(info.epsCount > 0
? Row( ? [
children: [ Text.rich(TextSpan(children: [
iconPage, WidgetSpan(child: iconPage),
iconSpacing, WidgetSpan(child: iconSpacing),
Text( WidgetSpan(child: Text(
"${info.epsCount}E / ${info.pagesCount}P", "${info.epsCount}E / ${info.pagesCount}P",
style: countLabelStyle, style: countLabelStyle,
strutStyle: iconLabelStrutStyle, strutStyle: iconLabelStrutStyle,
), softWrap: false,
], )),
) WidgetSpan(child: iconMargin),
: Container(), ])),
]
: []),
iconMargin, iconMargin,
], ],
), ),

View File

@ -113,6 +113,11 @@ class ImageReaderStruct {
final int? initPosition; final int? initPosition;
final ReaderType pagerType; final ReaderType pagerType;
final ReaderDirection pagerDirection; final ReaderDirection pagerDirection;
final Map<int, String> epNameMap;
final int epOrder;
final String comicTitle;
final FutureOr<dynamic> Function() onSelectDirection;
final FutureOr<dynamic> Function() onSelectReaderType;
const ImageReaderStruct({ const ImageReaderStruct({
required this.images, required this.images,
@ -125,6 +130,11 @@ class ImageReaderStruct {
this.initPosition, this.initPosition,
required this.pagerType, required this.pagerType,
required this.pagerDirection, required this.pagerDirection,
required this.epNameMap,
required this.epOrder,
required this.comicTitle,
required this.onSelectDirection,
required this.onSelectReaderType,
}); });
} }
@ -170,16 +180,6 @@ abstract class _ImageReaderState extends State<ImageReader> {
super.dispose(); super.dispose();
} }
@override
Widget build(BuildContext context) {
return Stack(
children: [
_buildViewer(),
_buildControllerAndBar(),
],
);
}
void _onPageControl(_ReaderControllerEventArgs? args) { void _onPageControl(_ReaderControllerEventArgs? args) {
if (args != null) { if (args != null) {
var event = args.key; var event = args.key;
@ -223,19 +223,63 @@ abstract class _ImageReaderState extends State<ImageReader> {
} }
} }
Widget _buildControllerAndBar() { @override
if (widget.struct.fullScreen) { Widget build(BuildContext context) {
return _buildController(); switch (currentFullScreenAction()) {
} case FullScreenAction.CONTROLLER:
return SafeArea( return Stack(
child: Column(
children: [ children: [
Expanded( _buildViewerAndBar(),
child: _buildController(hiddenFullScreen: true), _buildFullScreenController(),
],
);
case FullScreenAction.TOUCH_ONCE:
return _buildTouchOnceController(_buildViewerAndBar());
case FullScreenAction.THREE_AREA:
return Stack(
children: [
_buildViewerAndBar(),
_buildThreeAreaController(),
],
);
default:
return Container();
}
}
Widget _buildViewerAndBar() {
return Stack(
children: [
_buildViewer(),
widget.struct.fullScreen ? Container() : _buildBar(),
],
);
}
Widget _buildBar() {
return Column(
children: [
AppBar(
title: Text(
"${widget.struct.epNameMap[widget.struct.epOrder] ?? ""} - ${widget.struct.comicTitle}"),
backgroundColor: readerAppbarColor2,
actions: [
IconButton(
onPressed: widget.struct.onSelectDirection,
icon: Icon(Icons.grid_goldenratio),
), ),
IconButton(
onPressed: widget.struct.onSelectReaderType,
icon: Icon(Icons.view_day_outlined),
),
],
),
Expanded(child: Container()),
Container( Container(
height: 45,
color: readerAppbarColor2, color: readerAppbarColor2,
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Container(width: 15), Container(width: 15),
IconButton( IconButton(
@ -249,7 +293,7 @@ abstract class _ImageReaderState extends State<ImageReader> {
Expanded( Expanded(
child: Column( child: Column(
children: [ children: [
Container(height: 3), Expanded(child: Container()),
Container( Container(
height: 25, height: 25,
child: FlutterSlider( child: FlutterSlider(
@ -302,7 +346,7 @@ abstract class _ImageReaderState extends State<ImageReader> {
}), }),
), ),
), ),
Container(height: 3), Expanded(child: Container()),
], ],
), ),
), ),
@ -317,29 +361,15 @@ abstract class _ImageReaderState extends State<ImageReader> {
Container(width: 15), Container(width: 15),
], ],
), ),
), )
], ],
),
); );
} }
Widget _buildController({bool hiddenFullScreen = false}) {
switch (currentFullScreenAction()) {
case FullScreenAction.CONTROLLER:
if (hiddenFullScreen) {
return Container();
}
return _buildFullScreenController();
case FullScreenAction.TOUCH_ONCE:
return _buildTouchOnceController();
case FullScreenAction.THREE_AREA:
return _buildThreeAreaController();
default:
return Container();
}
}
Widget _buildFullScreenController() { Widget _buildFullScreenController() {
if (!widget.struct.fullScreen) {
return Container();
}
return Align( return Align(
alignment: Alignment.bottomLeft, alignment: Alignment.bottomLeft,
child: Material( child: Material(
@ -371,13 +401,13 @@ abstract class _ImageReaderState extends State<ImageReader> {
); );
} }
Widget _buildTouchOnceController() { Widget _buildTouchOnceController(Widget viewerAndBar) {
return GestureDetector( return GestureDetector(
behavior: HitTestBehavior.translucent, behavior: HitTestBehavior.translucent,
onTap: () { onTap: () {
widget.struct.onFullScreenChange(!widget.struct.fullScreen); widget.struct.onFullScreenChange(!widget.struct.fullScreen);
}, },
child: Container(), child: viewerAndBar,
); );
} }
@ -582,13 +612,13 @@ class _WebToonReaderState extends _ImageReaderState {
reverse: reverse:
widget.struct.pagerDirection == ReaderDirection.RIGHT_TO_LEFT, widget.struct.pagerDirection == ReaderDirection.RIGHT_TO_LEFT,
padding: EdgeInsets.only( padding: EdgeInsets.only(
top: widget.struct.fullScreen ? (scaffold.appBarMaxHeight ?? 0) : 0, top: (scaffold.appBarMaxHeight ?? 0),
bottom: bottom:
widget.struct.pagerDirection == ReaderDirection.TOP_TO_BOTTOM widget.struct.pagerDirection == ReaderDirection.TOP_TO_BOTTOM
? 130 ? 130
: (widget.struct.fullScreen : (widget.struct.fullScreen
? (scaffold.appBarMaxHeight ?? 0) ? (scaffold.appBarMaxHeight ?? 0)
: 0), : 45),
), ),
itemScrollController: _itemScrollController, itemScrollController: _itemScrollController,
itemPositionsListener: _itemPositionsListener, itemPositionsListener: _itemPositionsListener,
@ -759,8 +789,8 @@ class _GalleryReaderState extends _ImageReaderState {
@override @override
void initState() { void initState() {
_pageController = PageController(initialPage: super._startIndex);
super.initState(); super.initState();
_pageController = PageController(initialPage: super._startIndex);
} }
@override @override
@ -792,7 +822,7 @@ class _GalleryReaderState extends _ImageReaderState {
} }
Widget _buildViewer() { Widget _buildViewer() {
var gallery = PhotoViewGallery.builder( Widget gallery = PhotoViewGallery.builder(
scrollDirection: scrollDirection:
widget.struct.pagerDirection == ReaderDirection.TOP_TO_BOTTOM widget.struct.pagerDirection == ReaderDirection.TOP_TO_BOTTOM
? Axis.vertical ? Axis.vertical
@ -838,7 +868,7 @@ class _GalleryReaderState extends _ImageReaderState {
); );
}, },
); );
return GestureDetector( gallery = GestureDetector(
child: gallery, child: gallery,
onLongPress: () async { onLongPress: () async {
if (_current >= 0 && _current < widget.struct.images.length) { if (_current >= 0 && _current < widget.struct.images.length) {
@ -875,10 +905,15 @@ class _GalleryReaderState extends _ImageReaderState {
} }
}, },
); );
} var scaffold = Scaffold.of(context);
gallery = Container(
Widget _buildNextEpButton() { padding: EdgeInsets.only(
return Container(); top: widget.struct.fullScreen ? 0 : (scaffold.appBarMaxHeight ?? 0),
bottom: widget.struct.fullScreen ? 0 : 45,
),
child: gallery,
);
return gallery;
} }
} }