mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: replyitem: check if seek is valid
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:PiliPalaX/common/widgets/badge.dart';
|
import 'package:PiliPalaX/common/widgets/badge.dart';
|
||||||
import 'package:PiliPalaX/common/widgets/imageview.dart';
|
import 'package:PiliPalaX/common/widgets/imageview.dart';
|
||||||
import 'package:PiliPalaX/grpc/app/main/community/reply/v1/reply.pb.dart';
|
import 'package:PiliPalaX/grpc/app/main/community/reply/v1/reply.pb.dart';
|
||||||
@@ -721,30 +723,53 @@ InlineSpan buildContent(
|
|||||||
} else if (RegExp(r'^\b(?:\d+[::])?[0-5]?[0-9][::][0-5]?[0-9]\b$')
|
} else if (RegExp(r'^\b(?:\d+[::])?[0-5]?[0-9][::][0-5]?[0-9]\b$')
|
||||||
.hasMatch(matchStr)) {
|
.hasMatch(matchStr)) {
|
||||||
matchStr = matchStr.replaceAll(':', ':');
|
matchStr = matchStr.replaceAll(':', ':');
|
||||||
|
bool isValid = false;
|
||||||
|
try {
|
||||||
|
List<int> split = matchStr
|
||||||
|
.split(':')
|
||||||
|
.map((item) => int.parse(item))
|
||||||
|
.toList()
|
||||||
|
.reversed
|
||||||
|
.toList();
|
||||||
|
int seek = 0;
|
||||||
|
for (int i = 0; i < split.length; i++) {
|
||||||
|
seek += split[i] * pow(60, i).toInt();
|
||||||
|
}
|
||||||
|
int duration =
|
||||||
|
Get.find<VideoDetailController>(tag: Get.arguments['heroTag'])
|
||||||
|
.data
|
||||||
|
.timeLength ??
|
||||||
|
0;
|
||||||
|
isValid = seek * 1000 <= duration;
|
||||||
|
} catch (e) {
|
||||||
|
print('failed to validate: $e');
|
||||||
|
}
|
||||||
spanChildren.add(
|
spanChildren.add(
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: ' $matchStr ',
|
text: isValid ? ' $matchStr ' : matchStr,
|
||||||
style: isVideoPage
|
style: isValid && isVideoPage
|
||||||
? TextStyle(
|
? TextStyle(
|
||||||
color: Theme.of(context).colorScheme.primary,
|
color: Theme.of(context).colorScheme.primary,
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
recognizer: TapGestureRecognizer()
|
recognizer: isValid
|
||||||
..onTap = () {
|
? (TapGestureRecognizer()
|
||||||
// 跳转到指定位置
|
..onTap = () {
|
||||||
if (isVideoPage) {
|
// 跳转到指定位置
|
||||||
try {
|
if (isVideoPage) {
|
||||||
SmartDialog.showToast('跳转至:$matchStr');
|
try {
|
||||||
Get.find<VideoDetailController>(
|
SmartDialog.showToast('跳转至:$matchStr');
|
||||||
tag: Get.arguments['heroTag'])
|
Get.find<VideoDetailController>(
|
||||||
.plPlayerController
|
tag: Get.arguments['heroTag'])
|
||||||
.seekTo(Duration(seconds: Utils.duration(matchStr)),
|
.plPlayerController
|
||||||
type: 'slider');
|
.seekTo(Duration(seconds: Utils.duration(matchStr)),
|
||||||
} catch (e) {
|
type: 'slider');
|
||||||
SmartDialog.showToast('跳转失败: $e');
|
} catch (e) {
|
||||||
}
|
SmartDialog.showToast('跳转失败: $e');
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
})
|
||||||
|
: null,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user