mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
mod: split rcmd
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:PiliPlus/pages/live/view.dart';
|
||||||
import 'package:PiliPlus/pages/rank/index.dart';
|
import 'package:PiliPlus/pages/rank/index.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
@@ -22,7 +23,7 @@ List get tabsConfig => [
|
|||||||
'label': '直播',
|
'label': '直播',
|
||||||
'type': TabType.live,
|
'type': TabType.live,
|
||||||
'ctr': Get.find<LiveController>,
|
'ctr': Get.find<LiveController>,
|
||||||
'page': const RcmdPage(tabType: TabType.live),
|
'page': const LivePage(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'icon': const Icon(
|
'icon': const Icon(
|
||||||
@@ -32,7 +33,7 @@ List get tabsConfig => [
|
|||||||
'label': '推荐',
|
'label': '推荐',
|
||||||
'type': TabType.rcmd,
|
'type': TabType.rcmd,
|
||||||
'ctr': Get.find<RcmdController>,
|
'ctr': Get.find<RcmdController>,
|
||||||
'page': const RcmdPage(tabType: TabType.rcmd),
|
'page': const RcmdPage(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'icon': const Icon(
|
'icon': const Icon(
|
||||||
|
|||||||
129
lib/pages/live/view.dart
Normal file
129
lib/pages/live/view.dart
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||||
|
import 'package:PiliPlus/http/loading_state.dart';
|
||||||
|
import 'package:PiliPlus/pages/live/controller.dart';
|
||||||
|
import 'package:PiliPlus/pages/live/widgets/live_item.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:PiliPlus/common/constants.dart';
|
||||||
|
import 'package:PiliPlus/common/skeleton/video_card_v.dart';
|
||||||
|
import 'package:PiliPlus/common/widgets/http_error.dart';
|
||||||
|
import 'package:PiliPlus/pages/home/index.dart';
|
||||||
|
import 'package:PiliPlus/pages/main/index.dart';
|
||||||
|
|
||||||
|
import '../../utils/grid.dart';
|
||||||
|
|
||||||
|
class LivePage extends StatefulWidget {
|
||||||
|
const LivePage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<LivePage> createState() => _LivePageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LivePageState extends State<LivePage>
|
||||||
|
with AutomaticKeepAliveClientMixin {
|
||||||
|
late final _controller = Get.put(LiveController());
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get wantKeepAlive => true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
StreamController<bool> mainStream =
|
||||||
|
Get.find<MainController>().bottomBarStream;
|
||||||
|
StreamController<bool> searchBarStream =
|
||||||
|
Get.find<HomeController>().searchBarStream;
|
||||||
|
_controller.scrollController.addListener(
|
||||||
|
() {
|
||||||
|
final ScrollDirection direction =
|
||||||
|
_controller.scrollController.position.userScrollDirection;
|
||||||
|
if (direction == ScrollDirection.forward) {
|
||||||
|
mainStream.add(true);
|
||||||
|
searchBarStream.add(true);
|
||||||
|
} else if (direction == ScrollDirection.reverse) {
|
||||||
|
mainStream.add(false);
|
||||||
|
searchBarStream.add(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_controller.scrollController.removeListener(() {});
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
super.build(context);
|
||||||
|
return Container(
|
||||||
|
clipBehavior: Clip.hardEdge,
|
||||||
|
margin: const EdgeInsets.only(
|
||||||
|
left: StyleString.safeSpace, right: StyleString.safeSpace),
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.all(StyleString.imgRadius),
|
||||||
|
),
|
||||||
|
child: refreshIndicator(
|
||||||
|
onRefresh: () async {
|
||||||
|
await _controller.onRefresh();
|
||||||
|
},
|
||||||
|
child: CustomScrollView(
|
||||||
|
controller: _controller.scrollController,
|
||||||
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
|
slivers: [
|
||||||
|
SliverPadding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
top: StyleString.cardSpace,
|
||||||
|
bottom: MediaQuery.paddingOf(context).bottom,
|
||||||
|
),
|
||||||
|
sliver: Obx(
|
||||||
|
() => _controller.loadingState.value is Loading ||
|
||||||
|
_controller.loadingState.value is Success
|
||||||
|
? contentGrid(_controller.loadingState.value)
|
||||||
|
: HttpError(
|
||||||
|
errMsg: _controller.loadingState.value is Error
|
||||||
|
? (_controller.loadingState.value as Error).errMsg
|
||||||
|
: '没有相关数据',
|
||||||
|
callback: _controller.onReload,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget contentGrid(LoadingState loadingState) {
|
||||||
|
return SliverGrid(
|
||||||
|
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||||
|
// 行间距
|
||||||
|
mainAxisSpacing: StyleString.cardSpace,
|
||||||
|
// 列间距
|
||||||
|
crossAxisSpacing: StyleString.cardSpace,
|
||||||
|
// 最大宽度
|
||||||
|
maxCrossAxisExtent: Grid.maxRowWidth,
|
||||||
|
childAspectRatio: StyleString.aspectRatio,
|
||||||
|
mainAxisExtent: MediaQuery.textScalerOf(context).scale(90),
|
||||||
|
),
|
||||||
|
delegate: SliverChildBuilderDelegate(
|
||||||
|
(BuildContext context, int index) {
|
||||||
|
if (loadingState is Success &&
|
||||||
|
index == loadingState.response.length - 1) {
|
||||||
|
_controller.onLoadMore();
|
||||||
|
}
|
||||||
|
return loadingState is Success
|
||||||
|
? LiveCardV(
|
||||||
|
liveItem: loadingState.response[index],
|
||||||
|
)
|
||||||
|
: const VideoCardVSkeleton();
|
||||||
|
},
|
||||||
|
childCount: loadingState is Success ? loadingState.response.length : 10,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,10 +2,6 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||||
import 'package:PiliPlus/http/loading_state.dart';
|
import 'package:PiliPlus/http/loading_state.dart';
|
||||||
import 'package:PiliPlus/models/common/tab_type.dart';
|
|
||||||
import 'package:PiliPlus/pages/common/common_controller.dart';
|
|
||||||
import 'package:PiliPlus/pages/live/controller.dart';
|
|
||||||
import 'package:PiliPlus/pages/live/widgets/live_item.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
@@ -20,9 +16,7 @@ import '../../utils/grid.dart';
|
|||||||
import 'controller.dart';
|
import 'controller.dart';
|
||||||
|
|
||||||
class RcmdPage extends StatefulWidget {
|
class RcmdPage extends StatefulWidget {
|
||||||
const RcmdPage({super.key, required this.tabType});
|
const RcmdPage({super.key});
|
||||||
|
|
||||||
final TabType tabType;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<RcmdPage> createState() => _RcmdPageState();
|
State<RcmdPage> createState() => _RcmdPageState();
|
||||||
@@ -30,9 +24,7 @@ class RcmdPage extends StatefulWidget {
|
|||||||
|
|
||||||
class _RcmdPageState extends State<RcmdPage>
|
class _RcmdPageState extends State<RcmdPage>
|
||||||
with AutomaticKeepAliveClientMixin {
|
with AutomaticKeepAliveClientMixin {
|
||||||
late final CommonController _controller = widget.tabType == TabType.rcmd
|
late final _controller = Get.put(RcmdController());
|
||||||
? Get.put<RcmdController>(RcmdController())
|
|
||||||
: Get.put<LiveController>(LiveController());
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get wantKeepAlive => true;
|
bool get wantKeepAlive => true;
|
||||||
@@ -124,70 +116,59 @@ class _RcmdPageState extends State<RcmdPage>
|
|||||||
index == loadingState.response.length - 1) {
|
index == loadingState.response.length - 1) {
|
||||||
_controller.onLoadMore();
|
_controller.onLoadMore();
|
||||||
}
|
}
|
||||||
if (widget.tabType == TabType.rcmd) {
|
if (loadingState is Success) {
|
||||||
if (loadingState is Success) {
|
if (_controller.lastRefreshAt != null) {
|
||||||
RcmdController ctr = _controller as RcmdController;
|
if (_controller.lastRefreshAt == index) {
|
||||||
if (ctr.savedRcmdTip) {
|
return GestureDetector(
|
||||||
if (ctr.lastRefreshAt == index) {
|
onTap: () {
|
||||||
return GestureDetector(
|
_controller.animateToTop();
|
||||||
onTap: () {
|
_controller.onRefresh();
|
||||||
_controller.animateToTop();
|
},
|
||||||
_controller.onRefresh();
|
child: Card(
|
||||||
},
|
child: Container(
|
||||||
child: Card(
|
alignment: Alignment.center,
|
||||||
child: Container(
|
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||||
alignment: Alignment.center,
|
child: Text(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
'上次看到这里\n点击刷新',
|
||||||
child: Text(
|
textAlign: TextAlign.center,
|
||||||
'上次看到这里\n点击刷新',
|
style: TextStyle(
|
||||||
textAlign: TextAlign.center,
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||||
style: TextStyle(
|
|
||||||
color:
|
|
||||||
Theme.of(context).colorScheme.onSurfaceVariant,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
}
|
|
||||||
int actualIndex = ctr.lastRefreshAt == null
|
|
||||||
? index
|
|
||||||
: index > ctr.lastRefreshAt!
|
|
||||||
? index - 1
|
|
||||||
: index;
|
|
||||||
return VideoCardV(
|
|
||||||
videoItem: loadingState.response[actualIndex],
|
|
||||||
onRemove: () {
|
|
||||||
if (ctr.lastRefreshAt != null &&
|
|
||||||
actualIndex < ctr.lastRefreshAt!) {
|
|
||||||
ctr.lastRefreshAt = ctr.lastRefreshAt! - 1;
|
|
||||||
}
|
|
||||||
_controller.loadingState.value = LoadingState.success(
|
|
||||||
(loadingState.response as List)..removeAt(actualIndex));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return VideoCardV(
|
|
||||||
videoItem: loadingState.response[index],
|
|
||||||
onRemove: () {
|
|
||||||
_controller.loadingState.value = LoadingState.success(
|
|
||||||
(loadingState.response as List)..removeAt(index));
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
int actualIndex = _controller.lastRefreshAt == null
|
||||||
|
? index
|
||||||
|
: index > _controller.lastRefreshAt!
|
||||||
|
? index - 1
|
||||||
|
: index;
|
||||||
|
return VideoCardV(
|
||||||
|
videoItem: loadingState.response[actualIndex],
|
||||||
|
onRemove: () {
|
||||||
|
if (_controller.lastRefreshAt != null &&
|
||||||
|
actualIndex < _controller.lastRefreshAt!) {
|
||||||
|
_controller.lastRefreshAt = _controller.lastRefreshAt! - 1;
|
||||||
|
}
|
||||||
|
_controller.loadingState.value = LoadingState.success(
|
||||||
|
(loadingState.response as List)..removeAt(actualIndex));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return VideoCardV(
|
||||||
|
videoItem: loadingState.response[index],
|
||||||
|
onRemove: () {
|
||||||
|
_controller.loadingState.value = LoadingState.success(
|
||||||
|
(loadingState.response as List)..removeAt(index));
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return const VideoCardVSkeleton();
|
|
||||||
} else {
|
|
||||||
return loadingState is Success
|
|
||||||
? LiveCardV(
|
|
||||||
liveItem: loadingState.response[index],
|
|
||||||
)
|
|
||||||
: const VideoCardVSkeleton();
|
|
||||||
}
|
}
|
||||||
|
return const VideoCardVSkeleton();
|
||||||
},
|
},
|
||||||
childCount: loadingState is Success
|
childCount: loadingState is Success
|
||||||
? widget.tabType == TabType.rcmd &&
|
? _controller.lastRefreshAt != null
|
||||||
(_controller as RcmdController).lastRefreshAt != null
|
|
||||||
? loadingState.response.length + 1
|
? loadingState.response.length + 1
|
||||||
: loadingState.response.length
|
: loadingState.response.length
|
||||||
: 10,
|
: 10,
|
||||||
|
|||||||
Reference in New Issue
Block a user