mirror of
https://github.com/anas-elgarhy/Ayah-intellij.git
synced 2024-08-15 00:43:43 +00:00
😆 Compleate the plugin base yooooo 🥰
This commit is contained in:
parent
b5445bc622
commit
1f517aa479
7 changed files with 124 additions and 2 deletions
|
@ -0,0 +1,20 @@
|
||||||
|
package com.anas.intellij.plugins.ayah;
|
||||||
|
|
||||||
|
import com.intellij.openapi.application.PreloadingActivity;
|
||||||
|
import com.intellij.openapi.progress.ProgressIndicator;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: <a href="https://github.com/anas-elgarhy">Anas Elgarhy</a>
|
||||||
|
* @date: 8/19/22
|
||||||
|
*/
|
||||||
|
public class AyahPreLoadingActivity extends PreloadingActivity {
|
||||||
|
@Override
|
||||||
|
public void preload(@NotNull ProgressIndicator indicator) {
|
||||||
|
/*
|
||||||
|
// Start notification timer.
|
||||||
|
indicator.setText("Ayah is preloading...");
|
||||||
|
NotificationTimer.INSTANCE.start();
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,6 +19,7 @@ public class AyahStartupActivity implements StartupActivity {
|
||||||
@Override
|
@Override
|
||||||
public void runActivity(@NotNull final Project project) {
|
public void runActivity(@NotNull final Project project) {
|
||||||
final var basmalhOnStartSettingsState = AyahSettingsState.getInstance().getBasmalhOnStart();
|
final var basmalhOnStartSettingsState = AyahSettingsState.getInstance().getBasmalhOnStart();
|
||||||
|
// Basmalh on start
|
||||||
if (basmalhOnStartSettingsState.isActive()) {
|
if (basmalhOnStartSettingsState.isActive()) {
|
||||||
try {
|
try {
|
||||||
final var bassmalh = Ayah.getAyah(1,
|
final var bassmalh = Ayah.getAyah(1,
|
||||||
|
@ -34,5 +35,7 @@ public class AyahStartupActivity implements StartupActivity {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Start notification timer.
|
||||||
|
NotificationTimer.INSTANCE.start(project);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.anas.intellij.plugins.ayah;
|
||||||
|
|
||||||
|
import com.anas.intellij.plugins.ayah.settings.AyahSettingsState;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Timer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: <a href="https://github.com/anas-elgarhy">Anas Elgarhy</a>
|
||||||
|
* @date: 8/19/22
|
||||||
|
*/
|
||||||
|
public enum NotificationTimer {
|
||||||
|
INSTANCE
|
||||||
|
;
|
||||||
|
|
||||||
|
private final Timer timer;
|
||||||
|
private final NotificationTimerTask notificationTimerTask;
|
||||||
|
|
||||||
|
NotificationTimer() {
|
||||||
|
timer = new Timer();
|
||||||
|
notificationTimerTask = new NotificationTimerTask();
|
||||||
|
}
|
||||||
|
public void start(@NotNull Project project) {
|
||||||
|
notificationTimerTask.setProject(project);
|
||||||
|
timer.schedule(notificationTimerTask, 0,
|
||||||
|
(long) AyahSettingsState.getInstance().getIntervalTimeBetweenNotifications() * 60 * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateIntervalTimeBetweenNotifications(final int intervalTimeBetweenNotifications) {
|
||||||
|
timer.cancel();
|
||||||
|
timer.schedule(notificationTimerTask, 0, (long) intervalTimeBetweenNotifications * 60 * 1000);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
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.Notification;
|
||||||
|
import com.intellij.notification.NotificationType;
|
||||||
|
import com.intellij.openapi.actionSystem.AnAction;
|
||||||
|
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: <a href="https://github.com/anas-elgarhy">Anas Elgarhy</a>
|
||||||
|
* @date: 8/19/22
|
||||||
|
*/
|
||||||
|
public class NotificationTimerTask extends TimerTask {
|
||||||
|
private Project project;
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
final var settings = AyahSettingsState.getInstance();
|
||||||
|
|
||||||
|
try {
|
||||||
|
final var randomAyah = Ayah.getRandomAyah();
|
||||||
|
|
||||||
|
// Set up the notification.
|
||||||
|
final var notification = new Notification("Random Ayah Notification",
|
||||||
|
randomAyah.getSurah().getName(), randomAyah.getText(), NotificationType.INFORMATION);
|
||||||
|
|
||||||
|
notification.addAction(new AnAction() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||||
|
System.out.println("Action performed");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Show notification
|
||||||
|
notification.notify(project);
|
||||||
|
|
||||||
|
// Play sound if enabled.
|
||||||
|
if (settings.isAutoPlayAudio()) {
|
||||||
|
new AudioPlayer(settings.getVolume(), randomAyah.getAudioUrl()).play();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (final IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProject(final Project project) {
|
||||||
|
this.project = project;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
package com.anas.intellij.plugins.ayah.settings;
|
package com.anas.intellij.plugins.ayah.settings;
|
||||||
|
|
||||||
|
import com.anas.intellij.plugins.ayah.NotificationTimer;
|
||||||
import com.intellij.openapi.options.Configurable;
|
import com.intellij.openapi.options.Configurable;
|
||||||
import com.intellij.openapi.options.ConfigurationException;
|
|
||||||
import org.jetbrains.annotations.Nls;
|
import org.jetbrains.annotations.Nls;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
@ -40,6 +40,13 @@ public class AyahSettingsConfigurable implements Configurable {
|
||||||
settingsState.setAutoPlayAudio(settingsComponent.isAutoPlayAudio());
|
settingsState.setAutoPlayAudio(settingsComponent.isAutoPlayAudio());
|
||||||
settingsState.setPlayerId(settingsComponent.getPlayerId());
|
settingsState.setPlayerId(settingsComponent.getPlayerId());
|
||||||
settingsState.setVolume(settingsComponent.getVolume());
|
settingsState.setVolume(settingsComponent.getVolume());
|
||||||
|
|
||||||
|
// Update the timer with the new interval time between notifications if interval time between notifications has changed
|
||||||
|
if (settingsState.getIntervalTimeBetweenNotifications() !=
|
||||||
|
settingsComponent.getIntervalTimeBetweenNotifications()) {
|
||||||
|
NotificationTimer.INSTANCE
|
||||||
|
.updateIntervalTimeBetweenNotifications(settingsState.getIntervalTimeBetweenNotifications());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class AyahSettingsState implements PersistentStateComponent<AyahSettingsS
|
||||||
this.basmalhOnStart = basmalhOnStart;
|
this.basmalhOnStart = basmalhOnStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getIntervalTimeBetweenNotifications() {
|
public int getIntervalTimeBetweenNotifications() {
|
||||||
return intervalTimeBetweenNotifications;
|
return intervalTimeBetweenNotifications;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
<extensions defaultExtensionNs="com.intellij">
|
<extensions defaultExtensionNs="com.intellij">
|
||||||
|
|
||||||
<postStartupActivity implementation="com.anas.intellij.plugins.ayah.AyahStartupActivity" />
|
<postStartupActivity implementation="com.anas.intellij.plugins.ayah.AyahStartupActivity" />
|
||||||
|
<preloadingActivity implementation="com.anas.intellij.plugins.ayah.AyahPreLoadingActivity"/>
|
||||||
|
|
||||||
<applicationConfigurable parentId="Other Settings"
|
<applicationConfigurable parentId="Other Settings"
|
||||||
instance="com.anas.intellij.plugins.ayah.settings.AyahSettingsConfigurable"
|
instance="com.anas.intellij.plugins.ayah.settings.AyahSettingsConfigurable"
|
||||||
|
@ -36,5 +37,6 @@
|
||||||
|
|
||||||
<notificationGroup id="Random ayah from the quran" displayType="BALLOON" />
|
<notificationGroup id="Random ayah from the quran" displayType="BALLOON" />
|
||||||
<notificationGroup displayType="BALLOON" id="Basmalh on Start" />
|
<notificationGroup displayType="BALLOON" id="Basmalh on Start" />
|
||||||
|
<notificationGroup displayType="BALLOON" id="Random Ayah Notification" />
|
||||||
</extensions>
|
</extensions>
|
||||||
</idea-plugin>
|
</idea-plugin>
|
Loading…
Reference in a new issue