feat(app): 剧场页九宫格与极简我的页

This commit is contained in:
Zhou Weidong committed 2026-10-20 05:28:51 +08:00
1 parent dc8ca7b743
commit 35338cbfc8
46 files changed
+2353 -4358

No files matched your search

+8 -102
View File
@@ -1,59 +1,28 @@
// Author: fruit.com.cn
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../core/config/locale_controller.dart';
import '../../core/data/models/drama.dart';
import '../../core/data/models/watch_progress.dart';
import '../../core/data/repositories/watch_history_repository.dart';
import '../../core/theme/app_colors.dart';
import '../../l10n/app_localizations.dart';
enum MyPageAction { home, discover, resume }
import 'mine_types.dart';
/// 「我的」页状态:最近观看与根导航动作。
class MineLogic extends ChangeNotifier {
MineLogic({
required this.history,
required this.drama,
required int initialSection,
}) : section = initialSection {
refreshPosition();
MineLogic({required this.history}) {
refreshRecent();
}
final WatchHistoryRepository history;
Drama drama;
late Future<Duration?> position;
List<WatchProgress> recent = const [];
bool recentLoading = false;
String? recentError;
/// 续看位置读取失败:与"没有记录"区分开,失败要能重试(不能假装成从 0 开始)
bool positionFailed = false;
int section;
int filter = 0;
bool _disposed = false;
void notify() {
if (!_disposed) notifyListeners();
}
void refreshPosition() {
position = history
.resumePointFor(drama.id)
.then((point) {
positionFailed = false;
return point?.position;
})
.catchError((Object _) {
positionFailed = true;
notify();
return null;
});
refreshRecent();
}
/// 最近观看:服务端只给 dramaId/位置,剧名封面用已加载的目录卡片按 id 映射。
/// 最近观看:服务端只给 dramaId/位置,剧名封面用目录卡片按 id 映射。
Future<void> refreshRecent() async {
recentLoading = true;
recentError = null;
@@ -68,34 +37,9 @@ class MineLogic extends ChangeNotifier {
}
}
void selectSection(int index) {
section = index;
notify();
}
void selectFilter(int index) {
filter = index;
notify();
}
void syncPage({
required bool active,
required bool wasActive,
required Drama nextDrama,
required bool dramaChanged,
required int sectionRequest,
required int previousSectionRequest,
required int initialSection,
}) {
if (active && (!wasActive || dramaChanged)) {
drama = nextDrama;
refreshPosition();
notify();
}
if (sectionRequest != previousSectionRequest) {
section = initialSection;
notify();
}
/// 页面重新可见时刷新最近观看,避免停留在旧进度。
void syncPage({required bool active, required bool wasActive}) {
if (active && !wasActive) refreshRecent();
}
void act(
@@ -111,44 +55,6 @@ class MineLogic extends ChangeNotifier {
}
}
Future<void> showLanguage(BuildContext context) async {
final l10n = AppLocalizations.of(context)!;
await showModalBottomSheet<void>(
context: context,
backgroundColor: AppColors.ink,
showDragHandle: true,
isScrollControlled: true,
builder: (sheetContext) => SafeArea(
child: ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.sizeOf(sheetContext).height * 0.85,
),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(title: Text(l10n.language)),
for (final (code, label) in [
('en', l10n.english),
('zh', l10n.simplifiedChinese),
('id', l10n.bahasaIndonesia),
])
ListTile(
title: Text(label),
onTap: () {
context.read<LocaleController>().select(code);
Navigator.pop(sheetContext);
},
),
const SizedBox(height: 8),
],
),
),
),
),
);
}
@override
void dispose() {
_disposed = true;