merge main

This commit is contained in:
guozhigq
2023-11-12 12:02:31 +08:00
90 changed files with 2582 additions and 429 deletions

View File

@ -201,7 +201,7 @@ class _BangumiPageState extends State<BangumiPage>
},
),
),
const LoadingMore()
LoadingMore()
],
),
);

View File

@ -10,6 +10,8 @@ class PlDanmakuController {
// 按 6min 分段
int segCount = 0;
List<DmSegMobileReply> dmSegList = [];
// 已请求的段落标记
List<int> hasrequestSeg = [];
int currentSegIndex = 1;
int currentDmIndex = 0;

View File

@ -95,7 +95,9 @@ class _PlDanmakuState extends State<PlDanmaku> {
// 根据position判断是否有已缓存弹幕。没有则请求对应段
int segIndex = (currentPosition / (6 * 60 * 1000)).ceil();
segIndex = segIndex < 1 ? 1 : segIndex;
if (ctr.dmSegList[segIndex - 1].elems.isEmpty) {
if (ctr.dmSegList[segIndex - 1].elems.isEmpty &&
!ctr.hasrequestSeg.contains(segIndex - 1)) {
ctr.hasrequestSeg.add(segIndex - 1);
ctr.currentSegIndex = segIndex;
EasyThrottle.throttle('follow', const Duration(seconds: 1), () {
ctr.queryDanmaku();

View File

@ -17,6 +17,10 @@ class AuthorPanel extends StatelessWidget {
children: [
GestureDetector(
onTap: () {
// 番剧
if (item.modules.moduleAuthor.type == 'AUTHOR_TYPE_PGC') {
return;
}
feedBack();
Get.toNamed(
'/member?mid=${item.modules.moduleAuthor.mid}',

View File

@ -1,17 +1,21 @@
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:pilipala/common/widgets/network_img_layer.dart';
import 'package:pilipala/models/follow/result.dart';
import 'package:pilipala/pages/follow/index.dart';
import 'package:pilipala/pages/video/detail/introduction/widgets/group_panel.dart';
import 'package:pilipala/utils/feed_back.dart';
import 'package:pilipala/utils/utils.dart';
class FollowItem extends StatelessWidget {
final FollowItemModel item;
const FollowItem({super.key, required this.item});
final FollowController? ctr;
const FollowItem({super.key, required this.item, this.ctr});
@override
Widget build(BuildContext context) {
String heroTag = Utils.makeHeroTag(item!.mid);
String heroTag = Utils.makeHeroTag(item.mid);
return ListTile(
onTap: () {
feedBack();
@ -39,7 +43,29 @@ class FollowItem extends StatelessWidget {
overflow: TextOverflow.ellipsis,
),
dense: true,
trailing: const SizedBox(width: 6),
trailing: ctr!.isOwner.value
? SizedBox(
height: 34,
child: TextButton(
onPressed: () async {
await Get.bottomSheet(
GroupPanel(mid: item.mid!),
isScrollControlled: true,
);
},
style: TextButton.styleFrom(
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
foregroundColor: Theme.of(context).colorScheme.outline,
backgroundColor:
Theme.of(context).colorScheme.onInverseSurface, // 设置按钮背景色
),
child: const Text(
'已关注',
style: TextStyle(fontSize: 12),
),
),
)
: const SizedBox(),
);
}
}

View File

@ -84,7 +84,10 @@ class _FollowListState extends State<FollowList> {
),
);
} else {
return FollowItem(item: list[index]);
return FollowItem(
item: list[index],
ctr: widget.ctr,
);
}
},
)

View File

@ -1,3 +1,5 @@
import 'dart:math';
import 'package:easy_debounce/easy_throttle.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
@ -89,6 +91,7 @@ class _OwnerFollowListState extends State<OwnerFollowList>
return Obx(
() => followList.isNotEmpty
? ListView.builder(
physics: const AlwaysScrollableScrollPhysics(),
controller: scrollController,
itemCount: followList.length + 1,
itemBuilder: (BuildContext context, int index) {
@ -101,7 +104,10 @@ class _OwnerFollowListState extends State<OwnerFollowList>
MediaQuery.of(context).padding.bottom),
);
} else {
return FollowItem(item: followList[index]);
return FollowItem(
item: followList[index],
ctr: widget.ctr,
);
}
},
)

View File

@ -10,6 +10,7 @@ import 'package:pilipala/common/widgets/animated_dialog.dart';
import 'package:pilipala/common/widgets/http_error.dart';
import 'package:pilipala/common/widgets/overlay_pop.dart';
import 'package:pilipala/pages/main/index.dart';
import 'package:pilipala/pages/rcmd/index.dart';
import 'controller.dart';
import 'widgets/live_item.dart';
@ -118,7 +119,7 @@ class _LivePageState extends State<LivePage>
},
),
),
const LoadingMore()
LoadingMore(ctr: _liveController)
],
),
),
@ -180,24 +181,3 @@ class _LivePageState extends State<LivePage>
);
}
}
class LoadingMore extends StatelessWidget {
const LoadingMore({super.key});
@override
Widget build(BuildContext context) {
return SliverToBoxAdapter(
child: Container(
height: MediaQuery.of(context).padding.bottom + 80,
padding: EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom),
child: Center(
child: Text(
'加载中...',
style: TextStyle(
color: Theme.of(context).colorScheme.outline, fontSize: 13),
),
),
),
);
}
}

View File

@ -0,0 +1,204 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:pilipala/http/login.dart';
import 'package:gt3_flutter_plugin/gt3_flutter_plugin.dart';
import 'package:pilipala/models/login/index.dart';
class LoginPageController extends GetxController {
final GlobalKey mobFormKey = GlobalKey<FormState>();
final GlobalKey passwordFormKey = GlobalKey<FormState>();
final GlobalKey msgCodeFormKey = GlobalKey<FormState>();
final TextEditingController mobTextController = TextEditingController();
final TextEditingController passwordTextController = TextEditingController();
final TextEditingController msgCodeTextController = TextEditingController();
final FocusNode mobTextFieldNode = FocusNode();
final FocusNode passwordTextFieldNode = FocusNode();
final FocusNode msgCodeTextFieldNode = FocusNode();
final PageController pageViewController = PageController();
RxInt currentIndex = 0.obs;
final Gt3FlutterPlugin captcha = Gt3FlutterPlugin();
// 默认密码登录
RxInt loginType = 0.obs;
// 监听pageView切换
void onPageChange(int index) {
currentIndex.value = index;
}
// 输入手机号 下一页
void nextStep() async {
if ((mobFormKey.currentState as FormState).validate()) {
await pageViewController.animateToPage(
1,
duration: const Duration(microseconds: 3000),
curve: Curves.easeInOut,
);
passwordTextFieldNode.requestFocus();
}
}
// 上一页
void previousPage() async {
passwordTextFieldNode.unfocus();
await Future.delayed(const Duration(milliseconds: 200));
pageViewController.animateToPage(
0,
duration: const Duration(microseconds: 300),
curve: Curves.easeInOut,
);
}
// 切换登录方式
void changeLoginType() {
loginType.value = loginType.value == 0 ? 1 : 0;
if (loginType.value == 0) {
passwordTextFieldNode.requestFocus();
} else {
msgCodeTextFieldNode.requestFocus();
}
}
// app端密码登录
void loginInByAppPassword() async {
if ((passwordFormKey.currentState as FormState).validate()) {
var webKeyRes = await LoginHttp.getWebKey();
if (webKeyRes['status']) {
String rhash = webKeyRes['data']['hash'];
String key = webKeyRes['data']['key'];
LoginHttp.loginInByMobPwd(
tel: mobTextController.text,
password: passwordTextController.text,
key: key,
rhash: rhash,
);
} else {
SmartDialog.showToast(webKeyRes['msg']);
}
}
}
// 验证码登录
void loginInByCode() {
if ((msgCodeFormKey.currentState as FormState).validate()) {}
}
// app端验证码
void getMsgCode() async {
getCaptcha((data) async {
CaptchaDataModel captchaData = data;
var res = await LoginHttp.sendAppSmsCode(
cid: 86,
tel: 13734077064,
token: captchaData.token!,
challenge: captchaData.geetest!.challenge!,
validate: captchaData.validate!,
seccode: captchaData.seccode!,
);
print(res);
});
}
// 申请极验验证码
Future getCaptcha(oncall) async {
SmartDialog.showLoading(msg: '请求中...');
var result = await LoginHttp.queryCaptcha();
if (result['status']) {
CaptchaDataModel captchaData = result['data'];
var registerData = Gt3RegisterData(
challenge: captchaData.geetest!.challenge,
gt: captchaData.geetest!.gt!,
success: true,
);
captcha.addEventHandler(onShow: (Map<String, dynamic> message) async {
SmartDialog.dismiss();
}, onClose: (Map<String, dynamic> message) async {
SmartDialog.showToast('关闭验证');
}, onResult: (Map<String, dynamic> message) async {
debugPrint("Captcha result: $message");
String code = message["code"];
if (code == "1") {
// 发送 message["result"] 中的数据向 B 端的业务服务接口进行查询
SmartDialog.showToast('验证成功');
captchaData.validate = message['result']['geetest_validate'];
captchaData.seccode = message['result']['geetest_seccode'];
captchaData.geetest!.challenge =
message['result']['geetest_challenge'];
oncall(captchaData);
} else {
// 终端用户完成验证失败,自动重试 If the verification fails, it will be automatically retried.
debugPrint("Captcha result code : $code");
}
}, onError: (Map<String, dynamic> message) async {
String code = message["code"];
// 处理验证中返回的错误 Handling errors returned in verification
if (Platform.isAndroid) {
// Android 平台
if (code == "-2") {
// Dart 调用异常 Call exception
} else if (code == "-1") {
// Gt3RegisterData 参数不合法 Parameter is invalid
} else if (code == "201") {
// 网络无法访问 Network inaccessible
} else if (code == "202") {
// Json 解析错误 Analysis error
} else if (code == "204") {
// WebView 加载超时,请检查是否混淆极验 SDK Load timed out
} else if (code == "204_1") {
// WebView 加载前端页面错误,请查看日志 Error loading front-end page, please check the log
} else if (code == "204_2") {
// WebView 加载 SSLError
} else if (code == "206") {
// gettype 接口错误或返回为 null API error or return null
} else if (code == "207") {
// getphp 接口错误或返回为 null API error or return null
} else if (code == "208") {
// ajax 接口错误或返回为 null API error or return null
} else {
// 更多错误码参考开发文档 More error codes refer to the development document
// https://docs.geetest.com/sensebot/apirefer/errorcode/android
}
}
if (Platform.isIOS) {
// iOS 平台
if (code == "-1009") {
// 网络无法访问 Network inaccessible
} else if (code == "-1004") {
// 无法查找到 HOST Unable to find HOST
} else if (code == "-1002") {
// 非法的 URL Illegal URL
} else if (code == "-1001") {
// 网络超时 Network timeout
} else if (code == "-999") {
// 请求被意外中断, 一般由用户进行取消操作导致 The interrupted request was usually caused by the user cancelling the operation
} else if (code == "-21") {
// 使用了重复的 challenge Duplicate challenges are used
// 检查获取 challenge 是否进行了缓存 Check if the fetch challenge is cached
} else if (code == "-20") {
// 尝试过多, 重新引导用户触发验证即可 Try too many times, lead the user to request verification again
} else if (code == "-10") {
// 预判断时被封禁, 不会再进行图形验证 Banned during pre-judgment, and no more image captcha verification
} else if (code == "-2") {
// Dart 调用异常 Call exception
} else if (code == "-1") {
// Gt3RegisterData 参数不合法 Parameter is invalid
} else {
// 更多错误码参考开发文档 More error codes refer to the development document
// https://docs.geetest.com/sensebot/apirefer/errorcode/ios
}
}
});
captcha.startCaptcha(registerData);
} else {}
}
}

View File

@ -0,0 +1,4 @@
library login;
export './controller.dart';
export 'view.dart';

362
lib/pages/login/view.dart Normal file
View File

@ -0,0 +1,362 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'controller.dart';
class LoginPage extends StatefulWidget {
const LoginPage({super.key});
@override
State<LoginPage> createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
final LoginPageController _loginPageCtr = Get.put(LoginPageController());
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: Obx(
() => _loginPageCtr.currentIndex.value == 0
? IconButton(
onPressed: () async {
_loginPageCtr.mobTextFieldNode.unfocus();
await Future.delayed(const Duration(milliseconds: 200));
Get.back();
},
icon: const Icon(Icons.close_outlined),
)
: IconButton(
onPressed: () => _loginPageCtr.previousPage(),
icon: const Icon(Icons.arrow_back),
),
),
),
body: PageView(
physics: const NeverScrollableScrollPhysics(),
controller: _loginPageCtr.pageViewController,
onPageChanged: (int index) => _loginPageCtr.onPageChange(index),
children: [
Padding(
padding: EdgeInsets.only(
left: 20,
right: 20,
top: 10,
bottom: MediaQuery.of(context).padding.bottom + 10,
),
child: Form(
key: _loginPageCtr.mobFormKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Text(
'登录',
style: Theme.of(context).textTheme.titleLarge!.copyWith(
letterSpacing: 1,
height: 2.1,
fontSize: 34,
fontWeight: FontWeight.w500),
),
Row(
children: [
Text(
'请使用您的 BiliBili 账号登录。',
style: Theme.of(context).textTheme.titleSmall!,
),
GestureDetector(
onTap: () {},
child: const Icon(Icons.info_outline, size: 16),
)
],
),
Container(
margin: const EdgeInsets.only(top: 38, bottom: 15),
child: TextFormField(
controller: _loginPageCtr.mobTextController,
focusNode: _loginPageCtr.mobTextFieldNode,
keyboardType: TextInputType.number,
decoration: InputDecoration(
isDense: true,
labelText: '输入手机号码',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
),
),
// 校验用户名
validator: (v) {
return v!.trim().isNotEmpty ? null : "手机号码不能为空";
},
onSaved: (val) {
print(val);
},
onEditingComplete: () {
_loginPageCtr.nextStep();
},
),
),
GestureDetector(
onTap: () {
Get.offNamed(
'/webview',
parameters: {
'url':
'https://passport.bilibili.com/h5-app/passport/login',
'type': 'login',
'pageTitle': '登录bilibili',
},
);
},
child: Padding(
padding: const EdgeInsets.only(left: 2),
child: Text(
'使用网页端登录',
style: TextStyle(
color: Theme.of(context).colorScheme.primary),
),
),
),
const Spacer(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextButton(onPressed: () {}, child: const Text('中国大陆')),
TextButton(
style: TextButton.styleFrom(
padding: const EdgeInsets.fromLTRB(20, 0, 20, 0),
foregroundColor:
Theme.of(context).colorScheme.onPrimary,
backgroundColor:
Theme.of(context).colorScheme.primary, // 设置按钮背景色
),
onPressed: () => _loginPageCtr.nextStep(),
child: const Text('下一步'),
)
],
),
],
),
),
),
Padding(
padding: EdgeInsets.only(
left: 20,
right: 20,
top: 10,
bottom: MediaQuery.of(context).padding.bottom + 10,
),
child: Obx(
() => _loginPageCtr.loginType.value == 0
? Form(
key: _loginPageCtr.passwordFormKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Row(
children: [
Text(
'密码登录',
style: Theme.of(context)
.textTheme
.titleLarge!
.copyWith(
letterSpacing: 1,
height: 2.1,
fontSize: 34,
fontWeight: FontWeight.w500),
),
const SizedBox(width: 4),
IconButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.resolveWith(
(states) {
return Theme.of(context)
.colorScheme
.primary
.withOpacity(0.1);
}),
),
onPressed: () =>
_loginPageCtr.changeLoginType(),
icon: const Icon(Icons.swap_vert_outlined),
)
],
),
Text(
'请输入您的 BiliBili 密码。',
style: Theme.of(context).textTheme.titleSmall!,
),
Container(
margin: const EdgeInsets.only(top: 38, bottom: 15),
child: TextFormField(
controller: _loginPageCtr.passwordTextController,
focusNode: _loginPageCtr.passwordTextFieldNode,
keyboardType: TextInputType.visiblePassword,
decoration: InputDecoration(
isDense: true,
labelText: '输入密码',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
),
),
// 校验用户名
validator: (v) {
return v!.trim().isNotEmpty ? null : "密码不能为空";
},
onSaved: (val) {
print(val);
},
),
),
const Spacer(),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () => _loginPageCtr.previousPage(),
child: const Text('上一步'),
),
const SizedBox(width: 15),
TextButton(
style: TextButton.styleFrom(
padding:
const EdgeInsets.fromLTRB(20, 0, 20, 0),
foregroundColor:
Theme.of(context).colorScheme.onPrimary,
backgroundColor: Theme.of(context)
.colorScheme
.primary, // 设置按钮背景色
),
onPressed: () =>
_loginPageCtr.loginInByAppPassword(),
child: const Text('确认登录'),
)
],
),
],
),
)
: Form(
key: _loginPageCtr.msgCodeFormKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Row(
children: [
Text(
'验证码登录',
style: Theme.of(context)
.textTheme
.titleLarge!
.copyWith(
letterSpacing: 1,
height: 2.1,
fontSize: 34,
fontWeight: FontWeight.w500),
),
const SizedBox(width: 4),
IconButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.resolveWith(
(states) {
return Theme.of(context)
.colorScheme
.primary
.withOpacity(0.1);
}),
),
onPressed: () =>
_loginPageCtr.changeLoginType(),
icon: const Icon(Icons.swap_vert_outlined),
)
],
),
Text(
'请输入收到到验证码。',
style: Theme.of(context).textTheme.titleSmall!,
),
Container(
margin: const EdgeInsets.only(top: 38, bottom: 15),
child: Stack(
children: [
TextFormField(
controller:
_loginPageCtr.msgCodeTextController,
focusNode: _loginPageCtr.msgCodeTextFieldNode,
maxLength: 6,
keyboardType: TextInputType.number,
decoration: InputDecoration(
isDense: true,
labelText: '输入验证码',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
),
),
// 校验用户名
validator: (v) {
return v!.trim().isNotEmpty
? null
: "验证码不能为空";
},
onSaved: (val) {
print(val);
},
),
Positioned(
right: 8,
top: 4,
child: Center(
child: TextButton(
onPressed: () =>
_loginPageCtr.getMsgCode(),
child: const Text('获取验证码'),
),
),
),
],
),
),
const Spacer(),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () => _loginPageCtr.previousPage(),
child: const Text('上一步'),
),
const SizedBox(width: 15),
TextButton(
style: TextButton.styleFrom(
padding:
const EdgeInsets.fromLTRB(20, 0, 20, 0),
foregroundColor:
Theme.of(context).colorScheme.onPrimary,
backgroundColor: Theme.of(context)
.colorScheme
.primary, // 设置按钮背景色
),
onPressed: () => _loginPageCtr.loginInByCode(),
child: const Text('确认登录'),
)
],
),
],
),
),
),
),
],
),
);
}
}

View File

@ -29,6 +29,8 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
late Animation<double>? _slideAnimation;
int selectedIndex = 0;
int? _lastSelectTime; //上次点击时间
Box setting = GStrorage.setting;
late bool enableMYBar;
@override
void initState() {
@ -45,6 +47,7 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
Tween(begin: 0.8, end: 1.0).animate(_animationController!);
_lastSelectTime = DateTime.now().millisecondsSinceEpoch;
_pageController = PageController(initialPage: selectedIndex);
enableMYBar = setting.get(SettingBoxKey.enableMYBar, defaultValue: true);
}
void setIndex(int value) async {
@ -144,21 +147,38 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
builder: (context, AsyncSnapshot snapshot) {
return AnimatedSlide(
curve: Curves.easeInOutCubicEmphasized,
duration: const Duration(milliseconds: 1000),
duration: const Duration(milliseconds: 500),
offset: Offset(0, snapshot.data ? 0 : 1),
child: NavigationBar(
onDestinationSelected: (value) => setIndex(value),
selectedIndex: selectedIndex,
destinations: <Widget>[
..._mainController.navigationBars.map((e) {
return NavigationDestination(
icon: e['icon'],
selectedIcon: e['selectIcon'],
label: e['label'],
);
}).toList(),
],
),
child: enableMYBar
? NavigationBar(
onDestinationSelected: (value) => setIndex(value),
selectedIndex: selectedIndex,
destinations: <Widget>[
..._mainController.navigationBars.map((e) {
return NavigationDestination(
icon: e['icon'],
selectedIcon: e['selectIcon'],
label: e['label'],
);
}).toList(),
],
)
: BottomNavigationBar(
currentIndex: selectedIndex,
onTap: (value) => setIndex(value),
iconSize: 16,
selectedFontSize: 12,
unselectedFontSize: 12,
items: [
..._mainController.navigationBars.map((e) {
return BottomNavigationBarItem(
icon: e['icon'],
activeIcon: e['selectIcon'],
label: e['label'],
);
}).toList(),
],
),
);
},
),

View File

@ -6,6 +6,7 @@ class MemberDynamicPanelController extends GetxController {
int? mid;
String offset = '';
int count = 0;
bool hasMore = true;
@override
void onInit() {
@ -14,12 +15,16 @@ class MemberDynamicPanelController extends GetxController {
}
Future getMemberDynamic() async {
if (!hasMore) {
return {'status': false};
}
var res = await MemberHttp.memberDynamic(
offset: offset,
mid: mid,
);
if (res['status']) {
offset = res['data'].offset;
hasMore = res['data'].hasMore;
}
return res;
}

View File

@ -139,11 +139,14 @@ class LoadMoreListSource extends LoadingMoreBase<DynamicItemModel> {
if (res['status']) {
addAll(res['data'].items);
}
if (res['data'].hasMore) {
isSuccess = true;
} else {
isSuccess = false;
}
try {
if (res['data'].hasMore) {
isSuccess = true;
} else {
isSuccess = false;
}
} catch (_) {}
return isSuccess;
}
}

View File

@ -41,6 +41,7 @@ class MineController extends GetxController {
'pageTitle': '登录bilibili',
},
);
// Get.toNamed('/loginPage');
} else {
int mid = userInfo.value.mid!;
String face = userInfo.value.face!;

View File

@ -125,7 +125,7 @@ class _RcmdPageState extends State<RcmdPage>
},
),
),
const LoadingMore()
LoadingMore(ctr: _rcmdController)
],
),
),
@ -191,7 +191,8 @@ class _RcmdPageState extends State<RcmdPage>
}
class LoadingMore extends StatelessWidget {
const LoadingMore({super.key});
dynamic ctr;
LoadingMore({super.key, this.ctr});
@override
Widget build(BuildContext context) {
@ -199,11 +200,18 @@ class LoadingMore extends StatelessWidget {
child: Container(
height: MediaQuery.of(context).padding.bottom + 80,
padding: EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom),
child: Center(
child: Text(
'加载中...',
style: TextStyle(
color: Theme.of(context).colorScheme.outline, fontSize: 13),
child: GestureDetector(
onTap: () {
if (ctr != null) {
ctr!.onLoad();
}
},
child: Center(
child: Text(
'加载更多 👇',
style: TextStyle(
color: Theme.of(context).colorScheme.outline, fontSize: 13),
),
),
),
),

View File

@ -117,6 +117,13 @@ class SSearchController extends GetxController {
submit();
}
onLongSelect(word) {
int index = historyList.indexOf(word);
historyList.value = historyList.removeAt(index);
historyList.refresh();
histiryWord.put('cacheList', historyList);
}
onClearHis() {
historyList.value = [];
historyCacheList = [];

View File

@ -299,20 +299,24 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
),
),
// if (_searchController.historyList.isNotEmpty)
Wrap(
spacing: 8,
runSpacing: 8,
direction: Axis.horizontal,
textDirection: TextDirection.ltr,
children: [
for (int i = 0; i < _searchController.historyList.length; i++)
SearchText(
searchText: _searchController.historyList[i],
searchTextIdx: i,
onSelect: (value) => _searchController.onSelect(value),
)
],
),
Obx(() => Wrap(
spacing: 8,
runSpacing: 8,
direction: Axis.horizontal,
textDirection: TextDirection.ltr,
children: [
for (int i = 0;
i < _searchController.historyList.length;
i++)
SearchText(
searchText: _searchController.historyList[i],
searchTextIdx: i,
onSelect: (value) => _searchController.onSelect(value),
onLongSelect: (value) =>
_searchController.onLongSelect(value),
)
],
)),
],
),
),

View File

@ -4,8 +4,14 @@ class SearchText extends StatelessWidget {
final String? searchText;
final Function? onSelect;
final int? searchTextIdx;
const SearchText(
{super.key, this.searchText, this.onSelect, this.searchTextIdx});
final Function? onLongSelect;
const SearchText({
super.key,
this.searchText,
this.onSelect,
this.searchTextIdx,
this.onLongSelect,
});
@override
Widget build(BuildContext context) {
@ -18,6 +24,9 @@ class SearchText extends StatelessWidget {
onTap: () {
onSelect!(searchText);
},
onLongPress: () {
onLongSelect!(searchText);
},
borderRadius: BorderRadius.circular(6),
child: Padding(
padding:

View File

@ -16,8 +16,12 @@ class ExtraSetting extends StatefulWidget {
class _ExtraSettingState extends State<ExtraSetting> {
Box setting = GStrorage.setting;
static Box localCache = GStrorage.localCache;
late dynamic defaultReplySort;
late dynamic defaultDynamicType;
late dynamic enableSystemProxy;
late String defaultSystemProxyHost;
late String defaultSystemProxyPort;
@override
void initState() {
@ -28,6 +32,86 @@ class _ExtraSettingState extends State<ExtraSetting> {
// 优先展示全部动态 all
defaultDynamicType =
setting.get(SettingBoxKey.defaultDynamicType, defaultValue: 0);
enableSystemProxy =
setting.get(SettingBoxKey.enableSystemProxy, defaultValue: false);
defaultSystemProxyHost =
localCache.get(LocalCacheKey.systemProxyHost, defaultValue: '');
defaultSystemProxyPort =
localCache.get(LocalCacheKey.systemProxyPort, defaultValue: '');
}
// 设置代理
void twoFADialog() {
var systemProxyHost = '';
var systemProxyPort = '';
SmartDialog.show(
useSystem: true,
animationType: SmartAnimationType.centerFade_otherSlide,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('设置代理'),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 6),
TextField(
decoration: InputDecoration(
isDense: true,
labelText: defaultSystemProxyHost != ''
? defaultSystemProxyHost
: '请输入Host使用 . 分割',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
),
hintText: defaultSystemProxyHost,
),
onChanged: (e) {
systemProxyHost = e;
},
),
const SizedBox(height: 10),
TextField(
keyboardType: TextInputType.number,
decoration: InputDecoration(
isDense: true,
labelText: defaultSystemProxyPort != ''
? defaultSystemProxyPort
: '请输入Port',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
),
hintText: defaultSystemProxyPort,
),
onChanged: (e) {
systemProxyPort = e;
},
),
],
),
actions: [
TextButton(
onPressed: () async {
SmartDialog.dismiss();
},
child: Text(
'取消',
style: TextStyle(color: Theme.of(context).colorScheme.outline),
),
),
TextButton(
onPressed: () async {
localCache.put(LocalCacheKey.systemProxyHost, systemProxyHost);
localCache.put(LocalCacheKey.systemProxyPort, systemProxyPort);
SmartDialog.dismiss();
// Request.dio;
},
child: const Text('确认'),
)
],
);
},
);
}
@override
@ -135,6 +219,33 @@ class _ExtraSettingState extends State<ExtraSetting> {
],
),
),
ListTile(
enableFeedback: true,
onTap: () => twoFADialog(),
title: Text('设置代理', style: titleStyle),
subtitle: Text('设置代理 host:port', style: subTitleStyle),
trailing: Transform.scale(
scale: 0.8,
child: Switch(
thumbIcon: MaterialStateProperty.resolveWith<Icon?>(
(Set<MaterialState> states) {
if (states.isNotEmpty &&
states.first == MaterialState.selected) {
return const Icon(Icons.done);
}
return null; // All other states will use the default thumbIcon.
}),
value: enableSystemProxy,
onChanged: (val) {
setting.put(
SettingBoxKey.enableSystemProxy, !enableSystemProxy);
setState(() {
enableSystemProxy = !enableSystemProxy;
});
},
),
),
),
const SetSwitchItem(
title: '检查更新',
subTitle: '每次启动时检查是否需要更新',

View File

@ -3,6 +3,7 @@ import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:pilipala/models/video/play/quality.dart';
import 'package:pilipala/plugin/pl_player/index.dart';
import 'package:pilipala/services/service_locator.dart';
import 'package:pilipala/utils/storage.dart';
import 'widgets/switch_item.dart';
@ -37,6 +38,14 @@ class _PlaySettingState extends State<PlaySetting> {
defaultValue: BtmProgresBehavior.values.first.code);
}
@override
void dispose() {
super.dispose();
// 重新验证媒体通知后台播放设置
videoPlayerServiceHandler.revalidateSetting();
}
@override
Widget build(BuildContext context) {
TextStyle titleStyle = Theme.of(context).textTheme.titleMedium!;
@ -67,6 +76,12 @@ class _PlaySettingState extends State<PlaySetting> {
setKey: SettingBoxKey.p1080,
defaultVal: true,
),
const SetSwitchItem(
title: 'CDN优化',
subTitle: '使用优质CDN线路',
setKey: SettingBoxKey.enableCDN,
defaultVal: true,
),
const SetSwitchItem(
title: '自动播放',
subTitle: '进入详情页自动播放',
@ -79,6 +94,12 @@ class _PlaySettingState extends State<PlaySetting> {
setKey: SettingBoxKey.enableBackgroundPlay,
defaultVal: false,
),
const SetSwitchItem(
title: '自动PiP播放',
subTitle: 'app切换至后台时画中画播放',
setKey: SettingBoxKey.autoPiP,
defaultVal: false,
),
const SetSwitchItem(
title: '自动全屏',
subTitle: '视频开始播放时进入全屏',

View File

@ -1,7 +1,6 @@
import 'dart:io';
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/models/common/theme_type.dart';
@ -78,6 +77,12 @@ class _StyleSettingState extends State<StyleSetting> {
setKey: SettingBoxKey.iosTransition,
defaultVal: false,
),
const SetSwitchItem(
title: 'MD3样式底栏',
subTitle: '符合Material You设计规范的底栏',
setKey: SettingBoxKey.enableMYBar,
defaultVal: true,
),
// SetSwitchItem(
// title: '首页单列',
// subTitle: '每行展示一个内容卡片',

View File

@ -16,6 +16,7 @@ import 'package:pilipala/pages/video/detail/replyReply/index.dart';
import 'package:pilipala/plugin/pl_player/index.dart';
import 'package:pilipala/utils/storage.dart';
import 'package:pilipala/utils/utils.dart';
import 'package:pilipala/utils/video_utils.dart';
import 'package:screen_brightness/screen_brightness.dart';
import 'widgets/header_control.dart';
@ -83,6 +84,11 @@ class VideoDetailController extends GetxController
Floating? floating;
late PreferredSizeWidget headerControl;
late bool enableCDN;
late int? cacheVideoQa;
late String cacheDecode;
late int cacheAudioQa;
@override
void onInit() {
super.onInit();
@ -120,6 +126,15 @@ class VideoDetailController extends GetxController
videoDetailCtr: this,
floating: floating,
);
// CDN优化
enableCDN = setting.get(SettingBoxKey.enableCDN, defaultValue: true);
// 预设的画质
cacheVideoQa = setting.get(SettingBoxKey.defaultVideoQa);
// 预设的解码格式
cacheDecode = setting.get(SettingBoxKey.defaultDecode,
defaultValue: VideoDecodeFormats.values.last.code);
cacheAudioQa = setting.get(SettingBoxKey.defaultAudioQa,
defaultValue: AudioQuality.hiRes.code);
}
showReplyReplyPanel() {
@ -231,22 +246,19 @@ class VideoDetailController extends GetxController
var result = await VideoHttp.videoUrl(cid: cid.value, bvid: bvid);
if (result['status']) {
data = result['data'];
List<VideoItem> allVideosList = data.dash!.video!;
try {
// 当前可播放的最高质量视频
int currentHighVideoQa = allVideosList.first.quality!.code;
// 使用预设的画质 当前可用的最高质量
int cacheVideoQa = setting.get(SettingBoxKey.defaultVideoQa,
defaultValue: currentHighVideoQa);
// 预设的画质为null当前可用的最高质量
cacheVideoQa ??= currentHighVideoQa;
int resVideoQa = currentHighVideoQa;
if (cacheVideoQa <= currentHighVideoQa) {
if (cacheVideoQa! <= currentHighVideoQa) {
// 如果预设的画质低于当前最高
List<int> numbers = data.acceptQuality!
.where((e) => e <= currentHighVideoQa)
.toList();
resVideoQa = Utils.findClosestNumber(cacheVideoQa, numbers);
resVideoQa = Utils.findClosestNumber(cacheVideoQa!, numbers);
}
currentVideoQa = VideoQualityCode.fromCode(resVideoQa)!;
@ -260,9 +272,7 @@ class VideoDetailController extends GetxController
List supportDecodeFormats =
supportFormats.firstWhere((e) => e.quality == resVideoQa).codecs!;
// 默认从设置中取AVC
currentDecodeFormats = VideoDecodeFormatsCode.fromString(setting.get(
SettingBoxKey.defaultDecode,
defaultValue: VideoDecodeFormats.values.last.code))!;
currentDecodeFormats = VideoDecodeFormatsCode.fromString(cacheDecode)!;
try {
// 当前视频没有对应格式返回第一个
bool flag = false;
@ -285,7 +295,9 @@ class VideoDetailController extends GetxController
} catch (_) {
firstVideo = videosList.first;
}
videoUrl = firstVideo.baseUrl!;
videoUrl = enableCDN
? VideoUtils.getCdnUrl(firstVideo)
: (firstVideo.backupUrl ?? firstVideo.baseUrl!);
} catch (err) {
SmartDialog.showToast('firstVideo error: $err');
}
@ -295,8 +307,6 @@ class VideoDetailController extends GetxController
List<AudioItem> audiosList = data.dash!.audio!;
try {
int resultAudioQa = setting.get(SettingBoxKey.defaultAudioQa,
defaultValue: AudioQuality.hiRes.code);
if (data.dash!.dolby?.audio?.isNotEmpty == true) {
// 杜比
audiosList.insert(0, data.dash!.dolby!.audio!.first);
@ -309,9 +319,9 @@ class VideoDetailController extends GetxController
if (audiosList.isNotEmpty) {
List<int> numbers = audiosList.map((map) => map.id!).toList();
int closestNumber = Utils.findClosestNumber(resultAudioQa, numbers);
if (!numbers.contains(resultAudioQa) &&
numbers.any((e) => e > resultAudioQa)) {
int closestNumber = Utils.findClosestNumber(cacheAudioQa, numbers);
if (!numbers.contains(cacheAudioQa) &&
numbers.any((e) => e > cacheAudioQa)) {
closestNumber = 30280;
}
firstAudio = audiosList.firstWhere((e) => e.id == closestNumber);
@ -323,7 +333,9 @@ class VideoDetailController extends GetxController
SmartDialog.showToast('firstAudio error: $err');
}
audioUrl = firstAudio.baseUrl ?? '';
audioUrl = enableCDN
? VideoUtils.getCdnUrl(firstAudio)
: (firstAudio.backupUrl ?? firstAudio.baseUrl!);
//
if (firstAudio.id != null) {
currentAudioQa = AudioQualityCode.fromCode(firstAudio.id!)!;

View File

@ -8,6 +8,7 @@ import 'package:pilipala/http/constants.dart';
import 'package:pilipala/http/user.dart';
import 'package:pilipala/http/video.dart';
import 'package:pilipala/models/user/fav_folder.dart';
import 'package:pilipala/models/video/ai.dart';
import 'package:pilipala/models/video_detail_res.dart';
import 'package:pilipala/pages/video/detail/controller.dart';
import 'package:pilipala/pages/video/detail/reply/index.dart';
@ -61,12 +62,16 @@ class VideoIntroController extends GetxController {
RxString total = '1'.obs;
Timer? timer;
bool isPaused = false;
String heroTag = Get.arguments['heroTag'];
String heroTag = '';
late ModelResult modelResult;
@override
void onInit() {
super.onInit();
userInfo = userInfoCache.get('userInfoCache');
try {
heroTag = Get.arguments['heroTag'];
} catch (_) {}
if (Get.arguments.isNotEmpty) {
if (Get.arguments.containsKey('videoItem')) {
preRender = true;
@ -509,19 +514,7 @@ class VideoIntroController extends GetxController {
/// 列表循环或者顺序播放时,自动播放下一个
void nextPlay() {
late List episodes;
// if (videoDetail.value.ugcSeason != null) {
// UgcSeason ugcSeason = videoDetail.value.ugcSeason!;
// List<SectionItem> sections = ugcSeason.sections!;
// for (int i = 0; i < sections.length; i++) {
// List<EpisodeItem> episodesList = sections[i].episodes!;
// for (int j = 0; j < episodesList.length; j++) {
// if (episodesList[j].cid == lastPlayCid.value) {
// episodes = episodesList;
// continue;
// }
// }
// }
// }
bool isPages = false;
if (videoDetail.value.ugcSeason != null) {
UgcSeason ugcSeason = videoDetail.value.ugcSeason!;
List<SectionItem> sections = ugcSeason.sections!;
@ -531,6 +524,11 @@ class VideoIntroController extends GetxController {
List<EpisodeItem> episodesList = sections[i].episodes!;
episodes.addAll(episodesList);
}
} else if (videoDetail.value.pages != null) {
isPages = true;
List<Part> pages = videoDetail.value.pages!;
episodes = [];
episodes.addAll(pages);
}
int currentIndex = episodes.indexWhere((e) => e.cid == lastPlayCid.value);
@ -549,9 +547,9 @@ class VideoIntroController extends GetxController {
}
}
int cid = episodes[nextIndex].cid!;
String bvid = episodes[nextIndex].bvid!;
int aid = episodes[nextIndex].aid!;
changeSeasonOrbangu(bvid, cid, aid);
String rBvid = isPages ? bvid : episodes[nextIndex].bvid;
int rAid = isPages ? IdUtils.bv2av(bvid) : episodes[nextIndex].aid!;
changeSeasonOrbangu(rBvid, cid, rAid);
}
// 设置关注分组
@ -561,4 +559,25 @@ class VideoIntroController extends GetxController {
isScrollControlled: true,
);
}
// ai总结
Future aiConclusion() async {
SmartDialog.showLoading(msg: '正在生产ai总结');
var res = await VideoHttp.aiConclusion(
bvid: bvid,
cid: lastPlayCid.value,
upMid: videoDetail.value.owner!.mid!,
);
if (res['status']) {
if (res['data'].modelResult.resultType == 0) {
SmartDialog.showToast('该视频不支持ai总结');
}
if (res['data'].modelResult.resultType == 2 ||
res['data'].modelResult.resultType == 1) {
modelResult = res['data'].modelResult;
}
}
SmartDialog.dismiss();
return res;
}
}

View File

@ -11,6 +11,8 @@ import 'package:pilipala/common/widgets/stat/danmu.dart';
import 'package:pilipala/common/widgets/stat/view.dart';
import 'package:pilipala/models/video_detail_res.dart';
import 'package:pilipala/pages/video/detail/introduction/controller.dart';
import 'package:pilipala/pages/video/detail/widgets/ai_detail.dart';
import 'package:pilipala/services/service_locator.dart';
import 'package:pilipala/utils/feed_back.dart';
import 'package:pilipala/utils/storage.dart';
import 'package:pilipala/utils/utils.dart';
@ -226,6 +228,17 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
arguments: {'face': face, 'heroTag': memberHeroTag});
}
// ai总结
showAiBottomSheet() {
showBottomSheet(
context: context,
enableDrag: true,
builder: (BuildContext context) {
return AiDetail(modelResult: videoIntroController.modelResult);
},
);
}
@override
Widget build(BuildContext context) {
ThemeData t = Theme.of(context);
@ -238,70 +251,91 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
? Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () => showIntroDetail(),
child: Padding(
padding: const EdgeInsets.only(bottom: 6),
child: Text(
!loadingStatus
? widget.videoDetail!.title
: videoItem['title'],
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
)),
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () => showIntroDetail(),
child: Row(
children: [
StatView(
theme: 'gray',
view: !widget.loadingStatus
? widget.videoDetail!.stat!.view
: videoItem['stat'].view,
size: 'medium',
),
const SizedBox(width: 10),
StatDanMu(
theme: 'gray',
danmu: !widget.loadingStatus
? widget.videoDetail!.stat!.danmaku
: videoItem['stat'].danmaku,
size: 'medium',
),
const SizedBox(width: 10),
Text(
Utils.dateFormat(
!widget.loadingStatus
? widget.videoDetail!.pubdate
: videoItem['pubdate'],
formatType: 'detail'),
style: TextStyle(
fontSize: 12,
color: t.colorScheme.outline,
),
),
const SizedBox(width: 10),
if (videoIntroController.isShowOnlineTotal)
Obx(
() => Text(
'${videoIntroController.total.value}人在看',
style: TextStyle(
fontSize: 12,
color: t.colorScheme.outline,
),
),
),
],
child: Text(
!loadingStatus
? widget.videoDetail!.title
: videoItem['title'],
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(height: 7),
Stack(
children: [
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () => showIntroDetail(),
child: Padding(
padding: const EdgeInsets.only(top: 7, bottom: 6),
child: Row(
children: [
StatView(
theme: 'gray',
view: !widget.loadingStatus
? widget.videoDetail!.stat!.view
: videoItem['stat'].view,
size: 'medium',
),
const SizedBox(width: 10),
StatDanMu(
theme: 'gray',
danmu: !widget.loadingStatus
? widget.videoDetail!.stat!.danmaku
: videoItem['stat'].danmaku,
size: 'medium',
),
const SizedBox(width: 10),
Text(
Utils.dateFormat(
!widget.loadingStatus
? widget.videoDetail!.pubdate
: videoItem['pubdate'],
formatType: 'detail'),
style: TextStyle(
fontSize: 12,
color: t.colorScheme.outline,
),
),
const SizedBox(width: 10),
if (videoIntroController.isShowOnlineTotal)
Obx(
() => Text(
'${videoIntroController.total.value}人在看',
style: TextStyle(
fontSize: 12,
color: t.colorScheme.outline,
),
),
),
],
),
),
),
Positioned(
right: 10,
top: 6,
child: GestureDetector(
onTap: () async {
var res = await videoIntroController.aiConclusion();
if (res['status']) {
if (res['data'].modelResult.resultType == 2 ||
res['data'].modelResult.resultType == 1) {
showAiBottomSheet();
}
}
},
child:
Image.asset('assets/images/ai.png', height: 22),
),
)
],
),
// 点赞收藏转发 布局样式1
// SingleChildScrollView(
// padding: const EdgeInsets.only(top: 7, bottom: 7),

View File

@ -92,11 +92,11 @@ class VideoReplyController extends GetxController {
}
}
replies.insertAll(0, res['data'].topReplies);
count.value = res['data'].page.count;
replyList.value = replies;
} else {
replyList.addAll(replies);
}
count.value = res['data'].page.count;
}
isLoadingMore = false;
return res;

View File

@ -669,58 +669,70 @@ InlineSpan buildContent(
String matchUrl = matchMember;
if (content.jumpUrl.isNotEmpty && hasMatchMember) {
List urlKeys = content.jumpUrl.keys.toList().reversed.toList();
for (var index = 0; index < urlKeys.length; index++) {
var i = urlKeys[index];
if (i.contains('?')) {
urlKeys[index] = i.replaceAll('?', '\\?');
}
}
matchUrl = matchMember.splitMapJoin(
/// RegExp.escape() 转义特殊字符
RegExp(urlKeys.map((key) => key).join("|")),
// RegExp(RegExp.escape(urlKeys.join("|"))),
// RegExp('What does the fox say\\?'),
onMatch: (Match match) {
String matchStr = match[0]!;
String appUrlSchema = content.jumpUrl[matchStr]['app_url_schema'];
String appUrlSchema = '';
if (content.jumpUrl[matchStr] != null) {
appUrlSchema = content.jumpUrl[matchStr]['app_url_schema'];
}
// 默认不显示关键词
bool enableWordRe =
setting.get(SettingBoxKey.enableWordRe, defaultValue: false);
spanChilds.add(
TextSpan(
text: content.jumpUrl[matchStr]['title'],
style: TextStyle(
color: enableWordRe
? Theme.of(context).colorScheme.primary
: null,
),
recognizer: TapGestureRecognizer()
..onTap = () {
if (appUrlSchema == '') {
String str = Uri.parse(matchStr).pathSegments[0];
Map matchRes = IdUtils.matchAvorBv(input: str);
List matchKeys = matchRes.keys.toList();
if (matchKeys.isNotEmpty) {
if (matchKeys.first == 'BV') {
if (content.jumpUrl[matchStr] != null) {
spanChilds.add(
TextSpan(
text: content.jumpUrl[matchStr]['title'],
style: TextStyle(
color: enableWordRe
? Theme.of(context).colorScheme.primary
: null,
),
recognizer: TapGestureRecognizer()
..onTap = () {
if (appUrlSchema == '') {
String str = Uri.parse(matchStr).pathSegments[0];
Map matchRes = IdUtils.matchAvorBv(input: str);
List matchKeys = matchRes.keys.toList();
if (matchKeys.isNotEmpty) {
if (matchKeys.first == 'BV') {
Get.toNamed(
'/searchResult',
parameters: {'keyword': matchRes['BV']},
);
}
} else {
Get.toNamed(
'/searchResult',
parameters: {'keyword': matchRes['BV']},
'/webview',
parameters: {
'url': matchStr,
'type': 'url',
'pageTitle': ''
},
);
}
} else {
Get.toNamed(
'/webview',
parameters: {
'url': matchStr,
'type': 'url',
'pageTitle': ''
},
);
if (appUrlSchema.startsWith('bilibili://search') &&
enableWordRe) {
Get.toNamed('/searchResult', parameters: {
'keyword': content.jumpUrl[matchStr]['title']
});
}
}
} else {
if (appUrlSchema.startsWith('bilibili://search') &&
enableWordRe) {
Get.toNamed('/searchResult', parameters: {
'keyword': content.jumpUrl[matchStr]['title']
});
}
}
},
),
);
},
),
);
}
if (appUrlSchema.startsWith('bilibili://search') && enableWordRe) {
spanChilds.add(
WidgetSpan(

View File

@ -3,27 +3,24 @@ import 'dart:io';
import 'package:extended_nested_scroll_view/extended_nested_scroll_view.dart';
import 'package:floating/floating.dart';
import 'package:flutter/services.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:pilipala/common/widgets/network_img_layer.dart';
import 'package:pilipala/common/widgets/sliver_header.dart';
import 'package:pilipala/http/user.dart';
import 'package:pilipala/models/common/search_type.dart';
import 'package:pilipala/pages/bangumi/introduction/index.dart';
import 'package:pilipala/pages/danmaku/view.dart';
import 'package:pilipala/pages/video/detail/introduction/widgets/menu_row.dart';
import 'package:pilipala/pages/video/detail/reply/index.dart';
import 'package:pilipala/pages/video/detail/controller.dart';
import 'package:pilipala/pages/video/detail/introduction/index.dart';
import 'package:pilipala/pages/video/detail/related/index.dart';
import 'package:pilipala/plugin/pl_player/index.dart';
import 'package:pilipala/plugin/pl_player/models/play_repeat.dart';
import 'package:pilipala/services/service_locator.dart';
import 'package:pilipala/utils/storage.dart';
import 'widgets/app_bar.dart';
import 'widgets/header_control.dart';
class VideoDetailPage extends StatefulWidget {
@ -36,7 +33,7 @@ class VideoDetailPage extends StatefulWidget {
}
class _VideoDetailPageState extends State<VideoDetailPage>
with TickerProviderStateMixin, RouteAware {
with TickerProviderStateMixin, RouteAware, WidgetsBindingObserver {
late VideoDetailController videoDetailController;
PlPlayerController? plPlayerController;
final ScrollController _extendNestCtr = ScrollController();
@ -56,6 +53,8 @@ class _VideoDetailPageState extends State<VideoDetailPage>
// 自动退出全屏
late bool autoExitFullcreen;
late bool autoPlayEnable;
late bool autoPiP;
final floating = Floating();
@override
void initState() {
@ -63,14 +62,29 @@ class _VideoDetailPageState extends State<VideoDetailPage>
heroTag = Get.arguments['heroTag'];
videoDetailController = Get.put(VideoDetailController(), tag: heroTag);
videoIntroController = Get.put(VideoIntroController(), tag: heroTag);
videoIntroController.videoDetail.listen((value) {
videoPlayerServiceHandler.onVideoDetailChange(
value, videoDetailController.cid.value);
});
bangumiIntroController = Get.put(BangumiIntroController(), tag: heroTag);
bangumiIntroController.bangumiDetail.listen((value) {
videoPlayerServiceHandler.onVideoDetailChange(
value, videoDetailController.cid.value);
});
videoDetailController.cid.listen((p0) {
videoPlayerServiceHandler.onVideoDetailChange(
bangumiIntroController.bangumiDetail.value, p0);
});
statusBarHeight = localCache.get('statusBarHeight');
autoExitFullcreen =
setting.get(SettingBoxKey.enableAutoExit, defaultValue: false);
autoPlayEnable =
setting.get(SettingBoxKey.autoPlayEnable, defaultValue: true);
autoPiP = setting.get(SettingBoxKey.autoPiP, defaultValue: false);
videoSourceInit();
appbarStreamListen();
WidgetsBinding.instance.addObserver(this);
}
// 获取视频资源,初始化播放器
@ -153,6 +167,9 @@ class _VideoDetailPageState extends State<VideoDetailPage>
if (videoDetailController.floating != null) {
videoDetailController.floating!.dispose();
}
videoPlayerServiceHandler.onVideoDetailDispose();
WidgetsBinding.instance.removeObserver(this);
floating.dispose();
super.dispose();
}
@ -199,6 +216,17 @@ class _VideoDetailPageState extends State<VideoDetailPage>
.subscribe(this, ModalRoute.of(context) as PageRoute);
}
@override
void didChangeAppLifecycleState(AppLifecycleState lifecycleState) {
if (lifecycleState == AppLifecycleState.inactive && autoPiP) {
floating.enable(
aspectRatio: Rational(
videoDetailController.data.dash!.video!.first.width!,
videoDetailController.data.dash!.video!.first.height!,
));
}
}
@override
Widget build(BuildContext context) {
final videoHeight = MediaQuery.of(context).size.width * 9 / 16;
@ -497,6 +525,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
return PiPSwitcher(
childWhenDisabled: childWhenDisabled,
childWhenEnabled: childWhenEnabled,
floating: floating,
);
} else {
return childWhenDisabled;

View File

@ -0,0 +1,236 @@
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/models/video/ai.dart';
import 'package:pilipala/pages/video/detail/index.dart';
import 'package:pilipala/utils/storage.dart';
import 'package:pilipala/utils/utils.dart';
Box localCache = GStrorage.localCache;
late double sheetHeight;
class AiDetail extends StatelessWidget {
final ModelResult? modelResult;
const AiDetail({
Key? key,
this.modelResult,
}) : super(key: key);
@override
Widget build(BuildContext context) {
sheetHeight = localCache.get('sheetHeight');
return Container(
color: Theme.of(context).colorScheme.background,
padding: const EdgeInsets.only(left: 14, right: 14),
height: sheetHeight,
child: Column(
children: [
InkWell(
onTap: () => Get.back(),
child: Container(
height: 35,
padding: const EdgeInsets.only(bottom: 2),
child: Center(
child: Container(
width: 32,
height: 3,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary,
borderRadius: const BorderRadius.all(Radius.circular(3)),
),
),
),
),
),
Expanded(
child: SingleChildScrollView(
child: Column(
children: [
Text(
modelResult!.summary!,
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
height: 1.5,
),
),
const SizedBox(height: 20),
ListView.builder(
shrinkWrap: true,
itemCount: modelResult!.outline!.length,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return Column(
children: [
Text(
modelResult!.outline![index].title!,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
height: 1.5,
),
),
const SizedBox(height: 6),
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: modelResult!
.outline![index].partOutline!.length,
itemBuilder: (context, i) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Wrap(
children: [
RichText(
text: TextSpan(
style: TextStyle(
fontSize: 13,
color: Theme.of(context)
.colorScheme
.onBackground,
height: 1.5,
),
children: [
TextSpan(
text: Utils.tampToSeektime(
modelResult!
.outline![index]
.partOutline![i]
.timestamp!),
style: TextStyle(
color: Theme.of(context)
.colorScheme
.primary,
),
recognizer: TapGestureRecognizer()
..onTap = () {
// 跳转到指定位置
try {
Get.find<VideoDetailController>(
tag: Get.arguments[
'heroTag'])
.plPlayerController
.seekTo(
Duration(
seconds:
Utils.duration(
Utils.tampToSeektime(modelResult!
.outline![
index]
.partOutline![
i]
.timestamp!)
.toString(),
),
),
);
} catch (_) {}
},
),
const TextSpan(text: ' '),
TextSpan(
text: modelResult!
.outline![index]
.partOutline![i]
.content!),
],
),
),
],
),
],
);
},
),
const SizedBox(height: 20),
],
);
},
)
],
),
),
),
],
),
);
}
InlineSpan buildContent(BuildContext context, content) {
List descV2 = content.descV2;
// type
// 1 普通文本
// 2 @用户
List<TextSpan> spanChilds = List.generate(descV2.length, (index) {
final currentDesc = descV2[index];
switch (currentDesc.type) {
case 1:
List<InlineSpan> spanChildren = [];
RegExp urlRegExp = RegExp(r'https?://\S+\b');
Iterable<Match> 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);
return TextSpan(
text: '@${currentDesc.rawText}',
style: TextStyle(color: colorSchemePrimary),
recognizer: TapGestureRecognizer()
..onTap = () {
Get.toNamed(
'/member?mid=${currentDesc.bizId}',
arguments: {'face': '', 'heroTag': heroTag},
);
},
);
default:
return const TextSpan();
}
});
return TextSpan(children: spanChilds);
}
}

View File

@ -43,6 +43,7 @@ class _HeaderControlState extends State<HeaderControl> {
Box localCache = GStrorage.localCache;
Box videoStorage = GStrorage.video;
late List speedsList;
double buttonSpace = 8;
@override
void initState() {
@ -88,7 +89,6 @@ class _HeaderControlState extends State<HeaderControl> {
Expanded(
child: Material(
child: ListView(
physics: const NeverScrollableScrollPhysics(),
children: [
ListTile(
onTap: () {},
@ -182,8 +182,8 @@ class _HeaderControlState extends State<HeaderControl> {
/// 选择倍速
void showSetSpeedSheet() {
double currentSpeed = widget.controller!.playbackSpeed;
SmartDialog.show(
animationType: SmartAnimationType.centerFade_otherSlide,
showDialog(
context: Get.context!,
builder: (context) {
return AlertDialog(
title: const Text('播放速度'),
@ -196,12 +196,20 @@ class _HeaderControlState extends State<HeaderControl> {
for (var i in speedsList) ...[
if (i == currentSpeed) ...[
FilledButton(
onPressed: () => {setState(() => currentSpeed = i)},
onPressed: () async {
// setState(() => currentSpeed = i),
await widget.controller!.setPlaybackSpeed(i);
Get.back();
},
child: Text(i.toString()),
),
] else ...[
FilledButton.tonal(
onPressed: () => {setState(() => currentSpeed = i)},
onPressed: () async {
// setState(() => currentSpeed = i),
await widget.controller!.setPlaybackSpeed(i);
Get.back();
},
child: Text(i.toString()),
),
]
@ -219,10 +227,10 @@ class _HeaderControlState extends State<HeaderControl> {
),
TextButton(
onPressed: () async {
await SmartDialog.dismiss();
widget.controller!.setPlaybackSpeed(currentSpeed);
await widget.controller!.setDefaultSpeed();
Get.back();
},
child: const Text('确定'),
child: const Text('默认速度'),
),
],
);
@ -276,7 +284,7 @@ class _HeaderControlState extends State<HeaderControl> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('选择画质', style: titleStyle),
const SizedBox(width: 4),
SizedBox(width: buttonSpace),
Icon(
Icons.info_outline,
size: 16,
@ -793,7 +801,7 @@ class _HeaderControlState extends State<HeaderControl> {
),
fuc: () => Get.back(),
),
const SizedBox(width: 4),
SizedBox(width: buttonSpace),
ComBtn(
icon: const Icon(
FontAwesomeIcons.house,
@ -838,7 +846,7 @@ class _HeaderControlState extends State<HeaderControl> {
),
),
),
const SizedBox(width: 4),
SizedBox(width: buttonSpace),
if (Platform.isAndroid) ...[
SizedBox(
width: 34,
@ -870,7 +878,7 @@ class _HeaderControlState extends State<HeaderControl> {
),
),
),
const SizedBox(width: 4),
SizedBox(width: buttonSpace),
],
Obx(
() => SizedBox(
@ -888,7 +896,7 @@ class _HeaderControlState extends State<HeaderControl> {
),
),
),
const SizedBox(width: 4),
SizedBox(width: buttonSpace),
ComBtn(
icon: const Icon(
FontAwesomeIcons.sliders,