fix(following): 支持未登录追剧与历史
This commit is contained in:
1 parent
0d785bf1f8
commit
06a2f6d7c0
4 files changed
+292
-53
No files matched your search
@@ -314,6 +314,23 @@ class WatchRecordsController extends ChangeNotifier {
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
/// 切换账号/设备身份时清除内存数据,不删除服务端记录。
|
||||
void reset() {
|
||||
_requestSeq += 1;
|
||||
records = const [];
|
||||
total = 0;
|
||||
loading = false;
|
||||
loadingMore = false;
|
||||
hasMore = false;
|
||||
clearing = false;
|
||||
error = null;
|
||||
loadMoreError = null;
|
||||
actionError = null;
|
||||
lastErrorCode = null;
|
||||
_pageIndex = 0;
|
||||
_notify();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
|
||||
@@ -15,7 +15,6 @@ import '../../core/data/services/watch_records_controller.dart';
|
||||
import '../../core/formatting/error_text.dart';
|
||||
import '../../core/theme/app_colors.dart';
|
||||
import '../../core/theme/app_dimens.dart';
|
||||
import '../../core/widgets/auth_gate.dart';
|
||||
import '../../core/widgets/empty_state.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import '../player/open_player.dart';
|
||||
@@ -67,7 +66,7 @@ class _FollowingPageState extends State<FollowingPage> {
|
||||
history: context.read<WatchHistoryRepository>(),
|
||||
catalog: context.read<CatalogRepository>(),
|
||||
);
|
||||
if (_wasSignedIn) unawaited(_history.load());
|
||||
unawaited(_history.load());
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) unawaited(widget.favoriteController.load());
|
||||
});
|
||||
@@ -75,8 +74,16 @@ class _FollowingPageState extends State<FollowingPage> {
|
||||
|
||||
void _onAuthChanged() {
|
||||
final signedIn = _auth.isSignedIn;
|
||||
if (signedIn && !_wasSignedIn) unawaited(_history.load());
|
||||
if (signedIn == _wasSignedIn) return;
|
||||
_wasSignedIn = signedIn;
|
||||
_leaveEditing();
|
||||
_history.reset();
|
||||
widget.favoriteController.clear();
|
||||
unawaited(_reloadForIdentity());
|
||||
}
|
||||
|
||||
Future<void> _reloadForIdentity() async {
|
||||
await Future.wait([_history.load(), widget.favoriteController.load()]);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -104,7 +111,6 @@ class _FollowingPageState extends State<FollowingPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final signedIn = context.watch<AuthController>().isSignedIn;
|
||||
return ColoredBox(
|
||||
key: const Key('following-page'),
|
||||
color: AppColors.appBackground,
|
||||
@@ -114,47 +120,44 @@ class _FollowingPageState extends State<FollowingPage> {
|
||||
children: [
|
||||
_header(l10n),
|
||||
Expanded(
|
||||
child: !signedIn
|
||||
? const AuthGatePanel()
|
||||
: PageView(
|
||||
key: const Key('following-tab-pages'),
|
||||
controller: _pageController,
|
||||
onPageChanged: _onPageChanged,
|
||||
children: [
|
||||
FollowingKeepAliveTab(
|
||||
child: FollowingFavoritesGrid(
|
||||
controller: widget.favoriteController,
|
||||
selection: FollowingFavoriteSelection(
|
||||
editing: _editing,
|
||||
selected: _selected,
|
||||
onToggle: _toggleDrama,
|
||||
),
|
||||
scrollController: _favoriteScroll,
|
||||
onGoHome: widget.onGoHome,
|
||||
),
|
||||
),
|
||||
FollowingKeepAliveTab(
|
||||
child: _HistoryList(
|
||||
controller: _history,
|
||||
editing: _editing,
|
||||
scrollController: _historyScroll,
|
||||
onListEmptied: _exitEditingIfEmpty,
|
||||
),
|
||||
),
|
||||
],
|
||||
child: PageView(
|
||||
key: const Key('following-tab-pages'),
|
||||
controller: _pageController,
|
||||
onPageChanged: _onPageChanged,
|
||||
children: [
|
||||
FollowingKeepAliveTab(
|
||||
child: FollowingFavoritesGrid(
|
||||
controller: widget.favoriteController,
|
||||
selection: FollowingFavoriteSelection(
|
||||
editing: _editing,
|
||||
selected: _selected,
|
||||
onToggle: _toggleDrama,
|
||||
),
|
||||
scrollController: _favoriteScroll,
|
||||
onGoHome: widget.onGoHome,
|
||||
),
|
||||
),
|
||||
if (signedIn)
|
||||
FollowingEditSlot(
|
||||
tab: _tab,
|
||||
editing: _editing,
|
||||
favorites: widget.favoriteController,
|
||||
selected: _selected,
|
||||
actions: FollowingEditActions(
|
||||
onToggleAll: _toggleAll,
|
||||
onRemove: () => unawaited(_cancelSelected()),
|
||||
),
|
||||
),
|
||||
FollowingKeepAliveTab(
|
||||
child: _HistoryList(
|
||||
controller: _history,
|
||||
editing: _editing,
|
||||
scrollController: _historyScroll,
|
||||
onListEmptied: _exitEditingIfEmpty,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
FollowingEditSlot(
|
||||
tab: _tab,
|
||||
editing: _editing,
|
||||
favorites: widget.favoriteController,
|
||||
selected: _selected,
|
||||
actions: FollowingEditActions(
|
||||
onToggleAll: _toggleAll,
|
||||
onRemove: () => unawaited(_cancelSelected()),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -297,7 +300,7 @@ class _FollowingPageState extends State<FollowingPage> {
|
||||
final tab = FollowingTab.values[index];
|
||||
_leaveEditing();
|
||||
_tab.value = tab;
|
||||
if (tab == FollowingTab.history && _auth.isSignedIn) {
|
||||
if (tab == FollowingTab.history) {
|
||||
unawaited(_history.load());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import '../../core/platform/haptics.dart';
|
||||
import '../../core/theme/app_colors.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
import '../../core/widgets/app_pull_to_refresh.dart';
|
||||
import '../../core/widgets/auth_gate.dart';
|
||||
import '../../core/widgets/empty_state.dart';
|
||||
import '../../core/widgets/paged_list_footer.dart';
|
||||
import '../../core/widgets/subpage_header.dart';
|
||||
@@ -86,6 +85,7 @@ class _WatchRecordsBodyState extends State<_WatchRecordsBody> {
|
||||
final signedIn = _auth.isSignedIn;
|
||||
if (_signedIn == signedIn || !mounted) return;
|
||||
_signedIn = signedIn;
|
||||
controller.reset();
|
||||
unawaited(controller.load());
|
||||
}
|
||||
|
||||
@@ -106,9 +106,6 @@ class _WatchRecordsBodyState extends State<_WatchRecordsBody> {
|
||||
|
||||
Widget _content(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
if (controller.lastErrorCode == 200007) {
|
||||
return const AuthGatePanel();
|
||||
}
|
||||
if (controller.loading && controller.records.isEmpty) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(key: Key('watch-records-loading')),
|
||||
|
||||
Reference in new issue
Block a user