opt: live area

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-04-29 20:15:35 +08:00
parent 11a0f2faca
commit fb22e5ab66
5 changed files with 321 additions and 106 deletions

View File

@@ -15,6 +15,8 @@ class LiveController extends CommonListController {
queryData(); queryData();
} }
int? count;
// area // area
int? areaId; int? areaId;
String? sortType; String? sortType;
@@ -29,6 +31,13 @@ class LiveController extends CommonListController {
Pair<LiveCardList?, LiveCardList?>(first: null, second: null).obs; Pair<LiveCardList?, LiveCardList?>(first: null, second: null).obs;
final RxBool isLogin = Accounts.main.isLogin.obs; final RxBool isLogin = Accounts.main.isLogin.obs;
@override
void checkIsEnd(int length) {
if (count != null && length >= count!) {
isEnd = true;
}
}
@override @override
List? getDataList(response) { List? getDataList(response) {
return response.cardList; return response.cardList;
@@ -38,11 +47,15 @@ class LiveController extends CommonListController {
bool customHandleResponse(bool isRefresh, Success response) { bool customHandleResponse(bool isRefresh, Success response) {
if (isRefresh) { if (isRefresh) {
if (areaIndex.value == 0) { if (areaIndex.value == 0) {
if (response.response.hasMore == 0) {
isEnd = true;
}
topState.value = Pair( topState.value = Pair(
first: response.response.followItem, first: response.response.followItem,
second: response.response.areaItem, second: response.response.areaItem,
); );
} else { } else {
count = response.response.count;
newTags = response.response.newTags; newTags = response.response.newTags;
if (sortType != null) { if (sortType != null) {
tagIndex.value = tagIndex.value =
@@ -69,6 +82,7 @@ class LiveController extends CommonListController {
@override @override
Future<void> onRefresh() { Future<void> onRefresh() {
count = null;
currentPage = 1; currentPage = 1;
isEnd = false; isEnd = false;
if (areaIndex.value != 0) { if (areaIndex.value != 0) {
@@ -109,6 +123,7 @@ class LiveController extends CommonListController {
areaId = cardLiveItem?.areaV2Id; areaId = cardLiveItem?.areaV2Id;
parentAreaId = cardLiveItem?.areaV2ParentId; parentAreaId = cardLiveItem?.areaV2ParentId;
count = null;
currentPage = 1; currentPage = 1;
isEnd = false; isEnd = false;
queryData(); queryData();
@@ -118,6 +133,7 @@ class LiveController extends CommonListController {
tagIndex.value = index; tagIndex.value = index;
this.sortType = sortType; this.sortType = sortType;
count = null;
currentPage = 1; currentPage = 1;
isEnd = false; isEnd = false;
queryData(); queryData();

View File

@@ -147,69 +147,70 @@ class _LivePageState extends CommonPageState<LivePage, LiveController>
childCount: 10, childCount: 10,
), ),
), ),
Success() => loadingState.response?.isNotEmpty == true Success() => SliverMainAxisGroup(
? SliverMainAxisGroup( slivers: [
slivers: [ if (controller.newTags?.isNotEmpty == true)
if (controller.newTags?.isNotEmpty == true) SliverToBoxAdapter(
SliverToBoxAdapter( child: SelfSizedHorizontalList(
child: SelfSizedHorizontalList( gapSize: 12,
gapSize: 12, padding: const EdgeInsets.only(bottom: 8),
padding: const EdgeInsets.only(bottom: 8), childBuilder: (index) {
childBuilder: (index) { late final item = controller.newTags![index];
late final item = controller.newTags![index]; return Obx(
return Obx( () => SearchText(
() => SearchText( fontSize: 13,
fontSize: 13, padding: const EdgeInsets.symmetric(
padding: const EdgeInsets.symmetric( horizontal: 8,
horizontal: 8, vertical: 3,
vertical: 3, ),
), text: '${item.name}',
text: '${item.name}', bgColor: index == controller.tagIndex.value
bgColor: index == controller.tagIndex.value ? theme.colorScheme.secondaryContainer
? theme.colorScheme.secondaryContainer : Colors.transparent,
: Colors.transparent, textColor: index == controller.tagIndex.value
textColor: index == controller.tagIndex.value ? theme.colorScheme.onSecondaryContainer
? theme.colorScheme.onSecondaryContainer : null,
: null, onTap: (value) {
onTap: (value) { controller.onSelectTag(
controller.onSelectTag( index,
index, item.sortType,
item.sortType, );
); },
}, ),
), );
); },
}, itemCount: controller.newTags!.length,
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,
),
), ),
], ),
) loadingState.response?.isNotEmpty == true
: HttpError(onReload: controller.onReload), ? 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( Error() => HttpError(
errMsg: loadingState.errMsg, errMsg: loadingState.errMsg,
onReload: controller.onReload, onReload: controller.onReload,

View File

@@ -1,9 +1,13 @@
import 'dart:math';
import 'package:PiliPlus/http/live.dart'; import 'package:PiliPlus/http/live.dart';
import 'package:PiliPlus/http/loading_state.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_data_list_item.dart';
import 'package:PiliPlus/models/live/live_second_list/data.dart'; import 'package:PiliPlus/models/live/live_second_list/data.dart';
import 'package:PiliPlus/models/live/live_second_list/tag.dart';
import 'package:PiliPlus/pages/common/common_list_controller.dart'; import 'package:PiliPlus/pages/common/common_list_controller.dart';
import 'package:PiliPlus/utils/storage.dart'; import 'package:PiliPlus/utils/storage.dart';
import 'package:get/get.dart';
class LiveAreaChildController class LiveAreaChildController
extends CommonListController<LiveSecondData, CardLiveItem> { extends CommonListController<LiveSecondData, CardLiveItem> {
@@ -11,8 +15,14 @@ class LiveAreaChildController
final dynamic areaId; final dynamic areaId;
final dynamic parentAreaId; final dynamic parentAreaId;
int? count;
String? sortType; String? sortType;
// tag
final RxInt tagIndex = 0.obs;
List<LiveSecondTag>? newTags;
final isLogin = Accounts.main.isLogin; final isLogin = Accounts.main.isLogin;
@override @override
@@ -21,8 +31,19 @@ class LiveAreaChildController
queryData(); queryData();
} }
@override
void checkIsEnd(int length) {
if (count != null && length >= count!) {
isEnd = true;
}
}
@override @override
List<CardLiveItem>? getDataList(LiveSecondData response) { List<CardLiveItem>? getDataList(LiveSecondData response) {
count = response.count;
newTags = response.newTags;
tagIndex.value =
max(0, newTags?.indexWhere((e) => e.sortType == sortType) ?? 0);
return response.cardList; return response.cardList;
} }
@@ -35,4 +56,11 @@ class LiveAreaChildController
parentAreaId: parentAreaId, parentAreaId: parentAreaId,
sortType: sortType, sortType: sortType,
); );
void onSelectTag(int index, String? sortType) {
tagIndex.value = index;
this.sortType = sortType;
onRefresh();
}
} }

View File

@@ -2,10 +2,12 @@ import 'package:PiliPlus/common/constants.dart';
import 'package:PiliPlus/common/skeleton/video_card_v.dart'; import 'package:PiliPlus/common/skeleton/video_card_v.dart';
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart'; import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
import 'package:PiliPlus/common/widgets/refresh_indicator.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'; 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_data_list_item.dart';
import 'package:PiliPlus/pages/live/widgets/live_item_app.dart'; import 'package:PiliPlus/pages/live/widgets/live_item_app.dart';
import 'package:PiliPlus/pages/live_area_detail/child/controller.dart'; import 'package:PiliPlus/pages/live_area_detail/child/controller.dart';
import 'package:PiliPlus/pages/search/widgets/search_text.dart';
import 'package:PiliPlus/utils/grid.dart'; import 'package:PiliPlus/utils/grid.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
@@ -34,6 +36,7 @@ class _LiveAreaChildPageState extends State<LiveAreaChildPage>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context); super.build(context);
final ThemeData theme = Theme.of(context);
return refreshIndicator( return refreshIndicator(
onRefresh: _controller.onRefresh, onRefresh: _controller.onRefresh,
child: CustomScrollView( child: CustomScrollView(
@@ -45,14 +48,16 @@ class _LiveAreaChildPageState extends State<LiveAreaChildPage>
top: StyleString.safeSpace, top: StyleString.safeSpace,
bottom: MediaQuery.paddingOf(context).bottom + 80, bottom: MediaQuery.paddingOf(context).bottom + 80,
), ),
sliver: Obx(() => _buildBody(_controller.loadingState.value)), sliver:
Obx(() => _buildBody(theme, _controller.loadingState.value)),
), ),
], ],
), ),
); );
} }
Widget _buildBody(LoadingState<List<CardLiveItem>?> loadingState) { Widget _buildBody(
ThemeData theme, LoadingState<List<CardLiveItem>?> loadingState) {
return switch (loadingState) { return switch (loadingState) {
Loading() => SliverGrid( Loading() => SliverGrid(
gridDelegate: SliverGridDelegateWithExtentAndRatio( gridDelegate: SliverGridDelegateWithExtentAndRatio(
@@ -69,28 +74,69 @@ class _LiveAreaChildPageState extends State<LiveAreaChildPage>
childCount: 10, childCount: 10,
), ),
), ),
Success() => loadingState.response?.isNotEmpty == true Success() => SliverMainAxisGroup(
? SliverGrid( slivers: [
gridDelegate: SliverGridDelegateWithExtentAndRatio( if (_controller.newTags?.isNotEmpty == true)
mainAxisSpacing: StyleString.cardSpace, SliverToBoxAdapter(
crossAxisSpacing: StyleString.cardSpace, child: Padding(
maxCrossAxisExtent: Grid.smallCardWidth, padding: const EdgeInsets.only(bottom: 12),
childAspectRatio: StyleString.aspectRatio, child: SelfSizedHorizontalList(
mainAxisExtent: MediaQuery.textScalerOf(context).scale(90), gapSize: 12,
childBuilder: (index) {
late final item = _controller.newTags![index];
return Obx(
() => SearchText(
fontSize: 14,
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 3,
),
text: '${item.name}',
bgColor: index == _controller.tagIndex.value
? theme.colorScheme.secondaryContainer
: Colors.transparent,
textColor: index == _controller.tagIndex.value
? theme.colorScheme.onSecondaryContainer
: null,
onTap: (value) {
_controller.onSelectTag(
index,
item.sortType,
);
},
),
);
},
itemCount: _controller.newTags!.length,
),
),
), ),
delegate: SliverChildBuilderDelegate( loadingState.response?.isNotEmpty == true
(context, index) { ? SliverGrid(
if (index == loadingState.response!.length - 1) { gridDelegate: SliverGridDelegateWithExtentAndRatio(
_controller.onLoadMore(); mainAxisSpacing: StyleString.cardSpace,
} crossAxisSpacing: StyleString.cardSpace,
return LiveCardVApp(item: loadingState.response![index]); maxCrossAxisExtent: Grid.smallCardWidth,
}, childAspectRatio: StyleString.aspectRatio,
childCount: loadingState.response!.length, mainAxisExtent:
), MediaQuery.textScalerOf(context).scale(90),
) ),
: HttpError( delegate: SliverChildBuilderDelegate(
onReload: _controller.onReload, (context, index) {
), if (index == loadingState.response!.length - 1) {
_controller.onLoadMore();
}
return LiveCardVApp(
item: loadingState.response![index]);
},
childCount: loadingState.response!.length,
),
)
: HttpError(
onReload: _controller.onReload,
),
],
),
Error() => HttpError( Error() => HttpError(
errMsg: loadingState.errMsg, errMsg: loadingState.errMsg,
onReload: _controller.onReload, onReload: _controller.onReload,

View File

@@ -1,3 +1,5 @@
import 'package:PiliPlus/common/widgets/button/icon_button.dart';
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
import 'package:PiliPlus/common/widgets/scroll_physics.dart'; import 'package:PiliPlus/common/widgets/scroll_physics.dart';
import 'package:PiliPlus/http/loading_state.dart'; import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/models/live/live_area_list/area_item.dart'; import 'package:PiliPlus/models/live/live_area_list/area_item.dart';
@@ -59,27 +61,48 @@ class _LiveAreaDetailPageState extends State<LiveAreaDetailPage> {
? DefaultTabController( ? DefaultTabController(
initialIndex: _controller.initialIndex, initialIndex: _controller.initialIndex,
length: loadingState.response!.length, length: loadingState.response!.length,
child: Column( child: Builder(
crossAxisAlignment: CrossAxisAlignment.start, builder: (context) {
children: [ return Column(
TabBar( crossAxisAlignment: CrossAxisAlignment.start,
isScrollable: true, children: [
tabAlignment: TabAlignment.start, Row(
tabs: loadingState.response! children: [
.map((e) => Tab(text: e.name ?? '')) Expanded(
.toList(), child: TabBar(
), dividerHeight: 0,
Expanded( dividerColor: Colors.transparent,
child: tabBarView( isScrollable: true,
children: loadingState.response! tabAlignment: TabAlignment.start,
.map((e) => LiveAreaChildPage( tabs: loadingState.response!
areaId: e.id, .map((e) => Tab(text: e.name ?? ''))
parentAreaId: e.parentId, .toList(),
)) ),
.toList(), ),
), iconButton(
), context: context,
], icon: Icons.menu,
bgColor: Colors.transparent,
onPressed: () {
_showTags(context, theme, loadingState.response!);
},
),
],
),
const Divider(height: 1),
Expanded(
child: tabBarView(
children: loadingState.response!
.map((e) => LiveAreaChildPage(
areaId: e.id,
parentAreaId: e.parentId,
))
.toList(),
),
),
],
);
},
), ),
) )
: LiveAreaChildPage( : LiveAreaChildPage(
@@ -92,4 +115,105 @@ class _LiveAreaDetailPageState extends State<LiveAreaDetailPage> {
), ),
}; };
} }
Widget _tagItem({
required ThemeData theme,
required AreaItem item,
required VoidCallback onTap,
}) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
NetworkImgLayer(
width: 45,
height: 45,
src: item.pic,
type: 'emote',
),
const SizedBox(height: 4),
Text(
item.name!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 12),
),
],
),
);
}
void _showTags(BuildContext context, ThemeData theme, List<AreaItem> list) {
showModalBottomSheet(
context: context,
useSafeArea: true,
isScrollControlled: true,
builder: (_) {
return DraggableScrollableSheet(
minChildSize: 0,
maxChildSize: 1,
initialChildSize: 1,
snap: true,
expand: false,
snapSizes: const [1],
builder: (_, scrollController) {
return NotificationListener<DraggableScrollableNotification>(
onNotification: (notification) {
if (notification.extent <= 1e-5) {
Get.back();
}
return false;
},
child: Column(
children: [
AppBar(
centerTitle: true,
backgroundColor: Colors.transparent,
automaticallyImplyLeading: false,
title: Text(widget.parentName),
actions: [
IconButton(
onPressed: Get.back,
icon: const Icon(Icons.clear),
),
const SizedBox(width: 12),
],
),
Expanded(
child: GridView.builder(
controller: scrollController,
padding: EdgeInsets.only(
top: 12,
bottom: MediaQuery.paddingOf(context).bottom + 80,
),
itemCount: list.length,
gridDelegate:
const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 100,
mainAxisSpacing: 10,
crossAxisSpacing: 10,
mainAxisExtent: 80,
),
itemBuilder: (_, index) {
return _tagItem(
theme: theme,
item: list[index],
onTap: () {
Get.back();
DefaultTabController.of(context).index = index;
},
);
},
),
),
],
),
);
},
);
},
);
}
} }