Skip to content

Commit

Permalink
add danmaku settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Predidit committed May 20, 2024
1 parent ec35b1b commit b824cff
Show file tree
Hide file tree
Showing 7 changed files with 536 additions and 41 deletions.
144 changes: 144 additions & 0 deletions lib/bean/settings/settings.dart
Original file line number Diff line number Diff line change
@@ -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('确定'),
)
],
);
}
}

7 changes: 7 additions & 0 deletions lib/pages/my/my_module.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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());
Expand Down
7 changes: 7 additions & 0 deletions lib/pages/my/my_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
70 changes: 30 additions & 40 deletions lib/pages/player/player_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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),
// ),
],
),
)
Expand Down
Loading

0 comments on commit b824cff

Please sign in to comment.