// 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 []; bool recentLoading = false; String? recentError; bool _disposed = false; void notify() { if (!_disposed) notifyListeners(); } /// 最近观看:服务端只给 dramaId/位置,剧名封面用目录卡片按 id 映射。 Future refreshRecent() async { recentLoading = true; recentError = null; notify(); try { recent = await history.recent(limit: 20); } 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(); } }