Fix save audio edition issue 🥰

This commit is contained in:
Anas Elgarhy 2022-08-21 11:26:36 +02:00
parent e3e47fc9c8
commit 003a4afee7
7 changed files with 65 additions and 34 deletions

View file

@ -23,7 +23,7 @@ public class AyahStartupActivity implements StartupActivity {
if (basmalhOnStartSettingsState.isActive()) { if (basmalhOnStartSettingsState.isActive()) {
try { try {
final var bassmalh = Ayah.getAyah(1, final var bassmalh = Ayah.getAyah(1,
basmalhOnStartSettingsState.getEditionId()); basmalhOnStartSettingsState.getEdition().getEditionIdentifier());
NotificationGroupManager.getInstance() NotificationGroupManager.getInstance()
.getNotificationGroup("Basmalh on Start") .getNotificationGroup("Basmalh on Start")
.createNotification(bassmalh.getText(), NotificationType.INFORMATION).notify(project); .createNotification(bassmalh.getText(), NotificationType.INFORMATION).notify(project);

View file

@ -29,9 +29,9 @@ public class NotificationTimerTask extends TimerTask {
public void run() { public void run() {
final var settings = AyahSettingsState.getInstance(); final var settings = AyahSettingsState.getInstance();
LOGGER.info("Player id: " + settings.getEditionId()); LOGGER.info("Player id: " + settings.getEdition());
try { try {
final var randomAyah = Ayah.getRandomAyah(settings.getEditionId()); final var randomAyah = Ayah.getRandomAyah(settings.getEdition().getEditionIdentifier());
LOGGER.info("Random Ayah: " + randomAyah.getText()); LOGGER.info("Random Ayah: " + randomAyah.getText());
LOGGER.info("Rsndom ayah edition: " + randomAyah.getEdition()); LOGGER.info("Rsndom ayah edition: " + randomAyah.getEdition());

View file

@ -38,7 +38,7 @@ public class AyahSettingsConfigurable implements Configurable {
settingsState.setBasmalhOnStart(settingsComponent.getBasmalhOnStart()); settingsState.setBasmalhOnStart(settingsComponent.getBasmalhOnStart());
settingsState.setIntervalTimeBetweenNotifications(settingsComponent.getIntervalTimeBetweenNotifications()); settingsState.setIntervalTimeBetweenNotifications(settingsComponent.getIntervalTimeBetweenNotifications());
settingsState.setAutoPlayAudio(settingsComponent.isAutoPlayAudio()); settingsState.setAutoPlayAudio(settingsComponent.isAutoPlayAudio());
settingsState.setEditionId(settingsComponent.getEdition().getIdentifier()); settingsState.setEdition(settingsComponent.getSelectedEdition());
// Update the timer with the new interval time between notifications if interval time between notifications has changed // Update the timer with the new interval time between notifications if interval time between notifications has changed
if (settingsState.getIntervalTimeBetweenNotifications() != if (settingsState.getIntervalTimeBetweenNotifications() !=

View file

@ -24,7 +24,7 @@ public class AyahSettingsState implements PersistentStateComponent<AyahSettingsS
private BasmalhOnStart basmalhOnStart; private BasmalhOnStart basmalhOnStart;
private int intervalTimeBetweenNotifications; // in minutes private int intervalTimeBetweenNotifications; // in minutes
private boolean autoPlayAudio; private boolean autoPlayAudio;
private String editionId; private SelectedEdition edition;
public static AyahSettingsState getInstance() { public static AyahSettingsState getInstance() {
return ApplicationManager.getApplication().getService(AyahSettingsState.class); return ApplicationManager.getApplication().getService(AyahSettingsState.class);
@ -35,9 +35,10 @@ public class AyahSettingsState implements PersistentStateComponent<AyahSettingsS
intervalTimeBetweenNotifications = 30; // 30 minutes intervalTimeBetweenNotifications = 30; // 30 minutes
autoPlayAudio = false; autoPlayAudio = false;
try { try {
editionId = Edition.getRandomEdition(EditionFormat.AUDIO, "ar").getIdentifier(); edition = new SelectedEdition(Edition
.getEditions(EditionFormat.AUDIO)[0].getIdentifier(), 0);
} catch (final IOException e) { } catch (final IOException e) {
editionId = null; edition = null;
} }
} }
@ -76,11 +77,11 @@ public class AyahSettingsState implements PersistentStateComponent<AyahSettingsS
this.autoPlayAudio = autoPlayAudio; this.autoPlayAudio = autoPlayAudio;
} }
public String getEditionId() { public SelectedEdition getEdition() {
return editionId; return edition;
} }
public void setEditionId(final String editionId) { public void setEdition(final SelectedEdition edition) {
this.editionId = editionId; this.edition = edition;
} }
} }

View file

@ -13,16 +13,17 @@ public class BasmalhOnStart {
private boolean isActive; private boolean isActive;
private boolean isNotificationActive; private boolean isNotificationActive;
private boolean isSoundActive; private boolean isSoundActive;
private String editionId; private SelectedEdition edition;
public BasmalhOnStart() { public BasmalhOnStart() {
isActive = true; isActive = true;
isNotificationActive = true; isNotificationActive = true;
isSoundActive = false; isSoundActive = false;
try { try {
editionId = Edition.getRandomEdition(EditionFormat.AUDIO, "ar").getIdentifier(); edition = new SelectedEdition(Edition
.getEditions(EditionFormat.AUDIO)[0].getIdentifier(), 0);
} catch (final IOException e) { } catch (final IOException e) {
editionId = null; edition = null;
} }
} }
@ -50,11 +51,11 @@ public class BasmalhOnStart {
isSoundActive = soundActive; isSoundActive = soundActive;
} }
public String getEditionId() { public SelectedEdition getEdition() {
return editionId; return edition;
} }
public void setEditionId(final String editionId) { public void setEdition(final SelectedEdition edition) {
this.editionId = editionId; this.edition = edition;
} }
} }

View file

@ -0,0 +1,25 @@
package com.anas.intellij.plugins.ayah.settings;
import com.anas.alqurancloudapi.edition.Edition;
/**
* @author: <a href="https://github.com/anas-elgarhy">Anas Elgarhy</a>
* @date: 8/21/22
*/
public class SelectedEdition {
private final String editionIdentifier;
private final int index;
public SelectedEdition(final String editionIdentifier, final int index) {
this.editionIdentifier = editionIdentifier;
this.index = index;
}
public String getEditionIdentifier() {
return editionIdentifier;
}
public int getIndex() {
return index;
}
}

View file

@ -5,7 +5,6 @@ import com.anas.alqurancloudapi.edition.Edition;
import com.anas.alqurancloudapi.edition.EditionFormat; import com.anas.alqurancloudapi.edition.EditionFormat;
import com.intellij.ui.components.JBCheckBox; import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBLabel; import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBSlider;
import com.intellij.util.ui.FormBuilder; import com.intellij.util.ui.FormBuilder;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
@ -70,9 +69,9 @@ public class SettingsComponent {
) )
.getPanel(); .getPanel();
loadComboBoxesValues();
setup(); setup();
addListeners(); addListeners();
loadComboBoxesValues();
} }
private void setup() { private void setup() {
@ -87,11 +86,11 @@ public class SettingsComponent {
notificationsAudioCheckBox.setSelected(settings.isAutoPlayAudio()); notificationsAudioCheckBox.setSelected(settings.isAutoPlayAudio());
basmalhPlayerIdComboBox.setEnabled(settings.getBasmalhOnStart().isActive()); basmalhPlayerIdComboBox.setEnabled(settings.getBasmalhOnStart().isActive());
if (settings.getBasmalhOnStart().getEditionId() != null) { if (settings.getBasmalhOnStart().getEdition() != null) {
basmalhPlayerIdComboBox.setSelectedItem(new ReadableEdition(settings.getBasmalhOnStart().getEditionId())); basmalhPlayerIdComboBox.setSelectedIndex(settings.getBasmalhOnStart().getEdition().getIndex());
} }
if (settings.getEditionId() != null) { if (settings.getEdition() != null) {
ayahPlayerIdComboBox.setSelectedItem(new ReadableEdition(settings.getEditionId())); ayahPlayerIdComboBox.setSelectedIndex(settings.getEdition().getIndex());
} }
} }
@ -120,12 +119,14 @@ public class SettingsComponent {
public boolean isModified() { public boolean isModified() {
final var settings = AyahSettingsState.getInstance(); final var settings = AyahSettingsState.getInstance();
return settings.getBasmalhOnStart().getEditionId() != null && return settings.getBasmalhOnStart().getEdition() != null &&
!settings.getBasmalhOnStart().getEditionId() !settings.getBasmalhOnStart().getEdition().getEditionIdentifier()
.equals(((ReadableEdition) basmalhPlayerIdComboBox.getSelectedItem()).getEdition()) || .equals(((ReadableEdition) basmalhPlayerIdComboBox.getSelectedItem())
settings.getEditionId() != null && .getEdition().getIdentifier()) ||
!settings.getEditionId() settings.getEdition() != null &&
.equals(((ReadableEdition) ayahPlayerIdComboBox.getSelectedItem()).getEdition()) || !settings.getEdition().getEditionIdentifier()
.equals(((ReadableEdition) ayahPlayerIdComboBox.getSelectedItem())
.getEdition().getIdentifier()) ||
settings.getIntervalTimeBetweenNotifications() != notificationsIntervalSpinnerModel.getNumber().intValue() || settings.getIntervalTimeBetweenNotifications() != notificationsIntervalSpinnerModel.getNumber().intValue() ||
settings.getBasmalhOnStart().isActive() != basmalhOnStartCheckBox.isSelected() || settings.getBasmalhOnStart().isActive() != basmalhOnStartCheckBox.isSelected() ||
settings.getBasmalhOnStart().isSoundActive() != autoPlayBasmalhCheckBox.isSelected() || settings.getBasmalhOnStart().isSoundActive() != autoPlayBasmalhCheckBox.isSelected() ||
@ -144,8 +145,9 @@ public class SettingsComponent {
final var b = new BasmalhOnStart(); final var b = new BasmalhOnStart();
b.setActive(basmalhOnStartCheckBox.isSelected()); b.setActive(basmalhOnStartCheckBox.isSelected());
b.setSoundActive(autoPlayBasmalhCheckBox.isSelected()); b.setSoundActive(autoPlayBasmalhCheckBox.isSelected());
b.setEditionId(((ReadableEdition) Objects.requireNonNull( b.setEdition(new SelectedEdition(((ReadableEdition) Objects.requireNonNull(
basmalhPlayerIdComboBox.getSelectedItem())).getEdition().getIdentifier()); basmalhPlayerIdComboBox.getSelectedItem())).getEdition().getIdentifier(), basmalhPlayerIdComboBox.getSelectedIndex()));
b.setNotificationActive(notificationsAudioCheckBox.isSelected());
return b; return b;
} }
@ -157,7 +159,9 @@ public class SettingsComponent {
return notificationsAudioCheckBox.isSelected(); return notificationsAudioCheckBox.isSelected();
} }
public Edition getEdition() { public SelectedEdition getSelectedEdition() {
return ((ReadableEdition) ayahPlayerIdComboBox.getSelectedItem()).getEdition(); return new SelectedEdition(((ReadableEdition) ayahPlayerIdComboBox
.getSelectedItem()).getEdition().getIdentifier(),
ayahPlayerIdComboBox.getSelectedIndex());
} }
} }