fix(player): 修复首次双击点赞状态刷新
This commit is contained in:
1 parent
978c309cd7
commit
1b50a73bfc
3 files changed
+165
-13
No files matched your search
@@ -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