mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-25 21:05:52 +08:00
feat: live area page
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -3,6 +3,7 @@ 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_second_list/tag.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';
|
||||
@@ -14,9 +15,16 @@ class LiveController extends CommonListController {
|
||||
queryData();
|
||||
}
|
||||
|
||||
// area
|
||||
int? areaId;
|
||||
String? sortType;
|
||||
int? parentAreaId;
|
||||
final RxInt areaIndex = 0.obs;
|
||||
|
||||
// tag
|
||||
final RxInt tagIndex = 0.obs;
|
||||
List<LiveSecondTag>? newTags;
|
||||
|
||||
final Rx<Pair<LiveCardList?, LiveCardList?>> topState =
|
||||
Pair<LiveCardList?, LiveCardList?>(first: null, second: null).obs;
|
||||
final RxBool isLogin = Accounts.main.isLogin.obs;
|
||||
@@ -28,11 +36,19 @@ class LiveController extends CommonListController {
|
||||
|
||||
@override
|
||||
bool customHandleResponse(bool isRefresh, Success response) {
|
||||
if (isRefresh && areaIndex.value == 0) {
|
||||
topState.value = Pair(
|
||||
first: response.response.followItem,
|
||||
second: response.response.areaItem,
|
||||
);
|
||||
if (isRefresh) {
|
||||
if (areaIndex.value == 0) {
|
||||
topState.value = Pair(
|
||||
first: response.response.followItem,
|
||||
second: response.response.areaItem,
|
||||
);
|
||||
} else {
|
||||
newTags = response.response.newTags;
|
||||
if (sortType != null) {
|
||||
tagIndex.value =
|
||||
newTags?.indexWhere((e) => e.sortType == sortType) ?? -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -45,6 +61,7 @@ class LiveController extends CommonListController {
|
||||
isLogin: isLogin.value,
|
||||
areaId: areaId,
|
||||
parentAreaId: parentAreaId,
|
||||
sortType: sortType,
|
||||
);
|
||||
}
|
||||
return LiveHttp.liveFeedIndex(pn: currentPage, isLogin: isLogin.value);
|
||||
@@ -72,6 +89,12 @@ class LiveController extends CommonListController {
|
||||
first: data.followItem,
|
||||
second: data.areaItem,
|
||||
);
|
||||
areaIndex.value = (data.areaItem?.cardData?.areaEntranceV3?.list
|
||||
?.indexWhere((e) =>
|
||||
e.areaV2Id == areaId &&
|
||||
e.areaV2ParentId == parentAreaId) ??
|
||||
-2) +
|
||||
1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +102,9 @@ class LiveController extends CommonListController {
|
||||
if (index == areaIndex.value) {
|
||||
return;
|
||||
}
|
||||
tagIndex.value = 0;
|
||||
newTags = null;
|
||||
sortType = null;
|
||||
areaIndex.value = index;
|
||||
areaId = cardLiveItem?.areaV2Id;
|
||||
parentAreaId = cardLiveItem?.areaV2ParentId;
|
||||
@@ -87,4 +113,13 @@ class LiveController extends CommonListController {
|
||||
isEnd = false;
|
||||
queryData();
|
||||
}
|
||||
|
||||
void onSelectTag(int index, String? sortType) {
|
||||
tagIndex.value = index;
|
||||
this.sortType = sortType;
|
||||
|
||||
currentPage = 1;
|
||||
isEnd = false;
|
||||
queryData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/skeleton/video_card_v.dart';
|
||||
import 'package:PiliPlus/common/widgets/button/icon_button.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';
|
||||
@@ -11,6 +12,7 @@ import 'package:PiliPlus/models/live/live_feed_index/card_list.dart';
|
||||
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_area/view.dart';
|
||||
import 'package:PiliPlus/pages/live_follow/view.dart';
|
||||
import 'package:PiliPlus/pages/search/widgets/search_text.dart';
|
||||
import 'package:PiliPlus/utils/grid.dart';
|
||||
@@ -73,39 +75,60 @@ class _LivePageState extends CommonPageState<LivePage, LiveController>
|
||||
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,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SelfSizedHorizontalList(
|
||||
gapSize: 12,
|
||||
padding:
|
||||
const EdgeInsets.only(top: 10, bottom: 10, right: 12),
|
||||
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,
|
||||
),
|
||||
);
|
||||
},
|
||||
itemCount:
|
||||
data.second!.cardData!.areaEntranceV3!.list!.length + 1,
|
||||
),
|
||||
iconButton(
|
||||
size: 26,
|
||||
iconSize: 16,
|
||||
context: context,
|
||||
tooltip: '全部标签',
|
||||
icon: Icons.widgets,
|
||||
onPressed: () {
|
||||
Get.to(const LiveAreaPage());
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
const SliverToBoxAdapter(child: SizedBox(height: 10)),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -128,29 +151,70 @@ class _LivePageState extends CommonPageState<LivePage, LiveController>
|
||||
),
|
||||
),
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? 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,
|
||||
),
|
||||
? SliverMainAxisGroup(
|
||||
slivers: [
|
||||
if (controller.newTags?.isNotEmpty == true)
|
||||
SliverToBoxAdapter(
|
||||
child: SelfSizedHorizontalList(
|
||||
gapSize: 12,
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
childBuilder: (index) {
|
||||
late final item = controller.newTags![index];
|
||||
return Obx(
|
||||
() => SearchText(
|
||||
fontSize: 13,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 3,
|
||||
),
|
||||
text: '${item.name}',
|
||||
bgColor: index == controller.tagIndex.value
|
||||
? Theme.of(context)
|
||||
.colorScheme
|
||||
.secondaryContainer
|
||||
: Colors.transparent,
|
||||
textColor: index == controller.tagIndex.value
|
||||
? Theme.of(context)
|
||||
.colorScheme
|
||||
.onSecondaryContainer
|
||||
: null,
|
||||
onTap: (value) {
|
||||
controller.onSelectTag(
|
||||
index,
|
||||
item.sortType,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
itemCount: controller.newTags!.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(
|
||||
@@ -216,7 +280,6 @@ class _LivePageState extends CommonPageState<LivePage, LiveController>
|
||||
),
|
||||
if (item.cardData?.myIdolV1?.list?.isNotEmpty == true)
|
||||
_buildFollowBody(theme, item.cardData!.myIdolV1!.list!),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user