chore(client): 归档原型阶段未提交改动(binding/logic/view 分层与各页迭代)
为什么:客户端原型在 14d7bd3 之后又做了一轮(页面分层、发现页、分类滑动、播放器控件等),
一直留在工作区没入库。下一批账号链路要改其中的 app.dart / home_view / player_view / mine_view,
先归档这批既存改动,本批的实际 diff 才说得清边界。
只归档,不改行为:当前工作区 flutter analyze 0 问题、flutter test 148 全过。
This commit is contained in:
1 parent
14d7bd39c7
commit
77d5748dbb
33 files changed
+1264
-1064
No files matched your search
@@ -1,26 +1,72 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../models/drama.dart';
|
||||
import '../repositories/catalog_repository.dart';
|
||||
|
||||
import '../models/drama.dart';
|
||||
import '../models/home_feed.dart';
|
||||
import '../repositories/catalog_repository.dart';
|
||||
import '../remote/api_client.dart';
|
||||
|
||||
/// 目录状态:首页/发现页聚合数据 + 详情按需加载。
|
||||
///
|
||||
/// 列表卡片不含剧集,只有进详情或播放时才取一次详情,
|
||||
/// 这样首页接口能保持很小的响应体。
|
||||
class CatalogController extends ChangeNotifier {
|
||||
CatalogController(this.repository);
|
||||
|
||||
final CatalogRepository repository;
|
||||
|
||||
List<Drama> dramas = const [];
|
||||
HomeFeed feed = const HomeFeed();
|
||||
bool loading = false;
|
||||
String? error;
|
||||
|
||||
List<Drama> get dramas => feed.dramas;
|
||||
List<FeedBanner> get banners => feed.banners;
|
||||
List<FeedSection> get sections => feed.sections;
|
||||
|
||||
Future<void> load() async {
|
||||
loading = true;
|
||||
error = null;
|
||||
notifyListeners();
|
||||
try {
|
||||
dramas = await repository.fetchDramas();
|
||||
feed = await repository.fetchHomeFeed();
|
||||
} on ApiException catch (exception) {
|
||||
error = exception.message;
|
||||
} catch (_) {
|
||||
error = 'The catalog could not be loaded.';
|
||||
error = 'catalogError';
|
||||
} finally {
|
||||
loading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/// 需要完整剧集时补一次详情;已加载过则直接返回,避免重复请求。
|
||||
Future<Drama> requireDetail(Drama drama) async {
|
||||
if (drama.detailLoaded) return drama;
|
||||
final detail = await repository.fetchDrama(drama.id);
|
||||
_replace(detail);
|
||||
return detail;
|
||||
}
|
||||
|
||||
/// 播放前解析票据:返回带播放地址的剧集,锁定集保持无地址。
|
||||
Future<Episode> resolvePlay(Episode episode) async {
|
||||
if (episode.videoUrl.isNotEmpty) return episode;
|
||||
final ticket = await repository.resolvePlay(episode.id);
|
||||
return ticket.accessible ? episode.withVideoUrl(ticket.playUrl) : episode;
|
||||
}
|
||||
|
||||
void _replace(Drama detail) {
|
||||
final sections = feed.sections
|
||||
.map(
|
||||
(section) => FeedSection(
|
||||
code: section.code,
|
||||
title: section.title,
|
||||
dramas: [
|
||||
for (final drama in section.dramas)
|
||||
if (drama.id == detail.id) detail else drama,
|
||||
],
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
feed = HomeFeed(banners: feed.banners, sections: sections);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
@@ -128,6 +128,9 @@ class PlaybackSession extends ChangeNotifier {
|
||||
if (!slot.retiring && !_closed) slot.prepared = true;
|
||||
} catch (error) {
|
||||
slot.failure = error;
|
||||
if (kDebugMode) {
|
||||
debugPrint('片源准备失败 ${episodes[index].videoUrl}: $error');
|
||||
}
|
||||
}
|
||||
}();
|
||||
return slot;
|
||||
@@ -149,14 +152,23 @@ class PlaybackSession extends ChangeNotifier {
|
||||
/// use exactly the same mechanism without warming an unrelated episode.
|
||||
Future<void> select(int index, {int? preloadIndex}) async {
|
||||
if (_closed || index < 0 || index >= episodes.length) return;
|
||||
// 切到另一集时,上一集按下的暂停不跟着走:滑过去就应该自动播放。
|
||||
// 重复选中同一集(例如页面重新可见)不在这里恢复,尊重用户按下的暂停。
|
||||
if (!_selected || index != _currentIndex) {
|
||||
_userWantsPlay = true;
|
||||
}
|
||||
final request = ++_generation;
|
||||
_selected = true;
|
||||
_currentIndex = index;
|
||||
_nextIndex = preloadIndex;
|
||||
_error = null;
|
||||
if (!_visible) {
|
||||
_loading = false;
|
||||
_notify();
|
||||
return;
|
||||
}
|
||||
_loading = preparedPlayerAt(index) == null && !isLocked;
|
||||
_notify();
|
||||
if (!_visible) return;
|
||||
final acquired = await _coordinator._acquire(
|
||||
this,
|
||||
() => _visible && request == _generation,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:video_player/video_player.dart';
|
||||
|
||||
import '../../config/app_config.dart';
|
||||
import '../models/drama.dart';
|
||||
import '../models/player_port.dart';
|
||||
|
||||
@@ -7,11 +8,25 @@ class VideoPlayerPort implements PlayerPort {
|
||||
VideoPlayerPort(
|
||||
Episode episode, {
|
||||
Future<ClosedCaptionFile>? closedCaptionFile,
|
||||
}) : controller = VideoPlayerController.asset(
|
||||
episode.assetPath,
|
||||
closedCaptionFile: closedCaptionFile,
|
||||
videoPlayerOptions: VideoPlayerOptions(mixWithOthers: false),
|
||||
);
|
||||
}) : controller = _open(episode, closedCaptionFile);
|
||||
|
||||
/// 后端下发的是相对路径(`/files/...`),交给播放器前补上服务地址。
|
||||
/// 否则 Uri 没有 scheme/host,AVPlayer 和 ExoPlayer 都加载不了。
|
||||
static Uri resolveUri(Episode episode) =>
|
||||
Uri.parse(AppConfig.mediaUrl(episode.videoUrl));
|
||||
|
||||
static VideoPlayerController _open(
|
||||
Episode episode,
|
||||
Future<ClosedCaptionFile>? closedCaptionFile,
|
||||
) {
|
||||
final options = VideoPlayerOptions(mixWithOthers: false);
|
||||
// 片源统一由后端下发(详情里的可播放地址 / 播放票据)
|
||||
return VideoPlayerController.networkUrl(
|
||||
resolveUri(episode),
|
||||
closedCaptionFile: closedCaptionFile,
|
||||
videoPlayerOptions: options,
|
||||
);
|
||||
}
|
||||
|
||||
final VideoPlayerController controller;
|
||||
Future<void>? _initialization;
|
||||
|
||||
Reference in new issue
Block a user