-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
964 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v0.1.12 | ||
v0.1.13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
计划 | ||
- [x] 下载? / 小说翻页? / 高清画质? | ||
- [x] 下载? / / 高清画质? | ||
|
||
v0.1.13 | ||
- [x] 小说左右翻页 | ||
|
||
v0.1.11 | ||
- [x] 修复登录, 以及登录造成的开启很慢等 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import 'package:daisy/configs/reader_controller_type.dart'; | ||
import 'package:daisy/ffi.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../commons.dart'; | ||
|
||
enum NovelReaderType { | ||
move, | ||
html, | ||
} | ||
|
||
const _propertyName = "NovelReaderType"; | ||
late NovelReaderType _NovelReaderType; | ||
|
||
Future initNovelReaderType() async { | ||
_NovelReaderType = _fromString(await native.loadProperty(k: _propertyName)); | ||
} | ||
|
||
NovelReaderType _fromString(String valueForm) { | ||
for (var value in NovelReaderType.values) { | ||
if (value.toString() == valueForm) { | ||
return value; | ||
} | ||
} | ||
return NovelReaderType.values.first; | ||
} | ||
|
||
NovelReaderType get currentNovelReaderType => _NovelReaderType; | ||
|
||
String novelReaderTypeName(NovelReaderType direction, BuildContext context) { | ||
switch (direction) { | ||
case NovelReaderType.move: | ||
return "平移"; | ||
case NovelReaderType.html: | ||
return "网页"; | ||
} | ||
} | ||
|
||
Future chooseNovelReaderType(BuildContext context) async { | ||
final Map<String, NovelReaderType> map = {}; | ||
for (var element in NovelReaderType.values) { | ||
map[novelReaderTypeName(element, context)] = element; | ||
} | ||
final newNovelReaderType = await chooseMapDialog( | ||
context, | ||
title: "请选择小说阅读器", | ||
values: map, | ||
); | ||
if (newNovelReaderType != null) { | ||
await native.saveProperty(k: _propertyName, v: "$newNovelReaderType"); | ||
_NovelReaderType = newNovelReaderType; | ||
} | ||
} | ||
|
||
Widget novelReaderTypeSetting(BuildContext context) { | ||
return StatefulBuilder( | ||
builder: (BuildContext context, void Function(void Function()) setState) { | ||
return ListTile( | ||
onTap: () async { | ||
await chooseNovelReaderType(context); | ||
setState(() {}); | ||
}, | ||
title: const Text("小说阅读器类型"), | ||
subtitle: Text(novelReaderTypeName(_NovelReaderType, context)), | ||
); | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class NovelFanComponentController { | ||
_NovelFanComponentState? _state; | ||
|
||
toPrevious() { | ||
_state?._toPrevious(); | ||
} | ||
|
||
toNext() { | ||
_state?._toNext(); | ||
} | ||
} | ||
|
||
class NovelFanComponent extends StatefulWidget { | ||
final Widget? previous; | ||
final Widget? next; | ||
final Widget current; | ||
final void Function()? onNextSetState; | ||
final void Function()? onPreviousSetState; | ||
final NovelFanComponentController? controller; | ||
|
||
const NovelFanComponent({ | ||
this.previous, | ||
this.onPreviousSetState, | ||
this.next, | ||
this.onNextSetState, | ||
this.controller, | ||
required this.current, | ||
Key? key, | ||
}) : super(key: key); | ||
|
||
@override | ||
State<StatefulWidget> createState() => _NovelFanComponentState(); | ||
} | ||
|
||
class _NovelFanComponentState extends State<NovelFanComponent> | ||
with SingleTickerProviderStateMixin { | ||
late AnimationController animationController = | ||
AnimationController(vsync: this); | ||
|
||
@override | ||
void initState() { | ||
animationController.addListener(_onAnimat); | ||
widget.controller?._state = this; | ||
super.initState(); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
animationController.removeListener(_onAnimat); | ||
animationController.dispose(); | ||
widget.controller?._state = null; | ||
super.dispose(); | ||
} | ||
|
||
void _onAnimat() { | ||
moved = movedAnimeStar + | ||
(movedAnimeEnd - movedAnimeStar) * animationController.value; | ||
setState(() {}); | ||
} | ||
|
||
int touchState = 0; // 0未触摸 | ||
late Offset prePosition; | ||
late int direction; | ||
late int lastDirection; | ||
late double moved; | ||
|
||
late double movedAnimeStar; | ||
late double movedAnimeEnd; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return GestureDetector( | ||
onPanStart: (detail) { | ||
if (animationController.isAnimating) { | ||
return; | ||
} | ||
touchState = 1; | ||
prePosition = detail.globalPosition; | ||
moved = 0; | ||
}, | ||
onPanUpdate: (detail) { | ||
if (detail.globalPosition.dx != prePosition.dx) { | ||
if (touchState == 1) { | ||
touchState = 2; | ||
direction = detail.globalPosition.dx < prePosition.dx ? -1 : 1; | ||
lastDirection = detail.globalPosition.dx < prePosition.dx ? -1 : 1; | ||
moved += detail.globalPosition.dx - prePosition.dx; | ||
if (direction < 0 && widget.next == null) { | ||
// 直到下次touchDown不响应 | ||
touchState = 0; | ||
} else if (direction > 0 && widget.previous == null) { | ||
// 直到下次touchDown不响应 | ||
touchState = 0; | ||
} | ||
} else if (touchState == 2) { | ||
lastDirection = detail.globalPosition.dx < prePosition.dx ? -1 : 1; | ||
moved += detail.globalPosition.dx - prePosition.dx; | ||
} | ||
} | ||
prePosition = detail.globalPosition; | ||
setState(() {}); | ||
}, | ||
onPanEnd: (detail) async { | ||
if (touchState == 2) { | ||
// 滑动过 | ||
if (direction == lastDirection) { | ||
movedAnimeStar = moved; | ||
movedAnimeEnd = direction * MediaQuery.of(context).size.width; | ||
animationController.duration = const Duration(milliseconds: 240); | ||
await animationController.forward(from: 0); | ||
touchState = 0; | ||
if (direction < 0) { | ||
if (widget.onNextSetState != null) { | ||
widget.onNextSetState!(); | ||
} | ||
} | ||
if (direction > 0) { | ||
if (widget.onPreviousSetState != null) { | ||
widget.onPreviousSetState!(); | ||
} | ||
} | ||
// 滑动 | ||
} else { | ||
// 滑回 | ||
movedAnimeStar = moved; | ||
movedAnimeEnd = 0; | ||
animationController.duration = const Duration(milliseconds: 240); | ||
await animationController.forward(from: 0); | ||
} | ||
} | ||
}, | ||
child: Stack(children: [ | ||
_previous(), | ||
_current(), | ||
_next(), | ||
]), | ||
); | ||
} | ||
|
||
void _toPrevious() async { | ||
if (animationController.isAnimating) { | ||
return; | ||
} | ||
if (widget.previous == null) { | ||
return; | ||
} | ||
touchState = 2; | ||
direction = 1; | ||
movedAnimeStar = 0; | ||
movedAnimeEnd = direction * MediaQuery.of(context).size.width; | ||
animationController.duration = const Duration(milliseconds: 140); | ||
await animationController.forward(from: 0); | ||
touchState = 0; | ||
widget.onPreviousSetState!(); | ||
} | ||
|
||
void _toNext() async { | ||
if (animationController.isAnimating) { | ||
return; | ||
} | ||
if (widget.next == null) { | ||
return; | ||
} | ||
touchState = 2; | ||
direction = -1; | ||
movedAnimeStar = 0; | ||
movedAnimeEnd = direction * MediaQuery.of(context).size.width; | ||
animationController.duration = const Duration(milliseconds: 140); | ||
await animationController.forward(from: 0); | ||
touchState = 0; | ||
widget.onNextSetState!(); | ||
} | ||
|
||
Widget _previous() { | ||
if (widget.previous != null) { | ||
return widget.previous!; | ||
} | ||
return Container(); | ||
} | ||
|
||
Widget _current() { | ||
if (widget.previous != null && touchState > 0 && direction > 0) { | ||
return Transform.translate( | ||
offset: Offset( | ||
moved, | ||
0, | ||
), | ||
child: widget.current, | ||
); | ||
} | ||
return widget.current; | ||
} | ||
|
||
Widget _next() { | ||
if (widget.next != null && touchState > 0 && direction < 0) { | ||
return Transform.translate( | ||
offset: Offset( | ||
MediaQuery.of(context).size.width + moved, | ||
0, | ||
), | ||
child: widget.next, | ||
); | ||
} | ||
return Container(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.