feat(app): 剧场页九宫格与极简我的页
This commit is contained in:
1 parent
dc8ca7b743
commit
35338cbfc8
46 files changed
+2353
-4358
No files matched your search
@@ -4,12 +4,12 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../core/config/app_config.dart';
|
||||
import '../../core/data/models/content_category.dart';
|
||||
import '../../core/data/models/drama.dart';
|
||||
import '../../core/data/models/home_feed.dart';
|
||||
import '../../core/data/models/watch_progress.dart';
|
||||
import '../../core/data/repositories/catalog_repository.dart';
|
||||
import '../../core/data/repositories/search_repository.dart';
|
||||
import '../../core/data/repositories/watch_history_repository.dart';
|
||||
import '../../core/data/services/catalog_controller.dart';
|
||||
import '../../core/data/services/category_controller.dart';
|
||||
import '../../core/formatting/error_text.dart';
|
||||
import '../../core/theme/app_colors.dart';
|
||||
@@ -17,53 +17,34 @@ import '../../core/theme/app_dimens.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
import '../../core/widgets/app_bottom_nav.dart';
|
||||
import '../../core/widgets/empty_state.dart';
|
||||
import '../../core/widgets/remote_image.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import '../drama_detail/drama_detail_view.dart';
|
||||
import 'category_dramas_page.dart';
|
||||
import 'discover_binding.dart';
|
||||
import 'discover_logic.dart';
|
||||
import 'discover_types.dart';
|
||||
import 'widgets/category_grid.dart';
|
||||
import 'widgets/discover_header.dart';
|
||||
import 'widgets/discover_search_field.dart';
|
||||
import 'widgets/discover_search_results.dart';
|
||||
import 'widgets/drama_grid.dart';
|
||||
import 'widgets/feed_banner_carousel.dart';
|
||||
import 'widgets/ranking_section.dart';
|
||||
|
||||
part 'widgets/home_drama_grid.dart';
|
||||
|
||||
/// 剧场页:搜索 + 分类九宫格 + 榜单 + 全部剧目。
|
||||
class DiscoverPage extends StatefulWidget {
|
||||
const DiscoverPage({
|
||||
super.key,
|
||||
required this.drama,
|
||||
required this.duration,
|
||||
this.focusSearch = false,
|
||||
this.history,
|
||||
this.searchRepository,
|
||||
this.embedded = false,
|
||||
this.active = true,
|
||||
this.searchRequest = 0,
|
||||
this.signedIn = false,
|
||||
this.onSignIn,
|
||||
this.onCoins,
|
||||
this.onRewards,
|
||||
this.onAction,
|
||||
this.dramas,
|
||||
this.onDramaSelected,
|
||||
this.banners = const [],
|
||||
this.onBannerSelected,
|
||||
this.focusSearch = false,
|
||||
this.callbacks = const DiscoverPageCallbacks(),
|
||||
});
|
||||
|
||||
final Drama drama;
|
||||
final Duration duration;
|
||||
final bool focusSearch;
|
||||
final WatchHistoryRepository? history;
|
||||
final SearchRepository? searchRepository;
|
||||
final bool embedded;
|
||||
final bool active;
|
||||
final int searchRequest;
|
||||
final bool signedIn;
|
||||
final VoidCallback? onSignIn;
|
||||
final VoidCallback? onCoins;
|
||||
final VoidCallback? onRewards;
|
||||
final ValueChanged<DiscoverPageAction>? onAction;
|
||||
final List<Drama>? dramas;
|
||||
final ValueChanged<Drama>? onDramaSelected;
|
||||
final List<FeedBanner> banners;
|
||||
final ValueChanged<FeedBanner>? onBannerSelected;
|
||||
final bool focusSearch;
|
||||
final DiscoverPageCallbacks callbacks;
|
||||
|
||||
@override
|
||||
State<DiscoverPage> createState() => _DiscoverPageState();
|
||||
@@ -72,32 +53,28 @@ class DiscoverPage extends StatefulWidget {
|
||||
class _DiscoverPageState extends State<DiscoverPage> {
|
||||
late final DiscoverLogic logic;
|
||||
|
||||
bool get embedded => widget.callbacks.embedded;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
logic = DiscoverBinding().create(
|
||||
drama: widget.drama,
|
||||
history: widget.history ?? context.read<WatchHistoryRepository>(),
|
||||
search: widget.searchRepository ?? context.read<SearchRepository>(),
|
||||
);
|
||||
if (widget.focusSearch) {
|
||||
logic.searchOpen = true;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted && widget.active) logic.searchFocus.requestFocus();
|
||||
});
|
||||
}
|
||||
logic = DiscoverBinding().create(search: context.read<SearchRepository>());
|
||||
if (widget.focusSearch) _focusOnFirstFrame();
|
||||
}
|
||||
|
||||
void _focusOnFirstFrame() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted && widget.active) logic.openSearch();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant DiscoverPage oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
logic.syncDrama(
|
||||
logic.syncSearch(
|
||||
active: widget.active,
|
||||
wasActive: oldWidget.active,
|
||||
nextDrama: widget.drama,
|
||||
dramaChanged: oldWidget.drama.id != widget.drama.id,
|
||||
searchRequest: widget.searchRequest,
|
||||
previousSearchRequest: oldWidget.searchRequest,
|
||||
request: widget.searchRequest,
|
||||
previousRequest: oldWidget.searchRequest,
|
||||
isActive: () => mounted && widget.active,
|
||||
);
|
||||
}
|
||||
@@ -119,15 +96,14 @@ class _DiscoverPageState extends State<DiscoverPage> {
|
||||
Widget _page(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final categories = context.watch<CategoryController>();
|
||||
final allDramas = [...?widget.dramas, ...categories.visibleDramas];
|
||||
final visible = logic.visibleDramas(categories.visibleDramas);
|
||||
final banners = context.watch<CatalogController>().banners;
|
||||
final content = SafeArea(
|
||||
bottom: !widget.embedded,
|
||||
bottom: !embedded,
|
||||
child: Column(
|
||||
children: [
|
||||
_header(l10n),
|
||||
Expanded(child: _feed(l10n, categories, allDramas, visible)),
|
||||
if (!widget.embedded) _bottomNav(l10n),
|
||||
DiscoverHeader(onSearch: logic.openSearch, onProfile: _openProfile),
|
||||
Expanded(child: _feed(l10n, categories, banners)),
|
||||
if (!embedded) _bottomNav(l10n),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -135,7 +111,7 @@ class _DiscoverPageState extends State<DiscoverPage> {
|
||||
value: SystemUiOverlayStyle.light,
|
||||
child: Theme(
|
||||
data: AppTheme.dark(),
|
||||
child: widget.embedded
|
||||
child: embedded
|
||||
? content
|
||||
: Scaffold(backgroundColor: AppColors.ink, body: content),
|
||||
),
|
||||
@@ -145,523 +121,222 @@ class _DiscoverPageState extends State<DiscoverPage> {
|
||||
Widget _feed(
|
||||
AppLocalizations l10n,
|
||||
CategoryController categories,
|
||||
List<Drama> allDramas,
|
||||
List<Drama> visible,
|
||||
) => RefreshIndicator(
|
||||
key: const Key('discover-refresh'),
|
||||
color: AppColors.blue,
|
||||
backgroundColor: AppColors.card,
|
||||
onRefresh: () async {
|
||||
await Future.wait([categories.load(), logic.refreshResume()]);
|
||||
},
|
||||
child: CustomScrollView(
|
||||
controller: logic.scroll,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
if (widget.banners.isNotEmpty)
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: FeedBannerCarousel(
|
||||
banners: widget.banners,
|
||||
active: widget.active,
|
||||
onOpen: (banner) => widget.onBannerSelected?.call(banner),
|
||||
),
|
||||
List<FeedBanner> banners,
|
||||
) {
|
||||
return RefreshIndicator(
|
||||
key: const Key('discover-refresh'),
|
||||
color: AppColors.blue,
|
||||
backgroundColor: AppColors.card,
|
||||
onRefresh: categories.load,
|
||||
child: ListView(
|
||||
controller: logic.scroll,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.only(bottom: 24),
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: DiscoverSearchField(
|
||||
controller: logic.search,
|
||||
focusNode: logic.searchFocus,
|
||||
onChanged: (_) => logic.onSearchChanged(),
|
||||
loading: logic.searchLoading,
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(child: _search()),
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 14, 0, 12),
|
||||
child: _categories(l10n, categories),
|
||||
..._content(l10n, categories, banners),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _content(
|
||||
AppLocalizations l10n,
|
||||
CategoryController categories,
|
||||
List<FeedBanner> banners,
|
||||
) {
|
||||
if (logic.hasSearchQuery) return [_searchContent(l10n)];
|
||||
return _theaterContent(l10n, categories, banners);
|
||||
}
|
||||
|
||||
Widget _searchContent(AppLocalizations l10n) => DiscoverSearchResults(
|
||||
loading: logic.searchLoading,
|
||||
error: logic.searchError,
|
||||
results: logic.searchResults,
|
||||
onRetry: logic.retrySearch,
|
||||
onOpen: _openDrama,
|
||||
);
|
||||
|
||||
List<Widget> _theaterContent(
|
||||
AppLocalizations l10n,
|
||||
CategoryController categories,
|
||||
List<FeedBanner> banners,
|
||||
) {
|
||||
if (categories.loading && categories.feed.sections.isEmpty) {
|
||||
return [_block(const CircularProgressIndicator(strokeWidth: 2))];
|
||||
}
|
||||
final error = categories.error;
|
||||
if (error != null) {
|
||||
return [
|
||||
_block(
|
||||
EmptyState(
|
||||
key: const Key('home-categories-error'),
|
||||
icon: Icons.cloud_off_rounded,
|
||||
title: errorText(l10n, error, l10n.categoriesError),
|
||||
subtitle: l10n.emptyHint,
|
||||
actionLabel: l10n.retry,
|
||||
onAction: categories.load,
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 0, 0, 12),
|
||||
child: _languages(l10n, allDramas),
|
||||
];
|
||||
}
|
||||
return _theaterBlocks(l10n, categories, banners);
|
||||
}
|
||||
|
||||
List<Widget> _theaterBlocks(
|
||||
AppLocalizations l10n,
|
||||
CategoryController categories,
|
||||
List<FeedBanner> banners,
|
||||
) {
|
||||
final dramas = categories.feed.dramas;
|
||||
return [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
child: CategoryGrid(
|
||||
categories: categories.categories,
|
||||
onTap: (category) => _openCategory(category, categories),
|
||||
),
|
||||
),
|
||||
if (banners.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
child: FeedBannerCarousel(
|
||||
banners: banners,
|
||||
active: widget.active,
|
||||
onOpen: _openBanner,
|
||||
),
|
||||
),
|
||||
if (logic.resumeRecord != null && logic.resumeDrama(allDramas) != null)
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 14),
|
||||
child: _continueCard(
|
||||
l10n,
|
||||
logic.resumeDrama(allDramas)!,
|
||||
logic.resumeRecord!,
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 14),
|
||||
child: _quickActions(l10n, categories),
|
||||
),
|
||||
if (categories.feed.sections.isNotEmpty || dramas.isNotEmpty)
|
||||
RankingSection(
|
||||
sections: categories.feed.sections,
|
||||
fallback: dramas,
|
||||
onOpen: _openDrama,
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(14, 2, 14, 10),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 3,
|
||||
height: 18,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.blue,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.trendingMicroDramas,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: AppColors.onSurface,
|
||||
fontSize: AppDimens.previewSectionTitle,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
categories.selectCode(CategoryController.allCode),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: AppColors.accent,
|
||||
minimumSize: const Size(44, 44),
|
||||
padding: EdgeInsets.zero,
|
||||
),
|
||||
child: Text(
|
||||
'${l10n.all} ›',
|
||||
style: const TextStyle(fontSize: 10),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
_HomeDramaGrid(
|
||||
l10n: l10n,
|
||||
categories: categories,
|
||||
dramas: visible,
|
||||
searching: logic.hasSearchQuery,
|
||||
searchLoading: logic.searchLoading,
|
||||
searchError: logic.searchError,
|
||||
onRetrySearch: () => logic.retrySearch(),
|
||||
onOpen: (drama) => logic.openCard(
|
||||
context,
|
||||
drama,
|
||||
embedded: widget.embedded,
|
||||
onDramaSelected: widget.onDramaSelected,
|
||||
onAction: widget.onAction,
|
||||
),
|
||||
),
|
||||
],
|
||||
_sectionTitle(l10n.allDramas),
|
||||
if (dramas.isEmpty) _emptyCatalog(l10n) else _dramaGrid(l10n, dramas),
|
||||
];
|
||||
}
|
||||
|
||||
Widget _block(Widget child) =>
|
||||
SizedBox(height: 280, child: Center(child: child));
|
||||
|
||||
Widget _emptyCatalog(AppLocalizations l10n) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 40),
|
||||
child: EmptyState(
|
||||
key: const Key('discover-empty'),
|
||||
icon: Icons.movie_filter_outlined,
|
||||
title: l10n.noStories,
|
||||
subtitle: l10n.emptyHint,
|
||||
),
|
||||
);
|
||||
|
||||
Widget _header(AppLocalizations l10n) {
|
||||
return SizedBox(
|
||||
height: 46,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 24,
|
||||
height: 24,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.blue,
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.play_arrow_rounded,
|
||||
color: AppColors.onPrimary,
|
||||
size: 16,
|
||||
),
|
||||
Widget _dramaGrid(AppLocalizations l10n, List<Drama> dramas) {
|
||||
return DramaGrid(l10n: l10n, dramas: dramas, onOpen: _openDrama);
|
||||
}
|
||||
|
||||
Widget _sectionTitle(String title) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(14, 18, 14, 10),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 3,
|
||||
height: 18,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.blue,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
l10n.discoverTab,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Outfit',
|
||||
color: AppColors.onSurface,
|
||||
fontSize: 15,
|
||||
fontSize: AppDimens.previewSectionTitle,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
_HeaderIcon(
|
||||
key: const Key('discover-search-button'),
|
||||
icon: Icons.search_rounded,
|
||||
tooltip: l10n.search,
|
||||
onTap: logic.openSearch,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Semantics(
|
||||
button: true,
|
||||
label: widget.signedIn ? l10n.myTab : l10n.logIn,
|
||||
child: InkWell(
|
||||
key: const Key('discover-profile'),
|
||||
customBorder: const CircleBorder(),
|
||||
onTap: widget.signedIn ? widget.onCoins : widget.onSignIn,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: const LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [Color(0xFF6A5CFF), AppColors.blue],
|
||||
),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.person_rounded,
|
||||
color: AppColors.onSurface,
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _search() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
||||
child: SizedBox(
|
||||
height: 36,
|
||||
child: TextField(
|
||||
key: const Key('discover-search'),
|
||||
controller: logic.search,
|
||||
focusNode: logic.searchFocus,
|
||||
onChanged: (_) => logic.onSearchChanged(),
|
||||
|
||||
onTapOutside: (_) => logic.searchFocus.unfocus(),
|
||||
textInputAction: TextInputAction.search,
|
||||
style: const TextStyle(color: AppColors.onSurface, fontSize: 13),
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
filled: true,
|
||||
fillColor: AppColors.input,
|
||||
hintText: AppLocalizations.of(context)!.searchDiscover,
|
||||
hintStyle: const TextStyle(color: AppColors.cream, fontSize: 11),
|
||||
prefixIcon: const Icon(
|
||||
Icons.search_rounded,
|
||||
color: AppColors.subtle,
|
||||
size: 17,
|
||||
),
|
||||
suffixIcon: logic.searchLoading
|
||||
? const Padding(
|
||||
padding: EdgeInsets.all(11),
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: null,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
borderSide: const BorderSide(color: AppColors.blue, width: 1),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _categories(AppLocalizations l10n, CategoryController categories) {
|
||||
final choices = <({String code, String label})>[
|
||||
(code: CategoryController.allCode, label: l10n.recommended),
|
||||
for (final category in categories.categories)
|
||||
(code: 'category-${category.id}', label: category.name),
|
||||
];
|
||||
return SizedBox(
|
||||
key: const Key('home-category-chips'),
|
||||
height: AppDimens.tapTarget,
|
||||
child: ListView.separated(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: choices.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(width: 8),
|
||||
itemBuilder: (context, index) {
|
||||
final choice = choices[index];
|
||||
final selected = categories.selectedCode == choice.code;
|
||||
return Semantics(
|
||||
selected: selected,
|
||||
button: true,
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () => categories.selectCode(choice.code),
|
||||
child: Center(
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
alignment: Alignment.center,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15),
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? AppColors.blue : const Color(0xFF29272B),
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
border: Border.all(
|
||||
color: selected ? AppColors.blue : Colors.transparent,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
choice.label,
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color: selected ? AppColors.onPrimary : AppColors.muted,
|
||||
fontSize: AppDimens.chipFont,
|
||||
fontWeight: selected ? FontWeight.w700 : FontWeight.w500,
|
||||
height: 1.1,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _languages(AppLocalizations l10n, List<Drama> dramas) {
|
||||
final languages = logic.languagesOf(dramas);
|
||||
if (languages.isEmpty) return const SizedBox.shrink();
|
||||
final selected = logic.selectedLanguage;
|
||||
return SizedBox(
|
||||
key: const Key('discover-language-chips'),
|
||||
height: AppDimens.tapTarget,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
||||
scrollDirection: Axis.horizontal,
|
||||
children: [
|
||||
_languageChip(
|
||||
key: const Key('discover-language-all'),
|
||||
label: l10n.all,
|
||||
selected: selected == null,
|
||||
onTap: () => logic.selectLanguage(null),
|
||||
),
|
||||
for (final language in languages)
|
||||
_languageChip(
|
||||
key: Key('discover-language-$language'),
|
||||
label: _languageLabel(l10n, language),
|
||||
selected: selected == language,
|
||||
onTap: () => logic.selectLanguage(language),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _languageChip({
|
||||
required Key key,
|
||||
required String label,
|
||||
required bool selected,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: Center(
|
||||
child: ChoiceChip(
|
||||
key: key,
|
||||
label: Text(label),
|
||||
selected: selected,
|
||||
showCheckmark: false,
|
||||
onSelected: (_) => onTap(),
|
||||
selectedColor: AppColors.blue,
|
||||
backgroundColor: const Color(0xFF29272B),
|
||||
side: BorderSide.none,
|
||||
labelStyle: TextStyle(
|
||||
color: selected ? AppColors.onPrimary : AppColors.muted,
|
||||
fontSize: AppDimens.chipFont,
|
||||
fontWeight: selected ? FontWeight.w700 : FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _languageLabel(AppLocalizations l10n, String code) {
|
||||
if (code == 'zh-CN' || code == 'zh') return l10n.languageChinese;
|
||||
if (code == 'id') return l10n.languageIndonesian;
|
||||
if (code == 'en') return l10n.languageEnglish;
|
||||
return code;
|
||||
}
|
||||
|
||||
Widget _continueCard(
|
||||
AppLocalizations l10n,
|
||||
Drama drama,
|
||||
WatchProgress record,
|
||||
) {
|
||||
final progress = record.fraction;
|
||||
return Container(
|
||||
key: const Key('discover-continue-watching'),
|
||||
padding: const EdgeInsets.all(9),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.cardAlt,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: SizedBox(
|
||||
width: 52,
|
||||
height: 66,
|
||||
child: RemoteImage(
|
||||
drama.posterUrl,
|
||||
fit: BoxFit.cover,
|
||||
showFallbackIcon: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 9),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
l10n.continueWatching,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: AppColors.accent,
|
||||
fontSize: 8,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
drama.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: AppColors.onSurface,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
_resumeShort(drama, record),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(color: Color(0xFFBBBBBB), fontSize: 9),
|
||||
),
|
||||
const SizedBox(height: 7),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
child: LinearProgressIndicator(
|
||||
value: progress <= 0 ? null : progress,
|
||||
minHeight: 3,
|
||||
backgroundColor: const Color(0xFF474248),
|
||||
valueColor: const AlwaysStoppedAnimation(AppColors.blue),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
FilledButton(
|
||||
key: const Key('discover-continue-play'),
|
||||
onPressed: () => logic.openCard(
|
||||
context,
|
||||
drama,
|
||||
embedded: widget.embedded,
|
||||
onDramaSelected: widget.onDramaSelected,
|
||||
onAction: widget.onAction,
|
||||
),
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: AppColors.blue,
|
||||
foregroundColor: AppColors.onPrimary,
|
||||
minimumSize: const Size(56, 28),
|
||||
padding: EdgeInsets.zero,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(9),
|
||||
),
|
||||
textStyle: const TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
child: Text(l10n.resume),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _resumeShort(Drama drama, WatchProgress record) {
|
||||
final label = AppLocalizations.of(context)!;
|
||||
Episode? episode;
|
||||
for (final item in drama.episodes) {
|
||||
if (item.id == record.episodeId) {
|
||||
episode = item;
|
||||
break;
|
||||
void _openProfile() {
|
||||
final callback = widget.callbacks.onProfile;
|
||||
if (callback != null) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
_act(DiscoverPageAction.my);
|
||||
}
|
||||
|
||||
void _act(DiscoverPageAction action) {
|
||||
logic.act(
|
||||
context,
|
||||
action,
|
||||
embedded: embedded,
|
||||
onAction: widget.callbacks.onAction,
|
||||
);
|
||||
}
|
||||
|
||||
void _openCategory(ContentCategory category, CategoryController categories) {
|
||||
Navigator.of(context).push<void>(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => CategoryDramasPage(
|
||||
title: category.name,
|
||||
dramas: categories.dramasOf(category.id),
|
||||
onOpen: widget.callbacks.onDramaSelected == null ? null : _openDrama,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _openDrama(Drama drama) {
|
||||
final callback = widget.callbacks.onDramaSelected;
|
||||
if (callback != null) {
|
||||
callback(drama);
|
||||
return;
|
||||
}
|
||||
_pushDetail(drama);
|
||||
}
|
||||
|
||||
void _pushDetail(Drama drama) {
|
||||
Navigator.of(context).push<void>(
|
||||
MaterialPageRoute(builder: (_) => DramaDetailPage(drama: drama)),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _openBanner(FeedBanner banner) async {
|
||||
final dramaId = banner.dramaId;
|
||||
if (dramaId == null) return;
|
||||
for (final drama in context.read<CatalogController>().dramas) {
|
||||
if (drama.id == dramaId) {
|
||||
_pushDetail(drama);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (episode == null) return _duration(record.position);
|
||||
return label.episodeOfTotal(episode.number, drama.episodeCount);
|
||||
}
|
||||
|
||||
Widget _quickActions(AppLocalizations l10n, CategoryController categories) {
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _QuickAction(
|
||||
key: const Key('discover-quick-filter'),
|
||||
icon: Icons.tune_rounded,
|
||||
label: l10n.filter,
|
||||
color: AppColors.secondary,
|
||||
onTap: logic.openSearch,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 7),
|
||||
Expanded(
|
||||
child: _QuickAction(
|
||||
key: const Key('discover-quick-charts'),
|
||||
icon: Icons.local_fire_department_rounded,
|
||||
label: l10n.topCharts,
|
||||
color: AppColors.blue,
|
||||
onTap: () => categories.selectCode(CategoryController.hotCode),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 7),
|
||||
Expanded(
|
||||
child: _QuickAction(
|
||||
key: const Key('discover-quick-new'),
|
||||
icon: Icons.auto_awesome_rounded,
|
||||
label: l10n.newReleases,
|
||||
color: AppColors.gold,
|
||||
onTap: () => categories.selectCode(CategoryController.newCode),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 7),
|
||||
Expanded(
|
||||
child: _QuickAction(
|
||||
key: const Key('discover-quick-watchlist'),
|
||||
icon: Icons.bookmark_border_rounded,
|
||||
label: l10n.watchlist,
|
||||
color: AppColors.success,
|
||||
onTap: () => logic.act(
|
||||
context,
|
||||
DiscoverPageAction.watchlist,
|
||||
embedded: widget.embedded,
|
||||
onAction: widget.onAction,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
try {
|
||||
final drama = await context.read<CatalogRepository>().fetchDrama(dramaId);
|
||||
if (mounted) _pushDetail(drama);
|
||||
} catch (_) {
|
||||
if (!mounted) return;
|
||||
final message = AppLocalizations.of(context)!.detailLoadFailed;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
}
|
||||
|
||||
Widget _bottomNav(AppLocalizations l10n) => AppBottomNav(
|
||||
@@ -671,12 +346,7 @@ class _DiscoverPageState extends State<DiscoverPage> {
|
||||
icon: Icons.play_circle_outline_rounded,
|
||||
selectedIcon: Icons.play_circle_fill_rounded,
|
||||
label: l10n.homeTab,
|
||||
onTap: () => logic.act(
|
||||
context,
|
||||
DiscoverPageAction.home,
|
||||
embedded: widget.embedded,
|
||||
onAction: widget.onAction,
|
||||
),
|
||||
onTap: () => _act(DiscoverPageAction.home),
|
||||
),
|
||||
AppBottomNavItem(
|
||||
tabKey: const Key('discover-nav-current'),
|
||||
@@ -691,101 +361,8 @@ class _DiscoverPageState extends State<DiscoverPage> {
|
||||
icon: Icons.video_library_outlined,
|
||||
selectedIcon: Icons.video_library_rounded,
|
||||
label: l10n.myTab,
|
||||
onTap: () => logic.act(
|
||||
context,
|
||||
DiscoverPageAction.my,
|
||||
embedded: widget.embedded,
|
||||
onAction: widget.onAction,
|
||||
),
|
||||
onTap: () => _act(DiscoverPageAction.my),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
class _HeaderIcon extends StatelessWidget {
|
||||
const _HeaderIcon({
|
||||
super.key,
|
||||
required this.icon,
|
||||
required this.tooltip,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String tooltip;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
width: 36,
|
||||
height: 36,
|
||||
child: IconButton(
|
||||
tooltip: tooltip,
|
||||
onPressed: onTap,
|
||||
padding: EdgeInsets.zero,
|
||||
style: IconButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF2C2D33),
|
||||
foregroundColor: AppColors.onSurface,
|
||||
),
|
||||
icon: Icon(icon, size: 18),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _QuickAction extends StatelessWidget {
|
||||
const _QuickAction({
|
||||
super.key,
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.color,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final Color color;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: AppColors.quick,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
height: 62,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 3, vertical: 5),
|
||||
decoration: BoxDecoration(borderRadius: BorderRadius.circular(12)),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(icon, color: color, size: 16),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
label,
|
||||
maxLines: 2,
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: AppColors.muted,
|
||||
fontSize: 9,
|
||||
fontWeight: FontWeight.w500,
|
||||
height: 1.05,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _duration(Duration value) {
|
||||
final minutes = value.inMinutes.remainder(60).toString().padLeft(2, '0');
|
||||
final seconds = value.inSeconds.remainder(60).toString().padLeft(2, '0');
|
||||
return '$minutes:$seconds';
|
||||
}
|
||||
Reference in new issue
Block a user