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()) {
try {
final var bassmalh = Ayah.getAyah(1,
basmalhOnStartSettingsState.getEditionId());
basmalhOnStartSettingsState.getEdition().getEditionIdentifier());
NotificationGroupManager.getInstance()
.getNotificationGroup("Basmalh on Start")
.createNotification(bassmalh.getText(), NotificationType.INFORMATION).notify(project);

View file

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

View file

@ -38,7 +38,7 @@ public class AyahSettingsConfigurable implements Configurable {
settingsState.setBasmalhOnStart(settingsComponent.getBasmalhOnStart());
settingsState.setIntervalTimeBetweenNotifications(settingsComponent.getIntervalTimeBetweenNotifications());
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
if (settingsState.getIntervalTimeBetweenNotifications() !=

View file

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

View file

@ -13,16 +13,17 @@ public class BasmalhOnStart {
private boolean isActive;
private boolean isNotificationActive;
private boolean isSoundActive;
private String editionId;
private SelectedEdition edition;
public BasmalhOnStart() {
isActive = true;
isNotificationActive = true;
isSoundActive = false;
try {
editionId = Edition.getRandomEdition(EditionFormat.AUDIO, "ar").getIdentifier();
edition = new SelectedEdition(Edition
.getEditions(EditionFormat.AUDIO)[0].getIdentifier(), 0);
} catch (final IOException e) {
editionId = null;
edition = null;
}
}
@ -50,11 +51,11 @@ public class BasmalhOnStart {
isSoundActive = soundActive;
}
public String getEditionId() {
return editionId;
public SelectedEdition getEdition() {
return edition;
}
public void setEditionId(final String editionId) {
this.editionId = editionId;
public void setEdition(final SelectedEdition edition) {
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.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBSlider;
import com.intellij.util.ui.FormBuilder;
import net.miginfocom.swing.MigLayout;
@ -70,9 +69,9 @@ public class SettingsComponent {
)
.getPanel();
loadComboBoxesValues();
setup();
addListeners();
loadComboBoxesValues();
}
private void setup() {
@ -87,11 +86,11 @@ public class SettingsComponent {
notificationsAudioCheckBox.setSelected(settings.isAutoPlayAudio());
basmalhPlayerIdComboBox.setEnabled(settings.getBasmalhOnStart().isActive());
if (settings.getBasmalhOnStart().getEditionId() != null) {
basmalhPlayerIdComboBox.setSelectedItem(new ReadableEdition(settings.getBasmalhOnStart().getEditionId()));
if (settings.getBasmalhOnStart().getEdition() != null) {
basmalhPlayerIdComboBox.setSelectedIndex(settings.getBasmalhOnStart().getEdition().getIndex());
}
if (settings.getEditionId() != null) {
ayahPlayerIdComboBox.setSelectedItem(new ReadableEdition(settings.getEditionId()));
if (settings.getEdition() != null) {
ayahPlayerIdComboBox.setSelectedIndex(settings.getEdition().getIndex());
}
}
@ -120,12 +119,14 @@ public class SettingsComponent {
public boolean isModified() {
final var settings = AyahSettingsState.getInstance();
return settings.getBasmalhOnStart().getEditionId() != null &&
!settings.getBasmalhOnStart().getEditionId()
.equals(((ReadableEdition) basmalhPlayerIdComboBox.getSelectedItem()).getEdition()) ||
settings.getEditionId() != null &&
!settings.getEditionId()
.equals(((ReadableEdition) ayahPlayerIdComboBox.getSelectedItem()).getEdition()) ||
return settings.getBasmalhOnStart().getEdition() != null &&
!settings.getBasmalhOnStart().getEdition().getEditionIdentifier()
.equals(((ReadableEdition) basmalhPlayerIdComboBox.getSelectedItem())
.getEdition().getIdentifier()) ||
settings.getEdition() != null &&
!settings.getEdition().getEditionIdentifier()
.equals(((ReadableEdition) ayahPlayerIdComboBox.getSelectedItem())
.getEdition().getIdentifier()) ||
settings.getIntervalTimeBetweenNotifications() != notificationsIntervalSpinnerModel.getNumber().intValue() ||
settings.getBasmalhOnStart().isActive() != basmalhOnStartCheckBox.isSelected() ||
settings.getBasmalhOnStart().isSoundActive() != autoPlayBasmalhCheckBox.isSelected() ||
@ -144,8 +145,9 @@ public class SettingsComponent {
final var b = new BasmalhOnStart();
b.setActive(basmalhOnStartCheckBox.isSelected());
b.setSoundActive(autoPlayBasmalhCheckBox.isSelected());
b.setEditionId(((ReadableEdition) Objects.requireNonNull(
basmalhPlayerIdComboBox.getSelectedItem())).getEdition().getIdentifier());
b.setEdition(new SelectedEdition(((ReadableEdition) Objects.requireNonNull(
basmalhPlayerIdComboBox.getSelectedItem())).getEdition().getIdentifier(), basmalhPlayerIdComboBox.getSelectedIndex()));
b.setNotificationActive(notificationsAudioCheckBox.isSelected());
return b;
}
@ -157,7 +159,9 @@ public class SettingsComponent {
return notificationsAudioCheckBox.isSelected();
}
public Edition getEdition() {
return ((ReadableEdition) ayahPlayerIdComboBox.getSelectedItem()).getEdition();
public SelectedEdition getSelectedEdition() {
return new SelectedEdition(((ReadableEdition) ayahPlayerIdComboBox
.getSelectedItem()).getEdition().getIdentifier(),
ayahPlayerIdComboBox.getSelectedIndex());
}
}