mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-24 20:35:50 +08:00
show live rank
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
45
lib/pages/live_room/contribution_rank/controller.dart
Normal file
45
lib/pages/live_room/contribution_rank/controller.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'package:PiliPlus/http/live.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/common/live/live_contribution_rank_type.dart';
|
||||
import 'package:PiliPlus/models_new/live/live_contribution_rank/data.dart';
|
||||
import 'package:PiliPlus/models_new/live/live_contribution_rank/item.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
|
||||
class ContributionRankController
|
||||
extends
|
||||
CommonListController<
|
||||
LiveContributionRankData,
|
||||
LiveContributionRankItem
|
||||
> {
|
||||
final Object ruid;
|
||||
final Object roomId;
|
||||
final LiveContributionRankType type;
|
||||
|
||||
ContributionRankController({
|
||||
required this.ruid,
|
||||
required this.roomId,
|
||||
required this.type,
|
||||
});
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
queryData();
|
||||
}
|
||||
|
||||
@override
|
||||
List<LiveContributionRankItem>? getDataList(
|
||||
LiveContributionRankData response,
|
||||
) {
|
||||
return response.item;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<LiveContributionRankData>> customGetData() =>
|
||||
LiveHttp.liveContributionRank(
|
||||
ruid: ruid,
|
||||
roomId: roomId,
|
||||
page: page,
|
||||
type: type,
|
||||
);
|
||||
}
|
||||
248
lib/pages/live_room/contribution_rank/view.dart
Normal file
248
lib/pages/live_room/contribution_rank/view.dart
Normal file
@@ -0,0 +1,248 @@
|
||||
import 'package:PiliPlus/common/widgets/flutter/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/loading_widget.dart';
|
||||
import 'package:PiliPlus/common/widgets/pendant_avatar.dart';
|
||||
import 'package:PiliPlus/common/widgets/scroll_physics.dart';
|
||||
import 'package:PiliPlus/common/widgets/view_sliver_safe_area.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/common/live/live_contribution_rank_type.dart';
|
||||
import 'package:PiliPlus/models_new/live/live_contribution_rank/item.dart';
|
||||
import 'package:PiliPlus/models_new/live/live_contribution_rank/medal_info.dart';
|
||||
import 'package:PiliPlus/pages/live_room/contribution_rank/controller.dart';
|
||||
import 'package:PiliPlus/utils/extension/scroll_controller_ext.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class ContributionRankPanel extends StatefulWidget {
|
||||
const ContributionRankPanel({
|
||||
super.key,
|
||||
required this.ruid,
|
||||
required this.roomId,
|
||||
});
|
||||
|
||||
final Object ruid;
|
||||
final Object roomId;
|
||||
|
||||
@override
|
||||
State<ContributionRankPanel> createState() => _ContributionRankPanelState();
|
||||
}
|
||||
|
||||
class _ContributionRankPanelState extends State<ContributionRankPanel>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final TabController _tabController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(
|
||||
length: LiveContributionRankType.values.length,
|
||||
vsync: this,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 45,
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
tabs: LiveContributionRankType.values
|
||||
.map((e) => Tab(text: e.title))
|
||||
.toList(),
|
||||
dividerColor: Theme.of(
|
||||
context,
|
||||
).colorScheme.outline.withValues(alpha: 0.3),
|
||||
onTap: (index) {
|
||||
if (!_tabController.indexIsChanging) {
|
||||
Get.find<ContributionRankController>(
|
||||
tag:
|
||||
'${widget.roomId}${LiveContributionRankType.values[index].name}',
|
||||
).scrollController.animToTop();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: tabBarView(
|
||||
controller: _tabController,
|
||||
children: LiveContributionRankType.values
|
||||
.map(
|
||||
(e) => _ContributionRankType(
|
||||
ruid: widget.ruid,
|
||||
roomId: widget.roomId,
|
||||
type: e,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ContributionRankType extends StatefulWidget {
|
||||
const _ContributionRankType({
|
||||
required this.ruid,
|
||||
required this.roomId,
|
||||
required this.type,
|
||||
});
|
||||
|
||||
final Object ruid;
|
||||
final Object roomId;
|
||||
final LiveContributionRankType type;
|
||||
|
||||
@override
|
||||
State<_ContributionRankType> createState() => _ContributionRankTypeState();
|
||||
}
|
||||
|
||||
class _ContributionRankTypeState extends State<_ContributionRankType>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
late final _controller = Get.put(
|
||||
ContributionRankController(
|
||||
ruid: widget.ruid,
|
||||
roomId: widget.roomId,
|
||||
type: widget.type,
|
||||
),
|
||||
tag: '${widget.roomId}${widget.type.name}',
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
final showScore = widget.type == .online_rank;
|
||||
return Material(
|
||||
type: .transparency,
|
||||
child: refreshIndicator(
|
||||
onRefresh: _controller.onRefresh,
|
||||
child: CustomScrollView(
|
||||
controller: _controller.scrollController,
|
||||
slivers: [
|
||||
ViewSliverSafeArea(
|
||||
sliver: Obx(
|
||||
() => _buildBody(showScore, _controller.loadingState.value),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(
|
||||
bool showScore,
|
||||
LoadingState<List<LiveContributionRankItem>?> state,
|
||||
) {
|
||||
return switch (state) {
|
||||
Loading() => linearLoading,
|
||||
Success(:final response) =>
|
||||
response != null && response.isNotEmpty
|
||||
? SliverFixedExtentList.builder(
|
||||
itemCount: response.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = response[index];
|
||||
return _Item(
|
||||
index: index,
|
||||
item: item,
|
||||
showScore: showScore,
|
||||
);
|
||||
},
|
||||
itemExtent: 60,
|
||||
)
|
||||
: HttpError(onReload: _controller.onReload),
|
||||
Error(:final errMsg) => HttpError(
|
||||
errMsg: errMsg,
|
||||
onReload: _controller.onReload,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
|
||||
class _Item extends StatelessWidget {
|
||||
const _Item({
|
||||
required this.index,
|
||||
required this.item,
|
||||
required this.showScore,
|
||||
});
|
||||
|
||||
final int index;
|
||||
final bool showScore;
|
||||
final LiveContributionRankItem item;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
late final colorScheme = ColorScheme.of(context);
|
||||
return InkWell(
|
||||
onTap: () => Get.toNamed('/member?mid=${item.uid}'),
|
||||
child: Padding(
|
||||
padding: const .only(left: 10, top: 9, bottom: 8, right: 16),
|
||||
child: Row(
|
||||
spacing: 10,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 32,
|
||||
child: Center(
|
||||
child: Text(
|
||||
'${index + 1}',
|
||||
textAlign: .center,
|
||||
textScaler: .noScaling,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Utils.index2Color(index, colorScheme.outline),
|
||||
fontSize: 16,
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
PendantAvatar(
|
||||
avatar: item.face,
|
||||
size: 42,
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
spacing: 3,
|
||||
crossAxisAlignment: .start,
|
||||
children: [
|
||||
Text(item.name!),
|
||||
Row(
|
||||
children: [
|
||||
if (item.medalInfo case MedalInfo(
|
||||
:final medalName,
|
||||
:final level,
|
||||
))
|
||||
Text(
|
||||
'$medalName$level',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (showScore)
|
||||
Text(
|
||||
item.score.toString(),
|
||||
style: TextStyle(color: colorScheme.outline),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import 'package:PiliPlus/models_new/live/live_room_play_info/codec.dart';
|
||||
import 'package:PiliPlus/models_new/live/live_superchat/item.dart';
|
||||
import 'package:PiliPlus/pages/common/publish/publish_route.dart';
|
||||
import 'package:PiliPlus/pages/danmaku/danmaku_model.dart';
|
||||
import 'package:PiliPlus/pages/live_room/contribution_rank/view.dart';
|
||||
import 'package:PiliPlus/pages/live_room/send_danmaku/view.dart';
|
||||
import 'package:PiliPlus/pages/video/widgets/header_control.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/controller.dart';
|
||||
@@ -26,6 +27,7 @@ import 'package:PiliPlus/utils/accounts.dart';
|
||||
import 'package:PiliPlus/utils/danmaku_utils.dart';
|
||||
import 'package:PiliPlus/utils/duration_utils.dart';
|
||||
import 'package:PiliPlus/utils/extension/iterable_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension/size_ext.dart';
|
||||
import 'package:PiliPlus/utils/num_utils.dart';
|
||||
import 'package:PiliPlus/utils/platform_utils.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
@@ -43,6 +45,7 @@ class LiveRoomController extends GetxController {
|
||||
final String heroTag;
|
||||
|
||||
int roomId = Get.arguments;
|
||||
int? ruid;
|
||||
DanmakuController<DanmakuExtra>? danmakuController;
|
||||
PlPlayerController plPlayerController = PlPlayerController.getInstance(
|
||||
isLive: true,
|
||||
@@ -109,7 +112,6 @@ class LiveRoomController extends GetxController {
|
||||
|
||||
late final bool isLogin;
|
||||
late final int mid;
|
||||
late final int mainMid = Accounts.main.mid;
|
||||
|
||||
String? videoUrl;
|
||||
bool? isPlaying;
|
||||
@@ -123,18 +125,40 @@ class LiveRoomController extends GetxController {
|
||||
final RxString title = ''.obs;
|
||||
|
||||
final RxnString onlineCount = RxnString();
|
||||
Widget get onlineWidget => Obx(() {
|
||||
if (onlineCount.value case final onlineCount?) {
|
||||
return Text(
|
||||
'高能观众($onlineCount)',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.white,
|
||||
Widget get onlineWidget => GestureDetector(
|
||||
onTap: _showRank,
|
||||
child: Obx(() {
|
||||
if (onlineCount.value case final onlineCount?) {
|
||||
return Text(
|
||||
'高能观众($onlineCount)',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.white,
|
||||
),
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
}),
|
||||
);
|
||||
|
||||
void _showRank() {
|
||||
if (ruid case final ruid?) {
|
||||
final heightFactor =
|
||||
PlatformUtils.isMobile && !Get.mediaQuery.size.isPortrait ? 1.0 : 0.7;
|
||||
showModalBottomSheet(
|
||||
context: Get.context!,
|
||||
useSafeArea: true,
|
||||
clipBehavior: .hardEdge,
|
||||
isScrollControlled: true,
|
||||
constraints: const BoxConstraints(maxWidth: 450),
|
||||
builder: (context) => FractionallySizedBox(
|
||||
widthFactor: 1.0,
|
||||
heightFactor: heightFactor,
|
||||
child: ContributionRankPanel(ruid: ruid, roomId: roomId),
|
||||
),
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
});
|
||||
}
|
||||
|
||||
final RxnString watchedShow = RxnString();
|
||||
Widget get watchedWidget => Obx(() {
|
||||
@@ -207,6 +231,7 @@ class LiveRoomController extends GetxController {
|
||||
_showDialog('无法获取播放地址');
|
||||
return;
|
||||
}
|
||||
ruid = data.uid;
|
||||
if (data.roomId != null) {
|
||||
roomId = data.roomId!;
|
||||
}
|
||||
@@ -439,7 +464,7 @@ class LiveRoomController extends GetxController {
|
||||
: DmUtils.decimalToColor(extra['color']),
|
||||
type: DmUtils.getPosition(extra['mode']),
|
||||
// extra['send_from_me'] is invalid
|
||||
selfSend: uid == mainMid,
|
||||
selfSend: isLogin && uid == mid,
|
||||
extra: LiveDanmaku(
|
||||
id: extra['id_str'],
|
||||
mid: uid,
|
||||
|
||||
@@ -8,9 +8,11 @@ import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
|
||||
import 'package:PiliPlus/common/widgets/keep_alive_wrapper.dart';
|
||||
import 'package:PiliPlus/common/widgets/scroll_physics.dart';
|
||||
import 'package:PiliPlus/models/common/image_type.dart';
|
||||
import 'package:PiliPlus/models/common/live/live_contribution_rank_type.dart';
|
||||
import 'package:PiliPlus/models_new/live/live_room_info_h5/data.dart';
|
||||
import 'package:PiliPlus/models_new/live/live_superchat/item.dart';
|
||||
import 'package:PiliPlus/pages/danmaku/danmaku_model.dart';
|
||||
import 'package:PiliPlus/pages/live_room/contribution_rank/controller.dart';
|
||||
import 'package:PiliPlus/pages/live_room/controller.dart';
|
||||
import 'package:PiliPlus/pages/live_room/superchat/superchat_card.dart';
|
||||
import 'package:PiliPlus/pages/live_room/superchat/superchat_panel.dart';
|
||||
@@ -155,6 +157,11 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
..removeStatusLister(playerListener)
|
||||
..dispose();
|
||||
PageUtils.routeObserver.unsubscribe(this);
|
||||
for (final e in LiveContributionRankType.values) {
|
||||
Get.delete<ContributionRankController>(
|
||||
tag: '${_liveRoomController.roomId}${e.name}',
|
||||
);
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user