mirror of
https://github.com/anas-elgarhy/Ayah-intellij.git
synced 2024-08-15 00:43:43 +00:00
💙 base implement for audio system yooooo 🔊
This commit is contained in:
parent
bf012bf694
commit
b5445bc622
7 changed files with 99 additions and 16 deletions
|
@ -1,6 +1,8 @@
|
|||
package com.anas.intellij.plugins.ayah;
|
||||
|
||||
import com.anas.alqurancloudapi.Ayah;
|
||||
import com.anas.intellij.plugins.ayah.audio.AudioPlayer;
|
||||
import com.anas.intellij.plugins.ayah.settings.AyahSettingsState;
|
||||
import com.intellij.notification.NotificationGroupManager;
|
||||
import com.intellij.notification.NotificationType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
|
@ -16,19 +18,21 @@ import java.io.IOException;
|
|||
public class AyahStartupActivity implements StartupActivity {
|
||||
@Override
|
||||
public void runActivity(@NotNull final Project project) {
|
||||
// Messages.showDialog(project, "Hi yoo", "My First Message Yooo", new String[]{"Ok"}, 0, Messages.getInformationIcon());
|
||||
/*
|
||||
new Notification("com.anas.intellij.plugins.ayah.notificationGroup", "My First Notification",
|
||||
"My First Notification", NotificationType.INFORMATION).notify(project);
|
||||
*/
|
||||
try {
|
||||
final var rAyah = Ayah.getRandomAyah();
|
||||
NotificationGroupManager.getInstance()
|
||||
.getNotificationGroup("Random ayah from the quran")
|
||||
.createNotification(rAyah.getSurah().getName(),
|
||||
rAyah.getText(), NotificationType.INFORMATION).notify(project);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
final var basmalhOnStartSettingsState = AyahSettingsState.getInstance().getBasmalhOnStart();
|
||||
if (basmalhOnStartSettingsState.isActive()) {
|
||||
try {
|
||||
final var bassmalh = Ayah.getAyah(1,
|
||||
basmalhOnStartSettingsState.getPlayerId());
|
||||
NotificationGroupManager.getInstance()
|
||||
.getNotificationGroup("Basmalh on Start")
|
||||
.createNotification(bassmalh.getText(), NotificationType.INFORMATION).notify(project);
|
||||
|
||||
if (basmalhOnStartSettingsState.isSoundActive()) {
|
||||
new AudioPlayer(basmalhOnStartSettingsState.getVolume(), bassmalh.getAudioUrl()).play();
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package com.anas.intellij.plugins.ayah.audio;
|
||||
|
||||
/**
|
||||
* @author: <a href="https://github.com/anas-elgarhy">Anas Elgarhy</a>
|
||||
* @date: 8/19/22
|
||||
*/
|
||||
public class AudioPlayer {
|
||||
public AudioPlayer(final int volume, final String audioUrl) {
|
||||
}
|
||||
|
||||
public void play() {
|
||||
}
|
||||
}
|
|
@ -39,6 +39,7 @@ public class AyahSettingsConfigurable implements Configurable {
|
|||
settingsState.setIntervalTimeBetweenNotifications(settingsComponent.getIntervalTimeBetweenNotifications());
|
||||
settingsState.setAutoPlayAudio(settingsComponent.isAutoPlayAudio());
|
||||
settingsState.setPlayerId(settingsComponent.getPlayerId());
|
||||
settingsState.setVolume(settingsComponent.getVolume());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.anas.intellij.plugins.ayah.settings;
|
||||
|
||||
import com.anas.alqurancloudapi.edition.Edition;
|
||||
import com.anas.alqurancloudapi.edition.EditionFormat;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.State;
|
||||
|
@ -8,6 +10,8 @@ import com.intellij.util.xmlb.XmlSerializerUtil;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author: <a href="https://github.com/anas-elgarhy">Anas Elgarhy</a>
|
||||
* @date: 8/19/22
|
||||
|
@ -21,6 +25,7 @@ public class AyahSettingsState implements PersistentStateComponent<AyahSettingsS
|
|||
private int intervalTimeBetweenNotifications; // in minutes
|
||||
private boolean autoPlayAudio;
|
||||
private String playerId;
|
||||
private int volume;
|
||||
|
||||
public static AyahSettingsState getInstance() {
|
||||
return ApplicationManager.getApplication().getService(AyahSettingsState.class);
|
||||
|
@ -30,7 +35,12 @@ public class AyahSettingsState implements PersistentStateComponent<AyahSettingsS
|
|||
basmalhOnStart = new BasmalhOnStart();
|
||||
intervalTimeBetweenNotifications = 30; // 30 minutes
|
||||
autoPlayAudio = false;
|
||||
playerId = null;
|
||||
try {
|
||||
playerId = Edition.getRandomEdition(EditionFormat.AUDIO, "ar").getIdentifier();
|
||||
} catch (final IOException e) {
|
||||
playerId = null;
|
||||
}
|
||||
volume = 40; // 40%
|
||||
}
|
||||
|
||||
|
||||
|
@ -76,4 +86,11 @@ public class AyahSettingsState implements PersistentStateComponent<AyahSettingsS
|
|||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
public int getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
public void setVolume(final int volume) {
|
||||
this.volume = volume;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
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/19/22
|
||||
|
@ -9,12 +14,18 @@ public class BasmalhOnStart {
|
|||
private boolean isNotificationActive;
|
||||
private boolean isSoundActive;
|
||||
private String playerId;
|
||||
private int volume;
|
||||
|
||||
public BasmalhOnStart() {
|
||||
isActive = true;
|
||||
isNotificationActive = true;
|
||||
isSoundActive = false;
|
||||
playerId = null;
|
||||
try {
|
||||
playerId = Edition.getRandomEdition(EditionFormat.AUDIO, "ar").getIdentifier();
|
||||
} catch (final IOException e) {
|
||||
playerId = null;
|
||||
}
|
||||
volume = 40; // 40%
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
|
@ -48,4 +59,12 @@ public class BasmalhOnStart {
|
|||
public void setPlayerId(final String playerId) {
|
||||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
public int getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
public void setVolume(final int volume) {
|
||||
this.volume = volume;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ 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;
|
||||
|
||||
|
@ -23,18 +24,22 @@ public class SettingsComponent {
|
|||
private final JBCheckBox basmalhOnStartCheckBox;
|
||||
private final JBCheckBox autoPlayBasmalhCheckBox;
|
||||
private final JComboBox<String> basmalhPlayerIdComboBox;
|
||||
private final JBSlider basmalhVolumeSlider;
|
||||
private final JSpinner notificationsIntervalSpinner;
|
||||
private SpinnerNumberModel notificationsIntervalSpinnerModel;
|
||||
private final JBCheckBox notificationsAudioCheckBox;
|
||||
private final JComboBox<String> ayahPlayerIdComboBox;
|
||||
private final JBSlider ayahVolumeSlider;
|
||||
|
||||
{
|
||||
basmalhOnStartCheckBox = new JBCheckBox("Basmalh on start");
|
||||
autoPlayBasmalhCheckBox = new JBCheckBox("Auto play basmalh audio");
|
||||
basmalhPlayerIdComboBox = new JComboBox<>();
|
||||
basmalhVolumeSlider = new JBSlider();
|
||||
notificationsIntervalSpinner = new JSpinner();
|
||||
notificationsAudioCheckBox = new JBCheckBox("Notifications audio");
|
||||
ayahPlayerIdComboBox = new JComboBox<>();
|
||||
ayahVolumeSlider = new JBSlider();
|
||||
}
|
||||
|
||||
public SettingsComponent() {
|
||||
|
@ -51,6 +56,9 @@ public class SettingsComponent {
|
|||
"gap unrelated")
|
||||
.addComponent(basmalhPlayerIdComboBox,
|
||||
"grow, wrap")
|
||||
.addComponent(new JBLabel("Volume"),
|
||||
"gap 1")
|
||||
.addComponent(basmalhVolumeSlider, "grow, wrap")
|
||||
.build(),
|
||||
"span, grow, wrap"
|
||||
)
|
||||
|
@ -61,6 +69,8 @@ public class SettingsComponent {
|
|||
.addComponent(notificationsAudioCheckBox, "grow")
|
||||
.addComponent(new JBLabel("Ayah player"), "gap unrelated")
|
||||
.addComponent(ayahPlayerIdComboBox, "grow, wrap")
|
||||
.addComponent(new JBLabel("Volume"), "gap unrelated")
|
||||
.addComponent(ayahVolumeSlider, "grow, wrap")
|
||||
.build()
|
||||
)
|
||||
.getPanel();
|
||||
|
@ -82,6 +92,17 @@ public class SettingsComponent {
|
|||
notificationsAudioCheckBox.setSelected(settings.isAutoPlayAudio());
|
||||
basmalhPlayerIdComboBox.setEnabled(settings.getBasmalhOnStart().isActive());
|
||||
|
||||
basmalhVolumeSlider.setValue(settings.getBasmalhOnStart().getVolume());
|
||||
basmalhVolumeSlider.setPaintLabels(true);
|
||||
basmalhVolumeSlider.setPaintTicks(true);
|
||||
basmalhVolumeSlider.setMajorTickSpacing(20);
|
||||
basmalhVolumeSlider.setMinorTickSpacing(10);
|
||||
ayahVolumeSlider.setValue(settings.getVolume());
|
||||
ayahVolumeSlider.setPaintLabels(true);
|
||||
ayahVolumeSlider.setPaintTicks(true);
|
||||
ayahVolumeSlider.setMajorTickSpacing(20);
|
||||
ayahVolumeSlider.setMinorTickSpacing(10);
|
||||
|
||||
if (settings.getBasmalhOnStart().getPlayerId() != null) {
|
||||
basmalhPlayerIdComboBox.setSelectedItem(settings.getBasmalhOnStart().getPlayerId());
|
||||
}
|
||||
|
@ -124,7 +145,9 @@ public class SettingsComponent {
|
|||
settings.getIntervalTimeBetweenNotifications() != notificationsIntervalSpinnerModel.getNumber().intValue() ||
|
||||
settings.getBasmalhOnStart().isActive() != basmalhOnStartCheckBox.isSelected() ||
|
||||
settings.getBasmalhOnStart().isSoundActive() != autoPlayBasmalhCheckBox.isSelected() ||
|
||||
settings.isAutoPlayAudio() != notificationsAudioCheckBox.isSelected();
|
||||
settings.isAutoPlayAudio() != notificationsAudioCheckBox.isSelected() ||
|
||||
settings.getBasmalhOnStart().getVolume() != basmalhVolumeSlider.getValue() ||
|
||||
settings.getVolume() != ayahVolumeSlider.getValue();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
|
@ -140,6 +163,7 @@ public class SettingsComponent {
|
|||
b.setActive(basmalhOnStartCheckBox.isSelected());
|
||||
b.setSoundActive(autoPlayBasmalhCheckBox.isSelected());
|
||||
b.setPlayerId(Objects.requireNonNull(basmalhPlayerIdComboBox.getSelectedItem()).toString());
|
||||
b.setVolume(basmalhVolumeSlider.getValue());
|
||||
return b;
|
||||
}
|
||||
|
||||
|
@ -154,4 +178,8 @@ public class SettingsComponent {
|
|||
public String getPlayerId() {
|
||||
return Objects.requireNonNull(ayahPlayerIdComboBox.getSelectedItem()).toString();
|
||||
}
|
||||
|
||||
public int getVolume() {
|
||||
return ayahVolumeSlider.getValue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,5 +35,6 @@
|
|||
<applicationService serviceImplementation="com.anas.intellij.plugins.ayah.settings.AyahSettingsState" />
|
||||
|
||||
<notificationGroup id="Random ayah from the quran" displayType="BALLOON" />
|
||||
<notificationGroup displayType="BALLOON" id="Basmalh on Start" />
|
||||
</extensions>
|
||||
</idea-plugin>
|
Loading…
Reference in a new issue