diff --git a/lib/pages/setting/extra_setting.dart b/lib/pages/setting/extra_setting.dart index 9b3766085..ddb97436e 100644 --- a/lib/pages/setting/extra_setting.dart +++ b/lib/pages/setting/extra_setting.dart @@ -179,8 +179,7 @@ class _ExtraSettingState extends State { content: TextFormField( autofocus: true, initialValue: dynamicPeriod.toString(), - keyboardType: - TextInputType.numberWithOptions(decimal: true), + keyboardType: TextInputType.numberWithOptions(), onChanged: (value) { dynamicPeriod = int.tryParse(value) ?? 5; }, @@ -280,6 +279,63 @@ class _ExtraSettingState extends State { setKey: SettingBoxKey.horizontalMemberPage, defaultVal: false, ), + ListTile( + title: Text('评论折叠行数', style: titleStyle), + subtitle: Text('0行为不折叠', style: subTitleStyle), + leading: const Icon(Icons.compress), + trailing: Text( + '${GlobalData().replyLengthLimit.toString()}行', + style: Theme.of(context).textTheme.titleSmall, + ), + onTap: () { + String replyLengthLimit = + GlobalData().replyLengthLimit.toString(); + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text('评论折叠行数', style: TextStyle(fontSize: 18)), + content: TextFormField( + autofocus: true, + initialValue: replyLengthLimit, + keyboardType: TextInputType.numberWithOptions(), + onChanged: (value) { + replyLengthLimit = value; + }, + inputFormatters: [ + FilteringTextInputFormatter.allow(RegExp(r'\d+')), + ], + decoration: InputDecoration(suffixText: '行'), + ), + actions: [ + TextButton( + onPressed: Get.back, + child: Text( + '取消', + style: TextStyle( + color: Theme.of(context).colorScheme.outline, + ), + ), + ), + TextButton( + onPressed: () async { + Get.back(); + GlobalData().replyLengthLimit = + int.tryParse(replyLengthLimit) ?? 6; + await setting.put( + SettingBoxKey.replyLengthLimit, + GlobalData().replyLengthLimit, + ); + setState(() {}); + }, + child: Text('确定'), + ) + ], + ); + }, + ); + }, + ), Obx( () => ListTile( enableFeedback: true, diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index 938f050da..0acc3259b 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -3,6 +3,7 @@ import 'dart:math'; import 'package:PiliPalaX/common/widgets/imageview.dart'; import 'package:PiliPalaX/http/video.dart'; import 'package:PiliPalaX/utils/extension.dart'; +import 'package:PiliPalaX/utils/global_data.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -256,8 +257,11 @@ class ReplyItem extends StatelessWidget { String text = replyItem?.content?.message ?? ''; var textPainter = TextPainter( text: TextSpan(text: text), - maxLines: - replyItem!.content!.isText! && replyLevel == '1' ? 6 : 999, + maxLines: replyItem!.content!.isText! && + replyLevel == '1' && + GlobalData().replyLengthLimit != 0 + ? GlobalData().replyLengthLimit + : null, textDirection: Directionality.of(context), )..layout(maxWidth: constraints.maxWidth); bool didExceedMaxLines = textPainter.didExceedMaxLines; diff --git a/lib/pages/video/detail/reply/widgets/reply_item_grpc.dart b/lib/pages/video/detail/reply/widgets/reply_item_grpc.dart index ebfda2408..1d73fdf28 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item_grpc.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item_grpc.dart @@ -6,6 +6,7 @@ import 'package:PiliPalaX/grpc/app/main/community/reply/v1/reply.pb.dart'; import 'package:PiliPalaX/http/video.dart'; import 'package:PiliPalaX/pages/video/detail/reply/widgets/zan_grpc.dart'; import 'package:PiliPalaX/utils/extension.dart'; +import 'package:PiliPalaX/utils/global_data.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -268,7 +269,10 @@ class ReplyItemGrpc extends StatelessWidget { ); var textPainter = TextPainter( text: TextSpan(text: text, style: style), - maxLines: replyLevel == '1' ? 6 : null, + maxLines: + replyLevel == '1' && GlobalData().replyLengthLimit != 0 + ? GlobalData().replyLengthLimit + : null, textDirection: Directionality.of(context), )..layout(maxWidth: constraints.maxWidth); bool didExceedMaxLines = textPainter.didExceedMaxLines; diff --git a/lib/utils/global_data.dart b/lib/utils/global_data.dart index 42f8535b1..43791fda3 100644 --- a/lib/utils/global_data.dart +++ b/lib/utils/global_data.dart @@ -1,10 +1,10 @@ class GlobalData { int imgQuality = 10; - // int themeMode = 2; - bool grpcReply = true; + int replyLengthLimit = 6; + // 私有构造函数 GlobalData._(); diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 12a362c38..8e90e0592 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -136,6 +136,12 @@ class GStorage { static bool get horizontalMemberPage => setting.get(SettingBoxKey.horizontalMemberPage, defaultValue: false); + static int get replyLengthLimit => + setting.get(SettingBoxKey.replyLengthLimit, defaultValue: 6); + + static int get defaultPicQa => + setting.get(SettingBoxKey.defaultPicQa, defaultValue: 10); + static List get dynamicDetailRatio => setting.get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0]); @@ -203,15 +209,10 @@ class GStorage { // 视频设置 video = await Hive.openBox('video'); // 设置全局变量 - GlobalData().imgQuality = setting.get( - SettingBoxKey.defaultPicQa, - defaultValue: 10, - ); - // GlobalData().themeMode = setting.get( - // SettingBoxKey.themeMode, - // defaultValue: ThemeType.system.code, - // ); - GlobalData().grpcReply = grpcReply; + GlobalData() + ..imgQuality = defaultPicQa + ..grpcReply = grpcReply + ..replyLengthLimit = replyLengthLimit; } static Future exportAllSettings() async { @@ -341,6 +342,7 @@ class SettingBoxKey { exapndIntroPanelH = 'exapndIntroPanelH', horizontalSeasonPanel = 'horizontalSeasonPanel', horizontalMemberPage = 'horizontalMemberPage', + replyLengthLimit = 'replyLengthLimit', // Sponsor Block enableSponsorBlock = 'enableSponsorBlock',