😆 Compleate the plugin base yooooo 🥰

This commit is contained in:
Anas Elgarhy 2022-08-19 22:26:49 +02:00
parent b5445bc622
commit 1f517aa479
7 changed files with 124 additions and 2 deletions

View file

@ -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();
*/
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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

View file

@ -62,7 +62,7 @@ public class AyahSettingsState implements PersistentStateComponent<AyahSettingsS
this.basmalhOnStart = basmalhOnStart;
}
public long getIntervalTimeBetweenNotifications() {
public int getIntervalTimeBetweenNotifications() {
return intervalTimeBetweenNotifications;
}

View file

@ -27,6 +27,7 @@
<extensions defaultExtensionNs="com.intellij">
<postStartupActivity implementation="com.anas.intellij.plugins.ayah.AyahStartupActivity" />
<preloadingActivity implementation="com.anas.intellij.plugins.ayah.AyahPreLoadingActivity"/>
<applicationConfigurable parentId="Other Settings"
instance="com.anas.intellij.plugins.ayah.settings.AyahSettingsConfigurable"
@ -36,5 +37,6 @@
<notificationGroup id="Random ayah from the quran" displayType="BALLOON" />
<notificationGroup displayType="BALLOON" id="Basmalh on Start" />
<notificationGroup displayType="BALLOON" id="Random Ayah Notification" />
</extensions>
</idea-plugin>