mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-20 11:08:03 +08:00
feat: dyn reserve
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
|
||||
import 'package:PiliPlus/http/search.dart';
|
||||
import 'package:PiliPlus/http/dynamics.dart';
|
||||
import 'package:PiliPlus/models/dynamics/result.dart';
|
||||
import 'package:PiliPlus/utils/page_utils.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:PiliPlus/utils/app_scheme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
|
||||
@@ -10,49 +9,19 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
Widget addWidget(
|
||||
ThemeData theme, DynamicItemModel item, BuildContext context, type,
|
||||
{floor = 1}) {
|
||||
Map<dynamic, dynamic> dynamicProperty = {
|
||||
'ADDITIONAL_TYPE_UGC': item.modules.moduleDynamic!.additional!.ugc,
|
||||
// 直播预约
|
||||
'ADDITIONAL_TYPE_RESERVE': item.modules.moduleDynamic!.additional!.reserve,
|
||||
// 商品
|
||||
'ADDITIONAL_TYPE_GOODS': item.modules.moduleDynamic!.additional!.goods,
|
||||
// 比赛信息
|
||||
'ADDITIONAL_TYPE_MATCH': item.modules.moduleDynamic!.additional!.match,
|
||||
// 游戏信息
|
||||
'ADDITIONAL_TYPE_COMMON': item.modules.moduleDynamic!.additional!.common,
|
||||
};
|
||||
dynamic content = dynamicProperty[type];
|
||||
Color bgColor = floor == 1
|
||||
? theme.dividerColor.withOpacity(0.08)
|
||||
: theme.colorScheme.surface;
|
||||
switch (type) {
|
||||
case 'ADDITIONAL_TYPE_UGC':
|
||||
final content = item.modules.moduleDynamic!.additional!.ugc!;
|
||||
// 转发的投稿
|
||||
return InkWell(
|
||||
onTap: () async {
|
||||
String text = content.jumpUrl;
|
||||
RegExp bvRegex = RegExp(r'BV[0-9A-Za-z]{10}', caseSensitive: false);
|
||||
Iterable<Match> matches = bvRegex.allMatches(text);
|
||||
if (matches.isNotEmpty) {
|
||||
Match match = matches.first;
|
||||
String bvid = match.group(0)!;
|
||||
String cover = content.cover;
|
||||
try {
|
||||
int cid = await SearchHttp.ab2c(bvid: bvid);
|
||||
PageUtils.toVideoPage(
|
||||
'bvid=$bvid&cid=$cid',
|
||||
arguments: {
|
||||
'pic': cover,
|
||||
'heroTag': Utils.makeHeroTag(bvid),
|
||||
},
|
||||
);
|
||||
} catch (err) {
|
||||
SmartDialog.showToast(err.toString());
|
||||
}
|
||||
} else {
|
||||
debugPrint("No match found.");
|
||||
}
|
||||
},
|
||||
onTap: content.jumpUrl == null
|
||||
? null
|
||||
: () {
|
||||
PiliScheme.routePushFromUrl(content.jumpUrl!);
|
||||
},
|
||||
child: Container(
|
||||
padding:
|
||||
const EdgeInsets.only(left: 12, top: 8, right: 12, bottom: 8),
|
||||
@@ -71,13 +40,13 @@ Widget addWidget(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
content.title,
|
||||
content.title!,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
content.descSecond,
|
||||
content.descSecond!,
|
||||
style: TextStyle(
|
||||
color: theme.colorScheme.outline,
|
||||
fontSize: theme.textTheme.labelMedium!.fontSize,
|
||||
@@ -91,6 +60,7 @@ Widget addWidget(
|
||||
),
|
||||
);
|
||||
case 'ADDITIONAL_TYPE_RESERVE':
|
||||
final content = item.modules.moduleDynamic!.additional!.reserve!;
|
||||
return content.state != -1
|
||||
? content.title != null
|
||||
? Padding(
|
||||
@@ -102,30 +72,90 @@ Widget addWidget(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12, vertical: 10),
|
||||
color: bgColor,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
content.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 1),
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
style: TextStyle(
|
||||
color: theme.colorScheme.outline,
|
||||
fontSize: theme.textTheme.labelMedium!.fontSize,
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (content.desc1 != null)
|
||||
TextSpan(text: content.desc1['text']),
|
||||
const TextSpan(text: ' '),
|
||||
if (content.desc2 != null)
|
||||
TextSpan(text: content.desc2['text']),
|
||||
Text(
|
||||
content.title!,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 1),
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
style: TextStyle(
|
||||
color: theme.colorScheme.outline,
|
||||
fontSize:
|
||||
theme.textTheme.labelMedium!.fontSize,
|
||||
),
|
||||
children: [
|
||||
if (content.desc1 != null)
|
||||
TextSpan(text: content.desc1!.text),
|
||||
const TextSpan(text: ' '),
|
||||
if (content.desc2 != null)
|
||||
TextSpan(text: content.desc2!.text),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
),
|
||||
if (content.button != null)
|
||||
Builder(
|
||||
builder: (context) {
|
||||
final btn = content.button!;
|
||||
final isReserved = btn.status == btn.type;
|
||||
return FilledButton.tonal(
|
||||
style: FilledButton.styleFrom(
|
||||
foregroundColor: isReserved
|
||||
? theme.colorScheme.onSurfaceVariant
|
||||
: null,
|
||||
backgroundColor: isReserved
|
||||
? theme.colorScheme.onInverseSurface
|
||||
: null,
|
||||
visualDensity: VisualDensity.compact,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16),
|
||||
tapTargetSize:
|
||||
MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
onPressed: btn.disable == 1
|
||||
? null
|
||||
: () async {
|
||||
var res =
|
||||
await DynamicsHttp.dynReserve(
|
||||
reserveId: content.rid,
|
||||
curBtnStatus: btn.status,
|
||||
dynamicIdStr: item.idStr,
|
||||
reserveTotal: content.reserveTotal,
|
||||
);
|
||||
if (res['status']) {
|
||||
content
|
||||
..desc2?.text =
|
||||
res['data']['desc_update']
|
||||
..reserveTotal =
|
||||
res['data']['reserve_update']
|
||||
..button!.status = res['data']
|
||||
['final_btn_status'];
|
||||
if (context.mounted) {
|
||||
(context as Element?)
|
||||
?.markNeedsBuild();
|
||||
}
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
isReserved
|
||||
? btn.checkText!
|
||||
: btn.uncheckText!,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -134,11 +164,14 @@ Widget addWidget(
|
||||
: const SizedBox.shrink()
|
||||
: const SizedBox.shrink();
|
||||
case 'ADDITIONAL_TYPE_GOODS':
|
||||
// final content = item.modules.moduleDynamic!.additional!.goods;
|
||||
// 商品
|
||||
return const SizedBox.shrink();
|
||||
case 'ADDITIONAL_TYPE_MATCH':
|
||||
// final content = item.modules.moduleDynamic!.additional!.match;
|
||||
return const SizedBox.shrink();
|
||||
case 'ADDITIONAL_TYPE_COMMON':
|
||||
// final content = item.modules.moduleDynamic!.additional!.common;
|
||||
return const SizedBox.shrink();
|
||||
case 'ADDITIONAL_TYPE_VOTE':
|
||||
return const SizedBox.shrink();
|
||||
|
||||
Reference in New Issue
Block a user