Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db50cb4837 | ||
|
|
b4b90eec63 | ||
|
|
beff313814 | ||
|
|
0dc9cd38af | ||
|
|
8ff7676e60 | ||
|
|
bfe35220aa | ||
|
|
843faee4c5 | ||
|
|
f8bfeb0ec6 | ||
|
|
dd441fee66 | ||
|
|
2204b05d6c | ||
|
|
a1841804b6 | ||
|
|
5e31ad9c67 | ||
|
|
477b92291b | ||
|
|
fcc6186796 | ||
|
|
23179f6d17 | ||
|
|
996e8621fa | ||
|
|
8ad1cb988f | ||
|
|
4cef99dda2 | ||
|
|
4beeedd318 | ||
|
|
23043c61f4 | ||
|
|
8d56171bd2 | ||
|
|
ff0fafe938 | ||
|
|
8b7f369c16 | ||
|
|
5c0e40bddb |
+2
-2
@@ -1,6 +1,6 @@
|
||||
cask "plezy" do
|
||||
version "1.28.0"
|
||||
sha256 "06cb8af90f0dd5cfe1698111e4a74589d5659b49f2330e9cc29223ae53b08945"
|
||||
version "1.29.0"
|
||||
sha256 "5f856275e7d5fe66f25238708a41e9f04fa4d327a932a16626b1424807b05866"
|
||||
|
||||
url "https://github.com/edde746/plezy/releases/download/#{version}/plezy-macos.dmg"
|
||||
name "Plezy"
|
||||
|
||||
@@ -129,8 +129,11 @@ class MainActivity : FlutterActivity() {
|
||||
// Android TV devices — weaker GPUs, less Impeller testing
|
||||
if (packageManager.hasSystemFeature("android.software.leanback")) return true
|
||||
// Google Tensor SoC (Mali GPU) — Pixel 6+
|
||||
// SOC_MODEL may return marketing name ("Tensor G2") or internal ID ("GS201")
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
if (Build.SOC_MODEL.startsWith("Tensor", ignoreCase = true)) return true
|
||||
val soc = Build.SOC_MODEL
|
||||
if (soc.startsWith("Tensor", ignoreCase = true) ||
|
||||
soc.startsWith("GS", ignoreCase = true)) return true
|
||||
}
|
||||
// NVIDIA Tegra (Shield TV)
|
||||
if (Build.MANUFACTURER.equals("NVIDIA", ignoreCase = true)) return true
|
||||
|
||||
@@ -410,6 +410,17 @@ class MpvPlayerCore(private val activity: Activity) : SurfaceHolder.Callback {
|
||||
// Cancel all coroutines
|
||||
scope.cancel()
|
||||
|
||||
// Detach surface from MPV BEFORE removing views to prevent GPU mutex contention
|
||||
val p = player
|
||||
if (p != null) {
|
||||
try {
|
||||
runBlocking(Dispatchers.IO) { p.setProperty("vo", "null") }
|
||||
p.detachSurface()
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Failed to detach surface during dispose", e)
|
||||
}
|
||||
}
|
||||
|
||||
// Capture locals for deferred cleanup
|
||||
val sv = surfaceView
|
||||
val container = surfaceContainer
|
||||
@@ -427,16 +438,7 @@ class MpvPlayerCore(private val activity: Activity) : SurfaceHolder.Callback {
|
||||
pendingSurface = null
|
||||
isInitialized = false
|
||||
|
||||
// Deferred view removal
|
||||
Handler(Looper.getMainLooper()).postAtFrontOfQueue {
|
||||
sv?.holder?.removeCallback(this)
|
||||
if (container?.parent != null) {
|
||||
contentView.removeView(container)
|
||||
}
|
||||
}
|
||||
|
||||
// Close player on background thread
|
||||
val p = player
|
||||
// Close player on background thread, then remove views
|
||||
if (p != null) {
|
||||
Thread {
|
||||
try {
|
||||
@@ -446,9 +448,22 @@ class MpvPlayerCore(private val activity: Activity) : SurfaceHolder.Callback {
|
||||
}
|
||||
player = null
|
||||
Log.d(TAG, "Disposed (native)")
|
||||
Handler(Looper.getMainLooper()).post { onComplete?.invoke() }
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
sv?.holder?.removeCallback(this)
|
||||
if (container?.parent != null) {
|
||||
contentView.removeView(container)
|
||||
}
|
||||
onComplete?.invoke()
|
||||
}
|
||||
}.start()
|
||||
} else {
|
||||
// No player — safe to remove views immediately
|
||||
Handler(Looper.getMainLooper()).postAtFrontOfQueue {
|
||||
sv?.holder?.removeCallback(this)
|
||||
if (container?.parent != null) {
|
||||
contentView.removeView(container)
|
||||
}
|
||||
}
|
||||
onComplete?.invoke()
|
||||
}
|
||||
|
||||
|
||||
@@ -225,7 +225,7 @@ LazyDatabase _openConnection() {
|
||||
}
|
||||
}
|
||||
|
||||
return NativeDatabase(file, setup: (db) {
|
||||
return NativeDatabase.createInBackground(file, setup: (db) {
|
||||
db.execute('PRAGMA journal_mode=WAL');
|
||||
db.execute('PRAGMA synchronous=NORMAL');
|
||||
});
|
||||
|
||||
@@ -40,6 +40,28 @@ mixin GridFocusNodeMixin<T extends StatefulWidget> on State<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Evict focus nodes far from [centerIndex], keeping at most [keepCount] around it.
|
||||
void evictDistantFocusNodes(int centerIndex, {int keepCount = 200}) {
|
||||
if (gridItemFocusNodes.length <= keepCount) return;
|
||||
|
||||
final halfKeep = keepCount ~/ 2;
|
||||
final keepStart = centerIndex - halfKeep;
|
||||
final keepEnd = centerIndex + halfKeep;
|
||||
|
||||
final keysToRemove = <int>[];
|
||||
for (final key in gridItemFocusNodes.keys) {
|
||||
if (key < keepStart || key > keepEnd) {
|
||||
keysToRemove.add(key);
|
||||
}
|
||||
}
|
||||
for (final key in keysToRemove) {
|
||||
final node = gridItemFocusNodes.remove(key);
|
||||
if (node != null && !node.hasFocus) {
|
||||
node.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Dispose all grid-item focus nodes.
|
||||
void disposeGridFocusNodes() {
|
||||
for (final node in gridItemFocusNodes.values) {
|
||||
|
||||
+164
-73
@@ -40,7 +40,7 @@ String physicalKeyLabel(PhysicalKeyboardKey key) {
|
||||
final macLabel = _macKeyLabels[key.usbHidUsage];
|
||||
if (macLabel != null) return macLabel;
|
||||
}
|
||||
return _knownKeyLabels[key.usbHidUsage] ?? key.debugName ?? 'Unknown';
|
||||
return _keyLabels[key.usbHidUsage] ?? 'Unknown';
|
||||
}
|
||||
|
||||
/// macOS-specific overrides for keys that have standard symbols.
|
||||
@@ -70,60 +70,68 @@ const _macKeyLabels = <int, String>{
|
||||
0x00000012: 'fn', // fn
|
||||
};
|
||||
|
||||
const _knownKeyLabels = <int, String>{
|
||||
0x00070004: 'A', // keyA
|
||||
0x00070005: 'B', // keyB
|
||||
0x00070006: 'C', // keyC
|
||||
0x00070007: 'D', // keyD
|
||||
0x00070008: 'E', // keyE
|
||||
0x00070009: 'F', // keyF
|
||||
0x0007000a: 'G', // keyG
|
||||
0x0007000b: 'H', // keyH
|
||||
0x0007000c: 'I', // keyI
|
||||
0x0007000d: 'J', // keyJ
|
||||
0x0007000e: 'K', // keyK
|
||||
0x0007000f: 'L', // keyL
|
||||
0x00070010: 'M', // keyM
|
||||
0x00070011: 'N', // keyN
|
||||
0x00070012: 'O', // keyO
|
||||
0x00070013: 'P', // keyP
|
||||
0x00070014: 'Q', // keyQ
|
||||
0x00070015: 'R', // keyR
|
||||
0x00070016: 'S', // keyS
|
||||
0x00070017: 'T', // keyT
|
||||
0x00070018: 'U', // keyU
|
||||
0x00070019: 'V', // keyV
|
||||
0x0007001a: 'W', // keyW
|
||||
0x0007001b: 'X', // keyX
|
||||
0x0007001c: 'Y', // keyY
|
||||
0x0007001d: 'Z', // keyZ
|
||||
0x0007001e: '1', // digit1
|
||||
0x0007001f: '2', // digit2
|
||||
0x00070020: '3', // digit3
|
||||
0x00070021: '4', // digit4
|
||||
0x00070022: '5', // digit5
|
||||
0x00070023: '6', // digit6
|
||||
0x00070024: '7', // digit7
|
||||
0x00070025: '8', // digit8
|
||||
0x00070026: '9', // digit9
|
||||
0x00070027: '0', // digit0
|
||||
0x00070028: 'Enter', // enter
|
||||
0x00070029: 'Escape', // escape
|
||||
0x0007002a: 'Backspace', // backspace
|
||||
0x0007002b: 'Tab', // tab
|
||||
0x0007002c: 'Space', // space
|
||||
0x0007002d: '=', // equal
|
||||
0x0007002e: '-', // minus
|
||||
0x0007002f: '[', // bracketLeft
|
||||
0x00070030: ']', // bracketRight
|
||||
0x00070031: r'\', // backslash
|
||||
0x00070033: ';', // semicolon
|
||||
0x00070034: "'", // quote
|
||||
0x00070035: '`', // backquote
|
||||
0x00070036: ',', // comma
|
||||
0x00070037: '.', // period
|
||||
0x00070038: '/', // slash
|
||||
0x00070039: 'CapsLock', // capsLock
|
||||
/// Comprehensive key labels sourced from Flutter's PhysicalKeyboardKey._debugNames
|
||||
/// (keyboard_key.g.dart, USB HID keyboard usage page 0x0007).
|
||||
/// Common keys use short curated labels; the rest use Flutter's default names.
|
||||
const _keyLabels = <int, String>{
|
||||
// Letters
|
||||
0x00070004: 'A',
|
||||
0x00070005: 'B',
|
||||
0x00070006: 'C',
|
||||
0x00070007: 'D',
|
||||
0x00070008: 'E',
|
||||
0x00070009: 'F',
|
||||
0x0007000a: 'G',
|
||||
0x0007000b: 'H',
|
||||
0x0007000c: 'I',
|
||||
0x0007000d: 'J',
|
||||
0x0007000e: 'K',
|
||||
0x0007000f: 'L',
|
||||
0x00070010: 'M',
|
||||
0x00070011: 'N',
|
||||
0x00070012: 'O',
|
||||
0x00070013: 'P',
|
||||
0x00070014: 'Q',
|
||||
0x00070015: 'R',
|
||||
0x00070016: 'S',
|
||||
0x00070017: 'T',
|
||||
0x00070018: 'U',
|
||||
0x00070019: 'V',
|
||||
0x0007001a: 'W',
|
||||
0x0007001b: 'X',
|
||||
0x0007001c: 'Y',
|
||||
0x0007001d: 'Z',
|
||||
// Digits
|
||||
0x0007001e: '1',
|
||||
0x0007001f: '2',
|
||||
0x00070020: '3',
|
||||
0x00070021: '4',
|
||||
0x00070022: '5',
|
||||
0x00070023: '6',
|
||||
0x00070024: '7',
|
||||
0x00070025: '8',
|
||||
0x00070026: '9',
|
||||
0x00070027: '0',
|
||||
// Special keys
|
||||
0x00070028: 'Enter',
|
||||
0x00070029: 'Escape',
|
||||
0x0007002a: 'Backspace',
|
||||
0x0007002b: 'Tab',
|
||||
0x0007002c: 'Space',
|
||||
// Symbols
|
||||
0x0007002d: '-',
|
||||
0x0007002e: '=',
|
||||
0x0007002f: '[',
|
||||
0x00070030: ']',
|
||||
0x00070031: r'\',
|
||||
0x00070033: ';',
|
||||
0x00070034: "'",
|
||||
0x00070035: '`',
|
||||
0x00070036: ',',
|
||||
0x00070037: '.',
|
||||
0x00070038: '/',
|
||||
// Lock & function keys
|
||||
0x00070039: 'Caps Lock',
|
||||
0x0007003a: 'F1',
|
||||
0x0007003b: 'F2',
|
||||
0x0007003c: 'F3',
|
||||
@@ -136,22 +144,105 @@ const _knownKeyLabels = <int, String>{
|
||||
0x00070043: 'F10',
|
||||
0x00070044: 'F11',
|
||||
0x00070045: 'F12',
|
||||
0x0007004a: 'Home', // home
|
||||
0x0007004b: 'Page Up', // pageUp
|
||||
0x0007004c: 'Delete', // delete
|
||||
0x0007004d: 'End', // end
|
||||
0x0007004e: 'Page Down', // pageDown
|
||||
0x0007004f: 'Arrow Right', // arrowRight
|
||||
0x00070050: 'Arrow Left', // arrowLeft
|
||||
0x00070051: 'Arrow Down', // arrowDown
|
||||
0x00070052: 'Arrow Up', // arrowUp
|
||||
0x000700e0: 'Ctrl', // controlLeft
|
||||
0x000700e1: 'Shift', // shiftLeft
|
||||
0x000700e2: 'Alt', // altLeft
|
||||
0x000700e3: 'Meta', // metaLeft
|
||||
0x000700e4: 'Ctrl', // controlRight
|
||||
0x000700e5: 'Shift', // shiftRight
|
||||
0x000700e6: 'Alt', // altRight
|
||||
0x000700e7: 'Meta', // metaRight
|
||||
0x00000012: 'Fn', // fn
|
||||
0x00070046: 'Print Screen',
|
||||
0x00070047: 'Scroll Lock',
|
||||
0x00070048: 'Pause',
|
||||
0x00070049: 'Insert',
|
||||
// Navigation
|
||||
0x0007004a: 'Home',
|
||||
0x0007004b: 'Page Up',
|
||||
0x0007004c: 'Delete',
|
||||
0x0007004d: 'End',
|
||||
0x0007004e: 'Page Down',
|
||||
0x0007004f: 'Arrow Right',
|
||||
0x00070050: 'Arrow Left',
|
||||
0x00070051: 'Arrow Down',
|
||||
0x00070052: 'Arrow Up',
|
||||
// Numpad
|
||||
0x00070053: 'Num Lock',
|
||||
0x00070054: 'Numpad /',
|
||||
0x00070055: 'Numpad *',
|
||||
0x00070056: 'Numpad -',
|
||||
0x00070057: 'Numpad +',
|
||||
0x00070058: 'Numpad Enter',
|
||||
0x00070059: 'Numpad 1',
|
||||
0x0007005a: 'Numpad 2',
|
||||
0x0007005b: 'Numpad 3',
|
||||
0x0007005c: 'Numpad 4',
|
||||
0x0007005d: 'Numpad 5',
|
||||
0x0007005e: 'Numpad 6',
|
||||
0x0007005f: 'Numpad 7',
|
||||
0x00070060: 'Numpad 8',
|
||||
0x00070061: 'Numpad 9',
|
||||
0x00070062: 'Numpad 0',
|
||||
0x00070063: 'Numpad .',
|
||||
0x00070064: 'Intl Backslash',
|
||||
0x00070065: 'Context Menu',
|
||||
0x00070066: 'Power',
|
||||
0x00070067: 'Numpad =',
|
||||
// Extended function keys
|
||||
0x00070068: 'F13',
|
||||
0x00070069: 'F14',
|
||||
0x0007006a: 'F15',
|
||||
0x0007006b: 'F16',
|
||||
0x0007006c: 'F17',
|
||||
0x0007006d: 'F18',
|
||||
0x0007006e: 'F19',
|
||||
0x0007006f: 'F20',
|
||||
0x00070070: 'F21',
|
||||
0x00070071: 'F22',
|
||||
0x00070072: 'F23',
|
||||
0x00070073: 'F24',
|
||||
// Editing
|
||||
0x00070074: 'Open',
|
||||
0x00070075: 'Help',
|
||||
0x00070077: 'Select',
|
||||
0x00070079: 'Again',
|
||||
0x0007007a: 'Undo',
|
||||
0x0007007b: 'Cut',
|
||||
0x0007007c: 'Copy',
|
||||
0x0007007d: 'Paste',
|
||||
0x0007007e: 'Find',
|
||||
// Audio
|
||||
0x0007007f: 'Volume Mute',
|
||||
0x00070080: 'Volume Up',
|
||||
0x00070081: 'Volume Down',
|
||||
// Numpad extras
|
||||
0x00070085: 'Numpad ,',
|
||||
// International
|
||||
0x00070087: 'Intl Ro',
|
||||
0x00070088: 'Kana Mode',
|
||||
0x00070089: 'Intl Yen',
|
||||
0x0007008a: 'Convert',
|
||||
0x0007008b: 'Non Convert',
|
||||
0x00070090: 'Lang 1',
|
||||
0x00070091: 'Lang 2',
|
||||
0x00070092: 'Lang 3',
|
||||
0x00070093: 'Lang 4',
|
||||
0x00070094: 'Lang 5',
|
||||
0x0007009b: 'Abort',
|
||||
0x000700a3: 'Props',
|
||||
// Numpad advanced
|
||||
0x000700b6: 'Numpad (',
|
||||
0x000700b7: 'Numpad )',
|
||||
0x000700bb: 'Numpad Backspace',
|
||||
0x000700d0: 'Numpad Memory Store',
|
||||
0x000700d1: 'Numpad Memory Recall',
|
||||
0x000700d2: 'Numpad Memory Clear',
|
||||
0x000700d3: 'Numpad Memory Add',
|
||||
0x000700d4: 'Numpad Memory Subtract',
|
||||
0x000700d7: 'Numpad Sign Change',
|
||||
0x000700d8: 'Numpad Clear',
|
||||
0x000700d9: 'Numpad Clear Entry',
|
||||
// Modifiers
|
||||
0x000700e0: 'Ctrl',
|
||||
0x000700e1: 'Shift',
|
||||
0x000700e2: 'Alt',
|
||||
0x000700e3: 'Meta',
|
||||
0x000700e4: 'Ctrl',
|
||||
0x000700e5: 'Shift',
|
||||
0x000700e6: 'Alt',
|
||||
0x000700e7: 'Meta',
|
||||
// Fn
|
||||
0x00000012: 'Fn',
|
||||
};
|
||||
|
||||
@@ -83,6 +83,7 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
Timer? _indicatorTimer;
|
||||
final ValueNotifier<double> _indicatorProgress = ValueNotifier(0.0);
|
||||
bool _isAutoScrollPaused = false;
|
||||
bool _isTabVisible = true;
|
||||
HiddenLibrariesProvider? _hiddenLibrariesProvider;
|
||||
Set<String> _lastSeenHiddenKeys = {};
|
||||
|
||||
@@ -309,8 +310,8 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
// Restart auto-scroll when app becomes active again
|
||||
if (!_isAutoScrollPaused) _startAutoScroll();
|
||||
// Restart auto-scroll only if discover tab is visible
|
||||
if (_isTabVisible && !_isAutoScrollPaused) _startAutoScroll();
|
||||
// Refresh continue watching on mobile only
|
||||
// (on desktop, "resumed" fires on every window focus gain)
|
||||
if (Platform.isIOS || Platform.isAndroid) {
|
||||
@@ -390,12 +391,14 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
|
||||
@override
|
||||
void onTabHidden() {
|
||||
_isTabVisible = false;
|
||||
_autoScrollTimer?.cancel();
|
||||
_stopIndicatorProgress();
|
||||
}
|
||||
|
||||
@override
|
||||
void onTabShown() {
|
||||
_isTabVisible = true;
|
||||
if (!_isAutoScrollPaused) {
|
||||
_startAutoScroll();
|
||||
}
|
||||
|
||||
@@ -136,6 +136,7 @@ class DownloadsScreenState extends State<DownloadsScreen> with TickerProviderSta
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: CustomScrollView(
|
||||
primary: false,
|
||||
slivers: [
|
||||
DesktopSliverAppBar(
|
||||
title: _buildAppBarTitle(),
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import '../../../focus/dpad_navigator.dart';
|
||||
import '../../../focus/input_mode_tracker.dart';
|
||||
@@ -12,9 +13,11 @@ import '../../../models/plex_filter.dart';
|
||||
import '../../../models/plex_first_character.dart';
|
||||
import '../../../models/plex_sort.dart';
|
||||
import '../../../providers/settings_provider.dart';
|
||||
import '../../../services/image_cache_service.dart';
|
||||
import '../../../utils/error_message_utils.dart';
|
||||
import '../../../utils/grid_size_calculator.dart';
|
||||
import '../../../utils/layout_constants.dart';
|
||||
import '../../../utils/plex_image_helper.dart';
|
||||
import '../alpha_jump_bar.dart';
|
||||
import '../alpha_jump_helper.dart';
|
||||
import '../alpha_scroll_handle.dart';
|
||||
@@ -118,6 +121,12 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If neither the item nor its parents are loaded (evicted), the event
|
||||
// was already filtered by DeletionAware's upstream check against
|
||||
// deletionGlobalKeys/deletionRatingKeys, so this point is unreachable.
|
||||
// The grid self-corrects when _fetchRange updates _totalSize from the
|
||||
// server response on the next scroll.
|
||||
}
|
||||
|
||||
/// Remove an item at [index] and shift all higher indices down by 1
|
||||
@@ -166,7 +175,7 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
// Alpha jump bar state
|
||||
List<PlexFirstCharacter> _firstCharacters = [];
|
||||
AlphaJumpHelper _alphaHelper = AlphaJumpHelper(const []);
|
||||
int _currentFirstVisibleIndex = 0;
|
||||
final ValueNotifier<int> _currentFirstVisibleIndex = ValueNotifier<int>(0);
|
||||
int _currentColumnCount = 1;
|
||||
double _lastCrossAxisExtent = 0;
|
||||
double _effectiveTopPadding = _gridTopPadding;
|
||||
@@ -180,10 +189,16 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
// Incremented on each jump so that overlapping animations don't clobber each other.
|
||||
int _jumpScrollGeneration = 0;
|
||||
|
||||
// Scroll activity tracking (for phone scroll handle)
|
||||
bool _isScrollActive = false;
|
||||
// Scroll activity tracking (for phone scroll handle and range-load gating)
|
||||
final ValueNotifier<bool> _isScrollActive = ValueNotifier<bool>(false);
|
||||
Timer? _scrollActivityTimer;
|
||||
|
||||
// Eager prefetch throttle
|
||||
DateTime? _lastEagerPrefetch;
|
||||
// Alpha bar update: throttle (leading edge) + trailing timer (ensures final position)
|
||||
DateTime? _lastAlphaUpdate;
|
||||
Timer? _alphaUpdateTimer;
|
||||
|
||||
// Pagination state
|
||||
int _totalSize = 0;
|
||||
final Map<int, PlexMetadata> _loadedItems = {};
|
||||
@@ -193,6 +208,10 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
int _firstCharactersRequestId = 0;
|
||||
static const int _fetchSize = 200;
|
||||
Timer? _scrollIdleTimer;
|
||||
Timer? _retryTimer;
|
||||
int _retryCount = 0;
|
||||
bool _rangeLoadScheduled = false;
|
||||
bool _visibleRangeLoading = false;
|
||||
|
||||
// Focus nodes for filter chips
|
||||
final FocusNode _groupingChipFocusNode = FocusNode(debugLabel: 'grouping_chip');
|
||||
@@ -211,14 +230,18 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
@override
|
||||
void dispose() {
|
||||
_cancelToken?.cancel();
|
||||
_retryTimer?.cancel();
|
||||
_scrollActivityTimer?.cancel();
|
||||
_scrollIdleTimer?.cancel();
|
||||
_alphaUpdateTimer?.cancel();
|
||||
_scrollController.removeListener(_onScrollChanged);
|
||||
_scrollController.dispose();
|
||||
_groupingChipFocusNode.dispose();
|
||||
_filtersChipFocusNode.dispose();
|
||||
_sortChipFocusNode.dispose();
|
||||
_alphaJumpBarFocusNode.dispose();
|
||||
_currentFirstVisibleIndex.dispose();
|
||||
_isScrollActive.dispose();
|
||||
disposeGridFocusNodes();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -309,11 +332,11 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
void _resetForFullReload() {
|
||||
_scrollActivityTimer?.cancel();
|
||||
_scrollIdleTimer?.cancel();
|
||||
_isScrollActive = false;
|
||||
_isScrollActive.value = false;
|
||||
_hasJumpPin = false;
|
||||
_isJumpScrolling = false;
|
||||
_jumpScrollGeneration++;
|
||||
_currentFirstVisibleIndex = 0;
|
||||
_currentFirstVisibleIndex.value = 0;
|
||||
|
||||
// The browse tab state is kept alive across libraries, so ensure each
|
||||
// library starts from top instead of inheriting the previous offset.
|
||||
@@ -331,6 +354,7 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
Future<void> _loadContent() async {
|
||||
// Cancel any pending request
|
||||
_cancelToken?.cancel();
|
||||
_retryTimer?.cancel();
|
||||
_cancelToken = CancelToken();
|
||||
// Use a generation counter for the filter/sort loading phase
|
||||
final generation = ++_requestId;
|
||||
@@ -357,8 +381,8 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
_selectedGrouping = _getDefaultGrouping();
|
||||
_firstCharacters = [];
|
||||
_alphaHelper = AlphaJumpHelper(const []);
|
||||
_currentFirstVisibleIndex = 0;
|
||||
});
|
||||
_currentFirstVisibleIndex.value = 0;
|
||||
|
||||
try {
|
||||
final storage = await StorageService.getInstance();
|
||||
@@ -435,6 +459,7 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
Future<void> _loadItems() async {
|
||||
final currentRequestId = ++_requestId;
|
||||
_cancelToken?.cancel();
|
||||
_retryTimer?.cancel();
|
||||
_cancelToken = CancelToken();
|
||||
|
||||
setState(() {
|
||||
@@ -458,7 +483,7 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
final result = await client.getLibraryContent(
|
||||
widget.library.key,
|
||||
start: 0,
|
||||
size: _fetchSize,
|
||||
size: _calculateInitialFetchSize(),
|
||||
filters: filterParams,
|
||||
cancelToken: _cancelToken,
|
||||
);
|
||||
@@ -490,15 +515,15 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
|
||||
/// Fetch a range of items from the API and store them in the sparse map.
|
||||
/// After a successful fetch, re-checks for remaining gaps in the visible range.
|
||||
Future<void> _fetchRange(int start, int size) async {
|
||||
Future<bool> _fetchRange(int start, int size) async {
|
||||
// Clamp to totalSize
|
||||
if (start >= _totalSize) return;
|
||||
if (start >= _totalSize) return false;
|
||||
final clampedSize = size.clamp(0, _totalSize - start);
|
||||
if (clampedSize == 0) return;
|
||||
if (clampedSize == 0) return false;
|
||||
|
||||
// Deduplicate: track every index in-flight to prevent overlapping fetches
|
||||
final indices = List.generate(clampedSize, (i) => start + i);
|
||||
if (indices.every((i) => _loadingRanges.contains(i) || _loadedItems.containsKey(i))) return;
|
||||
if (indices.every((i) => _loadingRanges.contains(i) || _loadedItems.containsKey(i))) return true;
|
||||
_loadingRanges.addAll(indices);
|
||||
|
||||
final currentRequestId = _requestId;
|
||||
@@ -515,28 +540,31 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
cancelToken: _cancelToken,
|
||||
);
|
||||
|
||||
if (currentRequestId != _requestId || !mounted) return;
|
||||
if (currentRequestId != _requestId || !mounted) return false;
|
||||
|
||||
setState(() {
|
||||
for (var i = 0; i < result.items.length; i++) {
|
||||
_loadedItems[start + i] = result.items[i];
|
||||
}
|
||||
// Update totalSize in case it changed (e.g., items added/removed on server)
|
||||
if (result.totalSize != _totalSize) {
|
||||
_totalSize = result.totalSize;
|
||||
}
|
||||
});
|
||||
|
||||
// Re-check for remaining gaps in the visible range after this fetch
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_retryCount = 0;
|
||||
_prefetchImages(start, result.items);
|
||||
return true;
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return false;
|
||||
_retryCount++;
|
||||
final delay = Duration(milliseconds: 500 * (1 << _retryCount.clamp(0, 4)));
|
||||
_retryTimer?.cancel();
|
||||
_retryTimer = Timer(delay, () {
|
||||
if (mounted && currentRequestId == _requestId) {
|
||||
_loadVisibleRange();
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
// Silently ignore fetch errors for background range loads
|
||||
// (the initial load handles errors with UI feedback)
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
return false;
|
||||
} finally {
|
||||
_loadingRanges.removeAll(indices);
|
||||
}
|
||||
@@ -764,7 +792,7 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
void _navigateToGridNearScroll() {
|
||||
if (_totalSize == 0 || _currentColumnCount < 1) return;
|
||||
|
||||
final row = _currentFirstVisibleIndex ~/ _currentColumnCount;
|
||||
final row = _currentFirstVisibleIndex.value ~/ _currentColumnCount;
|
||||
var targetIndex = ((row + 1) * _currentColumnCount - 1).clamp(0, _totalSize - 1);
|
||||
|
||||
// Find nearest loaded item — skeleton cards have no FocusNode
|
||||
@@ -818,9 +846,7 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
/// The letter currently visible at the top of the grid, determined by
|
||||
/// how many items we've scrolled past relative to the API's cumulative
|
||||
/// firstCharacter counts.
|
||||
String get _currentAlphaLetter {
|
||||
return _alphaHelper.currentLetter(_currentFirstVisibleIndex);
|
||||
}
|
||||
String _alphaLetterFor(int index) => _alphaHelper.currentLetter(index);
|
||||
|
||||
/// Whether the alpha jump bar should be shown.
|
||||
/// Only shown when sorting by title (titleSort) and not in folders mode.
|
||||
@@ -872,9 +898,19 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
// Debounced scroll-idle handler: load visible range when scrolling settles
|
||||
_scrollIdleTimer?.cancel();
|
||||
_scrollIdleTimer = Timer(const Duration(milliseconds: 200), () {
|
||||
if (mounted) _loadVisibleRange();
|
||||
if (!mounted) return;
|
||||
// Discard stale in-flight tracking from eager prefetch during scroll
|
||||
// so _loadVisibleRange sees the full gap at the settled position.
|
||||
_loadingRanges.clear();
|
||||
_loadVisibleRange();
|
||||
_evictDistantItems();
|
||||
final firstVisible = _itemIndexFromScrollOffset(_scrollController.offset);
|
||||
evictDistantFocusNodes(firstVisible);
|
||||
});
|
||||
|
||||
// Eager prefetch: fetch data before scroll stops
|
||||
_checkEagerPrefetch();
|
||||
|
||||
if (!_shouldShowAlphaJumpBar || _currentColumnCount < 1) return;
|
||||
|
||||
// During a jump animation, skip alpha bar processing to avoid flashing.
|
||||
@@ -887,7 +923,17 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
_hasJumpPin = false;
|
||||
}
|
||||
|
||||
_updateVisibleIndex();
|
||||
// Throttle alpha bar updates to ~50fps, with a trailing-edge timer
|
||||
// so the final scroll position always gets an update
|
||||
final now = DateTime.now();
|
||||
if (_lastAlphaUpdate == null || now.difference(_lastAlphaUpdate!) >= const Duration(milliseconds: 20)) {
|
||||
_lastAlphaUpdate = now;
|
||||
_updateVisibleIndex();
|
||||
}
|
||||
_alphaUpdateTimer?.cancel();
|
||||
_alphaUpdateTimer = Timer(const Duration(milliseconds: 20), () {
|
||||
if (mounted) _updateVisibleIndex();
|
||||
});
|
||||
}
|
||||
|
||||
/// Recompute the first-visible-index from the current scroll offset.
|
||||
@@ -898,8 +944,8 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
// updates as soon as items with a new letter appear in that row.
|
||||
final maxIndex = _totalSize > 0 ? _totalSize - 1 : 0;
|
||||
final lastInRow = (firstInRow + _currentColumnCount - 1).clamp(0, maxIndex);
|
||||
if (lastInRow != _currentFirstVisibleIndex) {
|
||||
setState(() => _currentFirstVisibleIndex = lastInRow);
|
||||
if (lastInRow != _currentFirstVisibleIndex.value) {
|
||||
_currentFirstVisibleIndex.value = lastInRow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -932,7 +978,7 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
|
||||
_hasJumpPin = true;
|
||||
final clamped = targetIndex.clamp(0, _totalSize > 0 ? _totalSize - 1 : 0);
|
||||
setState(() => _currentFirstVisibleIndex = clamped);
|
||||
_currentFirstVisibleIndex.value = clamped;
|
||||
|
||||
_scrollToItemIndex(clamped);
|
||||
}
|
||||
@@ -1009,19 +1055,28 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
child: _isPhone(context)
|
||||
? AlphaScrollHandle(
|
||||
firstCharacters: _firstCharacters,
|
||||
onJump: _jumpToIndex,
|
||||
currentLetter: _currentAlphaLetter,
|
||||
isScrolling: _isScrollActive,
|
||||
? ValueListenableBuilder<int>(
|
||||
valueListenable: _currentFirstVisibleIndex,
|
||||
builder: (context, visibleIndex, _) => ValueListenableBuilder<bool>(
|
||||
valueListenable: _isScrollActive,
|
||||
builder: (context, scrolling, _) => AlphaScrollHandle(
|
||||
firstCharacters: _firstCharacters,
|
||||
onJump: _jumpToIndex,
|
||||
currentLetter: _alphaLetterFor(visibleIndex),
|
||||
isScrolling: scrolling,
|
||||
),
|
||||
),
|
||||
)
|
||||
: AlphaJumpBar(
|
||||
firstCharacters: _firstCharacters,
|
||||
onJump: _jumpToIndex,
|
||||
currentLetter: _currentAlphaLetter,
|
||||
focusNode: _alphaJumpBarFocusNode,
|
||||
onNavigateLeft: _navigateToGridNearScroll,
|
||||
onBack: _navigateToGridNearScroll,
|
||||
: ValueListenableBuilder<int>(
|
||||
valueListenable: _currentFirstVisibleIndex,
|
||||
builder: (context, visibleIndex, _) => AlphaJumpBar(
|
||||
firstCharacters: _firstCharacters,
|
||||
onJump: _jumpToIndex,
|
||||
currentLetter: _alphaLetterFor(visibleIndex),
|
||||
focusNode: _alphaJumpBarFocusNode,
|
||||
onNavigateLeft: _navigateToGridNearScroll,
|
||||
onBack: _navigateToGridNearScroll,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -1032,14 +1087,14 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
Widget _buildScrollableContent() {
|
||||
return NotificationListener<ScrollNotification>(
|
||||
onNotification: (notification) {
|
||||
// Track scroll activity for phone scroll handle
|
||||
// Track scroll activity for phone scroll handle and range-load gating
|
||||
if (notification is ScrollStartNotification) {
|
||||
if (!_isScrollActive) setState(() => _isScrollActive = true);
|
||||
_isScrollActive.value = true;
|
||||
_scrollActivityTimer?.cancel();
|
||||
} else if (notification is ScrollEndNotification) {
|
||||
_scrollActivityTimer?.cancel();
|
||||
_scrollActivityTimer = Timer(const Duration(milliseconds: 100), () {
|
||||
if (mounted) setState(() => _isScrollActive = false);
|
||||
if (mounted) _isScrollActive.value = false;
|
||||
});
|
||||
}
|
||||
return false;
|
||||
@@ -1053,10 +1108,23 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
);
|
||||
}
|
||||
|
||||
/// Self-healing: when a skeleton is rendered after scrolling stops,
|
||||
/// ensure the visible range gets loaded even if the scroll-idle path missed it.
|
||||
void _scheduleRangeLoad() {
|
||||
if (_rangeLoadScheduled || _isScrollActive.value) return;
|
||||
_rangeLoadScheduled = true;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_rangeLoadScheduled = false;
|
||||
if (mounted) _loadVisibleRange();
|
||||
});
|
||||
}
|
||||
|
||||
/// Determine the visible range and fetch any unloaded items within it.
|
||||
/// Covers the full visible area plus a buffer of _fetchSize/2 on each side,
|
||||
/// then finds the first unloaded contiguous block and fetches it.
|
||||
void _loadVisibleRange() {
|
||||
/// Serialized: only one visible-range fetch runs at a time to prevent
|
||||
/// concurrent calls from seeing each other's _loadingRanges and producing
|
||||
/// tiny fetch sizes.
|
||||
Future<void> _loadVisibleRange() async {
|
||||
if (_visibleRangeLoading) return;
|
||||
if (_totalSize == 0 || _currentColumnCount < 1 || !_scrollController.hasClients) return;
|
||||
if (_lastCrossAxisExtent <= 0) return;
|
||||
|
||||
@@ -1064,7 +1132,6 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
final viewportHeight = _scrollController.position.viewportDimension;
|
||||
final firstIndex = _itemIndexFromScrollOffset(offset);
|
||||
|
||||
// Calculate how many items fit in the viewport
|
||||
final itemWidth = _lastCrossAxisExtent / _currentColumnCount;
|
||||
final itemHeight = itemWidth / GridLayoutConstants.posterAspectRatio;
|
||||
final rowHeight = itemHeight + GridLayoutConstants.mainAxisSpacing;
|
||||
@@ -1073,12 +1140,10 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
final visibleRows = (viewportHeight / rowHeight).ceil() + 1;
|
||||
final visibleCount = visibleRows * _currentColumnCount;
|
||||
|
||||
// Expand the visible range by a buffer on each side
|
||||
final buffer = _fetchSize ~/ 2;
|
||||
final rangeStart = (firstIndex - buffer).clamp(0, _totalSize);
|
||||
final rangeEnd = (firstIndex + visibleCount + buffer).clamp(0, _totalSize);
|
||||
|
||||
// Find the first and last unloaded indices in the range
|
||||
int? fetchStart;
|
||||
int? fetchEnd;
|
||||
for (var i = rangeStart; i < rangeEnd; i++) {
|
||||
@@ -1089,10 +1154,155 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
}
|
||||
if (fetchStart == null || fetchEnd == null) return;
|
||||
|
||||
final fetchSize = fetchEnd - fetchStart;
|
||||
if (fetchSize <= 0) return;
|
||||
_retryTimer?.cancel();
|
||||
_visibleRangeLoading = true;
|
||||
try {
|
||||
final success = await _fetchRange(fetchStart, fetchEnd - fetchStart);
|
||||
if (success && mounted) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) _loadVisibleRange();
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
_visibleRangeLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
_fetchRange(fetchStart, fetchSize);
|
||||
/// Eagerly prefetch data when approaching unloaded boundaries during scroll.
|
||||
/// Throttled to at most once per 100ms to avoid spamming.
|
||||
void _checkEagerPrefetch() {
|
||||
if (_totalSize == 0 || _currentColumnCount < 1 || !_scrollController.hasClients) return;
|
||||
if (_lastCrossAxisExtent <= 0) return;
|
||||
|
||||
final now = DateTime.now();
|
||||
if (_lastEagerPrefetch != null && now.difference(_lastEagerPrefetch!) < const Duration(milliseconds: 100)) return;
|
||||
|
||||
final offset = _scrollController.offset;
|
||||
final viewportHeight = _scrollController.position.viewportDimension;
|
||||
final firstIndex = _itemIndexFromScrollOffset(offset);
|
||||
|
||||
final itemWidth = _lastCrossAxisExtent / _currentColumnCount;
|
||||
final itemHeight = itemWidth / GridLayoutConstants.posterAspectRatio;
|
||||
final rowHeight = itemHeight + GridLayoutConstants.mainAxisSpacing;
|
||||
if (rowHeight <= 0) return;
|
||||
|
||||
final visibleRows = (viewportHeight / rowHeight).ceil() + 1;
|
||||
final visibleCount = visibleRows * _currentColumnCount;
|
||||
|
||||
// Look 1 viewport ahead for unloaded items
|
||||
final lookAheadStart = (firstIndex + visibleCount).clamp(0, _totalSize);
|
||||
final lookAheadEnd = (lookAheadStart + visibleCount).clamp(0, _totalSize);
|
||||
|
||||
for (var i = lookAheadStart; i < lookAheadEnd; i++) {
|
||||
if (!_loadedItems.containsKey(i) && !_loadingRanges.contains(i)) {
|
||||
_lastEagerPrefetch = now;
|
||||
_fetchRange(i, _fetchSize);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check backward if nothing needed forward
|
||||
final lookBehindStart = (firstIndex - visibleCount).clamp(0, _totalSize);
|
||||
for (var i = firstIndex - 1; i >= lookBehindStart; i--) {
|
||||
if (!_loadedItems.containsKey(i) && !_loadingRanges.contains(i)) {
|
||||
_lastEagerPrefetch = now;
|
||||
_fetchRange(i, _fetchSize);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Compute initial fetch size based on viewport dimensions.
|
||||
int _calculateInitialFetchSize() {
|
||||
try {
|
||||
final screenSize = MediaQuery.of(context).size;
|
||||
final settingsProvider = context.read<SettingsProvider>();
|
||||
final maxExtent = GridSizeCalculator.getMaxCrossAxisExtent(context, settingsProvider.libraryDensity);
|
||||
final crossAxisSpacing = GridLayoutConstants.crossAxisSpacing;
|
||||
final columnCount =
|
||||
((screenSize.width + crossAxisSpacing) / (maxExtent + crossAxisSpacing)).ceil().clamp(1, 100);
|
||||
final itemWidth = screenSize.width / columnCount;
|
||||
final itemHeight = itemWidth / GridLayoutConstants.posterAspectRatio;
|
||||
final rowHeight = itemHeight + GridLayoutConstants.mainAxisSpacing;
|
||||
if (rowHeight <= 0) return _fetchSize;
|
||||
final visibleRows = (screenSize.height / rowHeight).ceil() + 1;
|
||||
final visibleCount = visibleRows * columnCount;
|
||||
return (visibleCount * 3).clamp(100, 500);
|
||||
} catch (_) {
|
||||
return _fetchSize;
|
||||
}
|
||||
}
|
||||
|
||||
/// Evict loaded items far from the current viewport to bound memory usage.
|
||||
static const int _maxLoadedItems = 500;
|
||||
static const int _evictionThreshold = 600;
|
||||
|
||||
void _evictDistantItems() {
|
||||
if (_loadedItems.length <= _evictionThreshold) return;
|
||||
|
||||
final centerIndex = _itemIndexFromScrollOffset(_scrollController.offset);
|
||||
final halfKeep = _maxLoadedItems ~/ 2;
|
||||
final keepStart = centerIndex - halfKeep;
|
||||
final keepEnd = centerIndex + halfKeep;
|
||||
|
||||
_loadedItems.removeWhere((index, _) => index < keepStart || index > keepEnd);
|
||||
}
|
||||
|
||||
/// Prefetch images for items near the viewport to reduce pop-in.
|
||||
void _prefetchImages(int startIndex, List<PlexMetadata> items) {
|
||||
if (!_scrollController.hasClients || _lastCrossAxisExtent <= 0 || _currentColumnCount < 1) return;
|
||||
|
||||
final offset = _scrollController.offset;
|
||||
final viewportHeight = _scrollController.position.viewportDimension;
|
||||
final firstVisible = _itemIndexFromScrollOffset(offset);
|
||||
final itemWidth = _lastCrossAxisExtent / _currentColumnCount;
|
||||
final itemHeight = itemWidth / GridLayoutConstants.posterAspectRatio;
|
||||
final rowHeight = itemHeight + GridLayoutConstants.mainAxisSpacing;
|
||||
if (rowHeight <= 0) return;
|
||||
|
||||
final visibleRows = (viewportHeight / rowHeight).ceil() + 1;
|
||||
final visibleEnd = firstVisible + visibleRows * _currentColumnCount;
|
||||
// Prefetch 2 rows beyond visible area
|
||||
final prefetchEnd = visibleEnd + 2 * _currentColumnCount;
|
||||
|
||||
final client = getClientForLibrary();
|
||||
final devicePixelRatio = PlexImageHelper.effectiveDevicePixelRatio(context);
|
||||
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
final index = startIndex + i;
|
||||
if (index < firstVisible || index > prefetchEnd) continue;
|
||||
|
||||
final thumb = items[i].thumb;
|
||||
if (thumb == null || thumb.isEmpty) continue;
|
||||
|
||||
final imageUrl = PlexImageHelper.getOptimizedImageUrl(
|
||||
client: client,
|
||||
thumbPath: thumb,
|
||||
maxWidth: itemWidth,
|
||||
maxHeight: itemHeight,
|
||||
devicePixelRatio: devicePixelRatio,
|
||||
enableTranscoding: PlexImageHelper.shouldTranscode(thumb),
|
||||
imageType: ImageType.poster,
|
||||
);
|
||||
if (imageUrl.isEmpty) continue;
|
||||
|
||||
final scaledWidth = itemWidth * devicePixelRatio;
|
||||
final scaledHeight = itemHeight * devicePixelRatio;
|
||||
final (_, memHeight) = PlexImageHelper.getMemCacheDimensions(
|
||||
displayWidth: scaledWidth.isFinite && scaledWidth > 0 ? scaledWidth.round() : 0,
|
||||
displayHeight: scaledHeight.isFinite && scaledHeight > 0 ? scaledHeight.round() : 0,
|
||||
);
|
||||
|
||||
precacheImage(
|
||||
CachedNetworkImageProvider(
|
||||
imageUrl,
|
||||
cacheManager: PlexImageCacheManager.instance,
|
||||
headers: const {'User-Agent': 'Plezy'},
|
||||
maxHeight: memHeight,
|
||||
),
|
||||
context,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the filters chip is visible
|
||||
@@ -1277,6 +1487,7 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
|
||||
|
||||
// Show skeleton placeholder for unloaded items
|
||||
if (item == null) {
|
||||
_scheduleRangeLoad();
|
||||
return const _SkeletonCard();
|
||||
}
|
||||
|
||||
@@ -1307,32 +1518,32 @@ class _SkeletonCard extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
return const Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Poster area — matches the Expanded poster in _buildGridCard
|
||||
Expanded(
|
||||
child: ClipRRect(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||
child: const SkeletonLoader(child: SizedBox.expand()),
|
||||
borderRadius: BorderRadius.all(Radius.circular(8)),
|
||||
child: SkeletonLoader(child: SizedBox.expand()),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
SizedBox(height: 4),
|
||||
// Title bar
|
||||
SkeletonLoader(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(4)),
|
||||
child: const SizedBox(height: 13, width: double.infinity),
|
||||
borderRadius: BorderRadius.all(Radius.circular(4)),
|
||||
child: SizedBox(height: 13, width: double.infinity),
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
SizedBox(height: 3),
|
||||
// Subtitle bar
|
||||
FractionallySizedBox(
|
||||
alignment: Alignment.centerLeft,
|
||||
widthFactor: 0.6,
|
||||
child: SkeletonLoader(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(4)),
|
||||
child: const SizedBox(height: 11),
|
||||
borderRadius: BorderRadius.all(Radius.circular(4)),
|
||||
child: SizedBox(height: 11),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -528,6 +528,21 @@ class _MainScreenState extends State<MainScreen> with RouteAware, WindowListener
|
||||
_isShowingProfileSelection = false;
|
||||
}
|
||||
|
||||
/// IndexedStack that disables tickers for offscreen children to prevent
|
||||
/// animation controllers on non-visible tabs from scheduling frames.
|
||||
Widget _buildTickerAwareStack() {
|
||||
return IndexedStack(
|
||||
index: _currentIndex,
|
||||
children: [
|
||||
for (var i = 0; i < _screens.length; i++)
|
||||
TickerMode(
|
||||
enabled: i == _currentIndex,
|
||||
child: _screens[i],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildScreens(bool offline) {
|
||||
return [
|
||||
for (final tab in _getVisibleTabs(offline))
|
||||
@@ -945,7 +960,7 @@ class _MainScreenState extends State<MainScreen> with RouteAware, WindowListener
|
||||
node: _contentFocusScope,
|
||||
// No autofocus - we control focus programmatically to prevent
|
||||
// autofocus from stealing focus back after setState() rebuilds
|
||||
child: IndexedStack(index: _currentIndex, children: _screens),
|
||||
child: _buildTickerAwareStack(),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -990,7 +1005,7 @@ class _MainScreenState extends State<MainScreen> with RouteAware, WindowListener
|
||||
|
||||
return OverlaySheetHost(
|
||||
child: Scaffold(
|
||||
body: IndexedStack(index: _currentIndex, children: _screens),
|
||||
body: _buildTickerAwareStack(),
|
||||
bottomNavigationBar: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
|
||||
@@ -84,7 +84,7 @@ class _MediaDetailScreenState extends State<MediaDetailScreen>
|
||||
late final ScrollController _scrollController;
|
||||
final ScrollController _extrasScrollController = ScrollController();
|
||||
bool _watchStateChanged = false;
|
||||
double _scrollOffset = 0;
|
||||
final ValueNotifier<double> _scrollOffset = ValueNotifier<double>(0);
|
||||
|
||||
// Inline season tabs
|
||||
int _selectedSeasonIndex = 0;
|
||||
@@ -348,14 +348,13 @@ class _MediaDetailScreenState extends State<MediaDetailScreen>
|
||||
}
|
||||
|
||||
void _onScroll() {
|
||||
setState(() {
|
||||
_scrollOffset = _scrollController.offset;
|
||||
});
|
||||
_scrollOffset.value = _scrollController.offset;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_scrollController.dispose();
|
||||
_scrollOffset.dispose();
|
||||
_extrasScrollController.dispose();
|
||||
_extrasFocusNode.dispose();
|
||||
_playButtonFocusNode.dispose();
|
||||
@@ -1205,7 +1204,7 @@ class _MediaDetailScreenState extends State<MediaDetailScreen>
|
||||
final isAlways = flattenSeasons == flattenSeasonsAlways;
|
||||
final isSingleSeason = flattenSeasons == flattenSeasonsSingleSeason;
|
||||
final shouldShowEpisodesDirectly =
|
||||
isAlways || seasonsWithServerId.length <= 1 || (isSingleSeason && seasonsWithServerId.length == 1);
|
||||
isAlways || seasonsWithServerId.isEmpty || (isSingleSeason && seasonsWithServerId.length == 1);
|
||||
|
||||
// Create focus nodes for season tabs
|
||||
_updateSeasonTabFocusNodes(seasonsWithServerId.length);
|
||||
@@ -2532,24 +2531,28 @@ class _MediaDetailScreenState extends State<MediaDetailScreen>
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: IgnorePointer(
|
||||
ignoring: _scrollOffset < 50,
|
||||
child: AnimatedOpacity(
|
||||
opacity: (_scrollOffset / 100).clamp(0.0, 1.0),
|
||||
duration: const Duration(milliseconds: 150),
|
||||
child: Container(
|
||||
height: MediaQuery.of(context).padding.top + 58,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Theme.of(context).scaffoldBackgroundColor.withValues(alpha: 0.8),
|
||||
Theme.of(context).scaffoldBackgroundColor.withValues(alpha: 0.5),
|
||||
Theme.of(context).scaffoldBackgroundColor.withValues(alpha: 0),
|
||||
],
|
||||
stops: const [0.0, 0.3, 1.0],
|
||||
),
|
||||
child: ValueListenableBuilder<double>(
|
||||
valueListenable: _scrollOffset,
|
||||
builder: (context, offset, child) => IgnorePointer(
|
||||
ignoring: offset < 50,
|
||||
child: AnimatedOpacity(
|
||||
opacity: (offset / 100).clamp(0.0, 1.0),
|
||||
duration: const Duration(milliseconds: 150),
|
||||
child: child!,
|
||||
),
|
||||
),
|
||||
child: Container(
|
||||
height: MediaQuery.of(context).padding.top + 58,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Theme.of(context).scaffoldBackgroundColor.withValues(alpha: 0.8),
|
||||
Theme.of(context).scaffoldBackgroundColor.withValues(alpha: 0.5),
|
||||
Theme.of(context).scaffoldBackgroundColor.withValues(alpha: 0),
|
||||
],
|
||||
stops: const [0.0, 0.3, 1.0],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -226,6 +226,7 @@ class _SearchScreenState extends State<SearchScreen> with Refreshable, FullRefre
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: CustomScrollView(
|
||||
primary: false,
|
||||
slivers: [
|
||||
DesktopSliverAppBar(title: Text(t.common.search), floating: true),
|
||||
SliverToBoxAdapter(
|
||||
|
||||
@@ -238,6 +238,7 @@ class _SettingsScreenState extends State<SettingsScreen> with FocusableTab {
|
||||
body: Focus(
|
||||
onKeyEvent: _handleKeyEvent,
|
||||
child: CustomScrollView(
|
||||
primary: false,
|
||||
slivers: [
|
||||
ExcludeFocus(child: CustomAppBar(title: Text(t.settings.title), pinned: true)),
|
||||
SliverPadding(
|
||||
@@ -1049,6 +1050,11 @@ class _SettingsScreenState extends State<SettingsScreen> with FocusableTab {
|
||||
selectedPath = await safService.pickDirectory();
|
||||
if (selectedPath != null) {
|
||||
pathType = 'saf';
|
||||
} else if (PlatformDetector.isTV()) {
|
||||
if (mounted) {
|
||||
showErrorSnackBar(context, t.settings.downloadLocationSelectError);
|
||||
}
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Use file_picker on desktop
|
||||
|
||||
@@ -934,15 +934,19 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
|
||||
|
||||
if (episodes.isEmpty) return;
|
||||
|
||||
// Sort by season then episode number, with Season 0 (Specials) at the end
|
||||
// Sort by aired date, falling back to season/episode number
|
||||
final sorted = List<PlexMetadata>.from(episodes)
|
||||
..sort((a, b) {
|
||||
final aIsSpecial = (a.parentIndex ?? 0) == 0;
|
||||
final bIsSpecial = (b.parentIndex ?? 0) == 0;
|
||||
if (aIsSpecial != bIsSpecial) return aIsSpecial ? 1 : -1;
|
||||
final seasonCmp = (a.parentIndex ?? 0).compareTo(b.parentIndex ?? 0);
|
||||
if (seasonCmp != 0) return seasonCmp;
|
||||
return (a.index ?? 0).compareTo(b.index ?? 0);
|
||||
final aDate = a.originallyAvailableAt ?? '';
|
||||
final bDate = b.originallyAvailableAt ?? '';
|
||||
if (aDate.isEmpty && bDate.isEmpty) {
|
||||
final seasonCmp = (a.parentIndex ?? 0).compareTo(b.parentIndex ?? 0);
|
||||
if (seasonCmp != 0) return seasonCmp;
|
||||
return (a.index ?? 0).compareTo(b.index ?? 0);
|
||||
}
|
||||
if (aDate.isEmpty) return 1;
|
||||
if (bDate.isEmpty) return -1;
|
||||
return aDate.compareTo(bDate);
|
||||
});
|
||||
|
||||
// Find current episode in the sorted list
|
||||
@@ -1009,7 +1013,6 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
|
||||
_trackManager?.mediaInfo = null;
|
||||
}
|
||||
|
||||
_startLiveTimelineUpdates();
|
||||
} catch (e) {
|
||||
appLogger.e('Failed to start live TV playback', error: e);
|
||||
_sendLiveTimeline('stopped');
|
||||
@@ -1873,6 +1876,10 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
|
||||
}
|
||||
|
||||
void _onVideoCompleted(bool completed) async {
|
||||
// Live TV streams are continuous — ignore spurious EOF events caused by
|
||||
// inter-segment gaps in the chunked MKV transcode stream.
|
||||
if (widget.isLive) return;
|
||||
|
||||
if (completed &&
|
||||
_nextEpisode != null &&
|
||||
!_showPlayNextDialog &&
|
||||
@@ -2049,8 +2056,15 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
|
||||
final state = player?.state.playing == true ? 'playing' : 'paused';
|
||||
_sendLiveTimeline(state);
|
||||
});
|
||||
// Send initial heartbeat immediately
|
||||
_sendLiveTimeline('playing');
|
||||
// Delay initial heartbeat to let the transcode session stabilize.
|
||||
// Sending time=0 immediately after player.open() causes the server
|
||||
// to spawn a duplicate transcode job with offset=-1 that 404s.
|
||||
Future.delayed(const Duration(seconds: 3), () {
|
||||
if (_liveTimelineTimer != null) {
|
||||
final state = player?.state.playing == true ? 'playing' : 'paused';
|
||||
_sendLiveTimeline(state);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _stopLiveTimelineUpdates() {
|
||||
@@ -2111,7 +2125,7 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
|
||||
final p = player!;
|
||||
// FFmpeg HTTP protocol reconnection
|
||||
await p.setProperty('stream-lavf-o',
|
||||
'reconnect=1,reconnect_at_eof=1,reconnect_streamed=1,reconnect_on_network_error=1,reconnect_delay_max=30');
|
||||
'reconnect=1,reconnect_streamed=1,reconnect_on_network_error=1,reconnect_delay_max=30');
|
||||
// Demuxer: retry up to 1000 times on stream reload failures
|
||||
await p.setProperty('demuxer-lavf-o', 'max_reload=1000');
|
||||
await p.setProperty('force-seekable', 'no');
|
||||
@@ -2906,43 +2920,54 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
|
||||
);
|
||||
},
|
||||
),
|
||||
// Watch Together: reconnecting to host overlay
|
||||
Consumer<WatchTogetherProvider>(
|
||||
builder: (context, provider, child) {
|
||||
if (!provider.isWaitingForHostReconnect) return const SizedBox.shrink();
|
||||
return Positioned(
|
||||
bottom: 120,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Center(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.black54,
|
||||
borderRadius: BorderRadius.all(Radius.circular(20)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const SizedBox(
|
||||
width: 14,
|
||||
height: 14,
|
||||
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white),
|
||||
// Watch Together overlays (isolated from video surface repaints)
|
||||
RepaintBoundary(
|
||||
child: Stack(
|
||||
children: [
|
||||
// Watch Together: reconnecting to host overlay
|
||||
Selector<WatchTogetherProvider, bool>(
|
||||
selector: (_, provider) => provider.isWaitingForHostReconnect,
|
||||
builder: (context, isWaiting, child) {
|
||||
if (!isWaiting) return const SizedBox.shrink();
|
||||
return Positioned(
|
||||
bottom: 120,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Center(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.black54,
|
||||
borderRadius: BorderRadius.all(Radius.circular(20)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (PlatformDetector.isTV())
|
||||
const Icon(Symbols.sync_rounded, size: 14, color: Colors.white)
|
||||
else
|
||||
const SizedBox(
|
||||
width: 14,
|
||||
height: 14,
|
||||
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
t.watchTogether.reconnectingToHost,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
t.watchTogether.reconnectingToHost,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
// Watch Together: participant join/leave notifications
|
||||
const ParticipantNotificationOverlay(),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Watch Together: participant join/leave notifications
|
||||
const ParticipantNotificationOverlay(),
|
||||
// Black overlay during exit (no spinner - just covers transparency)
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: _isExiting,
|
||||
|
||||
@@ -290,12 +290,12 @@ class KeyboardShortcutsService {
|
||||
onPreviousChapter?.call();
|
||||
break;
|
||||
case 'speed_increase':
|
||||
final newRateUp = (player.state.rate + 0.1).clamp(0.1, 3.0);
|
||||
final newRateUp = (player.state.rate + 0.25).clamp(0.25, 3.0);
|
||||
player.setRate(newRateUp);
|
||||
_settingsService.setDefaultPlaybackSpeed(newRateUp);
|
||||
break;
|
||||
case 'speed_decrease':
|
||||
final newRateDown = (player.state.rate - 0.1).clamp(0.1, 3.0);
|
||||
final newRateDown = (player.state.rate - 0.25).clamp(0.25, 3.0);
|
||||
player.setRate(newRateDown);
|
||||
_settingsService.setDefaultPlaybackSpeed(newRateDown);
|
||||
break;
|
||||
|
||||
@@ -1981,21 +1981,27 @@ class PlexClient {
|
||||
String? startingEpisodeKey,
|
||||
}) async {
|
||||
try {
|
||||
// Get machine identifier for building the URI
|
||||
final machineId = config.machineIdentifier ?? await getMachineIdentifier();
|
||||
if (machineId == null) {
|
||||
throw Exception('Could not get server machine identifier');
|
||||
}
|
||||
|
||||
// Build the URI for the show's episodes
|
||||
final uri = 'server://$machineId/com.plexapp.plugins.library/library/metadata/$showRatingKey/children';
|
||||
// When starting from a specific episode, use continuous mode
|
||||
// This lets the server determine playback order (respects episodeSort)
|
||||
if (startingEpisodeKey != null && shuffle == 0) {
|
||||
final uri = 'server://$machineId/com.plexapp.plugins.library/library/metadata/$startingEpisodeKey';
|
||||
return await createPlayQueue(
|
||||
uri: uri,
|
||||
type: 'video',
|
||||
continuous: 1,
|
||||
);
|
||||
}
|
||||
|
||||
// Create the play queue with optional starting episode
|
||||
final uri = 'server://$machineId/com.plexapp.plugins.library/library/metadata/$showRatingKey/children';
|
||||
return await createPlayQueue(
|
||||
uri: uri,
|
||||
type: 'video',
|
||||
shuffle: shuffle,
|
||||
key: startingEpisodeKey != null ? '/library/metadata/$startingEpisodeKey' : null,
|
||||
);
|
||||
} catch (e) {
|
||||
appLogger.e('Failed to create show play queue', error: e);
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:saf_util/saf_util.dart';
|
||||
import '../utils/platform_detector.dart';
|
||||
import 'package:saf_util/saf_util_platform_interface.dart';
|
||||
import 'package:saf_stream/saf_stream.dart';
|
||||
|
||||
@@ -22,6 +23,8 @@ class SafStorageService {
|
||||
/// Returns the content:// URI or null if cancelled
|
||||
Future<String?> pickDirectory() async {
|
||||
if (!isAvailable) return null;
|
||||
// SAF document picker is not available on Android TV
|
||||
if (TvDetectionService.isTVSync()) return null;
|
||||
try {
|
||||
// Pick directory with persistent write permission
|
||||
final doc = await _safUtil.pickDirectory(writePermission: true, persistablePermission: true);
|
||||
|
||||
@@ -606,8 +606,9 @@ class SettingsService extends BaseSharedPreferencesService {
|
||||
.cast<HotKeyModifier>()
|
||||
.toList();
|
||||
|
||||
// Try direct USB HID lookup first (new format), fall back to string parsing (backwards compat)
|
||||
final key = _usbHidKeyMap[keyString] ?? _findKeyByString(keyString);
|
||||
// Try parsing as USB HID code first (new format), fall back to string parsing (backwards compat)
|
||||
final usbHidCode = int.tryParse(keyString, radix: 16);
|
||||
final key = usbHidCode != null ? PhysicalKeyboardKey(usbHidCode) : _findKeyByString(keyString);
|
||||
if (key != null) {
|
||||
return HotKey(key: key, modifiers: modifiers.isNotEmpty ? modifiers : null);
|
||||
}
|
||||
@@ -617,82 +618,6 @@ class SettingsService extends BaseSharedPreferencesService {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Unified map for USB HID codes to PhysicalKeyboardKey
|
||||
static const _usbHidKeyMap = <String, PhysicalKeyboardKey>{
|
||||
// Special keys
|
||||
'0007002c': PhysicalKeyboardKey.space,
|
||||
'0007002a': PhysicalKeyboardKey.backspace,
|
||||
'0007004c': PhysicalKeyboardKey.delete,
|
||||
'00070028': PhysicalKeyboardKey.enter,
|
||||
'00070029': PhysicalKeyboardKey.escape,
|
||||
'0007002b': PhysicalKeyboardKey.tab,
|
||||
'00070039': PhysicalKeyboardKey.capsLock,
|
||||
// Arrow keys
|
||||
'00070050': PhysicalKeyboardKey.arrowLeft,
|
||||
'00070052': PhysicalKeyboardKey.arrowUp,
|
||||
'0007004f': PhysicalKeyboardKey.arrowRight,
|
||||
'00070051': PhysicalKeyboardKey.arrowDown,
|
||||
// Navigation keys
|
||||
'0007004a': PhysicalKeyboardKey.home,
|
||||
'0007004d': PhysicalKeyboardKey.end,
|
||||
'0007004b': PhysicalKeyboardKey.pageUp,
|
||||
'0007004e': PhysicalKeyboardKey.pageDown,
|
||||
// Symbol keys
|
||||
'0007002d': PhysicalKeyboardKey.equal,
|
||||
'0007002e': PhysicalKeyboardKey.minus,
|
||||
// Function keys
|
||||
'0007003a': PhysicalKeyboardKey.f1,
|
||||
'0007003b': PhysicalKeyboardKey.f2,
|
||||
'0007003c': PhysicalKeyboardKey.f3,
|
||||
'0007003d': PhysicalKeyboardKey.f4,
|
||||
'0007003e': PhysicalKeyboardKey.f5,
|
||||
'0007003f': PhysicalKeyboardKey.f6,
|
||||
'00070040': PhysicalKeyboardKey.f7,
|
||||
'00070041': PhysicalKeyboardKey.f8,
|
||||
'00070042': PhysicalKeyboardKey.f9,
|
||||
'00070043': PhysicalKeyboardKey.f10,
|
||||
'00070044': PhysicalKeyboardKey.f11,
|
||||
'00070045': PhysicalKeyboardKey.f12,
|
||||
// Number keys
|
||||
'00070027': PhysicalKeyboardKey.digit0,
|
||||
'0007001e': PhysicalKeyboardKey.digit1,
|
||||
'0007001f': PhysicalKeyboardKey.digit2,
|
||||
'00070020': PhysicalKeyboardKey.digit3,
|
||||
'00070021': PhysicalKeyboardKey.digit4,
|
||||
'00070022': PhysicalKeyboardKey.digit5,
|
||||
'00070023': PhysicalKeyboardKey.digit6,
|
||||
'00070024': PhysicalKeyboardKey.digit7,
|
||||
'00070025': PhysicalKeyboardKey.digit8,
|
||||
'00070026': PhysicalKeyboardKey.digit9,
|
||||
// Letter keys
|
||||
'00070004': PhysicalKeyboardKey.keyA,
|
||||
'00070005': PhysicalKeyboardKey.keyB,
|
||||
'00070006': PhysicalKeyboardKey.keyC,
|
||||
'00070007': PhysicalKeyboardKey.keyD,
|
||||
'00070008': PhysicalKeyboardKey.keyE,
|
||||
'00070009': PhysicalKeyboardKey.keyF,
|
||||
'0007000a': PhysicalKeyboardKey.keyG,
|
||||
'0007000b': PhysicalKeyboardKey.keyH,
|
||||
'0007000c': PhysicalKeyboardKey.keyI,
|
||||
'0007000d': PhysicalKeyboardKey.keyJ,
|
||||
'0007000e': PhysicalKeyboardKey.keyK,
|
||||
'0007000f': PhysicalKeyboardKey.keyL,
|
||||
'00070010': PhysicalKeyboardKey.keyM,
|
||||
'00070011': PhysicalKeyboardKey.keyN,
|
||||
'00070012': PhysicalKeyboardKey.keyO,
|
||||
'00070013': PhysicalKeyboardKey.keyP,
|
||||
'00070014': PhysicalKeyboardKey.keyQ,
|
||||
'00070015': PhysicalKeyboardKey.keyR,
|
||||
'00070016': PhysicalKeyboardKey.keyS,
|
||||
'00070017': PhysicalKeyboardKey.keyT,
|
||||
'00070018': PhysicalKeyboardKey.keyU,
|
||||
'00070019': PhysicalKeyboardKey.keyV,
|
||||
'0007001a': PhysicalKeyboardKey.keyW,
|
||||
'0007001b': PhysicalKeyboardKey.keyX,
|
||||
'0007001c': PhysicalKeyboardKey.keyY,
|
||||
'0007001d': PhysicalKeyboardKey.keyZ,
|
||||
};
|
||||
|
||||
// Map for pattern-based key name matching (lowercase keys for case-insensitive matching)
|
||||
static const _keyNameMap = <String, PhysicalKeyboardKey>{
|
||||
'space': PhysicalKeyboardKey.space,
|
||||
@@ -782,9 +707,8 @@ class SettingsService extends BaseSharedPreferencesService {
|
||||
// Format: PhysicalKeyboardKey#ec9ed(usbHidUsage: "0x0007002c", debugName: "Space")
|
||||
final usbHidMatch = RegExp(r'usbhidusage: "0x([0-9a-f]+)"').firstMatch(normalized);
|
||||
if (usbHidMatch != null) {
|
||||
final usbHidCode = usbHidMatch.group(1)!;
|
||||
final key = _usbHidKeyMap[usbHidCode];
|
||||
if (key != null) return key;
|
||||
final code = int.tryParse(usbHidMatch.group(1)!, radix: 16);
|
||||
if (code != null) return PhysicalKeyboardKey(code);
|
||||
}
|
||||
|
||||
// Try direct name matches
|
||||
|
||||
@@ -30,6 +30,21 @@ class WatchTogetherProvider with ChangeNotifier {
|
||||
String _displayName = 'User';
|
||||
String? _lastHandledCurrentPlaybackKey;
|
||||
|
||||
// Coalesce rapid-fire notifyListeners() calls into a single rebuild per frame.
|
||||
// During Watch Together join, 4-5 notifications fire within milliseconds;
|
||||
// this batches them into one rebuild to avoid overwhelming low-end devices.
|
||||
bool _notifyScheduled = false;
|
||||
|
||||
@override
|
||||
void notifyListeners() {
|
||||
if (_notifyScheduled) return;
|
||||
_notifyScheduled = true;
|
||||
scheduleMicrotask(() {
|
||||
_notifyScheduled = false;
|
||||
super.notifyListeners();
|
||||
});
|
||||
}
|
||||
|
||||
// Host reconnect grace period
|
||||
Timer? _hostReconnectTimer;
|
||||
bool _isWaitingForHostReconnect = false;
|
||||
|
||||
@@ -316,10 +316,11 @@ class WatchTogetherSyncManager {
|
||||
_clockOffset = 0;
|
||||
_pendingPingTimestamp = null;
|
||||
|
||||
// Initial burst of 3 pings for fast convergence
|
||||
// Initial burst of 2 pings for convergence, with wider spacing to reduce
|
||||
// main-thread pressure during the join event storm
|
||||
int burstCount = 0;
|
||||
Timer.periodic(const Duration(milliseconds: 200), (timer) {
|
||||
if (burstCount >= 3 || _player == null) {
|
||||
Timer.periodic(const Duration(milliseconds: 500), (timer) {
|
||||
if (burstCount >= 2 || _player == null) {
|
||||
timer.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:provider/provider.dart';
|
||||
|
||||
import '../../i18n/strings.g.dart';
|
||||
import '../../utils/dialogs.dart';
|
||||
import '../../utils/platform_detector.dart';
|
||||
import '../../utils/snackbar_helper.dart';
|
||||
import '../../widgets/overlay_sheet.dart';
|
||||
import '../models/watch_session.dart';
|
||||
@@ -85,10 +86,12 @@ class _SessionIndicator extends StatelessWidget {
|
||||
children: [
|
||||
// Sync indicator or group icon
|
||||
if (isSyncing)
|
||||
const SizedBox(
|
||||
SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white),
|
||||
child: PlatformDetector.isTV()
|
||||
? const Icon(Symbols.sync_rounded, size: 16, color: Colors.white)
|
||||
: const CircularProgressIndicator(strokeWidth: 2, color: Colors.white),
|
||||
)
|
||||
else
|
||||
Icon(Symbols.group, size: 18, color: isHost ? theme.colorScheme.primary : Colors.white),
|
||||
@@ -230,7 +233,13 @@ class _SessionMenuSheet extends StatelessWidget {
|
||||
title: Text(p.displayName),
|
||||
subtitle: p.isHost ? Text(t.watchTogether.host) : null,
|
||||
trailing: p.isBuffering
|
||||
? const SizedBox(width: 16, height: 16, child: CircularProgressIndicator(strokeWidth: 2))
|
||||
? SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: PlatformDetector.isTV()
|
||||
? const Icon(Symbols.hourglass_empty_rounded, size: 16)
|
||||
: const CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: null,
|
||||
dense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
@@ -388,10 +397,12 @@ class SyncingIndicator extends StatelessWidget {
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const SizedBox(
|
||||
SizedBox(
|
||||
width: 14,
|
||||
height: 14,
|
||||
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white),
|
||||
child: PlatformDetector.isTV()
|
||||
? const Icon(Symbols.sync_rounded, size: 14, color: Colors.white)
|
||||
: const CircularProgressIndicator(strokeWidth: 2, color: Colors.white),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(t.watchTogether.syncing, style: const TextStyle(color: Colors.white, fontSize: 12)),
|
||||
|
||||
@@ -63,10 +63,14 @@ class _HorizontalScrollWithArrowsState extends State<HorizontalScrollWithArrows>
|
||||
}
|
||||
|
||||
final position = _scrollController.position;
|
||||
setState(() {
|
||||
_canScrollLeft = position.pixels > 0;
|
||||
_canScrollRight = position.pixels < position.maxScrollExtent;
|
||||
});
|
||||
final newLeft = position.pixels > 0;
|
||||
final newRight = position.pixels < position.maxScrollExtent;
|
||||
if (newLeft != _canScrollLeft || newRight != _canScrollRight) {
|
||||
setState(() {
|
||||
_canScrollLeft = newLeft;
|
||||
_canScrollRight = newRight;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _animateScroll(double direction) {
|
||||
|
||||
+17
-52
@@ -172,14 +172,13 @@ class MediaCardState extends State<MediaCard> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final settingsProvider = context.watch<SettingsProvider>();
|
||||
final ViewMode viewMode;
|
||||
if (widget.forceListMode) {
|
||||
viewMode = ViewMode.list;
|
||||
} else if (widget.forceGridMode) {
|
||||
viewMode = ViewMode.grid;
|
||||
} else {
|
||||
viewMode = settingsProvider.viewMode;
|
||||
viewMode = context.select<SettingsProvider, ViewMode>((s) => s.viewMode);
|
||||
}
|
||||
|
||||
final semanticLabel = _buildSemanticLabel();
|
||||
@@ -195,7 +194,7 @@ class MediaCardState extends State<MediaCard> {
|
||||
onLongPress: _showContextMenu,
|
||||
onSecondaryTapDown: _storeTapPosition,
|
||||
onSecondaryTap: _showContextMenu,
|
||||
density: settingsProvider.libraryDensity,
|
||||
density: context.select<SettingsProvider, LibraryDensity>((s) => s.libraryDensity),
|
||||
isOffline: widget.isOffline,
|
||||
localPosterPath: localPosterPath,
|
||||
showServerName: widget.showServerName,
|
||||
@@ -352,7 +351,7 @@ class _MediaCardList extends StatelessWidget {
|
||||
final base = _basePosterWidth();
|
||||
// For episodes with thumbnail mode, use wider width to maintain reasonable thumbnail size
|
||||
if (item is PlexMetadata) {
|
||||
final mode = context.watch<SettingsProvider>().episodePosterMode;
|
||||
final mode = context.select<SettingsProvider, EpisodePosterMode>((s) => s.episodePosterMode);
|
||||
if ((item as PlexMetadata).usesWideAspectRatio(mode)) {
|
||||
return base * 1.6; // Wider for 16:9 thumbnails
|
||||
}
|
||||
@@ -364,7 +363,7 @@ class _MediaCardList extends StatelessWidget {
|
||||
final base = _basePosterWidth();
|
||||
// For episodes with thumbnail mode, use 16:9 aspect ratio
|
||||
if (item is PlexMetadata) {
|
||||
final mode = context.watch<SettingsProvider>().episodePosterMode;
|
||||
final mode = context.select<SettingsProvider, EpisodePosterMode>((s) => s.episodePosterMode);
|
||||
if ((item as PlexMetadata).usesWideAspectRatio(mode)) {
|
||||
// 16:9: height = width * 9/16 = base * 1.6 * 9/16 = base * 0.9
|
||||
return base * 0.9;
|
||||
@@ -627,7 +626,7 @@ class _MediaCardList extends StatelessWidget {
|
||||
],
|
||||
// Summary (hidden when spoiler protection is active)
|
||||
if (!(item is PlexMetadata &&
|
||||
context.watch<SettingsProvider>().hideSpoilers &&
|
||||
context.select<SettingsProvider, bool>((s) => s.hideSpoilers) &&
|
||||
(item as PlexMetadata).shouldHideSpoiler) &&
|
||||
item.summary != null) ...[
|
||||
Text(
|
||||
@@ -702,10 +701,10 @@ Widget _buildPosterImage(
|
||||
localFilePath: localPosterPath,
|
||||
);
|
||||
} else if (item is PlexMetadata) {
|
||||
final settingsProvider = context.watch<SettingsProvider>();
|
||||
final episodePosterMode = settingsProvider.episodePosterMode;
|
||||
final episodePosterMode = context.select<SettingsProvider, EpisodePosterMode>((s) => s.episodePosterMode);
|
||||
final hideSpoilers = context.select<SettingsProvider, bool>((s) => s.hideSpoilers);
|
||||
final shouldBlur =
|
||||
settingsProvider.hideSpoilers &&
|
||||
hideSpoilers &&
|
||||
item.shouldHideSpoiler &&
|
||||
episodePosterMode == EpisodePosterMode.episodeThumbnail;
|
||||
posterUrl = item.posterThumb(mode: episodePosterMode, mixedHubContext: mixedHubContext);
|
||||
@@ -842,7 +841,7 @@ class _MediaCardHelpers {
|
||||
|
||||
/// Builds watch progress overlay (checkmark for watched, progress bar for in-progress)
|
||||
static Widget buildWatchProgress(BuildContext context, PlexMetadata metadata) {
|
||||
final showUnwatchedCount = context.watch<SettingsProvider>().showUnwatchedCount;
|
||||
final showUnwatchedCount = context.select<SettingsProvider, bool>((s) => s.showUnwatchedCount);
|
||||
|
||||
final hasActiveProgress =
|
||||
metadata.viewOffset != null &&
|
||||
@@ -1066,55 +1065,21 @@ class _ClickableTextState extends State<_ClickableText> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Skeleton loader widget with subtle opacity pulse animation
|
||||
class SkeletonLoader extends StatefulWidget {
|
||||
/// Static skeleton placeholder with a fixed semi-transparent fill.
|
||||
class SkeletonLoader extends StatelessWidget {
|
||||
final Widget? child;
|
||||
final BorderRadius? borderRadius;
|
||||
|
||||
const SkeletonLoader({super.key, this.child, this.borderRadius});
|
||||
|
||||
@override
|
||||
State<SkeletonLoader> createState() => _SkeletonLoaderState();
|
||||
}
|
||||
|
||||
class _SkeletonLoaderState extends State<SkeletonLoader> with SingleTickerProviderStateMixin {
|
||||
late AnimationController _animationController;
|
||||
late Animation<double> _animation;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_animationController = AnimationController(duration: const Duration(milliseconds: 1500), vsync: this);
|
||||
_animation = Tween<double>(
|
||||
begin: 0.3,
|
||||
end: 0.7,
|
||||
).animate(CurvedAnimation(parent: _animationController, curve: Curves.easeInOut));
|
||||
_animationController.repeat(reverse: true);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_animationController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: _animation,
|
||||
builder: (context, child) {
|
||||
return Semantics(
|
||||
label: "skeleton-loader",
|
||||
identifier: "skeleton-loader",
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.onSurface.withValues(alpha: _animation.value * 0.15),
|
||||
borderRadius: widget.borderRadius ?? BorderRadius.circular(tokens(context).radiusSm),
|
||||
),
|
||||
child: widget.child,
|
||||
),
|
||||
);
|
||||
},
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.075),
|
||||
borderRadius: borderRadius ?? BorderRadius.circular(tokens(context).radiusSm),
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import 'package:cached_network_image/cached_network_image.dart';
|
||||
import '../services/image_cache_service.dart';
|
||||
import '../../services/plex_client.dart';
|
||||
import '../utils/plex_image_helper.dart';
|
||||
import 'media_card.dart';
|
||||
|
||||
/// Set to `true` to blur all artwork (for store screenshots).
|
||||
const kBlurArtwork = false;
|
||||
@@ -350,21 +349,25 @@ class PlexOptimizedImage extends StatelessWidget {
|
||||
alignment: alignment,
|
||||
errorBuilder: (context, error, stackTrace) => _buildErrorWidget(context, error),
|
||||
frameBuilder: (context, child, frame, wasSynchronouslyLoaded) {
|
||||
if (wasSynchronouslyLoaded || frame != null) return child;
|
||||
return _buildPlaceholder(context);
|
||||
if (wasSynchronouslyLoaded) return child;
|
||||
return AnimatedSwitcher(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
child: frame != null
|
||||
? child
|
||||
: _buildPlaceholder(context),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPlaceholder(BuildContext _) {
|
||||
return SizedBox(
|
||||
Widget _buildPlaceholder(BuildContext context) {
|
||||
return Container(
|
||||
width: width,
|
||||
height: height,
|
||||
child: SkeletonLoader(
|
||||
child: fallbackIcon != null
|
||||
? Center(child: AppIcon(fallbackIcon!, fill: 1, size: 40, color: Colors.white54))
|
||||
: null,
|
||||
),
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
child: fallbackIcon != null
|
||||
? Center(child: AppIcon(fallbackIcon!, fill: 1, size: 40, color: Colors.white54))
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -668,10 +668,11 @@ packages:
|
||||
material_symbols_icons:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: material_symbols_icons
|
||||
sha256: c62b15f2b3de98d72cbff0148812f5ef5159f05e61fc9f9a089ec2bb234df082
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
path: "."
|
||||
ref: "1d8cd83"
|
||||
resolved-ref: "1d8cd8325db29691a01738a25f220dd3515bd1e2"
|
||||
url: "https://github.com/edde746/material_symbols_icons"
|
||||
source: git
|
||||
version: "4.2906.0"
|
||||
meta:
|
||||
dependency: transitive
|
||||
|
||||
+5
-1
@@ -1,7 +1,7 @@
|
||||
name: plezy
|
||||
description: "A beautiful Plex client for Flutter"
|
||||
publish_to: "none"
|
||||
version: 1.29.0+61
|
||||
version: 1.30.0+62
|
||||
|
||||
environment:
|
||||
sdk: ^3.8.1
|
||||
@@ -87,6 +87,10 @@ dependency_overrides:
|
||||
url: https://github.com/edde746/auto_updater
|
||||
ref: 9e150f7
|
||||
path: packages/auto_updater_windows
|
||||
material_symbols_icons:
|
||||
git:
|
||||
url: https://github.com/edde746/material_symbols_icons
|
||||
ref: 1d8cd83
|
||||
|
||||
flutter:
|
||||
uses-material-design: true
|
||||
|
||||
Reference in New Issue
Block a user