feat(home): 首页按内容类型分频道 Feed 并支持分页
This commit is contained in:
1 parent
4d0be47ee3
commit
ae61d9ec4c
22 files changed
+1001
-71
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -22,6 +23,7 @@ import '../../core/theme/app_theme.dart';
|
||||
import '../../core/widgets/auth_gate.dart';
|
||||
import '../../core/widgets/download_action.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import '../home/home_feed_channel.dart';
|
||||
import 'comments_auth.dart';
|
||||
import 'player_binding.dart';
|
||||
import 'player_logic.dart';
|
||||
@@ -57,10 +59,13 @@ class PlayerPage extends StatefulWidget {
|
||||
this.onSearch,
|
||||
this.onMenu,
|
||||
this.feedDramas,
|
||||
this.feedChannel,
|
||||
this.onDramaChanged,
|
||||
this.onImmersiveChanged,
|
||||
this.onOpenFullPlayer,
|
||||
this.onRefreshFeed,
|
||||
this.onLoadMore,
|
||||
this.onChannelSelected,
|
||||
this.wallet,
|
||||
this.downloads,
|
||||
});
|
||||
@@ -77,10 +82,13 @@ class PlayerPage extends StatefulWidget {
|
||||
final VoidCallback? onSearch;
|
||||
final VoidCallback? onMenu;
|
||||
final List<Drama>? feedDramas;
|
||||
final HomeFeedChannel? feedChannel;
|
||||
final ValueChanged<Drama>? onDramaChanged;
|
||||
final ValueChanged<bool>? onImmersiveChanged;
|
||||
final Future<void> Function(Drama drama, Episode episode)? onOpenFullPlayer;
|
||||
final Future<bool> Function()? onRefreshFeed;
|
||||
final Future<void> Function()? onLoadMore;
|
||||
final ValueChanged<HomeFeedChannel>? onChannelSelected;
|
||||
final WalletController? wallet;
|
||||
final DownloadController? downloads;
|
||||
|
||||
@@ -123,6 +131,17 @@ class _PlayerPageState extends State<PlayerPage>
|
||||
void didUpdateWidget(covariant PlayerPage oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
logic.attach(widget, isMounted: () => mounted);
|
||||
if (widget.homeMode &&
|
||||
widget.feedDramas != null &&
|
||||
(!listEquals(oldWidget.feedDramas, widget.feedDramas) ||
|
||||
oldWidget.feedChannel != widget.feedChannel)) {
|
||||
logic.updateFeed(
|
||||
widget.feedDramas!,
|
||||
keepDramaId: oldWidget.feedChannel == widget.feedChannel
|
||||
? logic.currentDramaId
|
||||
: null,
|
||||
);
|
||||
}
|
||||
logic.onPageUpdated(oldWidget);
|
||||
}
|
||||
|
||||
@@ -250,6 +269,10 @@ class _PlayerPageState extends State<PlayerPage>
|
||||
final index = indices[position];
|
||||
widget.onDramaChanged?.call(logic.queue.entryAt(index).drama);
|
||||
unawaited(logic.selectEpisode(index));
|
||||
if (position >= indices.length - 3) {
|
||||
final loadMore = widget.onLoadMore;
|
||||
if (loadMore != null) unawaited(loadMore());
|
||||
}
|
||||
},
|
||||
itemBuilder: (context, position) =>
|
||||
_buildEpisode(context, indices[position], interactions),
|
||||
@@ -268,6 +291,8 @@ class _PlayerPageState extends State<PlayerPage>
|
||||
bottom: false,
|
||||
child: HomeFeedHeader(
|
||||
l10n: l10n,
|
||||
channel: widget.feedChannel ?? HomeFeedChannel.recommend,
|
||||
onChannelSelected: widget.onChannelSelected ?? (_) {},
|
||||
onRefresh: () async {
|
||||
final ok = await widget.onRefreshFeed?.call() ?? true;
|
||||
if (context.mounted && !ok) {
|
||||
|
||||
Reference in new issue
Block a user