Skip to content

Commit

Permalink
[General Settings] Added validation for sound click
Browse files Browse the repository at this point in the history
  • Loading branch information
rnayabed committed Jun 30, 2022
1 parent 1885da1 commit 510872d
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.stream_pi.server.window.settings.general;

public class GeneralSettingsActionGridRecord {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.stream_pi.server.window.settings.general;

public record GeneralSettingsConnectionRecord(String serverName, int port, String IP) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.stream_pi.server.window.settings.general;

public record GeneralSettingsLocationsRecord() {
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ public void saveSettings(GeneralSettingsRecord newSettingsRecord) throws SevereE

boolean soundOnActionClicked = newSettingsRecord.soundOnActionClickedStatus();

String soundOnActionClickedFilePath = newSettingsRecord.soundOnActionClickedFilePath();


Config config = Config.getInstance();

Expand Down Expand Up @@ -117,29 +115,6 @@ public void saveSettings(GeneralSettingsRecord newSettingsRecord) throws SevereE
}
}

if(soundOnActionClicked)
{
if(soundOnActionClickedFilePath.isBlank())
{
StreamPiAlert alert = new StreamPiAlert(I18N.getString("window.settings.GeneralSettings.soundFileCannotBeEmpty"), StreamPiAlertType.ERROR);
alert.show();

soundOnActionClicked = false;
}
else
{
File soundFile = new File(soundOnActionClickedFilePath);
if(!soundFile.exists() || !soundFile.isFile())
{

StreamPiAlert alert = new StreamPiAlert(I18N.getString("window.settings.GeneralSettings.soundFileNotFound"), StreamPiAlertType.ERROR);
alert.show();

soundOnActionClicked = false;
}
}
}

config.setServerName(newSettingsRecord.serverName());
config.setPort(newSettingsRecord.port());
config.setActionGridActionGap(newSettingsRecord.actionGridActionGap());
Expand All @@ -158,19 +133,17 @@ public void saveSettings(GeneralSettingsRecord newSettingsRecord) throws SevereE
config.setShowAlertsPopup(showAlertsPopup);
config.setStartupOnBoot(startOnBoot);

if(soundOnActionClicked)
{
serverListener.initSoundOnActionClicked();
}

config.setSoundOnActionClickedStatus(soundOnActionClicked);



config.setSoundOnActionClickedFilePath(soundOnActionClickedFilePath);
config.setSoundOnActionClickedFilePath(newSettingsRecord.soundOnActionClickedFilePath());

config.save();

if(soundOnActionClicked)
{
serverListener.initSoundOnActionClicked();
}

loadSettings();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.stream_pi.server.window.settings.general;

import java.util.Locale;

public record GeneralSettingsOthersRecord(Locale currentLanguageLocale, boolean minimiseToSystemTrayOnClose, boolean startOnBoot, boolean showAlertsPopup) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.stream_pi.server.window.settings.general;

public record GeneralSettingsSoundOnActionClickedRecord(boolean soundOnActionClickedStatus, String soundOnActionClickedFilePath) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
import com.stream_pi.server.controller.ServerListener;
import com.stream_pi.server.i18n.I18N;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.uihelper.*;
import com.stream_pi.util.validation.ValidatedControl;
import com.stream_pi.util.validation.ValidationResult;
import com.stream_pi.util.validation.ValidationSupport;
import com.stream_pi.util.validation.Validator;
import javafx.application.HostServices;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
Expand All @@ -24,6 +30,7 @@
import org.controlsfx.control.ToggleSwitch;

import java.awt.*;
import java.io.File;
import java.util.Locale;
import java.util.logging.Logger;

Expand All @@ -41,14 +48,10 @@ public class GeneralSettingsView extends VBox
private final CheckBox actionGridPaneActionBoxGapIsDefaultCheckBox;
private final CheckBox actionGridPaneActionDisplayTextFontSizeIsDefaultCheckBox;
private final ToggleSwitch startOnBootToggleSwitch;
private final HBoxWithSpaceBetween startOnBootHBox;
private final TextField soundOnActionClickedFilePathTextField;
private final ValidatedTextField soundOnActionClickedFilePathTextField;
private final ToggleSwitch soundOnActionClickedToggleSwitch;
private final HBoxWithSpaceBetween soundOnActionClickedToggleSwitchHBox;
private final ToggleSwitch minimiseToSystemTrayOnCloseToggleSwitch;
private final HBoxWithSpaceBetween minimiseToSystemTrayOnCloseHBox;
private final ToggleSwitch showAlertsPopupToggleSwitch;
private final HBoxWithSpaceBetween showAlertsPopupHBox;
private final Button saveButton;
private final Button checkForUpdatesButton;
private final Button factoryResetButton;
Expand Down Expand Up @@ -92,14 +95,10 @@ public GeneralSettingsView(GeneralSettingsViewListener generalSettingsViewListen
actionGridPaneActionDisplayTextFontSizeIsDefaultCheckBox = new CheckBox(I18N.getString("window.settings.GeneralSettings.followProfileDefaults"));

startOnBootToggleSwitch = new ToggleSwitch();
startOnBootHBox = new HBoxWithSpaceBetween(I18N.getString("window.settings.GeneralSettings.startOnBoot"), startOnBootToggleSwitch);
startOnBootHBox.managedProperty().bind(startOnBootHBox.visibleProperty());

soundOnActionClickedToggleSwitch = new ToggleSwitch();
soundOnActionClickedToggleSwitchHBox = new HBoxWithSpaceBetween(I18N.getString("window.settings.GeneralSettings.soundOnActionClicked"), soundOnActionClickedToggleSwitch);


soundOnActionClickedFilePathTextField = new TextField();
soundOnActionClickedFilePathTextField = new ValidatedTextField();

FileChooserField soundOnActionClickedFilePathFileChooserField = new FileChooserField(soundOnActionClickedFilePathTextField,
new FileChooser.ExtensionFilter("Sounds","*.mp3","*.mp4", "*.m4a", "*.m4v","*.wav","*.aif", "*.aiff","*.fxm","*.flv","*.m3u8"));
Expand All @@ -108,13 +107,42 @@ public GeneralSettingsView(GeneralSettingsViewListener generalSettingsViewListen
soundOnActionClickedFilePathFileChooserField.setRememberThis(false);
soundOnActionClickedFilePathFileChooserField.getFileChooseButton().disableProperty().bind(soundOnActionClickedToggleSwitch.selectedProperty().not());

soundOnActionClickedFilePathFileChooserField.getFileChooseButton().disabledProperty().addListener((observableValue, oldValue, newValue) -> {
if(newValue)
{
validationSupport.deRegisterValidator(soundOnActionClickedFilePathTextField);
}
else
{
validationSupport.registerValidator(soundOnActionClickedFilePathTextField, (validatedControl, o) -> {

ValidationResult validationResult = new ValidationResult();
String soundFileAbsolutePath = ((ValidatedTextField) validatedControl).getText();

if(soundFileAbsolutePath.trim().isEmpty())
{
validationResult.addErrorIf(I18N.getString("window.settings.GeneralSettings.soundFileCannotBeEmpty"), ((TextField) validatedControl.getControl()).getText().isBlank());
}
else
{
File soundFile = new File(soundFileAbsolutePath);
if (!soundFile.exists() || !soundFile.isFile()) {
validationResult.addErrorIf(I18N.getString("window.settings.GeneralSettings.soundFileNotFound"), ((TextField) validatedControl.getControl()).getText().isBlank());
}
}

return validationResult;
});

validationSupport.manuallyValidateControl(soundOnActionClickedFilePathTextField);
}
});



minimiseToSystemTrayOnCloseToggleSwitch = new ToggleSwitch();
minimiseToSystemTrayOnCloseHBox = new HBoxWithSpaceBetween(I18N.getString("window.settings.GeneralSettings.minimiseToTrayOnClose"), minimiseToSystemTrayOnCloseToggleSwitch);
minimiseToSystemTrayOnCloseHBox.managedProperty().bind(minimiseToSystemTrayOnCloseHBox.visibleProperty());
minimiseToSystemTrayOnCloseHBox.setVisible(SystemTray.isSupported());

showAlertsPopupToggleSwitch = new ToggleSwitch();
showAlertsPopupHBox = new HBoxWithSpaceBetween(I18N.getString("window.settings.GeneralSettings.showPopupOnAlert"), showAlertsPopupToggleSwitch);

checkForUpdatesButton = new Button(I18N.getString("window.settings.GeneralSettings.checkForUpdates"));
checkForUpdatesButton.setOnAction(event-> generalSettingsViewListener.onCheckForUpdatesButtonClicked(checkForUpdatesButton));
Expand Down Expand Up @@ -157,13 +185,20 @@ public GeneralSettingsView(GeneralSettingsViewListener generalSettingsViewListen
.addRow(generateSubHeading(I18N.getString("window.settings.GeneralSettings.locations")))
.addRow(I18N.getString("window.settings.GeneralSettings.plugins"), pluginsPathDirectoryChooserField)
.addRow(I18N.getString("window.settings.GeneralSettings.themes"), themesPathDirectoryChooserField)
.addRow(I18N.getString("window.settings.GeneralSettings.soundOnActionClicked"), soundOnActionClickedFilePathFileChooserField)

.addRow(generateSubHeading(I18N.getString("window.settings.GeneralSettings.soundOnActionClicked")))
.addRow("Status", soundOnActionClickedToggleSwitch) //TODO: Implement new I18N for Sound On Action Clicked
.addRow("Sound File", soundOnActionClickedFilePathFileChooserField)

.addRow(generateSubHeading(I18N.getString("window.settings.GeneralSettings.others")))
.addRow(I18N.getString("window.settings.GeneralSettings.language"), languageChooserComboBox)
.addRow(I18N.getString("window.settings.GeneralSettings.soundOnActionClicked"), soundOnActionClickedToggleSwitch)
.addRow(I18N.getString("window.settings.GeneralSettings.minimiseToTrayOnClose"), minimiseToSystemTrayOnCloseToggleSwitch)
.addRow(I18N.getString("window.settings.GeneralSettings.startOnBoot"), startOnBootToggleSwitch)
.addRow(I18N.getString("window.settings.GeneralSettings.language"), languageChooserComboBox);

if(SystemTray.isSupported())
{
form.addRow(I18N.getString("window.settings.GeneralSettings.minimiseToTrayOnClose"), minimiseToSystemTrayOnCloseToggleSwitch);
}

form.addRow(I18N.getString("window.settings.GeneralSettings.startOnBoot"), startOnBootToggleSwitch)
.addRow(I18N.getString("window.settings.GeneralSettings.showPopupOnAlert"), showAlertsPopupToggleSwitch)
.addRow(I18N.getString("window.settings.GeneralSettings.factoryReset"), factoryResetButton)
.addRow(I18N.getString("window.settings.GeneralSettings.restart"), restartButton);
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/com/stream_pi/server/info/build.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#maven.buildNumber.plugin properties file
#Thu Jun 30 00:07:30 IST 2022
#Thu Jun 30 12:19:19 IST 2022
build.number=${buildNumber}
buildNumber=251
buildNumber=263

0 comments on commit 510872d

Please sign in to comment.