Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

add danmaku settings

Prediditb824cffb610d
diff --git a/lib/bean/settings/settings.dart b/lib/bean/settings/settings.dart
new file mode 100644
index 00000000..dc178ceb
--- /dev/null
+++ b/lib/bean/settings/settings.dart
@@ -0,0 +1,144 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
+import 'package:hive/hive.dart';
+import 'package:kazumi/utils/storage.dart';
+
+class SetSwitchItem extends StatefulWidget {
+ final String? title;
+ final String? subTitle;
+ final String? setKey;
+ final bool? defaultVal;
+ final Function? callFn;
+ final bool? needReboot;
+
+ const SetSwitchItem({
+ this.title,
+ this.subTitle,
+ this.setKey,
+ this.defaultVal,
+ this.callFn,
+ this.needReboot,
+ Key? key,
+ }) : super(key: key);
+
+ @override
+ State<SetSwitchItem> createState() => _SetSwitchItemState();
+}
+
+class _SetSwitchItemState extends State<SetSwitchItem> {
+ // ignore: non_constant_identifier_names
+ Box Setting = GStorage.setting;
+ late bool val;
+
+ @override
+ void initState() {
+ super.initState();
+ val = Setting.get(widget.setKey, defaultValue: widget.defaultVal ?? false);
+ }
+
+ void switchChange(value) async {
+ val = value ?? !val;
+ await Setting.put(widget.setKey, val);
+ if (widget.callFn != null) {
+ widget.callFn!.call(val);
+ }
+ if (widget.needReboot != null && widget.needReboot!) {
+ SmartDialog.showToast('重启生效');
+ }
+ setState(() {});
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ TextStyle titleStyle = Theme.of(context).textTheme.titleMedium!;
+ TextStyle subTitleStyle = Theme.of(context)
+ .textTheme
+ .labelMedium!
+ .copyWith(color: Theme.of(context).colorScheme.outline);
+ return ListTile(
+ enableFeedback: true,
+ onTap: () => switchChange(null),
+ title: Text(widget.title!, style: titleStyle),
+ subtitle: widget.subTitle != null
+ ? Text(widget.subTitle!, style: subTitleStyle)
+ : null,
+ trailing: Transform.scale(
+ alignment: Alignment.centerRight, // 缩放Switch的大小后保持右侧对齐, 避免右侧空隙过大
+ scale: 0.8,
+ child: Switch(
+ value: val,
+ onChanged: (val) => switchChange(val),
+ ),
+ ),
+ );
+ }
+}
+
+class SelectDialog<T> extends StatefulWidget {
+ final T value;
+ final String title;
+ final List<dynamic> values;
+ const SelectDialog(
+ {super.key,
+ required this.value,
+ required this.values,
+ required this.title});
+
+ @override
+ _SelectDialogState<T> createState() => _SelectDialogState<T>();
+}
+
+class _SelectDialogState<T> extends State<SelectDialog<T>> {
+ late T _tempValue;
+
+ @override
+ void initState() {
+ super.initState();
+ _tempValue = widget.value;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ TextStyle titleStyle = Theme.of(context).textTheme.titleMedium!;
+
+ return AlertDialog(
+ title: Text(widget.title),
+ contentPadding: const EdgeInsets.fromLTRB(0, 12, 0, 12),
+ content: StatefulBuilder(builder: (context, StateSetter setState) {
+ return SingleChildScrollView(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ for (var i in widget.values) ...[
+ RadioListTile(
+ value: i['value'],
+ title: Text(i['title'], style: titleStyle),
+ groupValue: _tempValue,
+ onChanged: (value) {
+ setState(() {
+ _tempValue = value as T;
+ });
+ },
+ ),
+ ]
+ ],
+ ),
+ );
+ }),
+ actions: [
+ TextButton(
+ onPressed: () => Navigator.pop(context),
+ child: Text(
+ '取消',
+ style: TextStyle(color: Theme.of(context).colorScheme.outline),
+ ),
+ ),
+ TextButton(
+ onPressed: () => Navigator.pop(context, _tempValue),
+ child: const Text('确定'),
+ )
+ ],
+ );
+ }
+}
+
diff --git a/lib/pages/my/my_module.dart b/lib/pages/my/my_module.dart
index 5ce8adb0..34833c91 100644
--- a/lib/pages/my/my_module.dart
+++ b/lib/pages/my/my_module.dart
@@ -1,3 +1,5 @@
+import 'dart:io';
+import 'package:kazumi/pages/settings/danmaku_settings.dart';
import 'package:kazumi/pages/my/my_page.dart';
import 'package:kazumi/pages/about/about_module.dart';
import 'package:kazumi/pages/plugin_editor/plugin_module.dart';
@@ -8,6 +10,11 @@ class MyModule extends Module {
@override
void routes(r) {
r.child("/", child: (_) => const MyPage());
+ r.child("/danmaku",
+ child: (_) => const DanmakuSettingsPage(),
+ transition: Platform.isWindows || Platform.isLinux || Platform.isMacOS
+ ? TransitionType.noTransition
+ : TransitionType.leftToRight);
r.module("/about", module: AboutModule());
r.module("/plugin", module: PluginModule());
r.module("/history", module: HistoryModule());
diff --git a/lib/pages/my/my_page.dart b/lib/pages/my/my_page.dart
index 9d458e66..45780051 100644
--- a/lib/pages/my/my_page.dart
+++ b/lib/pages/my/my_page.dart
@@ -30,6 +30,13 @@ class _MyPageState extends State<MyPage> {
dense: false,
title: const Text('规则管理'),
),
+ ListTile(
+ onTap: () async {
+ Modular.to.pushNamed('/tab/my/danmaku');
+ },
+ dense: false,
+ title: const Text('弹幕设置'),
+ ),
ListTile(
onTap: () {
Modular.to.pushNamed('/tab/my/about');
diff --git a/lib/pages/player/player_item.dart b/lib/pages/player/player_item.dart
index 50289f3a..ba6b82fc 100644
--- a/lib/pages/player/player_item.dart
+++ b/lib/pages/player/player_item.dart
@@ -21,6 +21,8 @@ import 'package:flutter_volume_controller/flutter_volume_controller.dart';
import 'package:kazumi/pages/history/history_controller.dart';
import 'package:kazumi/pages/info/info_controller.dart';
import 'package:kazumi/pages/favorite/favorite_controller.dart';
+import 'package:hive/hive.dart';
+import 'package:kazumi/utils/storage.dart';
import 'package:kazumi/bean/appbar/drag_to_move_bar.dart' as dtb;
class PlayerItem extends StatefulWidget {
@@ -31,12 +33,14 @@ class PlayerItem extends StatefulWidget {
}
class _PlayerItemState extends State<PlayerItem> with WindowListener {
+ Box setting = GStorage.setting;
final PlayerController playerController = Modular.get<PlayerController>();
final VideoPageController videoPageController =
Modular.get<VideoPageController>();
final HistoryController historyController = Modular.get<HistoryController>();
final InfoController infoController = Modular.get<InfoController>();
- final FavoriteController favoriteController = Modular.get<FavoriteController>();
+ final FavoriteController favoriteController =
+ Modular.get<FavoriteController>();
final FocusNode _focusNode = FocusNode();
late DanmakuController danmakuController;
late NavigationBarState navigationBarState;
@@ -244,14 +248,19 @@ class _PlayerItemState extends State<PlayerItem> with WindowListener {
Widget build(BuildContext context) {
// 弹幕设置
// bool _running = true;
- bool _border = true;
- double _opacity = 1.0;
+ bool _border = setting.get(SettingBoxKey.danmakuBorder, defaultValue: true);
+ double _opacity =
+ setting.get(SettingBoxKey.danmakuOpacity, defaultValue: 1.0);
double _duration = 8;
- double _fontSize = (Platform.isIOS || Platform.isAndroid) ? 16.0 : 25.0;
- double danmakuArea = 1.0;
- bool _hideTop = false;
- bool _hideBottom = false;
- bool _hideScroll = false;
+ double _fontSize = setting.get(SettingBoxKey.danmakuFontSize,
+ defaultValue: (Platform.isIOS || Platform.isAndroid) ? 16.0 : 25.0);
+ double danmakuArea =
+ setting.get(SettingBoxKey.danmakuArea, defaultValue: 1.0);
+ bool _hideTop = !setting.get(SettingBoxKey.danmakuTop, defaultValue: true);
+ bool _hideBottom =
+ !setting.get(SettingBoxKey.danmakuBottom, defaultValue: true);
+ bool _hideScroll =
+ !setting.get(SettingBoxKey.danmakuScroll, defaultValue: true);
isFavorite = favoriteController.isFavorite(infoController.bangumiItem);
@@ -688,51 +697,32 @@ class _PlayerItemState extends State<PlayerItem> with WindowListener {
),
// 追番
IconButton(
- icon: Icon(isFavorite
- ? Icons.favorite
- : Icons.favorite_outline, color: Colors.white),
+ icon: Icon(
+ isFavorite
+ ? Icons.favorite
+ : Icons.favorite_outline,
+ color: Colors.white),
onPressed: () async {
if (isFavorite) {
favoriteController
.deleteFavorite(
- infoController.bangumiItem);
- SmartDialog.showToast('取消追番成功');
+ infoController
+ .bangumiItem);
+ SmartDialog.showToast(
+ '取消追番成功');
} else {
favoriteController
.addFavorite(
- infoController.bangumiItem);
- SmartDialog.showToast('自己追的番要好好看完哦');
+ infoController
+ .bangumiItem);
+ SmartDialog.showToast(
+ '自己追的番要好好看完哦');
}
setState(() {
isFavorite = !isFavorite;
});
},
),
- // 追番
- // IconButton(
- // icon: (videoController.follow)
- // ? Icon(Icons.favorite,
- // color: Colors.white)
- // : Icon(Icons.favorite_border,
- // color: Colors.white),
- // onPressed: () {
- // popularController.updateFollow(
- // videoController.link,
- // !(videoController.follow));
- // videoController.follow =
- // !videoController.follow;
- // SmartDialog.showToast(
- // videoController.follow
- // ? '自己追的番要好好看完哦'
- // : '取消追番成功',
- // displayType:
- // SmartToastType.last);
- // },
- // splashColor: Theme.of(context)
- // .colorScheme
- // .tertiary
- // .withOpacity(0.5),
- // ),
],
),
)
diff --git a/lib/pages/settings/danmaku_settings.dart b/lib/pages/settings/danmaku_settings.dart
new file mode 100644
index 00000000..61327dcf
--- /dev/null
+++ b/lib/pages/settings/danmaku_settings.dart
@@ -0,0 +1,322 @@
+import 'dart:io';
+import 'package:flutter/material.dart';
+import 'package:flutter_modular/flutter_modular.dart';
+import 'package:kazumi/bean/settings/settings.dart';
+import 'package:provider/provider.dart';
+import 'package:kazumi/pages/menu/menu.dart';
+import 'package:kazumi/utils/storage.dart';
+import 'package:hive/hive.dart';
+import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
+import 'package:kazumi/pages/popular/popular_controller.dart';
+import 'package:kazumi/bean/appbar/sys_app_bar.dart';
+
+class DanmakuSettingsPage extends StatefulWidget {
+ const DanmakuSettingsPage({super.key});
+
+ @override
+ State<DanmakuSettingsPage> createState() => _DanmakuSettingsPageState();
+}
+
+class _DanmakuSettingsPageState extends State<DanmakuSettingsPage> {
+ late NavigationBarState navigationBarState;
+ Box setting = GStorage.setting;
+ late dynamic defaultDanmakuArea;
+ late dynamic defaultDanmakuOpacity;
+ late dynamic defaultDanmakuFontSize;
+ final PopularController popularController = Modular.get<PopularController>();
+
+ @override
+ void initState() {
+ super.initState();
+ navigationBarState =
+ Provider.of<NavigationBarState>(context, listen: false);
+ defaultDanmakuArea =
+ setting.get(SettingBoxKey.danmakuArea, defaultValue: 1.0);
+ defaultDanmakuOpacity = setting.get(SettingBoxKey.danmakuOpacity, defaultValue: 1.0);
+ defaultDanmakuFontSize = setting.get(SettingBoxKey.danmakuFontSize, defaultValue: (Platform.isIOS || Platform.isAndroid) ? 16.0 : 25.0);
+ }
+
+ void onBackPressed(BuildContext context) {
+ navigationBarState.showNavigate();
+ Navigator.of(context).pop();
+ }
+
+ void updateDanmakuArea(double i) async {
+ await setting.put(SettingBoxKey.danmakuArea, i);
+ setState(() {
+ defaultDanmakuArea = i;
+ });
+ }
+
+ void updateDanmakuOpacity(double i) async {
+ await setting.put(SettingBoxKey.danmakuOpacity, i);
+ setState(() {
+ defaultDanmakuOpacity = i;
+ });
+ }
+
+ void updateDanmakuFontSize(double i) async {
+ await setting.put(SettingBoxKey.danmakuFontSize, i);
+ setState(() {
+ defaultDanmakuFontSize = i;
+ });
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ navigationBarState.hideNavigate();
+ });
+ return PopScope(
+ canPop: false,
+ onPopInvoked: (bool didPop) async {
+ onBackPressed(context);
+ },
+ child: Scaffold(
+ appBar: const SysAppBar(title: Text('弹幕设置')),
+ body: Column(
+ children: [
+ const InkWell(
+ child: SetSwitchItem(
+ title: '弹幕描边',
+ setKey: SettingBoxKey.danmakuBorder,
+ defaultVal: true,
+ ),
+ ),
+ ListTile(
+ onTap: () async {
+ final List<double> danFontList = [
+ 10.0,
+ 11.0,
+ 12.0,
+ 13.0,
+ 14.0,
+ 15.0,
+ 16.0,
+ 17.0,
+ 18.0,
+ 19.0,
+ 20.0,
+ 21.0,
+ 22.0,
+ 23.0,
+ 24.0,
+ 25.0,
+ 26.0,
+ 27.0,
+ 28.0,
+ 29.0,
+ 30.0,
+ 31.0,
+ 32.0,
+ ];
+ SmartDialog.show(
+ useAnimation: false,
+ builder: (context) {
+ return AlertDialog(
+ title: const Text('字体大小'),
+ content: StatefulBuilder(builder:
+ (BuildContext context, StateSetter setState) {
+ return Wrap(
+ spacing: 8,
+ runSpacing: 2,
+ children: [
+ for (final double i in danFontList) ...<Widget>[
+ if (i == defaultDanmakuFontSize) ...<Widget>[
+ FilledButton(
+ onPressed: () async {
+ updateDanmakuFontSize(i);
+ SmartDialog.dismiss();
+ },
+ child: Text(i.toString()),
+ ),
+ ] else ...[
+ FilledButton.tonal(
+ onPressed: () async {
+ updateDanmakuFontSize(i);
+ SmartDialog.dismiss();
+ },
+ child: Text(i.toString()),
+ ),
+ ]
+ ]
+ ],
+ );
+ }),
+ actions: <Widget>[
+ TextButton(
+ onPressed: () => SmartDialog.dismiss(),
+ child: Text(
+ '取消',
+ style: TextStyle(
+ color: Theme.of(context).colorScheme.outline),
+ ),
+ ),
+ TextButton(
+ onPressed: () async {
+ updateDanmakuFontSize((Platform.isIOS || Platform.isAndroid) ? 16.0 : 25.0);
+ SmartDialog.dismiss();
+ },
+ child: const Text('默认设置'),
+ ),
+ ],
+ );
+ });
+ },
+ dense: false,
+ title: const Text('字体大小'),
+ subtitle: Text('$defaultDanmakuFontSize',
+ style: Theme.of(context)
+ .textTheme
+ .labelMedium!
+ .copyWith(color: Theme.of(context).colorScheme.outline)),
+ ),
+ ListTile(
+ onTap: () async {
+ final List<double> danOpacityList = [
+ 0.1,
+ 0.2,
+ 0.3,
+ 0.4,
+ 0.5,
+ 0.6,
+ 0.7,
+ 0.8,
+ 0.9,
+ 1.0,
+ ];
+ SmartDialog.show(
+ useAnimation: false,
+ builder: (context) {
+ return AlertDialog(
+ title: const Text('弹幕不透明度'),
+ content: StatefulBuilder(builder:
+ (BuildContext context, StateSetter setState) {
+ return Wrap(
+ spacing: 8,
+ runSpacing: 2,
+ children: [
+ for (final double i in danOpacityList) ...<Widget>[
+ if (i == defaultDanmakuOpacity) ...<Widget>[
+ FilledButton(
+ onPressed: () async {
+ updateDanmakuOpacity(i);
+ SmartDialog.dismiss();
+ },
+ child: Text(i.toString()),
+ ),
+ ] else ...[
+ FilledButton.tonal(
+ onPressed: () async {
+ updateDanmakuOpacity(i);
+ SmartDialog.dismiss();
+ },
+ child: Text(i.toString()),
+ ),
+ ]
+ ]
+ ],
+ );
+ }),
+ actions: <Widget>[
+ TextButton(
+ onPressed: () => SmartDialog.dismiss(),
+ child: Text(
+ '取消',
+ style: TextStyle(
+ color: Theme.of(context).colorScheme.outline),
+ ),
+ ),
+ TextButton(
+ onPressed: () async {
+ updateDanmakuOpacity(1.0);
+ SmartDialog.dismiss();
+ },
+ child: const Text('默认设置'),
+ ),
+ ],
+ );
+ });
+ },
+ dense: false,
+ title: const Text('弹幕不透明度'),
+ subtitle: Text('$defaultDanmakuOpacity',
+ style: Theme.of(context)
+ .textTheme
+ .labelMedium!
+ .copyWith(color: Theme.of(context).colorScheme.outline)),
+ ),
+ ListTile(
+ onTap: () async {
+ final List<double> danAreaList = [
+ 0.25,
+ 0.5,
+ 1.0,
+ ];
+ SmartDialog.show(
+ useAnimation: false,
+ builder: (context) {
+ return AlertDialog(
+ title: const Text('弹幕区域'),
+ content: StatefulBuilder(builder:
+ (BuildContext context, StateSetter setState) {
+ return Wrap(
+ spacing: 8,
+ runSpacing: 2,
+ children: [
+ for (final double i in danAreaList) ...<Widget>[
+ if (i == defaultDanmakuArea) ...<Widget>[
+ FilledButton(
+ onPressed: () async {
+ updateDanmakuArea(i);
+ SmartDialog.dismiss();
+ },
+ child: Text(i.toString()),
+ ),
+ ] else ...[
+ FilledButton.tonal(
+ onPressed: () async {
+ updateDanmakuArea(i);
+ SmartDialog.dismiss();
+ },
+ child: Text(i.toString()),
+ ),
+ ]
+ ]
+ ],
+ );
+ }),
+ actions: <Widget>[
+ TextButton(
+ onPressed: () => SmartDialog.dismiss(),
+ child: Text(
+ '取消',
+ style: TextStyle(
+ color: Theme.of(context).colorScheme.outline),
+ ),
+ ),
+ TextButton(
+ onPressed: () async {
+ updateDanmakuArea(1.0);
+ SmartDialog.dismiss();
+ },
+ child: const Text('默认设置'),
+ ),
+ ],
+ );
+ });
+ },
+ dense: false,
+ title: const Text('弹幕区域'),
+ subtitle: Text('占据 $defaultDanmakuArea 屏幕',
+ style: Theme.of(context)
+ .textTheme
+ .labelMedium!
+ .copyWith(color: Theme.of(context).colorScheme.outline)),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
diff --git a/lib/request/bangumi.dart b/lib/request/bangumi.dart
index 0ad23fac..d50778bf 100644
--- a/lib/request/bangumi.dart
+++ b/lib/request/bangumi.dart
@@ -69,7 +69,7 @@ class BangumiHTTP {
// Bangumi API 文档要求的UA格式
var httpHeaders = {
'user-agent':
- 'Predidit/Kazumi/0.0.1 (Android) (https://github.com/Predidit/Kazumi)',
+ 'Predidit/Kazumi/${Api.version} (Android) (https://github.com/Predidit/Kazumi)',
'referer': '',
};
Map<String, String> keywordMap = {'type': '2', 'responseGroup': 'large', 'max_results': '25'};
diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart
index 718ebe68..6ec67367 100644
--- a/lib/utils/storage.dart
+++ b/lib/utils/storage.dart
@@ -5,6 +5,7 @@ import 'package:kazumi/modules/history/history_module.dart';
class GStorage {
static late Box<BangumiItem> favorites;
static late Box<History> histories;
+ static late final Box<dynamic> setting;
static Future init() async {
Hive.registerAdapter(BangumiItemAdapter());
@@ -12,8 +13,32 @@ class GStorage {
Hive.registerAdapter(HistoryAdapter());
favorites = await Hive.openBox('favorites');
histories = await Hive.openBox('histories');
+ setting = await Hive.openBox('setting');
}
// 阻止实例化
GStorage._();
+}
+
+class SettingBoxKey {
+ static const String hAenable = 'hAenable',
+ searchEnhanceEnable = 'searchEnhanceEnable',
+ autoUpdate = 'autoUpdate',
+ alwaysOntop = 'alwaysOntop',
+ danmakuEnhance = 'danmakuEnhance',
+ danmakuBorder = 'danmakuBorder',
+ danmakuOpacity = 'danmakuOpacity',
+ danmakuFontSize = 'danmakuFontSize',
+ danmakuTop = 'danmakuTop',
+ danmakuScroll = 'danmakuScroll',
+ danmakuBottom = 'danmakuBottom',
+ danmakuArea = 'danmakuArea',
+ themeMode = 'themeMode',
+ themeColor = 'themeColor',
+ privateMode = 'privateMode',
+ autoPlay = 'autoPlay',
+ playResume = 'playResume',
+ oledEnhance = 'oledEnhance',
+ displayMode = 'displayMode',
+ enableSystemProxy = 'enableSystemProxy';
}
\ No newline at end of file