1053 lines
34 KiB
Dart
1053 lines
34 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../core/data/models/drama.dart';
|
|
import '../../core/data/repositories/playback_repository.dart';
|
|
import '../../core/data/repositories/watch_history_repository.dart';
|
|
import '../../core/data/services/catalog_controller.dart';
|
|
import '../../core/data/services/favorite_controller.dart';
|
|
import '../../core/data/services/interaction_controller.dart';
|
|
import '../../core/data/services/platform_share_service.dart';
|
|
import '../../core/formatting/error_text.dart';
|
|
import '../../core/formatting/localized_content.dart';
|
|
import '../../core/platform/haptics.dart';
|
|
import '../../core/theme/app_colors.dart';
|
|
import '../../core/theme/app_dimens.dart';
|
|
import '../../core/theme/app_theme.dart';
|
|
import '../../core/widgets/auth_gate.dart';
|
|
import '../../core/widgets/download_action.dart';
|
|
import '../../core/widgets/empty_state.dart';
|
|
import '../../core/widgets/glass_panel.dart';
|
|
import '../../core/widgets/remote_image.dart';
|
|
import '../../l10n/app_localizations.dart';
|
|
import '../interaction/widgets/report_dialog.dart';
|
|
import 'drama_detail_binding.dart';
|
|
import 'drama_detail_logic.dart';
|
|
|
|
const String _reportMenuValue = 'report';
|
|
|
|
class DramaDetailPage extends StatefulWidget {
|
|
const DramaDetailPage({super.key, required this.drama});
|
|
|
|
final Drama drama;
|
|
|
|
@override
|
|
State<DramaDetailPage> createState() => _DramaDetailPageState();
|
|
}
|
|
|
|
class _DramaDetailPageState extends State<DramaDetailPage> {
|
|
late final DramaDetailLogic logic;
|
|
bool _synopsisExpanded = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
logic = DramaDetailBinding().create(
|
|
drama: widget.drama,
|
|
history: context.read<WatchHistoryRepository>(),
|
|
playback: context.read<PlaybackRepository>(),
|
|
favorites: context.read<FavoriteController>(),
|
|
);
|
|
_load();
|
|
}
|
|
|
|
void _load() {
|
|
unawaited(
|
|
logic.load(
|
|
() => context.read<CatalogController>().requireDetail(widget.drama),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
logic.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Theme(
|
|
data: AppTheme.dark(),
|
|
child: ListenableBuilder(
|
|
listenable: logic,
|
|
builder: (context, _) => _page(context),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _page(BuildContext context) {
|
|
final l10n = AppLocalizations.of(context)!;
|
|
if (logic.loading) return _loading(l10n);
|
|
if (logic.failed) return _failed(l10n);
|
|
final drama = logic.drama;
|
|
if (drama.episodes.isEmpty) return _empty(l10n, drama);
|
|
|
|
return Scaffold(
|
|
backgroundColor: AppColors.ink,
|
|
body: CustomScrollView(
|
|
key: const Key('detail-scroll'),
|
|
slivers: [
|
|
SliverToBoxAdapter(child: _hero(context, l10n, drama)),
|
|
SliverToBoxAdapter(child: _metadata(l10n, drama)),
|
|
SliverToBoxAdapter(child: _synopsis(l10n, drama)),
|
|
SliverToBoxAdapter(child: _primaryActions(context, l10n)),
|
|
SliverToBoxAdapter(child: _episodeHeader(l10n, drama)),
|
|
SliverToBoxAdapter(child: _episodeChips(drama)),
|
|
_episodeGrid(context, l10n, drama),
|
|
const SliverToBoxAdapter(child: SizedBox(height: 32)),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _loading(AppLocalizations l10n) => Scaffold(
|
|
backgroundColor: AppColors.ink,
|
|
appBar: AppBar(
|
|
backgroundColor: AppColors.ink,
|
|
foregroundColor: AppColors.onPrimary,
|
|
title: Text(localizedDramaTitle(l10n, widget.drama)),
|
|
),
|
|
body: const Center(child: CircularProgressIndicator()),
|
|
);
|
|
|
|
Widget _failed(AppLocalizations l10n) => Scaffold(
|
|
backgroundColor: AppColors.ink,
|
|
appBar: AppBar(
|
|
backgroundColor: AppColors.ink,
|
|
foregroundColor: AppColors.onPrimary,
|
|
title: Text(localizedDramaTitle(l10n, widget.drama)),
|
|
),
|
|
body: Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 32),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(
|
|
errorText(l10n, logic.failureMessage, l10n.detailError),
|
|
textAlign: TextAlign.center,
|
|
style: const TextStyle(color: AppColors.muted),
|
|
),
|
|
const SizedBox(height: 16),
|
|
FilledButton(onPressed: _load, child: Text(l10n.retry)),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
Widget _empty(AppLocalizations l10n, Drama drama) => Scaffold(
|
|
backgroundColor: AppColors.ink,
|
|
appBar: AppBar(
|
|
backgroundColor: AppColors.ink,
|
|
foregroundColor: AppColors.onPrimary,
|
|
title: Text(localizedDramaTitle(l10n, drama)),
|
|
),
|
|
body: EmptyState(
|
|
key: const Key('drama-detail-empty'),
|
|
icon: Icons.video_library_outlined,
|
|
title: l10n.noEpisodesYet,
|
|
subtitle: l10n.emptyHint,
|
|
actionLabel: l10n.retry,
|
|
onAction: _load,
|
|
),
|
|
);
|
|
|
|
Widget _hero(BuildContext context, AppLocalizations l10n, Drama drama) {
|
|
return Stack(
|
|
children: [
|
|
AspectRatio(
|
|
key: const Key('detail-hero'),
|
|
aspectRatio: 16 / 9,
|
|
child: Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
RemoteImage(
|
|
drama.posterUrl,
|
|
fit: BoxFit.cover,
|
|
showFallbackIcon: true,
|
|
),
|
|
const DecoratedBox(
|
|
decoration: BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [
|
|
Color(0x260B0C10),
|
|
Color(0x000B0C10),
|
|
AppColors.ink,
|
|
],
|
|
stops: [0, 0.5, 1],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Positioned(
|
|
top: MediaQuery.paddingOf(context).top + 8,
|
|
left: 16,
|
|
right: 16,
|
|
child: Row(
|
|
children: [
|
|
_GlassCircleButton(
|
|
key: const Key('detail-back'),
|
|
tooltip: MaterialLocalizations.of(context).backButtonTooltip,
|
|
icon: Icons.chevron_left_rounded,
|
|
onPressed: () => Navigator.of(context).maybePop(),
|
|
),
|
|
const Spacer(),
|
|
_GlassCircleButton(
|
|
key: const Key('detail-share'),
|
|
tooltip: l10n.share,
|
|
icon: Icons.share_outlined,
|
|
onPressed: () => unawaited(_shareDrama(l10n, drama)),
|
|
),
|
|
const SizedBox(width: 8),
|
|
_favoriteButton(
|
|
context,
|
|
l10n,
|
|
key: const Key('detail-favorite-top'),
|
|
),
|
|
const SizedBox(width: 8),
|
|
_reportAction(context, l10n),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _metadata(AppLocalizations l10n, Drama drama) {
|
|
final genres = [
|
|
if (drama.genre.isNotEmpty) drama.genre,
|
|
if (drama.category.isNotEmpty) drama.category,
|
|
];
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(20, 2, 20, 0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Container(
|
|
key: const Key('detail-episode-count'),
|
|
padding: const EdgeInsets.symmetric(horizontal: 9, vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.secondary.withValues(alpha: 0.15),
|
|
borderRadius: BorderRadius.circular(999),
|
|
border: Border.all(
|
|
color: AppColors.secondary.withValues(alpha: 0.3),
|
|
),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const SizedBox(
|
|
width: 6,
|
|
height: 6,
|
|
child: DecoratedBox(
|
|
decoration: BoxDecoration(
|
|
color: AppColors.secondary,
|
|
shape: BoxShape.circle,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 5),
|
|
Text(
|
|
l10n.episodeCount(drama.episodeCount),
|
|
style: const TextStyle(
|
|
color: AppColors.secondary,
|
|
fontSize: 10,
|
|
fontWeight: FontWeight.w700,
|
|
letterSpacing: 0.5,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 10),
|
|
Text(
|
|
localizedDramaTitle(l10n, drama),
|
|
key: const Key('detail-title'),
|
|
style: const TextStyle(
|
|
fontFamily: 'Outfit',
|
|
color: AppColors.onSurface,
|
|
fontSize: 24,
|
|
fontWeight: FontWeight.w700,
|
|
height: 1.15,
|
|
letterSpacing: 0,
|
|
),
|
|
),
|
|
const SizedBox(height: 5),
|
|
Text(
|
|
l10n.seasonOneOriginalRelease,
|
|
style: const TextStyle(
|
|
color: AppColors.muted,
|
|
fontSize: 11,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
const SizedBox(height: 10),
|
|
Wrap(
|
|
spacing: 7,
|
|
runSpacing: 7,
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
children: [
|
|
if (drama.viewCount > 0)
|
|
_metaPill(
|
|
icon: Icons.local_fire_department_rounded,
|
|
label: '${_compactCount(drama.viewCount)} ${l10n.views}',
|
|
color: AppColors.blue,
|
|
),
|
|
for (final genre in genres)
|
|
_metaPill(label: genre, color: AppColors.cream),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _metaPill({
|
|
IconData? icon,
|
|
required String label,
|
|
required Color color,
|
|
}) {
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white.withValues(alpha: 0.05),
|
|
borderRadius: BorderRadius.circular(7),
|
|
border: Border.all(color: AppColors.border),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
if (icon != null) ...[
|
|
Icon(icon, size: 13, color: color),
|
|
const SizedBox(width: 4),
|
|
],
|
|
Text(
|
|
label,
|
|
style: TextStyle(
|
|
color: color,
|
|
fontSize: 11,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _synopsis(AppLocalizations l10n, Drama drama) {
|
|
final text = localizedDramaSynopsis(l10n, drama);
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(20, 14, 20, 0),
|
|
child: GlassPanel(
|
|
key: const Key('detail-synopsis-card'),
|
|
radius: AppDimens.glassSmallRadius,
|
|
blur: 12,
|
|
padding: const EdgeInsets.fromLTRB(13, 11, 13, 9),
|
|
gradient: const LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [Color(0x1A12141A), Color(0x3312141A)],
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
text,
|
|
key: const Key('detail-synopsis'),
|
|
maxLines: _synopsisExpanded ? 100 : 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: const TextStyle(
|
|
color: AppColors.muted,
|
|
fontSize: 13,
|
|
height: 1.45,
|
|
),
|
|
),
|
|
Align(
|
|
alignment: Alignment.centerRight,
|
|
child: TextButton(
|
|
key: const Key('detail-synopsis-toggle'),
|
|
onPressed: () =>
|
|
setState(() => _synopsisExpanded = !_synopsisExpanded),
|
|
style: TextButton.styleFrom(
|
|
foregroundColor: AppColors.secondary,
|
|
minimumSize: const Size(44, 32),
|
|
padding: const EdgeInsets.symmetric(horizontal: 4),
|
|
textStyle: const TextStyle(
|
|
fontSize: 11,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(_synopsisExpanded ? l10n.showLess : l10n.more),
|
|
Icon(
|
|
_synopsisExpanded
|
|
? Icons.keyboard_arrow_up_rounded
|
|
: Icons.keyboard_arrow_down_rounded,
|
|
size: 16,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _primaryActions(BuildContext context, AppLocalizations l10n) {
|
|
final continueIndex = logic.continueIndex;
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(20, 12, 20, 0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: SizedBox(
|
|
height: 52,
|
|
child: FilledButton.icon(
|
|
key: const Key('detail-cta'),
|
|
onPressed: () =>
|
|
logic.openPlayer(context, continueIndex ?? 0),
|
|
style: FilledButton.styleFrom(
|
|
backgroundColor: AppColors.blue,
|
|
foregroundColor: AppColors.onPrimary,
|
|
shape: const StadiumBorder(),
|
|
textStyle: const TextStyle(
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
icon: const Icon(Icons.play_arrow_rounded, size: 20),
|
|
label: Text(
|
|
continueIndex == null
|
|
? l10n.startWatching
|
|
: l10n.continueEpisode(continueIndex + 1),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 10),
|
|
_squareAction(
|
|
key: const Key('detail-favorite'),
|
|
tooltip: l10n.favorite,
|
|
icon:
|
|
context.watch<FavoriteController>().isSaved(logic.drama.id)
|
|
? Icons.bookmark_rounded
|
|
: Icons.bookmark_border_rounded,
|
|
selected: context.watch<FavoriteController>().isSaved(
|
|
logic.drama.id,
|
|
),
|
|
onPressed: () => _toggleFavorite(l10n),
|
|
),
|
|
const SizedBox(width: 10),
|
|
_squareAction(
|
|
key: const Key('detail-download'),
|
|
tooltip: l10n.downloads,
|
|
icon: Icons.download_outlined,
|
|
onPressed: _downloadCurrent,
|
|
),
|
|
],
|
|
),
|
|
if (_continueFraction != null) ...[
|
|
const SizedBox(height: 9),
|
|
_ResumeBar(
|
|
fraction: _continueFraction!,
|
|
label: l10n.resumeProgress(
|
|
_clock(logic.progress!.position),
|
|
_clock(logic.progress!.duration),
|
|
),
|
|
),
|
|
],
|
|
if (logic.progressError != null) ...[
|
|
const SizedBox(height: 8),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
errorText(l10n, logic.progressError, l10n.progressError),
|
|
style: const TextStyle(
|
|
color: AppColors.muted,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
),
|
|
TextButton(
|
|
onPressed: () => unawaited(logic.loadContinue()),
|
|
child: Text(l10n.retry),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _episodeHeader(AppLocalizations l10n, Drama drama) {
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(20, 22, 20, 10),
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
l10n.episodes,
|
|
style: const TextStyle(
|
|
fontFamily: 'Outfit',
|
|
color: AppColors.onSurface,
|
|
fontSize: 17,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
const SizedBox(width: 5),
|
|
Text(
|
|
'(${drama.episodeCount})',
|
|
style: const TextStyle(
|
|
color: AppColors.subtle,
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
const Spacer(),
|
|
Container(
|
|
key: const Key('detail-episodes-range'),
|
|
padding: const EdgeInsets.symmetric(horizontal: 11, vertical: 5),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.card,
|
|
borderRadius: BorderRadius.circular(999),
|
|
border: Border.all(color: AppColors.border),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(
|
|
l10n.all,
|
|
style: const TextStyle(
|
|
color: AppColors.muted,
|
|
fontSize: 11,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
const SizedBox(width: 3),
|
|
const Icon(
|
|
Icons.keyboard_arrow_down_rounded,
|
|
size: 15,
|
|
color: AppColors.muted,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _episodeChips(Drama drama) {
|
|
final selected = logic.continueIndex ?? 0;
|
|
return SizedBox(
|
|
key: const Key('detail-episode-chips'),
|
|
height: 44,
|
|
child: ListView.separated(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
scrollDirection: Axis.horizontal,
|
|
itemCount: drama.episodes.length,
|
|
separatorBuilder: (_, _) => const SizedBox(width: 8),
|
|
itemBuilder: (context, index) {
|
|
final episode = drama.episodes[index];
|
|
final active = index == selected;
|
|
final locked = episode.locked || (!episode.isFree && index > 0);
|
|
return InkWell(
|
|
key: Key('detail-episode-chip-${episode.number}'),
|
|
onTap: () => logic.openPlayer(context, index),
|
|
borderRadius: BorderRadius.circular(12),
|
|
child: Container(
|
|
width: 46,
|
|
height: 44,
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color: active
|
|
? AppColors.blue
|
|
: locked
|
|
? AppColors.secondary.withValues(alpha: 0.16)
|
|
: AppColors.card,
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(
|
|
color: active
|
|
? AppColors.blue
|
|
: locked
|
|
? AppColors.secondary.withValues(alpha: 0.35)
|
|
: AppColors.border,
|
|
),
|
|
),
|
|
child: Text(
|
|
'${episode.number}',
|
|
style: TextStyle(
|
|
color: active
|
|
? AppColors.onPrimary
|
|
: locked
|
|
? AppColors.secondary
|
|
: AppColors.muted,
|
|
fontSize: 13,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _episodeGrid(
|
|
BuildContext context,
|
|
AppLocalizations l10n,
|
|
Drama drama,
|
|
) {
|
|
return SliverPadding(
|
|
key: const Key('detail-episode-grid'),
|
|
padding: const EdgeInsets.fromLTRB(20, 14, 20, 0),
|
|
sliver: SliverGrid(
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 2,
|
|
mainAxisSpacing: 10,
|
|
crossAxisSpacing: 10,
|
|
mainAxisExtent: 108,
|
|
),
|
|
delegate: SliverChildBuilderDelegate(
|
|
(context, index) =>
|
|
_episodeCard(context, l10n, drama, drama.episodes[index], index),
|
|
childCount: drama.episodes.length,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _episodeCard(
|
|
BuildContext context,
|
|
AppLocalizations l10n,
|
|
Drama drama,
|
|
Episode episode,
|
|
int index,
|
|
) {
|
|
final locked = episode.locked || (!episode.isFree && index > 0);
|
|
return Material(
|
|
key: Key('detail-episode-card-${episode.number}'),
|
|
color: AppColors.card,
|
|
borderRadius: BorderRadius.circular(16),
|
|
clipBehavior: Clip.antiAlias,
|
|
child: InkWell(
|
|
onTap: () => logic.openPlayer(context, index),
|
|
child: LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final thumbWidth = (constraints.maxWidth - 70).clamp(58.0, 96.0);
|
|
return Padding(
|
|
padding: const EdgeInsets.all(8),
|
|
child: Row(
|
|
children: [
|
|
SizedBox(
|
|
key: Key('detail-episode-thumb-${episode.number}'),
|
|
width: thumbWidth,
|
|
height: 64,
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(10),
|
|
child: Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
RemoteImage(
|
|
drama.posterUrl,
|
|
fit: BoxFit.cover,
|
|
showFallbackIcon: true,
|
|
),
|
|
const DecoratedBox(
|
|
decoration: BoxDecoration(color: Color(0x33000000)),
|
|
),
|
|
Center(
|
|
child: Container(
|
|
width: 24,
|
|
height: 24,
|
|
decoration: BoxDecoration(
|
|
color: locked
|
|
? Colors.black54
|
|
: AppColors.blue.withValues(alpha: 0.9),
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: Icon(
|
|
locked
|
|
? Icons.lock_rounded
|
|
: Icons.play_arrow_rounded,
|
|
size: 14,
|
|
color: AppColors.onPrimary,
|
|
),
|
|
),
|
|
),
|
|
if (episode.durationSec > 0)
|
|
Positioned(
|
|
right: 4,
|
|
bottom: 4,
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 4,
|
|
vertical: 1,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: Colors.black.withValues(alpha: 0.68),
|
|
borderRadius: BorderRadius.circular(4),
|
|
),
|
|
child: Text(
|
|
_clock(
|
|
Duration(seconds: episode.durationSec),
|
|
),
|
|
style: const TextStyle(
|
|
color: AppColors.cream,
|
|
fontSize: 8,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Wrap(
|
|
spacing: 4,
|
|
runSpacing: 2,
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
children: [
|
|
_episodeBadge(
|
|
episode.isFree && !locked
|
|
? l10n.free
|
|
: l10n.coins,
|
|
locked ? AppColors.secondary : AppColors.success,
|
|
),
|
|
Text(
|
|
l10n.episodeLabel(episode.number),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: const TextStyle(
|
|
color: AppColors.subtle,
|
|
fontSize: 9.5,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
localizedEpisodeTitle(l10n, episode.number),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
color: locked
|
|
? AppColors.muted
|
|
: AppColors.onSurface,
|
|
fontSize: 11.5,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
const SizedBox(height: 3),
|
|
GestureDetector(
|
|
onTap: () =>
|
|
requestEpisodeDownload(context, episode.id),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Icon(
|
|
Icons.download_outlined,
|
|
size: 12,
|
|
color: AppColors.subtle,
|
|
),
|
|
const SizedBox(width: 3),
|
|
Flexible(
|
|
child: Text(
|
|
l10n.downloads,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: const TextStyle(
|
|
color: AppColors.subtle,
|
|
fontSize: 9,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _episodeBadge(String label, Color color) {
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 1),
|
|
decoration: BoxDecoration(
|
|
color: color.withValues(alpha: 0.14),
|
|
borderRadius: BorderRadius.circular(5),
|
|
border: Border.all(color: color.withValues(alpha: 0.28)),
|
|
),
|
|
child: Text(
|
|
label,
|
|
style: TextStyle(
|
|
color: color,
|
|
fontSize: 8.5,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _squareAction({
|
|
required Key key,
|
|
required String tooltip,
|
|
required IconData icon,
|
|
required VoidCallback onPressed,
|
|
bool selected = false,
|
|
}) {
|
|
return SizedBox(
|
|
key: key,
|
|
width: 48,
|
|
height: 48,
|
|
child: IconButton(
|
|
tooltip: tooltip,
|
|
onPressed: onPressed,
|
|
style: IconButton.styleFrom(
|
|
backgroundColor: selected ? AppColors.raised : AppColors.card,
|
|
foregroundColor: selected ? AppColors.blue : AppColors.cream,
|
|
side: BorderSide(
|
|
color: selected ? AppColors.blue : AppColors.outlineDark,
|
|
),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
),
|
|
icon: Icon(icon, size: 21),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _favoriteButton(
|
|
BuildContext context,
|
|
AppLocalizations l10n, {
|
|
required Key key,
|
|
}) {
|
|
final saved = context.watch<FavoriteController>().isSaved(logic.drama.id);
|
|
return _GlassCircleButton(
|
|
key: key,
|
|
tooltip: l10n.favorite,
|
|
icon: saved ? Icons.bookmark_rounded : Icons.bookmark_border_rounded,
|
|
selected: saved,
|
|
onPressed: () => _toggleFavorite(l10n),
|
|
);
|
|
}
|
|
|
|
Widget _reportAction(BuildContext context, AppLocalizations l10n) {
|
|
return PopupMenuButton<String>(
|
|
key: const Key('detail-more'),
|
|
tooltip: l10n.more,
|
|
color: AppColors.card,
|
|
onSelected: (_) => unawaited(_reportDrama(l10n)),
|
|
itemBuilder: (_) => [
|
|
PopupMenuItem(value: _reportMenuValue, child: Text(l10n.reportDrama)),
|
|
],
|
|
child: const _GlassCircle(
|
|
child: Icon(
|
|
Icons.more_horiz_rounded,
|
|
color: AppColors.onSurface,
|
|
size: 20,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _shareDrama(AppLocalizations l10n, Drama drama) async {
|
|
try {
|
|
await const PlatformShareService().shareDrama(
|
|
title: localizedDramaTitle(l10n, drama),
|
|
synopsis: localizedDramaSynopsis(l10n, drama),
|
|
footer: l10n.shareFooter,
|
|
);
|
|
} catch (_) {
|
|
if (!mounted) return;
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(SnackBar(content: Text(l10n.shareFailed)));
|
|
}
|
|
}
|
|
|
|
Future<void> _toggleFavorite(AppLocalizations l10n) async {
|
|
if (!await ensureSignedIn(context)) return;
|
|
if (!mounted) return;
|
|
unawaited(context.read<Haptics>().lightImpact());
|
|
final ok = await logic.toggleFavorite();
|
|
if (ok || !mounted) return;
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(SnackBar(content: Text(l10n.favoriteToggleFailed)));
|
|
}
|
|
|
|
void _downloadCurrent() {
|
|
final episodes = logic.drama.episodes;
|
|
if (episodes.isEmpty) return;
|
|
final index = (logic.continueIndex ?? 0).clamp(0, episodes.length - 1);
|
|
requestEpisodeDownload(context, episodes[index].id);
|
|
}
|
|
|
|
Future<void> _reportDrama(AppLocalizations l10n) async {
|
|
if (!await ensureSignedIn(context) || !mounted) return;
|
|
final draft = await showReportDialog(context, title: l10n.reportDrama);
|
|
if (draft == null || !mounted) return;
|
|
unawaited(context.read<Haptics>().lightImpact());
|
|
final result = await context.read<InteractionController>().reportDrama(
|
|
logic.drama.id,
|
|
reason: draft.reason,
|
|
description: draft.description,
|
|
);
|
|
if (!mounted) return;
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(
|
|
result.isSuccess
|
|
? l10n.reportSubmitted
|
|
: result.errorMessage ?? l10n.reportFailed,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
double? get _continueFraction {
|
|
final record = logic.progress;
|
|
if (record == null || !record.hasPosition) return null;
|
|
if (logic.continueIndex == null) return null;
|
|
return record.fraction;
|
|
}
|
|
|
|
String _clock(Duration duration) {
|
|
final minutes = duration.inMinutes.remainder(60).toString().padLeft(2, '0');
|
|
final seconds = duration.inSeconds.remainder(60).toString().padLeft(2, '0');
|
|
return duration.inHours > 0
|
|
? '${duration.inHours}:$minutes:$seconds'
|
|
: '$minutes:$seconds';
|
|
}
|
|
}
|
|
|
|
class _GlassCircleButton extends StatelessWidget {
|
|
const _GlassCircleButton({
|
|
super.key,
|
|
required this.tooltip,
|
|
required this.icon,
|
|
required this.onPressed,
|
|
this.selected = false,
|
|
});
|
|
|
|
final String tooltip;
|
|
final IconData icon;
|
|
final VoidCallback onPressed;
|
|
final bool selected;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return _GlassCircle(
|
|
child: IconButton(
|
|
tooltip: tooltip,
|
|
onPressed: onPressed,
|
|
padding: EdgeInsets.zero,
|
|
icon: Icon(
|
|
icon,
|
|
size: 20,
|
|
color: selected ? AppColors.blue : AppColors.onSurface,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _GlassCircle extends StatelessWidget {
|
|
const _GlassCircle({required this.child});
|
|
|
|
final Widget child;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SizedBox(
|
|
width: 40,
|
|
height: 40,
|
|
child: GlassPanel(radius: 999, blur: 14, child: child),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ResumeBar extends StatelessWidget {
|
|
const _ResumeBar({required this.fraction, this.label});
|
|
|
|
final double fraction;
|
|
final String? label;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.circular(AppDimens.progressRadius),
|
|
child: LinearProgressIndicator(
|
|
value: fraction,
|
|
minHeight: AppDimens.progressLineHeight,
|
|
backgroundColor: Colors.white24,
|
|
valueColor: const AlwaysStoppedAnimation(AppColors.blue),
|
|
),
|
|
),
|
|
if (label != null) ...[
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
label!,
|
|
style: const TextStyle(
|
|
color: AppColors.muted,
|
|
fontSize: AppDimens.caption,
|
|
),
|
|
),
|
|
],
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
String _compactCount(int value) {
|
|
if (value >= 1000000) {
|
|
final scaled = value / 1000000;
|
|
return '${scaled.toStringAsFixed(scaled >= 10 ? 0 : 1)}M';
|
|
}
|
|
if (value >= 1000) {
|
|
final scaled = value / 1000;
|
|
return '${scaled.toStringAsFixed(scaled >= 10 ? 0 : 1)}K';
|
|
}
|
|
return '$value';
|
|
}
|