Skip to content

Commit

Permalink
Merge branch 'main' into fix
Browse files Browse the repository at this point in the history
  • Loading branch information
guozhigq committed Apr 2, 2024
2 parents 53b103b + c6de1fa commit 3fa72f5
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 67 deletions.
2 changes: 2 additions & 0 deletions lib/http/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,6 @@ class Api {
/// 排行榜
static const String getRankApi = "/x/web-interface/ranking/v2";

/// 取消订阅
static const String cancelSub = '/x/v3/fav/season/unfav';
}
17 changes: 17 additions & 0 deletions lib/http/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,21 @@ class UserHttp {
return {'status': false, 'msg': res.data['message']};
}
}

// 取消订阅
static Future cancelSub({required int seasonId}) async {
var res = await Request().post(
Api.cancelSub,
queryParameters: {
'platform': 'web',
'season_id': seasonId,
'csrf': await Request.getCsrf(),
},
);
if (res.data['code'] == 0) {
return {'status': true};
} else {
return {'status': false, 'msg': res.data['message']};
}
}
}
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void main() async {
.then((_) async {
await GStrorage.init();
await setupServiceLocator();
clearLogs();
Request();
await Request.setCookie();
RecommendFilter();
Expand Down
5 changes: 5 additions & 0 deletions lib/models/member/info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,23 @@ class Vip {
this.status,
this.dueDate,
this.label,
this.nicknameColor,
});

int? type;
int? status;
int? dueDate;
Map? label;
int? nicknameColor;

Vip.fromJson(Map<String, dynamic> json) {
type = json['type'];
status = json['status'];
dueDate = json['due_date'];
label = json['label'];
nicknameColor = json['nickname_color'] == ''
? null
: int.parse("0xFF${json['nickname_color'].replaceAll('#', '')}");
}
}

Expand Down
39 changes: 21 additions & 18 deletions lib/pages/history/widgets/item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -258,24 +258,27 @@ class HistoryItem extends StatelessWidget {
),
),
),
Positioned(
left: 3,
right: 3,
bottom: 0,
child: ClipRRect(
borderRadius: BorderRadius.only(
bottomLeft:
Radius.circular(StyleString.imgRadius.x),
bottomRight:
Radius.circular(StyleString.imgRadius.x),
),
child: LinearProgressIndicator(
value: videoItem.progress == -1
? 100
: videoItem.progress / videoItem.duration,
),
),
)
videoItem.progress != 0
? Positioned(
left: 3,
right: 3,
bottom: 0,
child: ClipRRect(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(
StyleString.imgRadius.x),
bottomRight: Radius.circular(
StyleString.imgRadius.x),
),
child: LinearProgressIndicator(
value: videoItem.progress == -1
? 100
: videoItem.progress /
videoItem.duration,
),
),
)
: const SizedBox()
],
),
VideoContent(videoItem: videoItem, ctr: ctr)
Expand Down
13 changes: 10 additions & 3 deletions lib/pages/member/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ class _MemberPageState extends State<MemberPage>
future: _futureBuilderFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
Map data = snapshot.data!;
if (data['status']) {
Map? data = snapshot.data;
if (data != null && data['status']) {
return Obx(
() => Stack(
alignment: AlignmentDirectional.center,
Expand All @@ -302,7 +302,14 @@ class _MemberPageState extends State<MemberPage>
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(fontWeight: FontWeight.bold),
.copyWith(
fontWeight: FontWeight.bold,
color: _memberController.memberInfo.value
.vip!.nicknameColor !=
null
? Color(_memberController.memberInfo
.value.vip!.nicknameColor!)
: null),
)),
const SizedBox(width: 2),
if (_memberController.memberInfo.value.sex == '女')
Expand Down
53 changes: 20 additions & 33 deletions lib/pages/member/widgets/seasons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,32 @@ class MemberSeasonsPanel extends StatelessWidget {
itemBuilder: (context, index) {
MemberSeasonsList item = data!.seasonsList![index];
return Padding(
padding: const EdgeInsets.only(bottom: 12, right: 4),
padding: const EdgeInsets.only(bottom: 12),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 12, left: 4),
child: Row(
children: [
Text(
item.meta!.name!,
maxLines: 1,
style: Theme.of(context).textTheme.titleSmall!,
),
const SizedBox(width: 10),
PBadge(
stack: 'relative',
size: 'small',
text: item.meta!.total.toString(),
),
const Spacer(),
SizedBox(
width: 35,
height: 35,
child: IconButton(
onPressed: () => Get.toNamed(
'/memberSeasons?mid=${item.meta!.mid}&seasonId=${item.meta!.seasonId}'),
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.zero),
),
icon: const Icon(
Icons.arrow_forward,
size: 20,
),
),
)
],
ListTile(
onTap: () => Get.toNamed(
'/memberSeasons?mid=${item.meta!.mid}&seasonId=${item.meta!.seasonId}'),
title: Text(
item.meta!.name!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.titleSmall!,
),
dense: true,
leading: PBadge(
stack: 'relative',
size: 'small',
text: item.meta!.total.toString(),
),
trailing: const Icon(
Icons.arrow_forward,
size: 20,
),
),
const SizedBox(height: 10),
LayoutBuilder(
builder: (context, boxConstraints) {
return GridView.builder(
Expand Down
36 changes: 36 additions & 0 deletions lib/pages/subscription/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,40 @@ class SubController extends GetxController {
Future onLoad() async {
querySubFolder(type: 'onload');
}

// 取消订阅
Future<void> cancelSub(SubFolderItemData subFolderItem) async {
showDialog(
context: Get.context!,
builder: (context) => AlertDialog(
title: const Text('提示'),
content: const Text('确定取消订阅吗?'),
actions: [
TextButton(
onPressed: () {
Get.back();
},
child: Text(
'取消',
style: TextStyle(color: Theme.of(context).colorScheme.outline),
),
),
TextButton(
onPressed: () async {
var res = await UserHttp.cancelSub(seasonId: subFolderItem.id!);
if (res['status']) {
subFolderData.value.list!.remove(subFolderItem);
subFolderData.update((val) {});
SmartDialog.showToast('取消订阅成功');
} else {
SmartDialog.showToast(res['msg']);
}
Get.back();
},
child: const Text('确定'),
),
],
),
);
}
}
3 changes: 2 additions & 1 deletion lib/pages/subscription/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class _SubPageState extends State<SubPage> {
itemBuilder: (context, index) {
return SubItem(
subFolderItem:
_subController.subFolderData.value.list![index]);
_subController.subFolderData.value.list![index],
cancelSub: _subController.cancelSub);
},
),
);
Expand Down
33 changes: 30 additions & 3 deletions lib/pages/subscription/widgets/item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import '../../../models/user/sub_folder.dart';

class SubItem extends StatelessWidget {
final SubFolderItemData subFolderItem;
const SubItem({super.key, required this.subFolderItem});
final Function(SubFolderItemData) cancelSub;
const SubItem({
super.key,
required this.subFolderItem,
required this.cancelSub,
});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -51,7 +56,10 @@ class SubItem extends StatelessWidget {
},
),
),
VideoContent(subFolderItem: subFolderItem)
VideoContent(
subFolderItem: subFolderItem,
cancelSub: cancelSub,
)
],
),
);
Expand All @@ -64,7 +72,8 @@ class SubItem extends StatelessWidget {

class VideoContent extends StatelessWidget {
final SubFolderItemData subFolderItem;
const VideoContent({super.key, required this.subFolderItem});
final Function(SubFolderItemData)? cancelSub;
const VideoContent({super.key, required this.subFolderItem, this.cancelSub});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -100,6 +109,24 @@ class VideoContent extends StatelessWidget {
color: Theme.of(context).colorScheme.outline,
),
),
const Spacer(),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
SizedBox(
height: 35,
width: 35,
child: IconButton(
onPressed: () => cancelSub?.call(subFolderItem),
style: TextButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.outline,
padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
),
icon: const Icon(Icons.delete_outline, size: 18),
),
)
],
)
],
),
),
Expand Down
40 changes: 36 additions & 4 deletions lib/pages/video/detail/reply/widgets/reply_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,18 @@ InlineSpan buildContent(
if (jumpUrlKeysList.isNotEmpty) {
patternStr += '|${jumpUrlKeysList.join('|')}';
}
RegExp bv23Regex = RegExp(r'https://b23\.tv/[a-zA-Z0-9]{7}');
final RegExp pattern = RegExp(patternStr);
List<String> matchedStrs = [];
void addPlainTextSpan(str) {
spanChilds.add(TextSpan(
spanChilds.add(
TextSpan(
text: str,
recognizer: TapGestureRecognizer()
..onTap = () =>
replyReply?.call(replyItem.root == 0 ? replyItem : fReplyItem)));
replyReply?.call(replyItem.root == 0 ? replyItem : fReplyItem),
),
);
}

// 分割文本并处理每个部分
Expand Down Expand Up @@ -734,8 +738,36 @@ InlineSpan buildContent(
return '';
},
onNonMatch: (String nonMatchStr) {
addPlainTextSpan(nonMatchStr);
return nonMatchStr;
return nonMatchStr.splitMapJoin(
bv23Regex,
onMatch: (Match match) {
String matchStr = match[0]!;
spanChilds.add(
TextSpan(
text: ' $matchStr ',
style: isVideoPage
? TextStyle(
color: Theme.of(context).colorScheme.primary,
)
: null,
recognizer: TapGestureRecognizer()
..onTap = () => Get.toNamed(
'/webview',
parameters: {
'url': matchStr,
'type': 'url',
'pageTitle': matchStr
},
),
),
);
return '';
},
onNonMatch: (String nonMatchOtherStr) {
addPlainTextSpan(nonMatchOtherStr);
return nonMatchOtherStr;
},
);
},
);

Expand Down
12 changes: 7 additions & 5 deletions lib/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,16 @@ class Utils {

static int findClosestNumber(int target, List<int> numbers) {
int minDiff = 127;
late int closestNumber;
int closestNumber = 0; // 初始化为0,表示没有找到比目标值小的整数
try {
for (int number in numbers) {
int diff = (number - target).abs();
if (number < target) {
int diff = target - number; // 计算目标值与当前整数的差值

if (diff < minDiff) {
minDiff = diff;
closestNumber = number;
if (diff < minDiff) {
minDiff = diff;
closestNumber = number;
}
}
}
} catch (_) {}
Expand Down

0 comments on commit 3fa72f5

Please sign in to comment.