refactor: codebase review cleanup
This commit is contained in:
+12
-27
@@ -6,6 +6,7 @@ import 'package:plezy/widgets/app_icon.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../focus/input_mode_tracker.dart';
|
||||
import '../mixins/context_menu_tap_mixin.dart';
|
||||
import '../models/plex_metadata.dart';
|
||||
import '../models/plex_playlist.dart';
|
||||
import '../providers/download_provider.dart';
|
||||
@@ -59,28 +60,12 @@ class MediaCard extends StatefulWidget {
|
||||
State<MediaCard> createState() => MediaCardState();
|
||||
}
|
||||
|
||||
class MediaCardState extends State<MediaCard> {
|
||||
final _contextMenuKey = GlobalKey<MediaContextMenuState>();
|
||||
Offset? _tapPosition;
|
||||
|
||||
void _storeTapPosition(TapDownDetails details) {
|
||||
_tapPosition = details.globalPosition;
|
||||
}
|
||||
|
||||
void _showContextMenu() {
|
||||
_contextMenuKey.currentState?.showContextMenu(context, position: _tapPosition);
|
||||
}
|
||||
|
||||
class MediaCardState extends State<MediaCard> with ContextMenuTapMixin<MediaCard> {
|
||||
/// Public method to trigger tap action (for keyboard/gamepad SELECT)
|
||||
void handleTap() {
|
||||
_handleTap(context);
|
||||
}
|
||||
|
||||
/// Public method to show context menu (for keyboard/gamepad context menu key)
|
||||
void showContextMenu() {
|
||||
_contextMenuKey.currentState?.showContextMenu(context);
|
||||
}
|
||||
|
||||
String _buildSemanticLabel() {
|
||||
final item = widget.item;
|
||||
|
||||
@@ -128,7 +113,7 @@ class MediaCardState extends State<MediaCard> {
|
||||
|
||||
void _handleTap(BuildContext context) async {
|
||||
// Ignore taps while context menu is open to avoid double-activating
|
||||
if (_contextMenuKey.currentState?.isContextMenuOpen == true) {
|
||||
if (contextMenuKey.currentState?.isContextMenuOpen == true) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -190,10 +175,10 @@ class MediaCardState extends State<MediaCard> {
|
||||
item: widget.item,
|
||||
semanticLabel: semanticLabel,
|
||||
onTap: () => _handleTap(context),
|
||||
onTapDown: _storeTapPosition,
|
||||
onLongPress: _showContextMenu,
|
||||
onSecondaryTapDown: _storeTapPosition,
|
||||
onSecondaryTap: _showContextMenu,
|
||||
onTapDown: storeTapPosition,
|
||||
onLongPress: showContextMenuFromTap,
|
||||
onSecondaryTapDown: storeTapPosition,
|
||||
onSecondaryTap: showContextMenuFromTap,
|
||||
density: context.select<SettingsProvider, int>((s) => s.libraryDensity),
|
||||
isOffline: widget.isOffline,
|
||||
localPosterPath: localPosterPath,
|
||||
@@ -203,7 +188,7 @@ class MediaCardState extends State<MediaCard> {
|
||||
// MediaContextMenu as a non-widget helper — only wrap with its key for
|
||||
// programmatic context menu access; gesture callbacks are on InkWell directly.
|
||||
return MediaContextMenu(
|
||||
key: _contextMenuKey,
|
||||
key: contextMenuKey,
|
||||
item: widget.item,
|
||||
onRefresh: widget.onRefresh,
|
||||
onRemoveFromContinueWatching: widget.onRemoveFromContinueWatching,
|
||||
@@ -228,10 +213,10 @@ class MediaCardState extends State<MediaCard> {
|
||||
child: InkWell(
|
||||
canRequestFocus: false,
|
||||
onTap: () => _handleTap(context),
|
||||
onTapDown: _storeTapPosition,
|
||||
onLongPress: _showContextMenu,
|
||||
onSecondaryTapDown: _storeTapPosition,
|
||||
onSecondaryTap: _showContextMenu,
|
||||
onTapDown: storeTapPosition,
|
||||
onLongPress: showContextMenuFromTap,
|
||||
onSecondaryTapDown: storeTapPosition,
|
||||
onSecondaryTap: showContextMenuFromTap,
|
||||
borderRadius: BorderRadius.circular(tokens(context).radiusSm),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(3, 3, 3, 1),
|
||||
|
||||
Reference in New Issue
Block a user