// Author: fruit.com.cn import 'package:flutter/material.dart'; import '../../core/data/models/watch_progress.dart'; import '../../core/data/repositories/watch_history_repository.dart'; import 'mine_types.dart'; /// 「我的」页状态:最近观看与根导航动作。 class MineLogic extends ChangeNotifier { MineLogic({required this.history}) { refreshRecent(); } final WatchHistoryRepository history; List recent = const []; int? watchRecordTotal; bool recentLoading = false; String? recentError; bool _disposed = false; void notify() { if (!_disposed) notifyListeners(); } /// 最近观看:取分页首屏,剧名封面仍由目录卡片按 id 映射。 Future refreshRecent() async { recentLoading = true; recentError = null; notify(); try { final page = await history.recent(pageIndex: 1, pageSize: 10); recent = page.list; watchRecordTotal = page.total; } catch (_) { recentError = 'progressError'; } finally { recentLoading = false; notify(); } } /// 页面重新可见时刷新最近观看,避免停留在旧进度。 void syncPage({required bool active, required bool wasActive}) { if (active && !wasActive) refreshRecent(); } void act( BuildContext context, MyPageAction action, { required bool embedded, ValueChanged? onAction, }) { if (embedded) { onAction?.call(action); } else { Navigator.pop(context, action); } } @override void dispose() { _disposed = true; super.dispose(); } }