feat(library): 支持设备追剧与观看历史
This commit is contained in:
1 parent
4c3acb047c
commit
0d785bf1f8
12 files changed
+232
-76
No files matched your search
@@ -6,7 +6,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../core/data/models/drama.dart';
|
||||
import '../../core/data/services/auth_controller.dart';
|
||||
import '../../core/data/services/favorite_controller.dart';
|
||||
import '../../core/formatting/count_format.dart';
|
||||
import '../../core/formatting/error_text.dart';
|
||||
@@ -77,11 +76,6 @@ class _FavoritesContentState extends State<FavoritesContent> {
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final signedIn = context.watch<AuthController>().isSignedIn;
|
||||
if (!signedIn) {
|
||||
_requested = false;
|
||||
return;
|
||||
}
|
||||
if (_requested) return;
|
||||
_requested = true;
|
||||
final favorites = context.read<FavoriteController>();
|
||||
@@ -93,7 +87,6 @@ class _FavoritesContentState extends State<FavoritesContent> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final signedIn = context.watch<AuthController>().isSignedIn;
|
||||
return SafeArea(
|
||||
bottom: false,
|
||||
child: Column(
|
||||
@@ -104,9 +97,9 @@ class _FavoritesContentState extends State<FavoritesContent> {
|
||||
showBack: widget.showBack,
|
||||
),
|
||||
Expanded(
|
||||
child: signedIn
|
||||
? _FavoritesBody(favorites: context.watch<FavoriteController>())
|
||||
: const AuthGatePanel(),
|
||||
child: _FavoritesBody(
|
||||
favorites: context.watch<FavoriteController>(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -122,6 +115,9 @@ class _FavoritesBody extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
if (favorites.lastErrorCode == 200007) {
|
||||
return const AuthGatePanel();
|
||||
}
|
||||
if (favorites.loading && favorites.cards.isEmpty) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(key: Key('favorites-loading')),
|
||||
|
||||
@@ -35,7 +35,6 @@ class WatchRecordsPage extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final signedIn = context.watch<AuthController>().isSignedIn;
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
return Theme(
|
||||
data: AppTheme.dark(),
|
||||
@@ -49,11 +48,7 @@ class WatchRecordsPage extends StatelessWidget {
|
||||
title: l10n.watchHistory,
|
||||
backKey: const Key('watch-records-back'),
|
||||
),
|
||||
Expanded(
|
||||
child: signedIn
|
||||
? const _WatchRecordsBody()
|
||||
: const AuthGatePanel(),
|
||||
),
|
||||
Expanded(child: const _WatchRecordsBody()),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -71,10 +66,15 @@ class _WatchRecordsBody extends StatefulWidget {
|
||||
|
||||
class _WatchRecordsBodyState extends State<_WatchRecordsBody> {
|
||||
late final WatchRecordsController controller;
|
||||
late final AuthController _auth;
|
||||
late bool _signedIn;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_auth = context.read<AuthController>();
|
||||
_signedIn = _auth.isSignedIn;
|
||||
_auth.addListener(_handleAuthChanged);
|
||||
controller = WatchRecordsBinding().create(
|
||||
history: context.read<WatchHistoryRepository>(),
|
||||
catalog: context.read<CatalogRepository>(),
|
||||
@@ -82,8 +82,16 @@ class _WatchRecordsBodyState extends State<_WatchRecordsBody> {
|
||||
unawaited(controller.load());
|
||||
}
|
||||
|
||||
void _handleAuthChanged() {
|
||||
final signedIn = _auth.isSignedIn;
|
||||
if (_signedIn == signedIn || !mounted) return;
|
||||
_signedIn = signedIn;
|
||||
unawaited(controller.load());
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_auth.removeListener(_handleAuthChanged);
|
||||
controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -98,6 +106,9 @@ 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