Skip to content

Commit

Permalink
🚀 more novelreader type
Browse files Browse the repository at this point in the history
  • Loading branch information
niuhuan committed Nov 29, 2022
1 parent 35c7055 commit 3f12a34
Show file tree
Hide file tree
Showing 10 changed files with 964 additions and 78 deletions.
24 changes: 7 additions & 17 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,16 @@ jobs:
config:
- target: linux
host: ubuntu-latest
flutter_version: '3.3.8'
flutter_version: '3.3.9'
- target: windows
host: windows-latest
flutter_version: '3.3.8'
flutter_version: '3.3.9'
- target: macos
host: macos-11
flutter_version: '3.3.8'
flutter_version: '3.3.9'
- target: ios
host: macos-11
flutter_version: '3.3.8'
- target: ios
host: macos-11
flutter_version: '2.10.5'
flutter_version: '3.3.9'
- target: android-arm32
host: ubuntu-latest
flutter_version: '2.10.5'
Expand All @@ -90,13 +87,13 @@ jobs:
flutter_version: '2.10.5'
- target: android-arm32
host: ubuntu-latest
flutter_version: '3.3.8'
flutter_version: '3.3.9'
- target: android-arm64
host: ubuntu-latest
flutter_version: '3.3.8'
flutter_version: '3.3.9'
- target: android-x86_64
host: ubuntu-latest
flutter_version: '3.3.8'
flutter_version: '3.3.9'

runs-on: ${{ matrix.config.host }}

Expand Down Expand Up @@ -190,13 +187,6 @@ jobs:
run: |
dart pub global activate ffigen 4.1.3
- name: Install LLVM and Clang (macos/ios)
if: steps.check_asset.outputs.skip_build != 'true' && matrix.config.target == 'ios' && startsWith(matrix.config.flutter_version, '2')
uses: KyleMayes/install-llvm-action@v1
with:
version: ${{ env.LLVM_VERSION }}
cached: ${{ steps.cache-llvm.outputs.cache-hit }}

- name: Install LLVM and Clang (Linux/Android)
if: steps.check_asset.outputs.skip_build != 'true' && ( matrix.config.target == 'android-arm32' || matrix.config.target == 'android-arm64' || matrix.config.target == 'android-x86_64' || matrix.config.target == 'linux' )
run: |
Expand Down
2 changes: 1 addition & 1 deletion ci/version.code.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.1.12
v0.1.13
5 changes: 4 additions & 1 deletion ci/version.info.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
计划
- [x] 下载? / 小说翻页? / 高清画质?
- [x] 下载? / / 高清画质?

v0.1.13
- [x] 小说左右翻页

v0.1.11
- [x] 修复登录, 以及登录造成的开启很慢等
68 changes: 68 additions & 0 deletions lib/configs/novel_reader_type.dart
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)),
);
},
);
}
3 changes: 3 additions & 0 deletions lib/screens/about_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:daisy/configs/themes.dart';
import 'package:daisy/configs/versions.dart';
import 'package:flutter/material.dart';

import '../configs/novel_reader_type.dart';
import '../cross.dart';
import 'components/badged.dart';
import 'login_screen.dart';
Expand Down Expand Up @@ -69,6 +70,8 @@ class _AboutState extends State<AboutScreen> {
const Divider(),
androidDisplayModeSetting(),
const Divider(),
novelReaderTypeSetting(context),
const Divider(),
],
),
);
Expand Down
208 changes: 208 additions & 0 deletions lib/screens/components/novel_fan_component.dart
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();
}
}
2 changes: 2 additions & 0 deletions lib/screens/init_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:daisy/configs/android_version.dart';
import 'package:daisy/configs/login.dart';
import 'package:daisy/configs/novel_background_color.dart';
import 'package:daisy/configs/novel_font_color.dart';
import 'package:daisy/configs/novel_reader_type.dart';
import 'package:daisy/configs/reader_controller_type.dart';
import 'package:daisy/configs/reader_direction.dart';
import 'package:daisy/configs/reader_slider_position.dart';
Expand Down Expand Up @@ -35,6 +36,7 @@ class _InitScreenState extends State<InitScreen> {
await initReaderDirection();
await initReaderSliderPosition();
await initReaderType();
await initNovelReaderType();
await initNovelFontSize();
await initNovelFontColor();
await initNovelBackgroundColor();
Expand Down
Loading

0 comments on commit 3f12a34

Please sign in to comment.