diff --git a/lib/constants/api.dart b/lib/constants/api.dart index 86b5ddc..00e8b7d 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -520,4 +520,7 @@ class LiveAPI { ///获取直播间用户 static const String getLiveUsers = '/v1/live/live/user_data'; + + ///当前用户直播信息获取 + static const String getLiveInfo = '/v1/live/live/info'; } diff --git a/lib/pages/live/live_stream/live_blur_page.dart b/lib/pages/live/live_stream/live_blur_page.dart index b6e88b7..7f97d71 100644 --- a/lib/pages/live/live_stream/live_blur_page.dart +++ b/lib/pages/live/live_stream/live_blur_page.dart @@ -36,7 +36,7 @@ class _LiveBlurPageState extends State { @override void initState() { super.initState(); - _isAttention = widget.streamModel.isFollow == 1; + _isAttention = widget.streamModel?.isFollow == 1; } @override diff --git a/lib/pages/live/live_stream/live_page.dart b/lib/pages/live/live_stream/live_page.dart index 5dd2cc5..c825f0c 100644 --- a/lib/pages/live/live_stream/live_page.dart +++ b/lib/pages/live/live_stream/live_page.dart @@ -15,6 +15,7 @@ import 'package:recook/pages/live/live_stream/live_users_view.dart'; import 'package:recook/pages/live/live_stream/pick_view/pick_cart.dart'; import 'package:recook/pages/live/live_stream/show_goods_list.dart'; import 'package:recook/pages/live/models/live_exit_model.dart'; +import 'package:recook/pages/live/models/live_resume_model.dart'; import 'package:recook/pages/live/models/live_stream_info_model.dart'; import 'package:recook/pages/live/models/topic_list_model.dart'; import 'package:recook/pages/live/tencent_im/tencent_im_tool.dart'; @@ -34,7 +35,11 @@ import 'package:image_picker/image_picker.dart'; import 'package:wakelock/wakelock.dart'; class LivePage extends StatefulWidget { - LivePage({Key key}) : super(key: key); + final bool resumeLive; + + ///只在resumeLive 为`true`时可用 + final LiveResumeModel model; + LivePage({Key key, this.resumeLive = false, this.model}) : super(key: key); @override _LivePageState createState() => _LivePageState(); @@ -94,6 +99,30 @@ class _LivePageState extends State { onCloudVideoCreated: (controller) async { _livePusher = await LivePusher.create(); _livePusher.startPreview(controller); + if (widget.resumeLive) { + _isStream = true; + liveItemId = widget.model.liveItemId; + _streamInfoModel = + LiveStreamInfoModel.fromLiveResume(widget.model); + _livePusher.startPush(widget.model.pushUrl); + setState(() {}); + TencentIMTool.login().then((_) { + DPrint.printLongJson('用户登陆'); + getLiveStreamModel(liveItemId).then((model) { + if (model == null) + Navigator.pop(context); + else { + setState(() { + _streamInfoModel = model; + }); + TencentImPlugin.applyJoinGroup( + groupId: model.groupId, reason: 'enterLive'); + TencentImPlugin.addListener(parseMessage); + group = TencentGroupTool.fromId(model.groupId); + } + }); + }); + } }, ), ), diff --git a/lib/pages/live/models/live_resume_model.dart b/lib/pages/live/models/live_resume_model.dart new file mode 100644 index 0000000..8afb4cc --- /dev/null +++ b/lib/pages/live/models/live_resume_model.dart @@ -0,0 +1,140 @@ +class LiveResumeModel { + int liveItemId; + String pushUrl; + String groupId; + String nickname; + String headImgUrl; + int userId; + int praise; + List goodsLists; + + LiveResumeModel( + {this.liveItemId, + this.pushUrl, + this.groupId, + this.nickname, + this.headImgUrl, + this.userId, + this.praise, + this.goodsLists}); + + LiveResumeModel.fromJson(Map json) { + liveItemId = json['liveItemId']; + pushUrl = json['pushUrl']; + groupId = json['groupId']; + nickname = json['nickname']; + headImgUrl = json['headImgUrl']; + userId = json['userId']; + praise = json['praise']; + if (json['goodsLists'] != null) { + goodsLists = new List(); + json['goodsLists'].forEach((v) { + goodsLists.add(new GoodsLists.fromJson(v)); + }); + } + } + + Map toJson() { + final Map data = new Map(); + data['liveItemId'] = this.liveItemId; + data['pushUrl'] = this.pushUrl; + data['groupId'] = this.groupId; + data['nickname'] = this.nickname; + data['headImgUrl'] = this.headImgUrl; + data['userId'] = this.userId; + data['praise'] = this.praise; + if (this.goodsLists != null) { + data['goodsLists'] = this.goodsLists.map((v) => v.toJson()).toList(); + } + return data; + } +} + +class GoodsLists { + int id; + String goodsName; + String brandImg; + String brandName; + int brandId; + String description; + int inventory; + int salesVolume; + String mainPhotoUrl; + String promotionName; + String originalPrice; + String discountPrice; + String commission; + List tags; + int percent; + String startTime; + String endTime; + String coupon; + int isExplain; + + GoodsLists( + {this.id, + this.goodsName, + this.brandImg, + this.brandName, + this.brandId, + this.description, + this.inventory, + this.salesVolume, + this.mainPhotoUrl, + this.promotionName, + this.originalPrice, + this.discountPrice, + this.commission, + this.tags, + this.percent, + this.startTime, + this.endTime, + this.coupon, + this.isExplain}); + + GoodsLists.fromJson(Map json) { + id = json['id']; + goodsName = json['goodsName']; + brandImg = json['brandImg']; + brandName = json['brandName']; + brandId = json['brandId']; + description = json['description']; + inventory = json['inventory']; + salesVolume = json['salesVolume']; + mainPhotoUrl = json['mainPhotoUrl']; + promotionName = json['promotionName']; + originalPrice = json['originalPrice']; + discountPrice = json['discountPrice']; + commission = json['commission']; + tags = json['tags'].cast(); + percent = json['percent']; + startTime = json['startTime']; + endTime = json['endTime']; + coupon = json['coupon']; + isExplain = json['isExplain']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['goodsName'] = this.goodsName; + data['brandImg'] = this.brandImg; + data['brandName'] = this.brandName; + data['brandId'] = this.brandId; + data['description'] = this.description; + data['inventory'] = this.inventory; + data['salesVolume'] = this.salesVolume; + data['mainPhotoUrl'] = this.mainPhotoUrl; + data['promotionName'] = this.promotionName; + data['originalPrice'] = this.originalPrice; + data['discountPrice'] = this.discountPrice; + data['commission'] = this.commission; + data['tags'] = this.tags; + data['percent'] = this.percent; + data['startTime'] = this.startTime; + data['endTime'] = this.endTime; + data['coupon'] = this.coupon; + data['isExplain'] = this.isExplain; + return data; + } +} diff --git a/lib/pages/live/models/live_stream_info_model.dart b/lib/pages/live/models/live_stream_info_model.dart index 96df0dc..5490b7c 100644 --- a/lib/pages/live/models/live_stream_info_model.dart +++ b/lib/pages/live/models/live_stream_info_model.dart @@ -1,3 +1,5 @@ +import 'package:recook/pages/live/models/live_resume_model.dart'; + class LiveStreamInfoModel { String nickname; String headImgUrl; @@ -22,6 +24,15 @@ class LiveStreamInfoModel { this.groupId, this.goodsLists}); + LiveStreamInfoModel.fromLiveResume(LiveResumeModel model) { + this.nickname = model.nickname; + this.headImgUrl = model.headImgUrl; + this.groupId = model.groupId; + this.goodsLists = + model.goodsLists.map((e) => GoodsLists.fromJson(e.toJson())).toList(); + this.id = model.liveItemId; + } + LiveStreamInfoModel.fromJson(Map json) { nickname = json['nickname']; headImgUrl = json['headImgUrl']; diff --git a/lib/pages/tabBar/TabbarWidget.dart b/lib/pages/tabBar/TabbarWidget.dart index 3788d38..dbfe089 100644 --- a/lib/pages/tabBar/TabbarWidget.dart +++ b/lib/pages/tabBar/TabbarWidget.dart @@ -8,13 +8,16 @@ */ import 'package:flutter/material.dart'; import 'package:oktoast/oktoast.dart'; +import 'package:recook/constants/api.dart'; import 'package:recook/constants/config.dart'; import 'package:recook/constants/header.dart'; import 'package:recook/constants/styles.dart'; +import 'package:recook/manager/http_manager.dart'; import 'package:recook/manager/user_manager.dart'; import 'package:recook/pages/business/business_page.dart'; import 'package:recook/pages/home/home_page.dart'; import 'package:recook/pages/live/live_stream/live_page.dart'; +import 'package:recook/pages/live/models/live_resume_model.dart'; import 'package:recook/pages/live/video/add_video_page.dart'; import 'package:recook/pages/live/pages/discovery_page.dart'; import 'package:recook/pages/live/widget/live_fab_location.dart'; @@ -27,6 +30,7 @@ import 'package:recook/utils/custom_route.dart'; import 'package:recook/utils/permission_tool.dart'; import 'package:recook/utils/print_util.dart'; import 'package:recook/utils/versionInfo/version_tool.dart'; +import 'package:recook/widgets/alert.dart'; import 'package:recook/widgets/cache_tab_bar_view.dart'; import 'package:recook/widgets/custom_image_button.dart'; import 'package:recook/widgets/tabbarWidget/ace_bottom_navigation_bar.dart'; @@ -78,6 +82,7 @@ class _TabBarWidgetState extends State } _showBottomModalSheet() { + BuildContext fatherContext = context; showModalBottomSheet( context: context, builder: (context) { @@ -131,7 +136,53 @@ class _TabBarWidgetState extends State onTap: () { PermissionTool.haveCameraPermission().then((value) { PermissionTool.haveAudioPermission().then((value) { - CRoute.pushReplace(context, LivePage()); + GSDialog.of(context) + .showLoadingDialog(context, '加载中'); + HttpManager.post(LiveAPI.getLiveInfo, {}) + .then((resultData) { + GSDialog.of(context).dismiss(context); + LiveResumeModel model = LiveResumeModel.fromJson( + resultData.data['data']); + if (model.liveItemId == 0) + CRoute.pushReplace(context, LivePage()); + else { + Navigator.pop(context); + showDialog( + context: context, + child: NormalTextDialog( + title: '有未完成的直播间', + content: '', + items: ['结束直播', '继续直播', '开始新直播'], + listener: (index) { + Navigator.pop(fatherContext); + switch (index) { + case 0: + HttpManager.post(LiveAPI.exitLive, { + 'liveItemId': model.liveItemId, + }); + break; + case 1: + CRoute.push( + fatherContext, + LivePage( + resumeLive: true, + model: model, + )); + break; + case 2: + HttpManager.post(LiveAPI.exitLive, { + 'liveItemId': model.liveItemId, + }).then((_) { + CRoute.pushReplace( + context, LivePage()); + }); + break; + } + }, + ), + ); + } + }); }); }); },