Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/screens/libraries/tabs/base_library_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,24 @@ abstract class BaseLibraryTabState<T, W extends BaseLibraryTab<T>> extends State
/// snapshot keeps the epoch from reading stale here.
void _onSurfaceVisibilityChanged() {
if (!mounted || !_isLiveSurfaceVisible) return;
onSurfaceShown();
if (!_isLibraryContentStale) return;
_livePacer.schedule();
}

/// Whether this tab is the active library tab *and* actually on screen
/// (no opaque route such as the video player covering it).
@protected
bool get isSurfaceVisible => mounted && _isLiveSurfaceVisible;

/// Called whenever this tab becomes visible again: a covering route (the
/// video player, a detail screen) popped, its main tab was re-shown, or it
/// became the active library tab. Subclasses consume their own staleness
/// here; the default does nothing.
@protected
// ignore: no-empty-block - default no-op hook for subclasses
void onSurfaceShown() {}

@override
void didUpdateWidget(W oldWidget) {
super.didUpdateWidget(oldWidget);
Expand All @@ -250,6 +264,7 @@ abstract class BaseLibraryTabState<T, W extends BaseLibraryTab<T>> extends State
// Became the visible tab again: consume push-marked staleness (#1646).
// The library-changed branch above already reloads unconditionally.
refreshIfLibraryContentStale();
if (_isLiveSurfaceVisible) onSurfaceShown();
}

// Check if we should focus (became active after data loaded)
Expand Down
98 changes: 97 additions & 1 deletion lib/screens/libraries/tabs/library_recommended_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import '../../../widgets/settings_builder.dart';
import '../../../widgets/tv_browse_rail.dart';
import '../../../widgets/tv_spotlight_scaffold.dart';
import '../../main_screen.dart';
import '../../video_player_screen.dart';
import 'base_library_tab.dart';

/// Recommended tab for library screen
Expand Down Expand Up @@ -66,12 +67,73 @@ class _LibraryRecommendedTabState extends BaseLibraryTabState<MediaHub, LibraryR
}
}

/// Set when a watch event (playback progress, a scrobble, a mark) touched
/// this library while the hubs could not be refetched — typically while
/// the video player covers the tab. Consumed by [_runWatchStateReload] once
/// the tab is on screen again, so Continue Watching reflects the episode
/// that was just played without a manual refresh.
bool _watchStateStale = false;
Timer? _watchStateReloadTimer;
StreamSubscription<WatchStateEvent>? _libraryWatchSubscription;

/// Short debounce so the burst at player exit (route pop, final stopped
/// report, scrobble) collapses into one refetch, and the refetch runs after
/// the server has accepted the stopped report.
static const _watchStateReloadDebounce = Duration(milliseconds: 600);
static const _watchStateReloadPlayerRetry = Duration(milliseconds: 750);

@override
void initState() {
super.initState();
// [WatchStateAware] only delivers events for items already on screen.
// Playing something from this library that is not in Continue Watching
// yet must still bring it in, so listen library-wide just to mark stale.
_libraryWatchSubscription = WatchStateNotifier().stream.listen((event) {
if (!mounted) return;
if (event.serverId.value != widget.library.serverId) return;
if (event.librarySectionID != widget.library.id) return;
_markWatchStateStale();
});
}

@override
void dispose() {
_libraryWatchSubscription?.cancel();
_watchStateReloadTimer?.cancel();
_spotlight.dispose();
super.dispose();
}

void _markWatchStateStale() {
_watchStateStale = true;
if (isSurfaceVisible) _scheduleWatchStateReload();
}

void _scheduleWatchStateReload([Duration delay = _watchStateReloadDebounce]) {
_watchStateReloadTimer?.cancel();
_watchStateReloadTimer = Timer(delay, _runWatchStateReload);
}

void _runWatchStateReload() {
_watchStateReloadTimer = null;
if (!mounted || !_watchStateStale) return;
// Hidden again: the next [onSurfaceShown] picks it up.
if (!isSurfaceVisible) return;
// The player route is still tearing down (pop transition): try again
// shortly rather than racing its final stopped report.
if (VideoPlayerScreenState.activeGlobalKey != null) {
_scheduleWatchStateReload(_watchStateReloadPlayerRetry);
return;
}
_watchStateStale = false;
unawaited(performLiveLibraryRefresh());
}

@override
void onSurfaceShown() {
if (_watchStateStale) _scheduleWatchStateReload();
}

@override
String? get watchStateServerId => widget.library.serverId;

Expand Down Expand Up @@ -108,7 +170,14 @@ class _LibraryRecommendedTabState extends BaseLibraryTabState<MediaHub, LibraryR

@override
void onWatchStateChanged(WatchStateEvent event) {
if (event.changeType == WatchStateChangeType.progressUpdate) return;
if (event.changeType == WatchStateChangeType.progressUpdate) {
// Patch the progress bar in place right away; the refetch scheduled by
// _markWatchStateStale then brings the authoritative order (the series
// just played moves to the front) and the next episode once finished.
_patchViewOffset(event);
_markWatchStateStale();
return;
}

if (event.changeType == WatchStateChangeType.removedFromContinueWatching) {
_removeContinueWatchingItem(event.itemId);
Expand All @@ -128,6 +197,33 @@ class _LibraryRecommendedTabState extends BaseLibraryTabState<MediaHub, LibraryR
for (final item in refreshItems.values) {
unawaited(updateItem(item));
}
// A watched/unwatched flip changes what Continue Watching should show for
// the series (finished episode → next episode), which only a refetch knows.
_markWatchStateStale();
}

void _patchViewOffset(WatchStateEvent event) {
final viewOffset = event.viewOffset;
if (viewOffset == null || event.isNowWatched == true) return;
var changed = false;
final patched = <MediaHub>[];
for (final hub in items) {
final index = hub.items.indexWhere((item) => item.globalKey == event.globalKey);
if (index == -1 || hub.items[index].viewOffsetMs == viewOffset) {
patched.add(hub);
continue;
}
final newItems = List<MediaItem>.from(hub.items);
newItems[index] = newItems[index].copyWith(viewOffsetMs: viewOffset);
patched.add(hub.copyWith(items: newItems));
changed = true;
}
if (!changed || !mounted) return;
setState(() {
for (var i = 0; i < patched.length; i++) {
items[i] = patched[i];
}
});
}

void _removeContinueWatchingItem(String itemId) {
Expand Down
11 changes: 8 additions & 3 deletions lib/widgets/video_controls/widgets/content_strip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:material_symbols_icons/symbols.dart';
import 'package:provider/provider.dart';

import '../../../focus/dpad_navigator.dart';
import '../../../focus/focus_theme.dart';
import '../../../focus/focusable_wrapper.dart';
import '../../../i18n/strings.g.dart';
import '../../../media/media_item.dart';
Expand All @@ -29,6 +28,10 @@ import '../../optimized_media_image.dart';
import '../../settings_builder.dart';
import 'media_selector_thumbnail.dart';

/// Focused chapter/episode thumbnails grow a little more than library cards
/// so the selection reads at TV distance over video.
const double _focusedStripItemScale = 1.05;

/// Horizontal scrollable strip of chapter/queue items shown on swipe-up.
class ContentStrip extends StatefulWidget {
final Player player;
Expand Down Expand Up @@ -441,8 +444,10 @@ class ContentStripState extends State<ContentStrip> {
},
borderRadius: 6,
autoScroll: false,
useBackgroundFocus: true,
focusColor: FocusTheme.onMediaFocusFill,
// A solid white outline over video: the translucent fill sat
// behind the thumbnail and was barely visible on dark frames.
focusColor: Colors.white,
focusScale: _focusedStripItemScale,
child: item,
),
);
Expand Down
22 changes: 20 additions & 2 deletions lib/widgets/video_controls/widgets/player_focus_disc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,35 @@ class PlayerFocusDisc extends StatelessWidget {
const BoxShadow playerFocusShadow = BoxShadow(color: Color(0x59000000), blurRadius: 14, offset: Offset(0, 4));

/// Radius of the knob a focused timeline shows in place of its handle.
const double playerFocusKnobRadius = 9;
const double playerFocusKnobRadius = 11;

/// Gap between the knob and its focus halo ring, and the ring's stroke.
const double _playerFocusHaloGap = 4;
const double _playerFocusHaloWidth = 2.5;

/// Paints the focused-timeline knob: a white disc with the same shadow as
/// [PlayerFocusDisc], shared by the VOD slider thumb and the live-TV painter.
///
/// The played part of the track is white too, so a plain white disc blended
/// into it and the timeline barely looked selected. A dark edge separates the
/// knob from the track and a white halo ring marks it as the focused control,
/// readable on dark (OLED) and bright frames alike.
void paintPlayerFocusKnob(Canvas canvas, Offset center) {
canvas.drawCircle(
center + playerFocusShadow.offset / 2,
playerFocusKnobRadius,
playerFocusKnobRadius + _playerFocusHaloGap,
Paint()
..color = playerFocusShadow.color
..maskFilter = MaskFilter.blur(BlurStyle.normal, playerFocusShadow.blurSigma),
);
canvas.drawCircle(
center,
playerFocusKnobRadius + _playerFocusHaloGap + _playerFocusHaloWidth / 2,
Paint()
..style = PaintingStyle.stroke
..strokeWidth = _playerFocusHaloWidth
..color = Colors.white.withValues(alpha: 0.9),
);
canvas.drawCircle(center, playerFocusKnobRadius + 1.5, Paint()..color = Colors.black.withValues(alpha: 0.6));
canvas.drawCircle(center, playerFocusKnobRadius, Paint()..color = Colors.white);
}
Loading