Skip to content

Commit ef75b6a

Browse files
author
Igor Demyanov
committed
Add ButtonsHint on main screen
1 parent 81d6681 commit ef75b6a

10 files changed

Lines changed: 277 additions & 131 deletions

File tree

backend/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'dslideshow_backend'
2-
version: 9.5.1+1
2+
version: 9.5.2
33
description: A sample command-line application
44
publish_to: none
55
environment:

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#
1+
# 9.5.2
22
Fix CurrentTimeWidget background
33
Fix ButtonsHint colors
4+
Add ButtonsHint on main screen
45

56
# 9.5.1
67
Fix SystemMetricsWidget padding

dslideshow_flutter/lib/features/header/presentation/widgets/buttons_hint/buttons_hint.dart

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ import 'package:dslideshow_flutter/features/theme/presentation/theme.dart';
77
class ButtonsHintWidget extends StatelessWidget {
88
final SlideShowButtons buttons;
99

10-
// Цвета HUD
11-
static const Color _kHudColor = ThemeColors.buttonsHintColor;
12-
static const Color _kHudPressedColor = ThemeColors.buttonsHintPressedColor ;
13-
static const Color _kHudBg = ThemeColors.buttonsHintBackgroundColor ;
14-
1510
const ButtonsHintWidget({
1611
required this.buttons,
1712
super.key,
@@ -25,8 +20,8 @@ class ButtonsHintWidget extends StatelessWidget {
2520

2621
return Container(
2722
decoration: BoxDecoration(
28-
color: _kHudBg,
29-
border: Border.all(color: _kHudColor.withAlpha((255.0 * 0.5).round()), width: 1),
23+
color: ThemeColors.buttonsHintBackgroundColor,
24+
border: Border.all(color: ThemeColors.buttonsHintColor.withAlpha((255.0 * 0.5).round()), width: 1),
3025
borderRadius: BorderRadius.circular(4),
3126
),
3227
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
@@ -48,7 +43,7 @@ class ButtonsHintWidget extends StatelessWidget {
4843
}
4944

5045
Widget _buildHudButton(IconData icon, bool isPressed) {
51-
final color = isPressed ? _kHudPressedColor : _kHudColor;
46+
final color = isPressed ? ThemeColors.buttonsHintPressedColor : ThemeColors.buttonsHintColor;
5247

5348
return Container(
5449
padding: const EdgeInsets.all(4),

dslideshow_flutter/lib/features/header/presentation/widgets/buttons_hint/buttons_hint_bloc.dart

Lines changed: 117 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import 'dart:async';
22

33
import 'package:bloc/bloc.dart';
44
import 'package:dslideshow_backend/command.dart';
5+
import 'package:dslideshow_backend/config.dart';
6+
import 'package:dslideshow_flutter/features/slideshow/presentation/bloc/status/slideshow_status_bloc.dart';
7+
import 'package:dslideshow_flutter/features/theme/presentation/src/theme_colors.dart';
58
import 'package:dslideshow_flutter/src/service/frontend.dart';
69
import 'package:flutter/material.dart';
710
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -12,30 +15,72 @@ part 'buttons_hint_bloc.freezed.dart';
1215

1316
class ButtonsHintBloc extends Bloc<ButtonsHintEvent, ButtonsHintState> {
1417
final FrontendService frontendService;
18+
final SlideshowStatusBloc statusBloc;
19+
final AppConfig appConfig;
1520

1621
late StreamSubscription<ButtonEvent> _onButtonEventSubscription;
22+
late StreamSubscription _onStatusSubscription;
23+
late SlideshowStatusState _currentStatus;
24+
late Timer _hideHintTimer;
25+
DateTime _lastButtonActive = DateTime.now();
1726

18-
ButtonsHintBloc({required this.frontendService})
19-
: super(
20-
ButtonsHintDisplayState(
21-
isShow: false,
22-
normalColor: Colors.white,
23-
pushColor: Colors.blue.shade500,
24-
button0Icon: Icons.arrow_back,
25-
button0isPush: false,
26-
button1Icon: Icons.arrow_circle_down,
27-
button1isPush: false,
28-
button2Icon: Icons.arrow_circle_up,
29-
button2isPush: false,
30-
button3Icon: Icons.check_circle_outline_outlined,
31-
button3isPush: false,
32-
),
33-
) {
27+
ButtonsHintBloc({
28+
required this.frontendService,
29+
required this.statusBloc,
30+
required this.appConfig,
31+
}) : super(
32+
ButtonsHintDisplayState(
33+
isShow: false,
34+
normalColor: ThemeColors.buttonsHintColor,
35+
pushColor: ThemeColors.buttonsHintPressedColor,
36+
button0Icon: Icons.arrow_back,
37+
button0isPush: false,
38+
button1Icon: Icons.arrow_circle_down,
39+
button1isPush: false,
40+
button2Icon: Icons.arrow_circle_up,
41+
button2isPush: false,
42+
button3Icon: Icons.check_circle_outline_outlined,
43+
button3isPush: false,
44+
),
45+
) {
3446
on<ButtonsHintPushButtonEvent>(_onPushButtonEvent);
3547
on<ButtonsHintShowEvent>(_onShowEvent);
3648
_onButtonEventSubscription = frontendService.onButtonEvent.listen(
3749
_onButtonEvent,
3850
);
51+
on<ButtonsHintUpdateButtonsEvent>(_onUpdateButtons);
52+
_hideHintTimer = Timer(Duration(seconds: 5), _hideHint);
53+
_startAutoHideHint();
54+
_currentStatus = statusBloc.state;
55+
_onStatusChanged(_currentStatus, true);
56+
_onStatusSubscription = statusBloc.stream.listen(_onStatusChanged);
57+
}
58+
59+
void _startAutoHideHint([bool isForce = false]) {
60+
if (isForce || !_hideHintTimer.isActive) {
61+
_hideHintTimer = Timer(Duration(seconds: 5), _hideHint);
62+
}
63+
}
64+
65+
void _hideHint() {
66+
if (!_currentStatus.isMenu) {
67+
if ((DateTime.now().difference(_lastButtonActive).inSeconds > 5)) {
68+
add(ButtonsHintShowEvent(isShow: false));
69+
} else {
70+
_startAutoHideHint(true);
71+
}
72+
}
73+
}
74+
75+
FutureOr<void> _onStatusChanged(
76+
SlideshowStatusState state, [
77+
bool isForceUpdate = false,
78+
]) {
79+
if (isForceUpdate || _currentStatus.isMenu != state.isMenu) {
80+
_currentStatus = state;
81+
add(ButtonsHintUpdateButtonsEvent());
82+
}
83+
_currentStatus = state;
3984
}
4085

4186
FutureOr<void> _onPushButtonEvent(
@@ -67,15 +112,19 @@ class ButtonsHintBloc extends Bloc<ButtonsHintEvent, ButtonsHintState> {
67112
}
68113

69114
void _onButtonEvent(ButtonEvent event) {
115+
_lastButtonActive = DateTime.now();
70116
if (event.event == ButtonEventType.released) {
71117
add(ButtonsHintPushButtonEvent(button: event.button));
72118
}
119+
if (!_currentStatus.isMenu && !state.isShow){
120+
_onStatusChanged(_currentStatus, true);
121+
}
73122
}
74123

75124
@override
76125
Future<void> close() {
77126
_onButtonEventSubscription.cancel();
78-
127+
_onStatusSubscription.cancel();
79128
return super.close();
80129
}
81130

@@ -85,4 +134,55 @@ class ButtonsHintBloc extends Bloc<ButtonsHintEvent, ButtonsHintState> {
85134
) {
86135
emit(state.copyWith(isShow: event.isShow));
87136
}
137+
138+
FutureOr<void> _onUpdateButtons(
139+
ButtonsHintUpdateButtonsEvent event,
140+
Emitter<ButtonsHintState> emit,
141+
) {
142+
if (_currentStatus.isMenu) {
143+
emit(
144+
state.copyWith(
145+
isShow: true,
146+
button0Icon: Icons.arrow_back,
147+
button1Icon: Icons.arrow_circle_down,
148+
button2Icon: Icons.arrow_circle_up,
149+
button3Icon: Icons.check_circle_outline_outlined,
150+
),
151+
);
152+
} else {
153+
emit(
154+
state.copyWith(
155+
isShow: true,
156+
button0Icon: getIconDataBySlideshowAction(
157+
appConfig.slideshow.buttons.button0.action,
158+
),
159+
button1Icon: getIconDataBySlideshowAction(
160+
appConfig.slideshow.buttons.button1.action,
161+
),
162+
button2Icon: getIconDataBySlideshowAction(
163+
appConfig.slideshow.buttons.button2.action,
164+
),
165+
button3Icon: getIconDataBySlideshowAction(
166+
appConfig.slideshow.buttons.button3.action,
167+
),
168+
),
169+
);
170+
_startAutoHideHint(true);
171+
}
172+
}
173+
174+
IconData getIconDataBySlideshowAction(SlideshowAction action) {
175+
switch (action) {
176+
case SlideshowAction.none:
177+
return Icons.cancel;
178+
case SlideshowAction.pause:
179+
return Icons.pause;
180+
case SlideshowAction.showInfo:
181+
return Icons.info;
182+
case SlideshowAction.showMenu:
183+
return Icons.menu;
184+
case SlideshowAction.toggleScreen:
185+
return Icons.power_off;
186+
}
187+
}
88188
}

dslideshow_flutter/lib/features/header/presentation/widgets/buttons_hint/buttons_hint_bloc.freezed.dart

Lines changed: 50 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dslideshow_flutter/lib/features/header/presentation/widgets/buttons_hint/buttons_hint_event.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ class ButtonsHintEvent with _$ButtonsHintEvent {
99
const factory ButtonsHintEvent.pushButton({
1010
required ButtonType button,
1111
}) = ButtonsHintPushButtonEvent;
12+
const factory ButtonsHintEvent.updateButtons() = ButtonsHintUpdateButtonsEvent;
1213
}

0 commit comments

Comments
 (0)