88import java .time .LocalDateTime ;
99
1010import static de .rettichlp .ucutils .UCUtils .messageService ;
11+ import static de .rettichlp .ucutils .UCUtils .notificationService ;
1112import static de .rettichlp .ucutils .UCUtils .storage ;
1213import static de .rettichlp .ucutils .UCUtils .utilService ;
1314import static java .time .Duration .between ;
@@ -29,17 +30,7 @@ public Countdown(String title, Duration duration, Runnable runAfter) {
2930 this .title = title ;
3031 this .duration = duration ;
3132
32- storage .getCountdowns ().add (this );
33-
34- utilService .delayedAction (runAfter , this .duration .toMillis ());
35- }
36-
37- public Duration getRemainingDuration () {
38- return between (now (), this .startTime .plus (this .duration ));
39- }
40-
41- public Notification toWidget () {
42- return Notification .builder ()
33+ Notification countdownNotification = Notification .builder ()
4334 .componentSupplier (() -> {
4435 String millisToFriendlyString = messageService .millisToFriendlyString (getRemainingDuration ().toMillis ());
4536
@@ -48,7 +39,15 @@ public Notification toWidget() {
4839 .append (literal (":" ).withStyle (GRAY )).append (" " )
4940 .append (literal (millisToFriendlyString ));
5041 })
51- .displayDuration (this . duration )
42+ .displayDuration (duration )
5243 .build ();
44+
45+ storage .getCountdowns ().add (this );
46+ notificationService .getNotifications ().add (countdownNotification );
47+ utilService .delayedAction (runAfter , this .duration .toMillis ());
48+ }
49+
50+ public Duration getRemainingDuration () {
51+ return between (now (), this .startTime .plus (this .duration ));
5352 }
5453}
0 commit comments