X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fnotification%2FSoneLockedHandler.kt;h=2217baddf234451939c49082217926937f679179;hb=1ad1aae2e29c608c5e1ab89e125bf2267fed18c6;hp=583601b466ed9632a86e8b739e8e0d7c1f4dc42a;hpb=6d770b3aa761b4432517b4789a980c4ba75ed9fa;p=Sone.git diff --git a/src/main/kotlin/net/pterodactylus/sone/web/notification/SoneLockedHandler.kt b/src/main/kotlin/net/pterodactylus/sone/web/notification/SoneLockedHandler.kt index 583601b..2217bad 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/notification/SoneLockedHandler.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/notification/SoneLockedHandler.kt @@ -33,32 +33,32 @@ import javax.inject.* class SoneLockedHandler @Inject constructor( private val notificationManager: NotificationManager, @Named("soneLocked") private val notification: ListNotification, - private val executor: ScheduledExecutorService) { + @Named("notification") private val executor: ScheduledExecutorService) { private val future: AtomicReference> = AtomicReference() @Subscribe fun soneLocked(soneLockedEvent: SoneLockedEvent) { synchronized(future) { - future.get()?.also { cancelPreviousFuture(it, soneLockedEvent.sone) } - future.set(executor.schedule(showNotification(soneLockedEvent.sone), 5, TimeUnit.MINUTES)) + notification.add(soneLockedEvent.sone) + future.get()?.also(this::cancelPreviousFuture) + future.set(executor.schedule(::showNotification, 5, TimeUnit.MINUTES)) } } @Subscribe fun soneUnlocked(soneUnlockedEvent: SoneUnlockedEvent) { synchronized(future) { - future.get()?.also { cancelPreviousFuture(it, soneUnlockedEvent.sone) } + notification.remove(soneUnlockedEvent.sone) + future.get()?.also(::cancelPreviousFuture) } } - private fun cancelPreviousFuture(future: ScheduledFuture<*>, sone: Sone) { - notification.remove(sone) + private fun cancelPreviousFuture(future: ScheduledFuture<*>) { future.cancel(true) } - private fun showNotification(sone: Sone): () -> Unit = { - notification.add(sone) + private fun showNotification() { notificationManager.addNotification(notification) }