Improve code yooooo 🤍

This commit is contained in:
Anas Elgarhy 2022-08-19 17:47:08 +02:00
parent 2de9769dd0
commit c1b4af4cb5
1 changed files with 12 additions and 12 deletions

View File

@ -65,19 +65,28 @@ public class SettingsComponent {
.getPanel(); .getPanel();
setup(); setup();
addListeners();
loadComboBoxesValues();
} }
private void setup() { private void setup() {
final var settings = AyahSettingsState.getInstance(); final var settings = AyahSettingsState.getInstance();
notificationsIntervalSpinnerModel = new SpinnerNumberModel(settings.getIntervalTimeBetweenNotifications(), notificationsIntervalSpinnerModel = new SpinnerNumberModel(settings.getIntervalTimeBetweenNotifications(),
1, Integer.MAX_VALUE, 1); 1, Integer.MAX_VALUE, 1);
setupComboboxes(settings);
notificationsIntervalSpinner.setModel(notificationsIntervalSpinnerModel); notificationsIntervalSpinner.setModel(notificationsIntervalSpinnerModel);
basmalhOnStartCheckBox.setSelected(settings.getBasmalhOnStart().isActive()); basmalhOnStartCheckBox.setSelected(settings.getBasmalhOnStart().isActive());
autoPlayBasmalhCheckBox.setSelected(settings.getBasmalhOnStart().isSoundActive()); autoPlayBasmalhCheckBox.setSelected(settings.getBasmalhOnStart().isSoundActive());
autoPlayBasmalhCheckBox.setEnabled(settings.getBasmalhOnStart().isActive()); autoPlayBasmalhCheckBox.setEnabled(settings.getBasmalhOnStart().isActive());
notificationsAudioCheckBox.setSelected(settings.isAutoPlayAudio()); notificationsAudioCheckBox.setSelected(settings.isAutoPlayAudio());
addListeners(); basmalhPlayerIdComboBox.setEnabled(settings.getBasmalhOnStart().isActive());
if (settings.getBasmalhOnStart().getPlayerId() != null) {
basmalhPlayerIdComboBox.setSelectedItem(settings.getBasmalhOnStart().getPlayerId());
}
if (settings.getPlayerId() != null) {
ayahPlayerIdComboBox.setSelectedItem(settings.getPlayerId());
}
} }
private void addListeners() { private void addListeners() {
@ -91,14 +100,7 @@ public class SettingsComponent {
ayahPlayerIdComboBox.setEnabled(notificationsAudioCheckBox.isSelected())); ayahPlayerIdComboBox.setEnabled(notificationsAudioCheckBox.isSelected()));
} }
private void setupComboboxes(final AyahSettingsState settings) { private void loadComboBoxesValues() {
if (settings.getBasmalhOnStart().getPlayerId() != null) {
basmalhPlayerIdComboBox.setSelectedItem(settings.getBasmalhOnStart().getPlayerId());
}
if (settings.getPlayerId() != null) {
ayahPlayerIdComboBox.setSelectedItem(settings.getPlayerId());
}
try { try {
final var editions = Edition.getEditions(EditionFormat.AUDIO); final var editions = Edition.getEditions(EditionFormat.AUDIO);
for (final var edition : editions) { for (final var edition : editions) {
@ -110,8 +112,6 @@ public class SettingsComponent {
basmalhPlayerIdComboBox.addItem("Error can't get editions, please check internet connection"); basmalhPlayerIdComboBox.addItem("Error can't get editions, please check internet connection");
ayahPlayerIdComboBox.addItem("Error can't get editions, please check internet connection"); ayahPlayerIdComboBox.addItem("Error can't get editions, please check internet connection");
} }
basmalhPlayerIdComboBox.setEnabled(settings.getBasmalhOnStart().isActive());
} }
public boolean isModified() { public boolean isModified() {