feat(flutter): 完成 K28-A1 四 Tab 首页
This commit is contained in:
1 parent
f981f88e0d
commit
49f3e63ed0
25 files changed
+606
-689
No files matched your search
@@ -10,16 +10,15 @@ import '../../core/data/models/home_feed.dart';
|
||||
import '../../core/data/models/watch_progress.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/theme/app_colors.dart';
|
||||
import '../../core/theme/app_dimens.dart';
|
||||
import '../../core/widgets/empty_state.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import '../discover/widgets/drama_grid.dart';
|
||||
import '../discover/widgets/feed_banner_carousel.dart';
|
||||
import '../mine/widgets/continue_watching_card.dart';
|
||||
import 'home_browse_logic.dart';
|
||||
import 'widgets/home_browse_header.dart';
|
||||
import 'widgets/home_continue_watching.dart';
|
||||
import 'widgets/home_drama_grid.dart';
|
||||
|
||||
/// Browse-first home page with channels, hero, continuation, and catalogue.
|
||||
class HomeBrowseView extends StatefulWidget {
|
||||
@@ -77,11 +76,7 @@ class _HomeBrowseViewState extends State<HomeBrowseView> {
|
||||
|
||||
Widget _page(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final categories = context.watch<CategoryController>();
|
||||
final catalog = context.watch<CatalogController>();
|
||||
final source = categories.feed.dramas.isEmpty
|
||||
? catalog.dramas
|
||||
: categories.feed.dramas;
|
||||
return SafeArea(
|
||||
bottom: false,
|
||||
child: Column(
|
||||
@@ -90,57 +85,58 @@ class _HomeBrowseViewState extends State<HomeBrowseView> {
|
||||
onSearch: widget.onSearch,
|
||||
onProfile: widget.onProfile,
|
||||
),
|
||||
Expanded(child: _body(l10n, categories, catalog, source)),
|
||||
Expanded(child: _body(l10n, catalog)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _body(
|
||||
AppLocalizations l10n,
|
||||
CategoryController categories,
|
||||
CatalogController catalog,
|
||||
List<Drama> source,
|
||||
) {
|
||||
Widget _body(AppLocalizations l10n, CatalogController catalog) {
|
||||
return RefreshIndicator(
|
||||
key: const Key('home-refresh'),
|
||||
color: AppColors.blue,
|
||||
backgroundColor: AppColors.card,
|
||||
onRefresh: () async {
|
||||
await Future.wait([categories.load(), logic.refreshRecent()]);
|
||||
await Future.wait([catalog.load(), logic.refreshRecent()]);
|
||||
},
|
||||
child: ListView(
|
||||
key: const Key('home-browse-page'),
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.only(bottom: AppDimens.spaceXl),
|
||||
children: _sections(l10n, catalog, source),
|
||||
children: _sections(l10n, catalog),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _sections(
|
||||
AppLocalizations l10n,
|
||||
CatalogController catalog,
|
||||
List<Drama> source,
|
||||
) {
|
||||
List<Widget> _sections(AppLocalizations l10n, CatalogController catalog) {
|
||||
final source = catalog.dramas;
|
||||
final dramas = _channelDramas(source, logic.channel);
|
||||
final continueItems = _continueItems(logic.recent, catalog.dramas);
|
||||
final continueItem = _continueItem(logic.recent, catalog.dramas);
|
||||
final banners = catalog.banners.isEmpty
|
||||
? _fallbackBanners(source)
|
||||
: catalog.banners;
|
||||
return [
|
||||
_channels(l10n),
|
||||
if (catalog.banners.isNotEmpty) _hero(catalog.banners, source),
|
||||
if (continueItems.isNotEmpty) ...[
|
||||
if (banners.isNotEmpty) _hero(banners, source),
|
||||
if (continueItem != null) ...[
|
||||
_continueHeader(l10n),
|
||||
HomeContinueWatching(
|
||||
items: continueItems,
|
||||
onPlay: (drama, record) =>
|
||||
unawaited(widget.onOpenContinue(drama, record)),
|
||||
ContinueWatchingCard(
|
||||
cardKey: const Key('home-continue-watching'),
|
||||
playButtonKey: Key('home-continue-play-${continueItem.drama.id}'),
|
||||
progressKey: Key('home-continue-progress-${continueItem.drama.id}'),
|
||||
showRemaining: true,
|
||||
drama: continueItem.drama,
|
||||
record: continueItem.record,
|
||||
onResume: () => unawaited(
|
||||
widget.onOpenContinue(continueItem.drama, continueItem.record),
|
||||
),
|
||||
),
|
||||
],
|
||||
_channelHeader(l10n),
|
||||
if (dramas.isEmpty)
|
||||
_empty()
|
||||
else
|
||||
DramaGrid(
|
||||
HomeDramaGrid(
|
||||
l10n: l10n,
|
||||
dramas: dramas,
|
||||
onOpen: (drama) => unawaited(widget.onOpenDrama(drama)),
|
||||
@@ -148,6 +144,19 @@ class _HomeBrowseViewState extends State<HomeBrowseView> {
|
||||
];
|
||||
}
|
||||
|
||||
List<FeedBanner> _fallbackBanners(List<Drama> dramas) {
|
||||
if (dramas.isEmpty) return const [];
|
||||
final drama = dramas.first;
|
||||
return [
|
||||
FeedBanner(
|
||||
id: 'home-fallback-${drama.id}',
|
||||
imageUrl: drama.posterUrl,
|
||||
linkType: 'DRAMA',
|
||||
linkValue: drama.id,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
Widget _continueHeader(AppLocalizations l10n) => _sectionHeader(
|
||||
l10n.continueWatching,
|
||||
actionKey: const Key('home-continue-all'),
|
||||
@@ -314,20 +323,18 @@ class _HomeBrowseViewState extends State<HomeBrowseView> {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<HomeContinueItem> _continueItems(
|
||||
({Drama drama, WatchProgress record})? _continueItem(
|
||||
List<WatchProgress> records,
|
||||
List<Drama> dramas,
|
||||
) {
|
||||
final items = <HomeContinueItem>[];
|
||||
for (final record in records) {
|
||||
if (record.finished || !record.hasPosition) continue;
|
||||
for (final drama in dramas) {
|
||||
if (drama.id == record.dramaId) {
|
||||
items.add((drama: drama, record: record));
|
||||
break;
|
||||
return (drama: drama, record: record);
|
||||
}
|
||||
}
|
||||
}
|
||||
return items;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user