Merge pull request #4 from anas-elgarhy/fix-forget-playerid-issue

💙 Fix forget edition id issue after close the ide 🥰
This commit is contained in:
Anas Elgarhy 2022-08-21 13:14:00 +02:00 committed by GitHub
commit 5216086123
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 31 deletions

View file

@ -34,12 +34,7 @@ public class AyahSettingsState implements PersistentStateComponent<AyahSettingsS
basmalhOnStart = new BasmalhOnStart(); basmalhOnStart = new BasmalhOnStart();
intervalTimeBetweenNotifications = 30; // 30 minutes intervalTimeBetweenNotifications = 30; // 30 minutes
autoPlayAudio = false; autoPlayAudio = false;
try { edition = new SelectedEdition();
edition = new SelectedEdition(Edition
.getEditions(EditionFormat.AUDIO)[0].getIdentifier(), 0);
} catch (final IOException e) {
edition = null;
}
} }

View file

@ -11,20 +11,13 @@ import java.io.IOException;
*/ */
public class BasmalhOnStart { public class BasmalhOnStart {
private boolean isActive; private boolean isActive;
private boolean isNotificationActive;
private boolean isSoundActive; private boolean isSoundActive;
private SelectedEdition edition; private SelectedEdition edition;
public BasmalhOnStart() { public BasmalhOnStart() {
isActive = true; isActive = true;
isNotificationActive = true;
isSoundActive = false; isSoundActive = false;
try { edition = new SelectedEdition();
edition = new SelectedEdition(Edition
.getEditions(EditionFormat.AUDIO)[0].getIdentifier(), 0);
} catch (final IOException e) {
edition = null;
}
} }
public boolean isActive() { public boolean isActive() {
@ -35,14 +28,6 @@ public class BasmalhOnStart {
isActive = active; isActive = active;
} }
public boolean isNotificationActive() {
return isNotificationActive;
}
public void setNotificationActive(final boolean notificationActive) {
isNotificationActive = notificationActive;
}
public boolean isSoundActive() { public boolean isSoundActive() {
return isSoundActive; return isSoundActive;
} }

View file

@ -7,7 +7,7 @@ import com.anas.alqurancloudapi.edition.Edition;
* @date: 8/20/22 * @date: 8/20/22
*/ */
public class ReadableEdition { public class ReadableEdition {
private final Edition edition; private Edition edition;
public ReadableEdition(final Edition edition) { public ReadableEdition(final Edition edition) {
this.edition = edition; this.edition = edition;

View file

@ -1,14 +1,27 @@
package com.anas.intellij.plugins.ayah.settings; package com.anas.intellij.plugins.ayah.settings;
import com.anas.alqurancloudapi.edition.Edition; import com.anas.alqurancloudapi.edition.Edition;
import com.anas.alqurancloudapi.edition.EditionFormat;
import java.io.IOException;
/** /**
* @author: <a href="https://github.com/anas-elgarhy">Anas Elgarhy</a> * @author: <a href="https://github.com/anas-elgarhy">Anas Elgarhy</a>
* @date: 8/21/22 * @date: 8/21/22
*/ */
public class SelectedEdition { public class SelectedEdition {
private final String editionIdentifier; private String editionIdentifier;
private final int index; private int index;
// For XML serialization
public SelectedEdition() {
try {
editionIdentifier = Edition.getEditions(EditionFormat.AUDIO)[0].getIdentifier();
} catch (final IOException e) {
editionIdentifier = "ar.abdulbasitmurattal";
}
index = 0;
}
public SelectedEdition(final String editionIdentifier, final int index) { public SelectedEdition(final String editionIdentifier, final int index) {
this.editionIdentifier = editionIdentifier; this.editionIdentifier = editionIdentifier;
@ -19,7 +32,17 @@ public class SelectedEdition {
return editionIdentifier; return editionIdentifier;
} }
// For XML serialization
public void setEditionIdentifier(final String editionIdentifier) {
this.editionIdentifier = editionIdentifier;
}
public int getIndex() { public int getIndex() {
return index; return index;
} }
// For XML serialization
public void setIndex(final int index) {
this.index = index;
}
} }

View file

@ -86,13 +86,15 @@ public class SettingsComponent {
notificationsAudioCheckBox.setSelected(settings.isAutoPlayAudio()); notificationsAudioCheckBox.setSelected(settings.isAutoPlayAudio());
basmalhPlayerIdComboBox.setEnabled(settings.getBasmalhOnStart().isActive()); basmalhPlayerIdComboBox.setEnabled(settings.getBasmalhOnStart().isActive());
if (settings.getBasmalhOnStart().getEdition() != null) { if (basmalhPlayerIdComboBox.getItemCount() <= 0) {
basmalhPlayerIdComboBox.addItem(new ReadableEdition(settings.getBasmalhOnStart()
.getEdition().getEditionIdentifier()));
ayahPlayerIdComboBox.addItem(new ReadableEdition(settings.getEdition().getEditionIdentifier()));
}
basmalhPlayerIdComboBox.setSelectedIndex(settings.getBasmalhOnStart().getEdition().getIndex()); basmalhPlayerIdComboBox.setSelectedIndex(settings.getBasmalhOnStart().getEdition().getIndex());
}
if (settings.getEdition() != null) {
ayahPlayerIdComboBox.setSelectedIndex(settings.getEdition().getIndex()); ayahPlayerIdComboBox.setSelectedIndex(settings.getEdition().getIndex());
} }
}
private void addListeners() { private void addListeners() {
basmalhOnStartCheckBox.addActionListener(e -> basmalhOnStartCheckBox.addActionListener(e ->
@ -147,7 +149,6 @@ public class SettingsComponent {
b.setSoundActive(autoPlayBasmalhCheckBox.isSelected()); b.setSoundActive(autoPlayBasmalhCheckBox.isSelected());
b.setEdition(new SelectedEdition(((ReadableEdition) Objects.requireNonNull( b.setEdition(new SelectedEdition(((ReadableEdition) Objects.requireNonNull(
basmalhPlayerIdComboBox.getSelectedItem())).getEdition().getIdentifier(), basmalhPlayerIdComboBox.getSelectedIndex())); basmalhPlayerIdComboBox.getSelectedItem())).getEdition().getIdentifier(), basmalhPlayerIdComboBox.getSelectedIndex()));
b.setNotificationActive(notificationsAudioCheckBox.isSelected());
return b; return b;
} }