mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: live area
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,26 +1,90 @@
|
||||
import 'package:PiliPlus/common/widgets/pair.dart';
|
||||
import 'package:PiliPlus/http/live.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/live/live_feed_index/card_data_list_item.dart';
|
||||
import 'package:PiliPlus/models/live/live_feed_index/card_list.dart';
|
||||
import 'package:PiliPlus/models/live/live_feed_index/data.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:get/get_rx/src/rx_types/rx_types.dart';
|
||||
|
||||
class LiveController extends CommonListController<LiveIndexData, LiveCardList> {
|
||||
class LiveController extends CommonListController {
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
queryData();
|
||||
}
|
||||
|
||||
int? areaId;
|
||||
int? parentAreaId;
|
||||
final RxInt areaIndex = 0.obs;
|
||||
final Rx<Pair<LiveCardList?, LiveCardList?>> topState =
|
||||
Pair<LiveCardList?, LiveCardList?>(first: null, second: null).obs;
|
||||
final RxBool isLogin = Accounts.main.isLogin.obs;
|
||||
|
||||
@override
|
||||
List<LiveCardList>? getDataList(LiveIndexData response) {
|
||||
List? getDataList(response) {
|
||||
return response.cardList;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<LiveIndexData>> customGetData() =>
|
||||
LiveHttp.liveFeedIndex(pn: currentPage, isLogin: isLogin.value);
|
||||
bool customHandleResponse(bool isRefresh, Success response) {
|
||||
if (isRefresh && areaIndex.value == 0) {
|
||||
topState.value = Pair(
|
||||
first: response.response.followItem,
|
||||
second: response.response.areaItem,
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() {
|
||||
if (areaIndex.value != 0) {
|
||||
return LiveHttp.liveSecondList(
|
||||
pn: currentPage,
|
||||
isLogin: isLogin.value,
|
||||
areaId: areaId,
|
||||
parentAreaId: parentAreaId,
|
||||
);
|
||||
}
|
||||
return LiveHttp.liveFeedIndex(pn: currentPage, isLogin: isLogin.value);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onRefresh() async {
|
||||
currentPage = 1;
|
||||
isEnd = false;
|
||||
if (areaIndex.value != 0) {
|
||||
queryTop();
|
||||
}
|
||||
await queryData();
|
||||
}
|
||||
|
||||
Future<void> queryTop() async {
|
||||
final res = await LiveHttp.liveFeedIndex(
|
||||
pn: currentPage,
|
||||
isLogin: isLogin.value,
|
||||
moduleSelect: true,
|
||||
);
|
||||
if (res is Success) {
|
||||
final data = res.data;
|
||||
topState.value = Pair(
|
||||
first: data.followItem,
|
||||
second: data.areaItem,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void onSelectArea(int index, CardLiveItem? cardLiveItem) {
|
||||
if (index == areaIndex.value) {
|
||||
return;
|
||||
}
|
||||
areaIndex.value = index;
|
||||
areaId = cardLiveItem?.areaV2Id;
|
||||
parentAreaId = cardLiveItem?.areaV2ParentId;
|
||||
|
||||
currentPage = 1;
|
||||
isEnd = false;
|
||||
queryData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/skeleton/video_card_v.dart';
|
||||
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
||||
import 'package:PiliPlus/common/widgets/pair.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/common/widgets/self_sized_horizontal_list.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
@@ -11,7 +12,7 @@ import 'package:PiliPlus/pages/common/common_page.dart';
|
||||
import 'package:PiliPlus/pages/live/controller.dart';
|
||||
import 'package:PiliPlus/pages/live/widgets/live_item_app.dart';
|
||||
import 'package:PiliPlus/pages/live_follow/view.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/pages/search/widgets/search_text.dart';
|
||||
import 'package:PiliPlus/utils/grid.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -54,7 +55,10 @@ class _LivePageState extends CommonPageState<LivePage, LiveController>
|
||||
top: StyleString.cardSpace,
|
||||
bottom: MediaQuery.paddingOf(context).bottom + 80,
|
||||
),
|
||||
sliver: Obx(() => _buildBody(controller.loadingState.value)),
|
||||
sliver: SliverMainAxisGroup(slivers: [
|
||||
Obx(() => _buildTop(controller.topState.value)),
|
||||
Obx(() => _buildBody(controller.loadingState.value)),
|
||||
]),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -62,7 +66,51 @@ class _LivePageState extends CommonPageState<LivePage, LiveController>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState<List<LiveCardList>?> loadingState) {
|
||||
Widget _buildTop(Pair<LiveCardList?, LiveCardList?> data) {
|
||||
return SliverMainAxisGroup(
|
||||
slivers: [
|
||||
if (data.first != null)
|
||||
SliverToBoxAdapter(child: _buildFollowList(data.first!)),
|
||||
if (data.second?.cardData?.areaEntranceV3?.list?.isNotEmpty == true)
|
||||
SliverToBoxAdapter(
|
||||
child: SelfSizedHorizontalList(
|
||||
gapSize: 12,
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
childBuilder: (index) {
|
||||
late final item =
|
||||
data.second!.cardData!.areaEntranceV3!.list![index - 1];
|
||||
return Obx(
|
||||
() => SearchText(
|
||||
fontSize: 14,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 3,
|
||||
),
|
||||
text: index == 0 ? '推荐' : '${item.title}',
|
||||
bgColor: index == controller.areaIndex.value
|
||||
? Theme.of(context).colorScheme.secondaryContainer
|
||||
: Colors.transparent,
|
||||
textColor: index == controller.areaIndex.value
|
||||
? Theme.of(context).colorScheme.onSecondaryContainer
|
||||
: null,
|
||||
onTap: (value) {
|
||||
controller.onSelectArea(
|
||||
index,
|
||||
index == 0 ? null : item,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
itemCount:
|
||||
data.second!.cardData!.areaEntranceV3!.list!.length + 1,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState<List?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||
@@ -80,47 +128,30 @@ class _LivePageState extends CommonPageState<LivePage, LiveController>
|
||||
),
|
||||
),
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? Builder(builder: (context) {
|
||||
List<LiveCardList> list = loadingState.response!;
|
||||
LiveCardList? followItem;
|
||||
if (list.first.cardType == 'my_idol_v1') {
|
||||
followItem = list.first;
|
||||
list = list.sublist(1);
|
||||
}
|
||||
return SliverMainAxisGroup(
|
||||
slivers: [
|
||||
if (followItem != null)
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
sliver: SliverToBoxAdapter(
|
||||
child: _buildFollowList(followItem),
|
||||
),
|
||||
),
|
||||
if (list.isNotEmpty)
|
||||
SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||
mainAxisSpacing: StyleString.cardSpace,
|
||||
crossAxisSpacing: StyleString.cardSpace,
|
||||
maxCrossAxisExtent: Grid.smallCardWidth,
|
||||
childAspectRatio: StyleString.aspectRatio,
|
||||
mainAxisExtent:
|
||||
MediaQuery.textScalerOf(context).scale(90),
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (index == list.length - 1) {
|
||||
controller.onLoadMore();
|
||||
}
|
||||
return LiveCardVApp(
|
||||
item: list[index].cardData!.smallCardV1!,
|
||||
);
|
||||
},
|
||||
childCount: list.length,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
})
|
||||
? SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||
mainAxisSpacing: StyleString.cardSpace,
|
||||
crossAxisSpacing: StyleString.cardSpace,
|
||||
maxCrossAxisExtent: Grid.smallCardWidth,
|
||||
childAspectRatio: StyleString.aspectRatio,
|
||||
mainAxisExtent: MediaQuery.textScalerOf(context).scale(90),
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
controller.onLoadMore();
|
||||
}
|
||||
final item = loadingState.response![index];
|
||||
if (item is LiveCardList) {
|
||||
return LiveCardVApp(
|
||||
item: item.cardData!.smallCardV1!,
|
||||
);
|
||||
}
|
||||
return LiveCardVApp(item: item);
|
||||
},
|
||||
childCount: loadingState.response!.length,
|
||||
),
|
||||
)
|
||||
: HttpError(onReload: controller.onReload),
|
||||
Error() => HttpError(
|
||||
errMsg: loadingState.errMsg,
|
||||
@@ -183,22 +214,21 @@ class _LivePageState extends CommonPageState<LivePage, LiveController>
|
||||
),
|
||||
],
|
||||
),
|
||||
_buildFollowBody(theme, item.cardData?.myIdolV1?.list),
|
||||
if (item.cardData?.myIdolV1?.list?.isNotEmpty == true)
|
||||
_buildFollowBody(theme, item.cardData!.myIdolV1!.list!),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFollowBody(ThemeData theme, List<CardLiveItem>? list) {
|
||||
if (list.isNullOrEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
Widget _buildFollowBody(ThemeData theme, List<CardLiveItem> followList) {
|
||||
return MediaQuery.removePadding(
|
||||
context: context,
|
||||
removeLeft: context.orientation == Orientation.landscape,
|
||||
child: SelfSizedHorizontalList(
|
||||
gapSize: 5,
|
||||
childBuilder: (index) {
|
||||
final item = list[index];
|
||||
final item = followList[index];
|
||||
return SizedBox(
|
||||
width: 65,
|
||||
child: GestureDetector(
|
||||
@@ -244,7 +274,7 @@ class _LivePageState extends CommonPageState<LivePage, LiveController>
|
||||
),
|
||||
);
|
||||
},
|
||||
itemCount: list!.length,
|
||||
itemCount: followList.length,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@ class LiveCardVApp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String heroTag = Utils.makeHeroTag(item.id);
|
||||
String heroTag = Utils.makeHeroTag(item.roomid);
|
||||
return Card(
|
||||
clipBehavior: Clip.hardEdge,
|
||||
margin: EdgeInsets.zero,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Get.toNamed('/liveRoom?roomid=${item.id}');
|
||||
Get.toNamed('/liveRoom?roomid=${item.roomid}');
|
||||
},
|
||||
onLongPress: () => imageSaveDialog(
|
||||
title: item.title,
|
||||
|
||||
Reference in New Issue
Block a user