feat(app): 完善播放协议搜索与空状态
This commit is contained in:
1 parent
671e0ce143
commit
ef29fc5f15
85 files changed
+2976
-768
No files matched your search
@@ -19,12 +19,14 @@ import '../../core/widgets/auth_gate.dart';
|
||||
import '../../core/widgets/empty_state.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import '../player/open_player.dart';
|
||||
import 'following_grid_card.dart';
|
||||
import 'following_edit_bar.dart';
|
||||
import 'following_favorites_grid.dart';
|
||||
import 'following_history_card.dart';
|
||||
import 'following_keep_alive_tab.dart';
|
||||
import 'following_paged_grid.dart';
|
||||
|
||||
enum FollowingTab { favorites, history }
|
||||
const double _doneFontSize = 14;
|
||||
const double _doneTextGap = 12;
|
||||
|
||||
class FollowingPage extends StatefulWidget {
|
||||
const FollowingPage({
|
||||
@@ -50,21 +52,33 @@ class _FollowingPageState extends State<FollowingPage> {
|
||||
FollowingTab.favorites,
|
||||
);
|
||||
final ValueNotifier<bool> _editing = ValueNotifier(false);
|
||||
final ValueNotifier<Set<String>> _selected = ValueNotifier({});
|
||||
late final WatchRecordsController _history;
|
||||
late final AuthController _auth;
|
||||
bool _wasSignedIn = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_auth = context.read<AuthController>();
|
||||
_wasSignedIn = _auth.isSignedIn;
|
||||
_auth.addListener(_onAuthChanged);
|
||||
_history = WatchRecordsController(
|
||||
history: context.read<WatchHistoryRepository>(),
|
||||
catalog: context.read<CatalogRepository>(),
|
||||
);
|
||||
unawaited(_history.load());
|
||||
if (_wasSignedIn) unawaited(_history.load());
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) unawaited(widget.favoriteController.load());
|
||||
});
|
||||
}
|
||||
|
||||
void _onAuthChanged() {
|
||||
final signedIn = _auth.isSignedIn;
|
||||
if (signedIn && !_wasSignedIn) unawaited(_history.load());
|
||||
_wasSignedIn = signedIn;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pageController.dispose();
|
||||
@@ -72,6 +86,8 @@ class _FollowingPageState extends State<FollowingPage> {
|
||||
_historyScroll.dispose();
|
||||
_tab.dispose();
|
||||
_editing.dispose();
|
||||
_selected.dispose();
|
||||
_auth.removeListener(_onAuthChanged);
|
||||
_history.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -106,12 +122,15 @@ class _FollowingPageState extends State<FollowingPage> {
|
||||
onPageChanged: _onPageChanged,
|
||||
children: [
|
||||
FollowingKeepAliveTab(
|
||||
child: _FavoritesGrid(
|
||||
child: FollowingFavoritesGrid(
|
||||
controller: widget.favoriteController,
|
||||
editing: _editing,
|
||||
selection: FollowingFavoriteSelection(
|
||||
editing: _editing,
|
||||
selected: _selected,
|
||||
onToggle: _toggleDrama,
|
||||
),
|
||||
scrollController: _favoriteScroll,
|
||||
onGoHome: widget.onGoHome,
|
||||
onListEmptied: _exitEditingIfEmpty,
|
||||
),
|
||||
),
|
||||
FollowingKeepAliveTab(
|
||||
@@ -125,6 +144,17 @@ class _FollowingPageState extends State<FollowingPage> {
|
||||
],
|
||||
),
|
||||
),
|
||||
if (signedIn)
|
||||
FollowingEditSlot(
|
||||
tab: _tab,
|
||||
editing: _editing,
|
||||
favorites: widget.favoriteController,
|
||||
selected: _selected,
|
||||
actions: FollowingEditActions(
|
||||
onToggleAll: _toggleAll,
|
||||
onRemove: () => unawaited(_cancelSelected()),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -147,36 +177,43 @@ class _FollowingPageState extends State<FollowingPage> {
|
||||
builder: (context, editing, _) {
|
||||
return Row(
|
||||
children: [
|
||||
_tabButton(
|
||||
FollowingTab.favorites,
|
||||
l10n.followingTab,
|
||||
'favorites',
|
||||
selectedTab == FollowingTab.favorites,
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
Flexible(
|
||||
fit: FlexFit.loose,
|
||||
child: _tabButton(
|
||||
FollowingTab.favorites,
|
||||
l10n.followingTab,
|
||||
'favorites',
|
||||
selectedTab == FollowingTab.favorites,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppDimens.followingTabGap),
|
||||
Flexible(
|
||||
fit: FlexFit.loose,
|
||||
child: _tabButton(
|
||||
FollowingTab.history,
|
||||
l10n.watchHistory,
|
||||
'history',
|
||||
selectedTab == FollowingTab.history,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppDimens.followingTabGap),
|
||||
_tabButton(
|
||||
FollowingTab.history,
|
||||
l10n.watchHistory,
|
||||
'history',
|
||||
selectedTab == FollowingTab.history,
|
||||
),
|
||||
const Spacer(),
|
||||
if (editing)
|
||||
SizedBox(
|
||||
width: AppDimens.followingEditHitSize,
|
||||
height: AppDimens.followingEditHitSize,
|
||||
child: InkWell(
|
||||
key: const Key('following-edit'),
|
||||
onTap: _toggleEditing,
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
l10n.done,
|
||||
style: const TextStyle(
|
||||
color: AppColors.textPrimary,
|
||||
fontSize: AppDimens.followingTabFont,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
InkWell(
|
||||
key: const Key('following-edit'),
|
||||
onTap: _toggleEditing,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: _doneTextGap),
|
||||
child: Text(
|
||||
l10n.done,
|
||||
style: const TextStyle(
|
||||
color: AppColors.textPrimary,
|
||||
fontSize: _doneFontSize,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -223,7 +260,9 @@ class _FollowingPageState extends State<FollowingPage> {
|
||||
onTap: () => _selectTab(tab),
|
||||
child: SizedBox(
|
||||
height: AppDimens.followingHeaderHeight,
|
||||
child: Center(
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
widthFactor: 1,
|
||||
child: AnimatedDefaultTextStyle(
|
||||
duration: AppDimens.followingTabAnimationDuration,
|
||||
style: TextStyle(
|
||||
@@ -233,7 +272,7 @@ class _FollowingPageState extends State<FollowingPage> {
|
||||
fontSize: AppDimens.followingTabFont,
|
||||
fontWeight: selected ? FontWeight.w600 : FontWeight.w400,
|
||||
),
|
||||
child: Text(label, maxLines: 1),
|
||||
child: Text(label, maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -241,7 +280,7 @@ class _FollowingPageState extends State<FollowingPage> {
|
||||
}
|
||||
|
||||
void _selectTab(FollowingTab tab) {
|
||||
_editing.value = false;
|
||||
_leaveEditing();
|
||||
_tab.value = tab;
|
||||
if (_pageController.hasClients) {
|
||||
unawaited(
|
||||
@@ -256,99 +295,50 @@ class _FollowingPageState extends State<FollowingPage> {
|
||||
|
||||
void _onPageChanged(int index) {
|
||||
final tab = FollowingTab.values[index];
|
||||
_editing.value = false;
|
||||
_leaveEditing();
|
||||
_tab.value = tab;
|
||||
if (tab == FollowingTab.history && _auth.isSignedIn) {
|
||||
unawaited(_history.load());
|
||||
}
|
||||
}
|
||||
|
||||
void _toggleEditing() {
|
||||
_editing.value = !_editing.value;
|
||||
if (!_editing.value) _selected.value = {};
|
||||
}
|
||||
|
||||
void _leaveEditing() {
|
||||
_editing.value = false;
|
||||
_selected.value = {};
|
||||
}
|
||||
|
||||
void _toggleDrama(String id) {
|
||||
final next = {..._selected.value};
|
||||
if (!next.add(id)) next.remove(id);
|
||||
_selected.value = next;
|
||||
}
|
||||
|
||||
void _toggleAll(Set<String> ids) {
|
||||
final picked = _selected.value;
|
||||
final all = ids.isNotEmpty && ids.every(picked.contains);
|
||||
_selected.value = all ? {} : ids;
|
||||
}
|
||||
|
||||
Future<void> _cancelSelected() async {
|
||||
final ids = _selected.value.toList();
|
||||
if (ids.isEmpty || !mounted || !await confirmCancelFollowing(context)) {
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
final removed = await widget.favoriteController.removeMany(ids);
|
||||
if (!removed || !mounted) return;
|
||||
_selected.value = {};
|
||||
if (widget.favoriteController.cards.isEmpty) _editing.value = false;
|
||||
}
|
||||
|
||||
void _exitEditingIfEmpty() => _editing.value = false;
|
||||
}
|
||||
|
||||
class _FavoritesGrid extends StatelessWidget {
|
||||
const _FavoritesGrid({
|
||||
required this.controller,
|
||||
required this.editing,
|
||||
required this.scrollController,
|
||||
required this.onGoHome,
|
||||
required this.onListEmptied,
|
||||
});
|
||||
|
||||
final FavoriteController controller;
|
||||
final ValueListenable<bool> editing;
|
||||
final ScrollController scrollController;
|
||||
final VoidCallback onGoHome;
|
||||
final VoidCallback onListEmptied;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ValueListenableBuilder<bool>(
|
||||
valueListenable: editing,
|
||||
builder: (context, isEditing, _) {
|
||||
return ListenableBuilder(
|
||||
listenable: controller,
|
||||
builder: (context, _) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
return FollowingPagedGrid(
|
||||
key: const Key('following-favorites-grid'),
|
||||
scrollController: scrollController,
|
||||
loading: controller.loading,
|
||||
loadingMore: controller.loadingMore,
|
||||
hasMore: controller.hasMore,
|
||||
hasItems: controller.cards.isNotEmpty,
|
||||
showInitialLoading: false,
|
||||
errorMessage: controller.error == null
|
||||
? null
|
||||
: errorText(l10n, controller.error, l10n.favoritesError),
|
||||
loadMoreError: controller.loadMoreError == null
|
||||
? null
|
||||
: errorText(
|
||||
l10n,
|
||||
controller.loadMoreError,
|
||||
l10n.favoritesError,
|
||||
),
|
||||
onRefresh: controller.load,
|
||||
onLoadMore: controller.loadMore,
|
||||
itemCount: controller.cards.length + 1,
|
||||
empty: const SizedBox.shrink(),
|
||||
itemBuilder: (context, index) {
|
||||
if (index == controller.cards.length) {
|
||||
return FollowingAddCard(onTap: onGoHome);
|
||||
}
|
||||
final drama = controller.cards[index];
|
||||
final episode = drama.episodes.isEmpty
|
||||
? 1
|
||||
: drama.episodes.first.number;
|
||||
return FollowingGridCard(
|
||||
dramaId: drama.id,
|
||||
title: drama.title,
|
||||
posterUrl: drama.posterUrl,
|
||||
viewCount: drama.viewCount,
|
||||
editing: isEditing,
|
||||
subtitle: l10n.favoriteEpisodeProgress(
|
||||
episode,
|
||||
drama.episodeCount,
|
||||
),
|
||||
onTap: () => unawaited(playDramaFromCatalog(context, drama)),
|
||||
onRemove: () async {
|
||||
if (await _confirmRemove(context) &&
|
||||
await controller.remove(drama.id) &&
|
||||
controller.cards.isEmpty) {
|
||||
onListEmptied();
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _HistoryList extends StatelessWidget {
|
||||
const _HistoryList({
|
||||
required this.controller,
|
||||
@@ -415,7 +405,9 @@ class _HistoryList extends StatelessWidget {
|
||||
title: _historyTitle(l10n, record),
|
||||
posterUrl: record.displayCover,
|
||||
viewCount:
|
||||
record.drama?.viewCount ?? record.progress.playCount,
|
||||
record.progress.viewCount ??
|
||||
record.drama?.viewCount ??
|
||||
record.progress.playCount,
|
||||
progress: hasProgress ? progress : null,
|
||||
progressLabel: hasProgress
|
||||
? l10n.watchedPercent(watchedPercent)
|
||||
@@ -425,7 +417,7 @@ class _HistoryList extends StatelessWidget {
|
||||
onTap: openRecord,
|
||||
onContinue: openRecord,
|
||||
onRemove: () async {
|
||||
if (await _confirmRemove(context) &&
|
||||
if (await confirmHistoryRemove(context) &&
|
||||
await controller.remove(record.dramaId) &&
|
||||
controller.records.isEmpty) {
|
||||
onListEmptied();
|
||||
@@ -469,24 +461,3 @@ Future<void> _openHistory(
|
||||
episodeId: record.progress.episodeId,
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> _confirmRemove(BuildContext context) async {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
return await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
content: Text(l10n.confirmRemove),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext, false),
|
||||
child: Text(l10n.cancel),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.pop(dialogContext, true),
|
||||
child: Text(l10n.remove),
|
||||
),
|
||||
],
|
||||
),
|
||||
) ??
|
||||
false;
|
||||
}
|
||||
Reference in new issue
Block a user