💙 Fix forget edition id issue after close the ide 🥰

This commit is contained in:
Anas Elgarhy 2022-08-21 13:05:54 +02:00
parent 003a4afee7
commit 2738b54860
5 changed files with 35 additions and 31 deletions

View File

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

View File

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

View File

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

View File

@ -1,14 +1,27 @@
package com.anas.intellij.plugins.ayah.settings;
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>
* @date: 8/21/22
*/
public class SelectedEdition {
private final String editionIdentifier;
private final int index;
private String editionIdentifier;
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) {
this.editionIdentifier = editionIdentifier;
@ -19,7 +32,17 @@ public class SelectedEdition {
return editionIdentifier;
}
// For XML serialization
public void setEditionIdentifier(final String editionIdentifier) {
this.editionIdentifier = editionIdentifier;
}
public int getIndex() {
return index;
}
// For XML serialization
public void setIndex(final int index) {
this.index = index;
}
}

View File

@ -86,12 +86,14 @@ public class SettingsComponent {
notificationsAudioCheckBox.setSelected(settings.isAutoPlayAudio());
basmalhPlayerIdComboBox.setEnabled(settings.getBasmalhOnStart().isActive());
if (settings.getBasmalhOnStart().getEdition() != null) {
basmalhPlayerIdComboBox.setSelectedIndex(settings.getBasmalhOnStart().getEdition().getIndex());
}
if (settings.getEdition() != null) {
ayahPlayerIdComboBox.setSelectedIndex(settings.getEdition().getIndex());
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());
ayahPlayerIdComboBox.setSelectedIndex(settings.getEdition().getIndex());
}
private void addListeners() {
@ -147,7 +149,6 @@ public class SettingsComponent {
b.setSoundActive(autoPlayBasmalhCheckBox.isSelected());
b.setEdition(new SelectedEdition(((ReadableEdition) Objects.requireNonNull(
basmalhPlayerIdComboBox.getSelectedItem())).getEdition().getIdentifier(), basmalhPlayerIdComboBox.getSelectedIndex()));
b.setNotificationActive(notificationsAudioCheckBox.isSelected());
return b;
}