Merge branch 'feature-replyItem'
This commit is contained in:
@ -1,7 +1,6 @@
|
|||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:pilipala/common/widgets/badge.dart';
|
import 'package:pilipala/common/widgets/badge.dart';
|
||||||
@ -12,10 +11,9 @@ import 'package:pilipala/pages/preview/index.dart';
|
|||||||
import 'package:pilipala/pages/video/detail/index.dart';
|
import 'package:pilipala/pages/video/detail/index.dart';
|
||||||
import 'package:pilipala/pages/video/detail/reply_new/index.dart';
|
import 'package:pilipala/pages/video/detail/reply_new/index.dart';
|
||||||
import 'package:pilipala/utils/feed_back.dart';
|
import 'package:pilipala/utils/feed_back.dart';
|
||||||
import 'package:pilipala/utils/id_utils.dart';
|
|
||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
import 'package:pilipala/utils/url_utils.dart';
|
||||||
import 'package:pilipala/utils/utils.dart';
|
import 'package:pilipala/utils/utils.dart';
|
||||||
|
|
||||||
import 'zan.dart';
|
import 'zan.dart';
|
||||||
|
|
||||||
Box setting = GStrorage.setting;
|
Box setting = GStrorage.setting;
|
||||||
@ -541,7 +539,6 @@ InlineSpan buildContent(
|
|||||||
// fReplyItem 父级回复内容,用作二楼回复(回复详情)展示
|
// fReplyItem 父级回复内容,用作二楼回复(回复详情)展示
|
||||||
final content = replyItem.content;
|
final content = replyItem.content;
|
||||||
final List<InlineSpan> spanChilds = <InlineSpan>[];
|
final List<InlineSpan> spanChilds = <InlineSpan>[];
|
||||||
bool hasMatchMember = false;
|
|
||||||
|
|
||||||
// 投票
|
// 投票
|
||||||
if (content.vote.isNotEmpty) {
|
if (content.vote.isNotEmpty) {
|
||||||
@ -591,7 +588,7 @@ InlineSpan buildContent(
|
|||||||
if (patternStr.isNotEmpty) {
|
if (patternStr.isNotEmpty) {
|
||||||
patternStr += "|";
|
patternStr += "|";
|
||||||
}
|
}
|
||||||
patternStr += r'(\b\d{1,2}[::]\d{2}\b)';
|
patternStr += r'(\b\d{1,2}[::]\d{2}(?:[::]\d{2})?\b)';
|
||||||
final RegExp pattern = RegExp(patternStr);
|
final RegExp pattern = RegExp(patternStr);
|
||||||
List<String> matchedStrs = [];
|
List<String> matchedStrs = [];
|
||||||
void addPlainTextSpan(str) {
|
void addPlainTextSpan(str) {
|
||||||
@ -639,7 +636,9 @@ InlineSpan buildContent(
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else if (RegExp(r'^\b[0-9]{1,2}[::][0-9]{2}\b$').hasMatch(matchStr)) {
|
} else if (RegExp(r'^\b\d{1,2}[::]\d{2}(?:[::]\d{2})?\b$')
|
||||||
|
.hasMatch(matchStr)) {
|
||||||
|
matchStr = matchStr.replaceAll(':', ':');
|
||||||
spanChilds.add(
|
spanChilds.add(
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: ' $matchStr ',
|
text: ' $matchStr ',
|
||||||
@ -650,7 +649,6 @@ InlineSpan buildContent(
|
|||||||
..onTap = () {
|
..onTap = () {
|
||||||
// 跳转到指定位置
|
// 跳转到指定位置
|
||||||
try {
|
try {
|
||||||
matchStr = matchStr.replaceAll(':', ':');
|
|
||||||
SmartDialog.showToast('跳转至:$matchStr');
|
SmartDialog.showToast('跳转至:$matchStr');
|
||||||
Get.find<VideoDetailController>(tag: Get.arguments['heroTag'])
|
Get.find<VideoDetailController>(tag: Get.arguments['heroTag'])
|
||||||
.plPlayerController
|
.plPlayerController
|
||||||
@ -692,16 +690,54 @@ InlineSpan buildContent(
|
|||||||
color: Theme.of(context).colorScheme.primary,
|
color: Theme.of(context).colorScheme.primary,
|
||||||
),
|
),
|
||||||
recognizer: TapGestureRecognizer()
|
recognizer: TapGestureRecognizer()
|
||||||
..onTap = () {
|
..onTap = () async {
|
||||||
|
final String title = content.jumpUrl[matchStr]['title'];
|
||||||
if (appUrlSchema == '') {
|
if (appUrlSchema == '') {
|
||||||
final String str = Uri.parse(matchStr).pathSegments[0];
|
final String redirectUrl =
|
||||||
final Map matchRes = IdUtils.matchAvorBv(input: str);
|
await UrlUtils.parseRedirectUrl(matchStr);
|
||||||
final List matchKeys = matchRes.keys.toList();
|
final String pathSegment = Uri.parse(redirectUrl).path;
|
||||||
if (matchKeys.isNotEmpty) {
|
final String lastPathSegment =
|
||||||
if (matchKeys.first == 'BV') {
|
pathSegment.split('/').last;
|
||||||
|
if (lastPathSegment.startsWith('BV')) {
|
||||||
|
UrlUtils.matchUrlPush(
|
||||||
|
lastPathSegment,
|
||||||
|
title,
|
||||||
|
redirectUrl,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
Get.toNamed(
|
||||||
|
'/webview',
|
||||||
|
parameters: {
|
||||||
|
'url': redirectUrl,
|
||||||
|
'type': 'url',
|
||||||
|
'pageTitle': title
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (appUrlSchema.startsWith('bilibili://search')) {
|
||||||
|
Get.toNamed('/searchResult',
|
||||||
|
parameters: {'keyword': title});
|
||||||
|
} else if (matchStr.startsWith('https://b23.tv')) {
|
||||||
|
final String redirectUrl =
|
||||||
|
await UrlUtils.parseRedirectUrl(matchStr);
|
||||||
|
final String pathSegment = Uri.parse(redirectUrl).path;
|
||||||
|
final String lastPathSegment =
|
||||||
|
pathSegment.split('/').last;
|
||||||
|
if (lastPathSegment.startsWith('BV')) {
|
||||||
|
UrlUtils.matchUrlPush(
|
||||||
|
lastPathSegment,
|
||||||
|
title,
|
||||||
|
redirectUrl,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
Get.toNamed(
|
Get.toNamed(
|
||||||
'/searchResult',
|
'/webview',
|
||||||
parameters: {'keyword': matchRes['BV']},
|
parameters: {
|
||||||
|
'url': redirectUrl,
|
||||||
|
'type': 'url',
|
||||||
|
'pageTitle': title
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -710,16 +746,10 @@ InlineSpan buildContent(
|
|||||||
parameters: {
|
parameters: {
|
||||||
'url': matchStr,
|
'url': matchStr,
|
||||||
'type': 'url',
|
'type': 'url',
|
||||||
'pageTitle': ''
|
'pageTitle': title
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (appUrlSchema.startsWith('bilibili://search')) {
|
|
||||||
Get.toNamed('/searchResult', parameters: {
|
|
||||||
'keyword': content.jumpUrl[matchStr]['title']
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
61
lib/utils/url_utils.dart
Normal file
61
lib/utils/url_utils.dart
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
|
import '../http/search.dart';
|
||||||
|
import 'id_utils.dart';
|
||||||
|
import 'utils.dart';
|
||||||
|
|
||||||
|
class UrlUtils {
|
||||||
|
// 302重定向路由截取
|
||||||
|
static Future<String> parseRedirectUrl(String url) async {
|
||||||
|
late String redirectUrl;
|
||||||
|
final dio = Dio();
|
||||||
|
dio.options.followRedirects = false;
|
||||||
|
dio.options.validateStatus = (status) {
|
||||||
|
return status == 200 || status == 301 || status == 302;
|
||||||
|
};
|
||||||
|
final response = await dio.get(url);
|
||||||
|
if (response.statusCode == 302) {
|
||||||
|
redirectUrl = response.headers['location']?.first as String;
|
||||||
|
if (redirectUrl.endsWith('/')) {
|
||||||
|
redirectUrl = redirectUrl.substring(0, redirectUrl.length - 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (url.endsWith('/')) {
|
||||||
|
url = url.substring(0, url.length - 1);
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
return redirectUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 匹配url路由跳转
|
||||||
|
static matchUrlPush(
|
||||||
|
String pathSegment,
|
||||||
|
String title,
|
||||||
|
String redirectUrl,
|
||||||
|
) async {
|
||||||
|
final Map matchRes = IdUtils.matchAvorBv(input: pathSegment);
|
||||||
|
if (matchRes.containsKey('BV')) {
|
||||||
|
final String bv = matchRes['BV'];
|
||||||
|
final int cid = await SearchHttp.ab2c(bvid: bv);
|
||||||
|
final String heroTag = Utils.makeHeroTag(bv);
|
||||||
|
await Get.toNamed(
|
||||||
|
'/video?bvid=$bv&cid=$cid',
|
||||||
|
arguments: <String, String?>{
|
||||||
|
'pic': '',
|
||||||
|
'heroTag': heroTag,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await Get.toNamed(
|
||||||
|
'/webview',
|
||||||
|
parameters: {
|
||||||
|
'url': redirectUrl,
|
||||||
|
'type': 'url',
|
||||||
|
'pageTitle': title,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user