fix(player): 修复首次双击点赞状态刷新
This commit is contained in:
1 parent
978c309cd7
commit
1b50a73bfc
3 files changed
+165
-13
No files matched your search
@@ -519,9 +519,22 @@ class _PlayerPageState extends State<PlayerPage>
|
||||
Episode episode,
|
||||
) {
|
||||
_lastDoubleTapAt = DateTime.now();
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'[player-like] phase=double-tap-callback '
|
||||
'episodeId=${episode.id} '
|
||||
'busy=${interactions.isEpisodeBusy(episode.id)} '
|
||||
'liked=${interactions.isEpisodeLiked(episode.id)}',
|
||||
);
|
||||
}
|
||||
unawaited(_toggleLike(context, interactions, episode, likeOnly: true));
|
||||
}
|
||||
|
||||
void _refreshLikeState() {
|
||||
if (!mounted) return;
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
/// 收藏状态确认后同步右侧计数(总数没有独立计数接口,按 ±1 跟随)。
|
||||
void _applyFavoriteDelta(String dramaId, {required bool nowSaved}) {
|
||||
setState(() {
|
||||
@@ -978,6 +991,9 @@ class _PlayerPageState extends State<PlayerPage>
|
||||
'index=$index top=1 rail=1 progress=1',
|
||||
);
|
||||
}
|
||||
if (widget.homeMode && !_presentationActive && !theater) {
|
||||
_logRailLikeState('home', episode.id, interactions);
|
||||
}
|
||||
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
@@ -1209,6 +1225,7 @@ class _PlayerPageState extends State<PlayerPage>
|
||||
logic.session.preparedPlayerAt(index);
|
||||
final videoPort = port is VideoPlayerPort ? port : null;
|
||||
final videoReady = videoPort?.controller.value.isInitialized ?? false;
|
||||
_logRailLikeState('player', episode.id, interactions);
|
||||
return PlayerPlaybackOverlay(
|
||||
data: PlayerOverlayData(
|
||||
l10n: l10n,
|
||||
@@ -1270,6 +1287,20 @@ class _PlayerPageState extends State<PlayerPage>
|
||||
);
|
||||
}
|
||||
|
||||
void _logRailLikeState(
|
||||
String surface,
|
||||
String episodeId,
|
||||
InteractionController interactions,
|
||||
) {
|
||||
if (!kDebugMode) return;
|
||||
debugPrint(
|
||||
'[player-like] phase=rail-state surface=$surface '
|
||||
'episodeId=$episodeId '
|
||||
'liked=${interactions.isEpisodeLiked(episodeId)} '
|
||||
'count=${interactions.episodeLikeCount(episodeId)}',
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _presentFullPlayer(BuildContext context, int index) async {
|
||||
if (_presentationActive ||
|
||||
_preparingFullPlayer ||
|
||||
|
||||
@@ -99,18 +99,62 @@ extension _PlayerViewActions on _PlayerPageState {
|
||||
Episode episode, {
|
||||
bool likeOnly = false,
|
||||
}) async {
|
||||
final busyBefore = interactions.isEpisodeBusy(episode.id);
|
||||
final likedBefore = interactions.isEpisodeLiked(episode.id);
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'[player-like] phase=toggle-start '
|
||||
'episodeId=${episode.id} likeOnly=$likeOnly '
|
||||
'busy=$busyBefore liked=$likedBefore',
|
||||
);
|
||||
}
|
||||
unawaited(context.read<Haptics>().lightImpact());
|
||||
if (interactions.isEpisodeBusy(episode.id) ||
|
||||
(likeOnly && interactions.isEpisodeLiked(episode.id))) {
|
||||
if (busyBefore || (likeOnly && likedBefore)) {
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'[player-like] phase=toggle-skipped '
|
||||
'episodeId=${episode.id} '
|
||||
'reason=${busyBefore ? 'busy' : 'already-liked'}',
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!await ensureSignedIn(context) || !context.mounted) return;
|
||||
if (interactions.isEpisodeBusy(episode.id) ||
|
||||
(likeOnly && interactions.isEpisodeLiked(episode.id))) {
|
||||
final signedIn = await ensureSignedIn(context);
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'[player-like] phase=auth-result '
|
||||
'episodeId=${episode.id} signedIn=$signedIn '
|
||||
'mounted=${context.mounted}',
|
||||
);
|
||||
}
|
||||
if (!signedIn || !context.mounted) return;
|
||||
final busyAfterAuth = interactions.isEpisodeBusy(episode.id);
|
||||
final likedAfterAuth = interactions.isEpisodeLiked(episode.id);
|
||||
if (busyAfterAuth || (likeOnly && likedAfterAuth)) {
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'[player-like] phase=toggle-skipped-after-auth '
|
||||
'episodeId=${episode.id} '
|
||||
'reason=${busyAfterAuth ? 'busy' : 'already-liked'}',
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
final result = await interactions.toggleEpisodeLike(episode.id);
|
||||
if (result.isSuccess || !context.mounted) return;
|
||||
if (kDebugMode) {
|
||||
debugPrint(
|
||||
'[player-like] phase=toggle-result '
|
||||
'episodeId=${episode.id} success=${result.isSuccess} '
|
||||
'liked=${interactions.isEpisodeLiked(episode.id)} '
|
||||
'count=${interactions.episodeLikeCount(episode.id)} '
|
||||
'error=${result.errorMessage ?? '-'}',
|
||||
);
|
||||
}
|
||||
if (result.isSuccess) {
|
||||
_refreshLikeState();
|
||||
return;
|
||||
}
|
||||
if (!context.mounted) return;
|
||||
showCenteredToast(
|
||||
context,
|
||||
result.errorMessage ?? AppLocalizations.of(context)!.likeFailed,
|
||||
|
||||
Reference in new issue
Block a user