mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: custom reply length limit
Closes #55 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -179,8 +179,7 @@ class _ExtraSettingState extends State<ExtraSetting> {
|
||||
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<ExtraSetting> {
|
||||
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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
class GlobalData {
|
||||
int imgQuality = 10;
|
||||
|
||||
// int themeMode = 2;
|
||||
|
||||
bool grpcReply = true;
|
||||
|
||||
int replyLengthLimit = 6;
|
||||
|
||||
// 私有构造函数
|
||||
GlobalData._();
|
||||
|
||||
|
||||
@@ -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<double> 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<String> exportAllSettings() async {
|
||||
@@ -341,6 +342,7 @@ class SettingBoxKey {
|
||||
exapndIntroPanelH = 'exapndIntroPanelH',
|
||||
horizontalSeasonPanel = 'horizontalSeasonPanel',
|
||||
horizontalMemberPage = 'horizontalMemberPage',
|
||||
replyLengthLimit = 'replyLengthLimit',
|
||||
|
||||
// Sponsor Block
|
||||
enableSponsorBlock = 'enableSponsorBlock',
|
||||
|
||||
Reference in New Issue
Block a user