diff --git a/lib/http/member.dart b/lib/http/member.dart index db4a0f86..aa88ced9 100644 --- a/lib/http/member.dart +++ b/lib/http/member.dart @@ -68,7 +68,7 @@ class MemberHttp { String? accessKey = GStorage.localCache .get(LocalCacheKey.accessKey, defaultValue: {})['value']; Map data = { - if (accessKey != null) 'access_key': accessKey, + if (accessKey?.isNotEmpty == true) 'access_key': accessKey!, 'appkey': Constants.appKey, 'build': '1462100', 'c_locale': 'zh_CN', @@ -115,7 +115,7 @@ class MemberHttp { String? accessKey = GStorage.localCache .get(LocalCacheKey.accessKey, defaultValue: {})['value']; Map data = { - if (accessKey != null) 'access_key': accessKey, + if (accessKey?.isNotEmpty == true) 'access_key': accessKey!, 'appkey': Constants.appKey, 'build': '1462100', 'c_locale': 'zh_CN', @@ -168,7 +168,7 @@ class MemberHttp { String? accessKey = GStorage.localCache .get(LocalCacheKey.accessKey, defaultValue: {})['value']; Map data = { - if (accessKey != null) 'access_key': accessKey, + if (accessKey?.isNotEmpty == true) 'access_key': accessKey!, if (aid != null) 'aid': aid.toString(), 'appkey': Constants.appKey, 'build': '1462100', @@ -230,7 +230,7 @@ class MemberHttp { String? accessKey = GStorage.localCache .get(LocalCacheKey.accessKey, defaultValue: {})['value']; Map data = { - if (accessKey != null) 'access_key': accessKey, + if (accessKey?.isNotEmpty == true) 'access_key': accessKey!, 'appkey': Constants.appKey, 'build': '1462100', 'c_locale': 'zh_CN', diff --git a/lib/models/live/room_info.dart b/lib/models/live/room_info.dart index 7209ba08..09744a67 100644 --- a/lib/models/live/room_info.dart +++ b/lib/models/live/room_info.dart @@ -9,12 +9,14 @@ class RoomInfoModel { int? liveStatus; int? liveTime; PlayurlInfo? playurlInfo; + bool? isPortrait; RoomInfoModel.fromJson(Map json) { roomId = json['room_id']; liveStatus = json['live_status']; liveTime = json['live_time']; playurlInfo = PlayurlInfo.fromJson(json['playurl_info']); + isPortrait = json['is_portrait']; } } diff --git a/lib/pages/live_room/controller.dart b/lib/pages/live_room/controller.dart index 13454530..b4fe627d 100644 --- a/lib/pages/live_room/controller.dart +++ b/lib/pages/live_room/controller.dart @@ -58,9 +58,12 @@ class LiveRoomController extends GetxController { ); } + bool? isPortrait; + Future queryLiveInfo() async { var res = await LiveHttp.liveRoomInfo(roomId: roomId, qn: 10000); if (res['status']) { + isPortrait = res['data'].isPortrait; List codec = res['data'].playurlInfo.playurl.stream.first.format.first.codec; CodecItem item = codec.first; diff --git a/lib/pages/live_room/view.dart b/lib/pages/live_room/view.dart index ac9e1e21..554d8ee2 100644 --- a/lib/pages/live_room/view.dart +++ b/lib/pages/live_room/view.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:PiliPalaX/http/live.dart'; import 'package:PiliPalaX/pages/live_room/widgets/chat.dart'; +import 'package:PiliPalaX/utils/utils.dart'; import 'package:floating/floating.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; @@ -21,6 +22,7 @@ class LiveRoomPage extends StatefulWidget { } class _LiveRoomPageState extends State { + late final int _roomId; final LiveRoomController _liveRoomController = Get.put(LiveRoomController()); PlPlayerController? plPlayerController; late Future? _futureBuilder; @@ -31,6 +33,7 @@ class _LiveRoomPageState extends State { Floating? floating; late final _isLogin = GStorage.userInfo.get('userInfoCache') != null; + late final _node = FocusNode(); late final _ctr = TextEditingController(); void playCallBack() { @@ -40,6 +43,7 @@ class _LiveRoomPageState extends State { @override void initState() { super.initState(); + _roomId = int.parse(Get.parameters['roomid'] ?? '-1'); PlPlayerController.setPlayCallBack(playCallBack); if (Platform.isAndroid) { floating = Floating(); @@ -58,6 +62,7 @@ class _LiveRoomPageState extends State { void dispose() { PlPlayerController.setPlayCallBack(null); floating?.dispose(); + _node.dispose(); plPlayerController?.dispose(); _ctr.dispose(); super.dispose(); @@ -149,12 +154,25 @@ class _LiveRoomPageState extends State { return Obx( () => Row( children: [ - NetworkImgLayer( - width: 34, - height: 34, - type: 'avatar', - src: _liveRoomController - .roomInfoH5.value.anchorInfo!.baseInfo!.face, + GestureDetector( + onTap: () { + _node.unfocus(); + dynamic uid = _liveRoomController + .roomInfoH5.value.roomInfo?.uid; + Get.toNamed( + '/member?mid=$uid', + arguments: { + 'heroTag': Utils.makeHeroTag(uid), + }, + ); + }, + child: NetworkImgLayer( + width: 34, + height: 34, + type: 'avatar', + src: _liveRoomController.roomInfoH5.value + .anchorInfo!.baseInfo!.face, + ), ), const SizedBox(width: 10), Column( @@ -228,19 +246,29 @@ class _LiveRoomPageState extends State { verticalScreenForTwoSeconds(); } }, - child: SizedBox( - width: Get.size.width, - height: MediaQuery.of(context).orientation == - Orientation.landscape - ? Get.size.height - : Get.size.width * 9 / 16, - child: videoPlayerPanel, + child: Listener( + onPointerDown: (_) { + _node.unfocus(); + }, + child: SizedBox( + width: Get.size.width, + height: MediaQuery.of(context).orientation == + Orientation.landscape + ? Get.size.height + : Get.size.width * 9 / 16, + child: videoPlayerPanel, + ), ), ), Expanded( - child: LiveRoomChat( - roomId: int.parse(Get.parameters['roomid']!), - liveRoomController: _liveRoomController, + child: Listener( + onPointerDown: (_) { + _node.unfocus(); + }, + child: LiveRoomChat( + roomId: _roomId, + liveRoomController: _liveRoomController, + ), ), ), Container( @@ -264,6 +292,7 @@ class _LiveRoomPageState extends State { children: [ Expanded( child: TextField( + focusNode: _node, controller: _ctr, textInputAction: TextInputAction.send, onSubmitted: (value) { diff --git a/lib/pages/live_room/widgets/chat.dart b/lib/pages/live_room/widgets/chat.dart index 9a95bd67..671e7137 100644 --- a/lib/pages/live_room/widgets/chat.dart +++ b/lib/pages/live_room/widgets/chat.dart @@ -6,8 +6,11 @@ import 'package:PiliPalaX/models/live/danmu_info.dart'; import 'package:PiliPalaX/pages/live_room/controller.dart'; import 'package:PiliPalaX/services/loggeer.dart'; import 'package:PiliPalaX/tcp/live.dart'; +import 'package:PiliPalaX/utils/utils.dart'; +import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import '../../../utils/storage.dart'; @@ -72,6 +75,23 @@ class _LiveRoomChatState extends State { color: Color(0xFFAAAAAA), fontSize: 14, ), + recognizer: TapGestureRecognizer() + ..onTap = () { + try { + dynamic uid = + widget.liveRoomController.messages[index] + ['info'][0][15]['user']['uid']; + Get.toNamed( + '/member?mid=$uid', + arguments: { + 'heroTag': Utils.makeHeroTag(uid), + }, + ); + } catch (err) { + print(err.toString()); + // SmartDialog.showToast(err.toString()); + } + }, ), _buildMsg(widget.liveRoomController.messages[index]), ], @@ -153,12 +173,17 @@ class _LiveRoomChatState extends State { TextSpan _buildMsg(obj) { dynamic emots = jsonDecode(obj['info'][0][15]['extra'])['emots']; - if (emots != null) { - List list = emots.keys.map((e) { - return e.replaceAllMapped( - RegExp(r'\[(.*?)\]'), - (match) => r'\[' + match.group(1)! + r'\]', - ); + dynamic uemote = obj['info'][0][13]; + List list = [ + if (emots != null) emots.keys, + if (uemote is Map) uemote['emoticon_unique'].replaceFirst('upower_', '') + ]; + if (list.isNotEmpty) { + list = list.map((e) { + return e.toString().replaceAllMapped( + RegExp(r'\[(.*?)\]'), + (match) => r'\[' + match.group(1)! + r'\]', + ); }).toList(); RegExp regExp = RegExp(list.join('|')); final List spanChildren = []; @@ -166,13 +191,14 @@ class _LiveRoomChatState extends State { regExp, onMatch: (Match match) { String key = match[0]!; + dynamic emote = emots?[key] ?? uemote; spanChildren.add(WidgetSpan( child: ExcludeSemantics( child: NetworkImgLayer( - src: emots[key]['url'], + src: emote['url'], type: 'emote', - width: emots[key]['width'].toDouble(), - height: emots[key]['height'].toDouble(), + width: emote['width'].toDouble(), + height: emote['height'].toDouble(), semanticsLabel: key, )), ));