feat(player): 切集刷新互动计数统计
This commit is contained in:
1 parent
37353dac15
commit
188811fde6
11 files changed
+694
-20
No files matched your search
@@ -9,6 +9,7 @@ import 'package:provider/provider.dart';
|
||||
|
||||
import '../../core/config/app_config.dart';
|
||||
import '../../core/data/models/drama.dart';
|
||||
import '../../core/data/models/episode_stats.dart';
|
||||
import '../../core/data/repositories/comment_repository.dart';
|
||||
import '../../core/data/services/catalog_controller.dart';
|
||||
import '../../core/data/services/favorite_controller.dart';
|
||||
@@ -153,8 +154,7 @@ class _PlayerPageState extends State<PlayerPage>
|
||||
PlayerHeartOverlayController();
|
||||
final Set<String> _precachedPosterUrls = {};
|
||||
|
||||
/// 收藏切换后的本地增量:基准是详情快照,切换成功按服务端状态 ±1。
|
||||
final Map<String, int> _favoriteDelta = {};
|
||||
/// 评论接口返回的最新数量;统计快照优先,失败时保留这里的旧值。
|
||||
final Map<String, int> _commentCounts = {};
|
||||
|
||||
@override
|
||||
@@ -169,6 +169,7 @@ class _PlayerPageState extends State<PlayerPage>
|
||||
wallet: widget.wallet,
|
||||
downloads: widget.downloads,
|
||||
);
|
||||
logic.onEpisodeStatsUpdated = _applyEpisodeStats;
|
||||
logic.attach(widget, isMounted: () => mounted);
|
||||
_thumbnailService = PlaybackThumbnailService(
|
||||
sourceResolver: _resolveThumbnailSource,
|
||||
@@ -550,14 +551,39 @@ class _PlayerPageState extends State<PlayerPage>
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
/// 收藏状态确认后同步右侧计数(总数没有独立计数接口,按 ±1 跟随)。
|
||||
void _applyFavoriteDelta(String dramaId, {required bool nowSaved}) {
|
||||
void _applyEpisodeStats(EpisodeStats stats) {
|
||||
if (!mounted) return;
|
||||
context.read<InteractionController>().applyEpisodeStats(
|
||||
stats.episodeId,
|
||||
liked: stats.liked,
|
||||
likeCount: stats.likeCount,
|
||||
);
|
||||
if (stats.dramaId.isNotEmpty) {
|
||||
context.read<FavoriteController>().applyServerState(
|
||||
stats.dramaId,
|
||||
saved: stats.favorited,
|
||||
);
|
||||
}
|
||||
setState(() {
|
||||
_favoriteDelta[dramaId] =
|
||||
(_favoriteDelta[dramaId] ?? 0) + (nowSaved ? 1 : -1);
|
||||
_commentCounts[stats.episodeId] = stats.commentCount;
|
||||
});
|
||||
}
|
||||
|
||||
/// 收藏状态确认后同步右侧剧级计数。
|
||||
void _applyFavoriteDelta(Drama drama, {required bool nowSaved}) {
|
||||
final current = logic.dramaFavoriteCount(drama.id) ?? drama.favoriteCount;
|
||||
final next = current == null
|
||||
? null
|
||||
: nowSaved
|
||||
? current + 1
|
||||
: (current > 0 ? current - 1 : 0);
|
||||
logic.applyDramaFavoriteState(
|
||||
drama.id,
|
||||
favorited: nowSaved,
|
||||
favoriteCount: next,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _openComments(
|
||||
BuildContext context,
|
||||
Drama drama,
|
||||
@@ -573,6 +599,7 @@ class _PlayerPageState extends State<PlayerPage>
|
||||
try {
|
||||
final count = await comments.count(drama.id, episodeId: episode.id);
|
||||
if (!mounted) return;
|
||||
logic.applyEpisodeCommentCount(episode.id, count);
|
||||
setState(() => _commentCounts[episode.id] = count);
|
||||
} catch (_) {
|
||||
// 评论面板已经关闭,计数刷新失败时保留旧值即可。
|
||||
@@ -1159,10 +1186,12 @@ class _PlayerPageState extends State<PlayerPage>
|
||||
liked: interactions.isEpisodeLiked(episode.id),
|
||||
likeCount:
|
||||
interactions.episodeLikeCount(episode.id) ?? episode.likeCount,
|
||||
favoriteCount: drama.favoriteCount == null
|
||||
? null
|
||||
: drama.favoriteCount! + (_favoriteDelta[drama.id] ?? 0),
|
||||
commentCount: _commentCounts[episode.id] ?? episode.commentCount,
|
||||
favoriteCount:
|
||||
logic.dramaFavoriteCount(drama.id) ?? drama.favoriteCount,
|
||||
commentCount:
|
||||
logic.episodeStats(episode.id)?.commentCount ??
|
||||
_commentCounts[episode.id] ??
|
||||
episode.commentCount,
|
||||
saved: context.watch<FavoriteController>().isSaved(drama.id),
|
||||
onLike: () async {
|
||||
await _toggleLike(context, interactions, episode);
|
||||
@@ -1265,10 +1294,12 @@ class _PlayerPageState extends State<PlayerPage>
|
||||
liked: interactions.isEpisodeLiked(episode.id),
|
||||
likeCount:
|
||||
interactions.episodeLikeCount(episode.id) ?? episode.likeCount,
|
||||
commentCount: _commentCounts[episode.id] ?? episode.commentCount,
|
||||
favoriteCount: drama.favoriteCount == null
|
||||
? null
|
||||
: drama.favoriteCount! + (_favoriteDelta[drama.id] ?? 0),
|
||||
commentCount:
|
||||
logic.episodeStats(episode.id)?.commentCount ??
|
||||
_commentCounts[episode.id] ??
|
||||
episode.commentCount,
|
||||
favoriteCount:
|
||||
logic.dramaFavoriteCount(drama.id) ?? drama.favoriteCount,
|
||||
saved: context.watch<FavoriteController>().isSaved(drama.id),
|
||||
playing: logic.session.userWantsPlay,
|
||||
playbackSpeed: _playbackSpeed,
|
||||
|
||||
Reference in new issue
Block a user