diff --git a/src/main/java/com/anas/intellij/plugins/ayah/AyahPreLoadingActivity.java b/src/main/java/com/anas/intellij/plugins/ayah/AyahPreLoadingActivity.java
new file mode 100644
index 0000000..e5307ec
--- /dev/null
+++ b/src/main/java/com/anas/intellij/plugins/ayah/AyahPreLoadingActivity.java
@@ -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: Anas Elgarhy
+ * @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();
+*/
+ }
+}
diff --git a/src/main/java/com/anas/intellij/plugins/ayah/AyahStartupActivity.java b/src/main/java/com/anas/intellij/plugins/ayah/AyahStartupActivity.java
index 93d513b..72db903 100644
--- a/src/main/java/com/anas/intellij/plugins/ayah/AyahStartupActivity.java
+++ b/src/main/java/com/anas/intellij/plugins/ayah/AyahStartupActivity.java
@@ -19,6 +19,7 @@ public class AyahStartupActivity implements StartupActivity {
@Override
public void runActivity(@NotNull final Project project) {
final var basmalhOnStartSettingsState = AyahSettingsState.getInstance().getBasmalhOnStart();
+ // Basmalh on start
if (basmalhOnStartSettingsState.isActive()) {
try {
final var bassmalh = Ayah.getAyah(1,
@@ -34,5 +35,7 @@ public class AyahStartupActivity implements StartupActivity {
e.printStackTrace();
}
}
+ // Start notification timer.
+ NotificationTimer.INSTANCE.start(project);
}
}
diff --git a/src/main/java/com/anas/intellij/plugins/ayah/NotificationTimer.java b/src/main/java/com/anas/intellij/plugins/ayah/NotificationTimer.java
new file mode 100644
index 0000000..a88e7cb
--- /dev/null
+++ b/src/main/java/com/anas/intellij/plugins/ayah/NotificationTimer.java
@@ -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: Anas Elgarhy
+ * @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);
+ }
+}
diff --git a/src/main/java/com/anas/intellij/plugins/ayah/NotificationTimerTask.java b/src/main/java/com/anas/intellij/plugins/ayah/NotificationTimerTask.java
new file mode 100644
index 0000000..6d0674b
--- /dev/null
+++ b/src/main/java/com/anas/intellij/plugins/ayah/NotificationTimerTask.java
@@ -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: Anas Elgarhy
+ * @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;
+ }
+}
diff --git a/src/main/java/com/anas/intellij/plugins/ayah/settings/AyahSettingsConfigurable.java b/src/main/java/com/anas/intellij/plugins/ayah/settings/AyahSettingsConfigurable.java
index 611c8c6..3a184d9 100644
--- a/src/main/java/com/anas/intellij/plugins/ayah/settings/AyahSettingsConfigurable.java
+++ b/src/main/java/com/anas/intellij/plugins/ayah/settings/AyahSettingsConfigurable.java
@@ -1,7 +1,7 @@
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.ConfigurationException;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;
@@ -40,6 +40,13 @@ public class AyahSettingsConfigurable implements Configurable {
settingsState.setAutoPlayAudio(settingsComponent.isAutoPlayAudio());
settingsState.setPlayerId(settingsComponent.getPlayerId());
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
diff --git a/src/main/java/com/anas/intellij/plugins/ayah/settings/AyahSettingsState.java b/src/main/java/com/anas/intellij/plugins/ayah/settings/AyahSettingsState.java
index 780a889..b93fa5e 100644
--- a/src/main/java/com/anas/intellij/plugins/ayah/settings/AyahSettingsState.java
+++ b/src/main/java/com/anas/intellij/plugins/ayah/settings/AyahSettingsState.java
@@ -62,7 +62,7 @@ public class AyahSettingsState implements PersistentStateComponent
+
+
\ No newline at end of file