This commit is contained in:
lz_db
2026-10-25 11:46:44 +08:00
parent 893dfed0ed
commit 494f667719
63 changed files with 5213 additions and 239 deletions
+22 -2
View File
@@ -16,7 +16,10 @@ enum FeedStrategy {
latest('latest', '最新'),
hot('hot', '热度'),
liked('liked', '口碑'),
viewed('viewed', '热播');
viewed('viewed', '热播'),
// 搜索播放专用策略:数据由搜索页注入,不走网络 refresh;
// 顶部 Tab 不显示该项,仅作为独立播放器池存在
search('search', '搜索');
const FeedStrategy(this.apiValue, this.label);
@@ -106,7 +109,10 @@ class FeedState {
class FeedNotifier extends StateNotifier<FeedState> {
FeedNotifier(this._ref, this.strategy) : super(const FeedState()) {
pool = FeedPlayerPool(onWatchComplete: _onWatchComplete)..init();
refresh();
// search 策略由外部 injectItems 灌入数据,不走网络 refresh
if (strategy != FeedStrategy.search) {
refresh();
}
}
final Ref _ref;
@@ -123,6 +129,8 @@ class FeedNotifier extends StateNotifier<FeedState> {
/// 刷新(首屏 / 下拉 / 切策略)
Future<void> refresh() async {
// search 策略不支持下拉刷新(数据由搜索页注入)
if (strategy == FeedStrategy.search) return;
state = state.copyWith(isRefreshing: true, loadFailed: false);
try {
final page = await VideoService.fetchFeed(type: strategy.apiValue);
@@ -142,6 +150,8 @@ class FeedNotifier extends StateNotifier<FeedState> {
/// 加载更多(游标分页)
Future<void> loadMore() async {
// search 策略暂不支持自动加载更多(如需要可由搜索页同步注入新数据)
if (strategy == FeedStrategy.search) return;
if (!state.hasMore || state.isLoadingMore) return;
state = state.copyWith(isLoadingMore: true);
try {
@@ -159,6 +169,16 @@ class FeedNotifier extends StateNotifier<FeedState> {
}
}
/// 外部数据注入(仅 search 策略用):把搜索结果整列表灌入并定位到点击的那一条。
/// 池子由 SearchFeedScreen 独占,注入后立即绑定播放。
Future<void> injectItems(List<VideoItem> items, int initialIndex) async {
if (strategy != FeedStrategy.search) return;
if (items.isEmpty) return;
final index = initialIndex.clamp(0, items.length - 1);
state = FeedState(items: items, currentIndex: index);
await _bindAndReport(index);
}
/// 从全屏播放器返回后恢复:stopAll 清空了槽位,重新绑定当前页并播放。
/// 不上报观看(本次进入 Feed 时已上报过,且 _bindAndReport 有按日去重)。
Future<void> rebindCurrent() async {