Refine TV admin navigation and simulation flow
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -41,7 +41,9 @@ class _HomeViewState extends ConsumerState<HomeView> {
|
|||||||
|
|
||||||
final FocusNode _homeFocusNode = FocusNode(debugLabel: 'home_tv_root');
|
final FocusNode _homeFocusNode = FocusNode(debugLabel: 'home_tv_root');
|
||||||
final List<LogicalKeyboardKey> _recentKeys = [];
|
final List<LogicalKeyboardKey> _recentKeys = [];
|
||||||
|
final List<LogicalKeyboardKey> _simulationShortcutKeys = [];
|
||||||
Timer? _comboResetTimer;
|
Timer? _comboResetTimer;
|
||||||
|
Timer? _simulationShortcutTimer;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -57,6 +59,7 @@ class _HomeViewState extends ConsumerState<HomeView> {
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_comboResetTimer?.cancel();
|
_comboResetTimer?.cancel();
|
||||||
|
_simulationShortcutTimer?.cancel();
|
||||||
_homeFocusNode.dispose();
|
_homeFocusNode.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
@@ -79,6 +82,50 @@ class _HomeViewState extends ConsumerState<HomeView> {
|
|||||||
if (event is! KeyDownEvent) return KeyEventResult.ignored;
|
if (event is! KeyDownEvent) return KeyEventResult.ignored;
|
||||||
|
|
||||||
final key = event.logicalKey;
|
final key = event.logicalKey;
|
||||||
|
final isSimulating = ref.read(mockTimeOffsetProvider) != Duration.zero;
|
||||||
|
if (isSimulating && key == LogicalKeyboardKey.arrowLeft) {
|
||||||
|
_comboResetTimer?.cancel();
|
||||||
|
_recentKeys.clear();
|
||||||
|
_simulationShortcutTimer?.cancel();
|
||||||
|
_simulationShortcutTimer = Timer(
|
||||||
|
const Duration(seconds: 2),
|
||||||
|
_resetSimulationShortcut,
|
||||||
|
);
|
||||||
|
_simulationShortcutKeys.add(key);
|
||||||
|
if (_simulationShortcutKeys.length > 2) {
|
||||||
|
_simulationShortcutKeys.removeAt(0);
|
||||||
|
}
|
||||||
|
if (_matchesSimulationShortcut()) {
|
||||||
|
_resetSimulationShortcut();
|
||||||
|
ref.read(mockTimeOffsetProvider.notifier).state = Duration.zero;
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||||
|
if (!mounted) return;
|
||||||
|
await Navigator.of(context).push(
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (_) => const AdminScreen(
|
||||||
|
initialTab: 4,
|
||||||
|
focusSelectedTabOnOpen: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (mounted) {
|
||||||
|
_homeFocusNode.requestFocus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return KeyEventResult.handled;
|
||||||
|
} else if (isSimulating) {
|
||||||
|
_resetSimulationShortcut();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSimulating &&
|
||||||
|
(key == LogicalKeyboardKey.escape ||
|
||||||
|
key == LogicalKeyboardKey.goBack ||
|
||||||
|
key == LogicalKeyboardKey.browserBack)) {
|
||||||
|
ref.read(mockTimeOffsetProvider.notifier).state = Duration.zero;
|
||||||
|
return KeyEventResult.handled;
|
||||||
|
}
|
||||||
|
|
||||||
if (!_isComboKey(key)) {
|
if (!_isComboKey(key)) {
|
||||||
_resetCombo();
|
_resetCombo();
|
||||||
return KeyEventResult.ignored;
|
return KeyEventResult.ignored;
|
||||||
@@ -135,6 +182,17 @@ class _HomeViewState extends ConsumerState<HomeView> {
|
|||||||
_recentKeys.clear();
|
_recentKeys.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _matchesSimulationShortcut() {
|
||||||
|
return _simulationShortcutKeys.length == 2 &&
|
||||||
|
_simulationShortcutKeys[0] == LogicalKeyboardKey.arrowLeft &&
|
||||||
|
_simulationShortcutKeys[1] == LogicalKeyboardKey.arrowLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _resetSimulationShortcut() {
|
||||||
|
_simulationShortcutTimer?.cancel();
|
||||||
|
_simulationShortcutKeys.clear();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Audio trigger listener
|
// Audio trigger listener
|
||||||
@@ -189,8 +247,6 @@ class _HomeViewState extends ConsumerState<HomeView> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
final isSimulating = ref.watch(mockTimeOffsetProvider) != Duration.zero;
|
|
||||||
|
|
||||||
return Focus(
|
return Focus(
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
focusNode: _homeFocusNode,
|
focusNode: _homeFocusNode,
|
||||||
@@ -206,32 +262,6 @@ class _HomeViewState extends ConsumerState<HomeView> {
|
|||||||
},
|
},
|
||||||
child: screen,
|
child: screen,
|
||||||
),
|
),
|
||||||
|
|
||||||
if (isSimulating)
|
|
||||||
Positioned(
|
|
||||||
right: 64,
|
|
||||||
bottom: 64,
|
|
||||||
child: ElevatedButton.icon(
|
|
||||||
onPressed: () {
|
|
||||||
ref.read(mockTimeOffsetProvider.notifier).state = Duration.zero;
|
|
||||||
},
|
|
||||||
icon: const Icon(Icons.cancel, color: Colors.white),
|
|
||||||
label: const Text(
|
|
||||||
'BATALKAN SIMULASI',
|
|
||||||
style: TextStyle(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
letterSpacing: 2,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Colors.red.shade800,
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
|
||||||
elevation: 10,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user