diff --git a/lib/pages/rcmd/controller.dart b/lib/pages/rcmd/controller.dart index 1f21ab0d6..f3acb67da 100644 --- a/lib/pages/rcmd/controller.dart +++ b/lib/pages/rcmd/controller.dart @@ -14,6 +14,7 @@ class RcmdController extends GetxController { Box recVideo = GStrorage.recVideo; Box setting = GStrorage.setting; RxInt crossAxisCount = 2.obs; + late bool enableSaveLastData; @override void onInit() { @@ -28,6 +29,8 @@ class RcmdController extends GetxController { } videoList.value = list; } + enableSaveLastData = + setting.get(SettingBoxKey.enableSaveLastData, defaultValue: false); } // 获取推荐 @@ -49,7 +52,11 @@ class RcmdController extends GetxController { videoList.value = res['data']; } } else if (type == 'onRefresh') { - videoList.value = res['data']; + if (enableSaveLastData) { + videoList.insertAll(0, res['data']); + } else { + videoList.value = res['data']; + } } else if (type == 'onLoad') { videoList.addAll(res['data']); } diff --git a/lib/pages/setting/extra_setting.dart b/lib/pages/setting/extra_setting.dart index f56029e67..4bbb841cc 100644 --- a/lib/pages/setting/extra_setting.dart +++ b/lib/pages/setting/extra_setting.dart @@ -79,6 +79,12 @@ class _ExtraSettingState extends State { setKey: SettingBoxKey.enableWordRe, defaultVal: false, ), + const SetSwitchItem( + title: '首页推荐刷新', + subTitle: '下拉刷新时保留上次内容', + setKey: SettingBoxKey.enableSaveLastData, + defaultVal: false, + ), ListTile( dense: false, title: Text('评论展示', style: titleStyle), diff --git a/lib/pages/video/detail/introduction/widgets/intro_detail.dart b/lib/pages/video/detail/introduction/widgets/intro_detail.dart index d9846b193..1db23a1d7 100644 --- a/lib/pages/video/detail/introduction/widgets/intro_detail.dart +++ b/lib/pages/video/detail/introduction/widgets/intro_detail.dart @@ -1,5 +1,6 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import 'package:hive/hive.dart'; import 'package:pilipala/common/widgets/stat/danmu.dart'; @@ -129,7 +130,50 @@ class IntroDetail extends StatelessWidget { final currentDesc = descV2[index]; switch (currentDesc.type) { case 1: - return TextSpan(text: currentDesc.rawText); + List spanChildren = []; + RegExp urlRegExp = RegExp(r'https?://\S+\b'); + Iterable matches = urlRegExp.allMatches(currentDesc.rawText); + + int previousEndIndex = 0; + for (Match match in matches) { + if (match.start > previousEndIndex) { + spanChildren.add(TextSpan( + text: currentDesc.rawText + .substring(previousEndIndex, match.start))); + } + spanChildren.add( + TextSpan( + text: match.group(0), + style: TextStyle( + color: Theme.of(context).colorScheme.primary), // 设置颜色为蓝色 + recognizer: TapGestureRecognizer() + ..onTap = () { + // 处理点击事件 + try { + Get.toNamed( + '/webview', + parameters: { + 'url': match.group(0)!, + 'type': 'url', + 'pageTitle': match.group(0)!, + }, + ); + } catch (err) { + SmartDialog.showToast(err.toString()); + } + }, + ), + ); + previousEndIndex = match.end; + } + + if (previousEndIndex < currentDesc.rawText.length) { + spanChildren.add(TextSpan( + text: currentDesc.rawText.substring(previousEndIndex))); + } + + TextSpan result = TextSpan(children: spanChildren); + return result; case 2: final colorSchemePrimary = Theme.of(context).colorScheme.primary; final heroTag = Utils.makeHeroTag(currentDesc.bizId); diff --git a/lib/pages/webview/view.dart b/lib/pages/webview/view.dart index 301b1dfaf..8edd21896 100644 --- a/lib/pages/webview/view.dart +++ b/lib/pages/webview/view.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:url_launcher/url_launcher.dart'; import 'controller.dart'; import 'package:webview_flutter/webview_flutter.dart'; @@ -24,11 +25,20 @@ class _WebviewPageState extends State { style: Theme.of(context).textTheme.titleMedium, ), actions: [ - TextButton( + const SizedBox(width: 4), + IconButton( onPressed: () { _webviewController.controller.reload(); }, - child: const Text('刷新'), + icon: Icon(Icons.refresh_outlined, + color: Theme.of(context).colorScheme.primary), + ), + IconButton( + onPressed: () { + launchUrl(Uri.parse(_webviewController.url)); + }, + icon: Icon(Icons.open_in_browser_outlined, + color: Theme.of(context).colorScheme.primary), ), Obx( () => _webviewController.type.value == 'login' @@ -38,7 +48,7 @@ class _WebviewPageState extends State { ) : const SizedBox(), ), - const SizedBox(width: 10) + const SizedBox(width: 12) ], ), body: Column( diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 8a8dbc407..2b1f4969d 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -121,6 +121,7 @@ class SettingBoxKey { static const String enableWordRe = 'enableWordRe'; static const String enableSearchWord = 'enableSearchWord'; static const String enableRcmdDynamic = 'enableRcmdDynamic'; + static const String enableSaveLastData = 'enableSaveLastData'; /// 外观 static const String themeMode = 'themeMode';