fix(player): 修复详情往返播放位置丢失
This commit is contained in:
1 parent
fe49c6d8b2
commit
759a02375a
16 files changed
+464
-5
No files matched your search
@@ -14,6 +14,7 @@ import 'package:fruitshorts/core/data/repositories/playback_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
|
||||
import 'package:fruitshorts/core/data/services/catalog_controller.dart';
|
||||
import 'package:fruitshorts/core/data/services/favorite_controller.dart';
|
||||
import 'package:fruitshorts/core/data/services/playback_position_cache.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations.dart';
|
||||
import 'package:fruitshorts/pages/drama_detail/drama_detail_view.dart';
|
||||
|
||||
@@ -102,6 +103,7 @@ Future<void> _pumpDetail(
|
||||
value: InMemoryWatchHistoryRepository(),
|
||||
),
|
||||
Provider<PlaybackRepository>.value(value: FakePlaybackRepository()),
|
||||
Provider<PlaybackPositionCache>(create: (_) => PlaybackPositionCache()),
|
||||
ChangeNotifierProvider<FavoriteController>.value(value: favorites),
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => CatalogController(catalog)..load(),
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/data/models/drama.dart';
|
||||
import 'package:fruitshorts/core/data/models/watch_progress.dart';
|
||||
import 'package:fruitshorts/core/data/remote/api_client.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/favorite_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/playback_repository.dart';
|
||||
import 'package:fruitshorts/core/data/services/favorite_controller.dart';
|
||||
import 'package:fruitshorts/core/data/services/playback_position_cache.dart';
|
||||
import 'package:fruitshorts/pages/drama_detail/drama_detail_logic.dart';
|
||||
|
||||
import '../support/fake_watch_history.dart';
|
||||
@@ -13,12 +15,14 @@ DramaDetailLogic _logic(
|
||||
Drama drama,
|
||||
FakeWatchHistory history, {
|
||||
FavoriteController? favorites,
|
||||
PlaybackPositionCache? positionCache,
|
||||
}) =>
|
||||
DramaDetailLogic(
|
||||
drama: drama,
|
||||
history: history,
|
||||
playback: FakePlaybackRepository(),
|
||||
favorites: favorites ?? FavoriteController(InMemoryFavoriteRepository()),
|
||||
positionCache: positionCache ?? PlaybackPositionCache(),
|
||||
);
|
||||
|
||||
Drama _card(String id) => Drama(
|
||||
@@ -103,6 +107,31 @@ void main() {
|
||||
logic.dispose();
|
||||
});
|
||||
|
||||
test('should_prefer_recent_local_position_when_loading_continue', () async {
|
||||
final cache = PlaybackPositionCache();
|
||||
cache.save(
|
||||
episodeId: 'signal-3',
|
||||
dramaId: 'signal',
|
||||
position: const Duration(minutes: 1, seconds: 20),
|
||||
duration: const Duration(minutes: 3),
|
||||
);
|
||||
final history = FakeWatchHistory()
|
||||
..records['signal'] = const WatchProgress(
|
||||
dramaId: 'signal',
|
||||
episodeId: 'signal-1',
|
||||
position: Duration(seconds: 5),
|
||||
duration: Duration(minutes: 3),
|
||||
);
|
||||
final logic = _logic(_detail('signal'), history, positionCache: cache);
|
||||
|
||||
await logic.load(() async => _detail('signal'));
|
||||
|
||||
expect(logic.continueIndex, 2);
|
||||
expect(logic.progress?.position, const Duration(seconds: 80));
|
||||
expect(history.reads, isEmpty);
|
||||
logic.dispose();
|
||||
});
|
||||
|
||||
test('should_adjust_favorite_count_only_after_successful_changes', () async {
|
||||
final repository = InMemoryFavoriteRepository(cards: [_favoriteDrama]);
|
||||
final favorites = FavoriteController(repository);
|
||||
|
||||
@@ -27,6 +27,7 @@ import 'package:fruitshorts/core/data/services/auth_session_store.dart';
|
||||
import 'package:fruitshorts/core/data/services/catalog_controller.dart';
|
||||
import 'package:fruitshorts/core/data/services/download_controller.dart';
|
||||
import 'package:fruitshorts/core/data/services/favorite_controller.dart';
|
||||
import 'package:fruitshorts/core/data/services/playback_position_cache.dart';
|
||||
import 'package:fruitshorts/core/data/services/interaction_controller.dart';
|
||||
import 'package:fruitshorts/core/data/services/playback_session.dart';
|
||||
import 'package:fruitshorts/core/data/services/wallet_controller.dart';
|
||||
@@ -259,6 +260,25 @@ void main() {
|
||||
expect(player.initialIndex, 79);
|
||||
});
|
||||
|
||||
testWidgets('should_open_recent_cached_episode_when_detail_cta_is_tapped', (
|
||||
tester,
|
||||
) async {
|
||||
final cache = PlaybackPositionCache();
|
||||
cache.save(
|
||||
episodeId: 'detail-k38-3',
|
||||
dramaId: 'detail-k38',
|
||||
position: const Duration(minutes: 1, seconds: 20),
|
||||
duration: const Duration(minutes: 3),
|
||||
);
|
||||
await _pumpDetail(tester, positionCache: cache);
|
||||
|
||||
await tester.tap(find.byKey(const Key('detail-cta')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final player = tester.widget<PlayerPage>(find.byType(PlayerPage));
|
||||
expect(player.initialIndex, 2);
|
||||
});
|
||||
|
||||
testWidgets('should_fit_compact_viewport_and_keep_cta_visible', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -283,6 +303,7 @@ Future<void> _pumpDetail(
|
||||
WidgetTester tester, {
|
||||
Drama? drama,
|
||||
Size size = const Size(390, 844),
|
||||
PlaybackPositionCache? positionCache,
|
||||
}) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
@@ -303,6 +324,9 @@ Future<void> _pumpDetail(
|
||||
value: InMemoryWatchHistoryRepository(),
|
||||
),
|
||||
Provider<PlaybackRepository>.value(value: FakePlaybackRepository()),
|
||||
Provider<PlaybackPositionCache>.value(
|
||||
value: positionCache ?? PlaybackPositionCache(),
|
||||
),
|
||||
Provider<PlayerFactory>.value(value: createWidgetPlayer),
|
||||
Provider(create: (_) => PlaybackCoordinator()),
|
||||
Provider<InteractionRepository>.value(value: interactions),
|
||||
|
||||
Reference in new issue
Block a user