Skip to content

Commit

Permalink
feat: Option to hide camera name, server name and video status label
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa committed Sep 22, 2024
1 parent 2ef2cc4 commit 0efdd16
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 17 deletions.
7 changes: 5 additions & 2 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
"layoutName": "Layout name",
"layoutNameHint": "First floor",
"layoutTypeLabel": "Layout type",
"clearLayout": "Clear {amount} devices",
"clearLayout": "Remove {amount} {amount, plural, =1{device} other{devices}}",
"@clearLayout": {
"placeholders": {
"amount": {
Expand Down Expand Up @@ -349,7 +349,7 @@
"toDate": "To",
"today": "Today",
"yesterday": "Yesterday",
"never": "never",
"never": "Never",
"fromToDate": "From {from} to {to}",
"@fromToDate": {
"placeholders": {
Expand Down Expand Up @@ -639,6 +639,9 @@
"initialDeviceVolume": "Initial Camera Volume",
"runVideoTest": "Run Video Test",
"runVideoTestDescription": "Run a video test to check the state of video playback.",
"showCameraName": "Show Camera Name",
"always": "Always",
"onHover": "On hover",
"@@LOCALIZATION": {},
"dateLanguage": "Date and Language",
"language": "Language",
Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,9 @@
"initialDeviceVolume": "Initial Camera Volume",
"runVideoTest": "Run Video Test",
"runVideoTestDescription": "Run a video test to check the state of video playback.",
"showCameraName": "Show Camera Name",
"always": "Always",
"onHover": "On hover",
"@@LOCALIZATION": {},
"dateLanguage": "Date et Langue",
"language": "Langue",
Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,9 @@
"initialDeviceVolume": "Initial Camera Volume",
"runVideoTest": "Run Video Test",
"runVideoTestDescription": "Run a video test to check the state of video playback.",
"showCameraName": "Show Camera Name",
"always": "Always",
"onHover": "On hover",
"@@LOCALIZATION": {},
"dateLanguage": "Date and Language",
"language": "Language",
Expand Down
5 changes: 4 additions & 1 deletion lib/l10n/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
"layoutName": "Nome do layout",
"layoutNameHint": "Primeiro andar",
"layoutTypeLabel": "Tipo do layout",
"clearLayout": "Limpar {amount} câmeras",
"clearLayout": "Remover {amount} {amount, plural, =1{câmera} other{câmeras}}",
"@clearLayout": {
"placeholders": {
"amount": {
Expand Down Expand Up @@ -639,6 +639,9 @@
"initialDeviceVolume": "Volume Inicial da Câmera",
"runVideoTest": "Testar Vídeo",
"runVideoTestDescription": "Teste o vídeo para verificar o estado da reprodução de vídeo.",
"showCameraName": "Show Camera Name",
"always": "Always",
"onHover": "On hover",
"@@LOCALIZATION": {},
"dateLanguage": "Data e Idioma",
"language": "Idioma",
Expand Down
36 changes: 33 additions & 3 deletions lib/providers/settings_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import 'package:bluecherry_client/screens/settings/shared/options_chooser_tile.d
import 'package:bluecherry_client/utils/logging.dart';
import 'package:bluecherry_client/utils/storage.dart';
import 'package:bluecherry_client/utils/video_player.dart';
import 'package:bluecherry_client/widgets/hover_button.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand Down Expand Up @@ -57,14 +58,36 @@ enum DisplayOn {
onHover,
never;

static Iterable<Option<DisplayOn>> get options {
String locale(BuildContext context) {
final loc = AppLocalizations.of(context);
return switch (this) {
DisplayOn.always => loc.always,
DisplayOn.onHover => loc.onHover,
DisplayOn.never => loc.never,
};
}

static Iterable<Option<DisplayOn>> options(BuildContext context) {
return values.map<Option<DisplayOn>>((value) {
return Option(
value: value,
text: value.name,
text: value.locale(context),
);
});
}

T build<T>(T child, T never, Set<ButtonStates> states) {
if (this == DisplayOn.never) {
return never;
} else if (this == DisplayOn.always) {
return child;
} else if (this == DisplayOn.onHover) {
if (states.isHovering) return child;
return never;
} else {
throw UnimplementedError('DisplayOn $this not implemented');
}
}
}

class _SettingsOption<T> {
Expand Down Expand Up @@ -292,11 +315,17 @@ class SettingsProvider extends UnityProvider {
saveAs: (value) => value.index.toString(),
);
final kShowServerNameOn = _SettingsOption<DisplayOn>(
def: DisplayOn.always,
def: DisplayOn.onHover,
key: 'devices.show_server_name_on',
loadFrom: (value) => DisplayOn.values[int.parse(value)],
saveAs: (value) => value.index.toString(),
);
final kShowVideoStatusLabelOn = _SettingsOption<DisplayOn>(
def: DisplayOn.always,
key: 'devices.show_video_status_label_on',
loadFrom: (value) => DisplayOn.values[int.parse(value)],
saveAs: (value) => value.index.toString(),
);

// Downloads
final kDownloadOnMobileData = _SettingsOption<bool>(
Expand Down Expand Up @@ -545,6 +574,7 @@ class SettingsProvider extends UnityProvider {
kInitialDevicesVolume,
kShowCameraNameOn,
kShowServerNameOn,
kShowVideoStatusLabelOn,
kDownloadOnMobileData,
kChooseLocationEveryTime,
kAllowAppCloseWhenDownloading,
Expand Down
30 changes: 22 additions & 8 deletions lib/screens/layouts/desktop/viewport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,17 @@ class _DesktopTileViewportState extends State<DesktopTileViewport> {
),
child: RichText(
text: TextSpan(
text: widget.device.name,
style: theme.textTheme.labelLarge?.copyWith(
color: Colors.white,
shadows: outlinedText(),
),
children: [
if (states.isHovering)
settings.kShowCameraNameOn.value.build(
TextSpan(text: widget.device.name),
const TextSpan(),
states,
),
settings.kShowServerNameOn.value.build(
TextSpan(
text: '\n'
'${widget.device.externalData?.rackName ?? widget.device.server.name}',
Expand All @@ -200,6 +204,9 @@ class _DesktopTileViewportState extends State<DesktopTileViewport> {
shadows: outlinedText(),
),
),
const TextSpan(),
states,
),
if (states.isHovering && showDebugInfo)
TextSpan(
text:
Expand Down Expand Up @@ -307,13 +314,20 @@ class _DesktopTileViewportState extends State<DesktopTileViewport> {
const Spacer(),
if (states.isHovering) reloadButton,
],
Padding(
padding: const EdgeInsetsDirectional.only(
start: 6.0,
end: 6.0,
bottom: 6.0,
settings.kShowVideoStatusLabelOn.value.build(
Padding(
padding: const EdgeInsetsDirectional.only(
start: 6.0,
end: 6.0,
bottom: 6.0,
),
child: VideoStatusLabel(
video: video,
device: widget.device,
),
),
child: VideoStatusLabel(video: video, device: widget.device),
const SizedBox.shrink(),
states,
),
]),
),
Expand Down
15 changes: 12 additions & 3 deletions lib/screens/settings/server_and_devices.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import 'package:bluecherry_client/models/device.dart';
import 'package:bluecherry_client/models/server.dart';
import 'package:bluecherry_client/providers/settings_provider.dart';
import 'package:bluecherry_client/screens/layouts/desktop/viewport.dart';
import 'package:bluecherry_client/screens/layouts/video_status_label.dart';
Expand Down Expand Up @@ -410,7 +411,8 @@ class _DevicesSettingsState extends State<DevicesSettings> {
controller: _testPlayer,
device: Device.dump(
name: 'Camera Viewport',
),
id: 1,
)..server = Server.dump(name: 'Server Name'),
onFitChanged: (_) {},
showDebugInfo: true,
),
Expand All @@ -421,16 +423,23 @@ class _DevicesSettingsState extends State<DevicesSettings> {
title: 'Show Camera Name',
icon: Icons.camera_outlined,
value: settings.kShowCameraNameOn.value,
values: DisplayOn.options,
values: DisplayOn.options(context),
onChanged: (v) => settings.kShowCameraNameOn.value = v,
),
OptionsChooserTile<DisplayOn>(
title: 'Show Server Name',
icon: Icons.dvr,
value: settings.kShowServerNameOn.value,
values: DisplayOn.options,
values: DisplayOn.options(context),
onChanged: (v) => settings.kShowServerNameOn.value = v,
),
OptionsChooserTile<DisplayOn>(
title: 'Show Video Status Label',
icon: Icons.dvr,
value: settings.kShowVideoStatusLabelOn.value,
values: DisplayOn.options(context),
onChanged: (v) => settings.kShowVideoStatusLabelOn.value = v,
),
const SizedBox(height: 20.0),
],
],
Expand Down
4 changes: 4 additions & 0 deletions lib/widgets/hover_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ class HoverButton extends StatefulWidget {
static HoverButtonState of(BuildContext context) {
return context.findAncestorStateOfType<HoverButtonState>()!;
}

static HoverButtonState? maybeOf(BuildContext context) {
return context.findAncestorStateOfType<HoverButtonState>();
}
}

class HoverButtonState extends State<HoverButton> {
Expand Down

0 comments on commit 0efdd16

Please sign in to comment.