--- /dev/null
+package net.pterodactylus.sone.utils
+
+import java.util.function.*
+
+/** Allows easy invocation of Java Consumers. */
+operator fun <T> Consumer<T>.invoke(t: T) = accept(t)
import net.pterodactylus.sone.core.event.*
import net.pterodactylus.sone.data.*
import net.pterodactylus.sone.notify.*
+import net.pterodactylus.sone.utils.*
import net.pterodactylus.util.notify.*
+import java.util.function.*
import javax.inject.*
/**
* the [notification manager][NotificationManager] shows a [first start notification]
* [NotificationManager.hasFirstStartNotification].
*/
-class MarkPostKnownDuringFirstStartHandler(private val notificationManager: NotificationManager, private val markPostAsKnown: (Post) -> Unit) {
+class MarkPostKnownDuringFirstStartHandler @Inject constructor(private val notificationManager: NotificationManager, private val markPostAsKnown: Consumer<Post>) {
@Subscribe
fun newPostFound(newPostFoundEvent: NewPostFoundEvent) {
package net.pterodactylus.sone.web.notification
import com.google.inject.*
+import com.google.inject.binder.*
import net.pterodactylus.sone.core.*
import net.pterodactylus.sone.data.*
import net.pterodactylus.sone.main.*
import net.pterodactylus.sone.notify.*
import net.pterodactylus.util.notify.*
import java.util.concurrent.Executors.*
+import java.util.function.*
import javax.inject.*
import javax.inject.Singleton
override fun configure() {
bind(NotificationHandler::class.java).`in`(Singleton::class.java)
+ bind<MarkPostKnownDuringFirstStartHandler>().asSingleton()
}
@Provides
- @Singleton
- fun getMarkPostKnownDuringFirstStartHandler(core: Core, notificationManager: NotificationManager) =
- MarkPostKnownDuringFirstStartHandler(notificationManager, core::markPostKnown)
+ fun getMarkPostKnownHandler(core: Core): Consumer<Post> = Consumer { core.markPostKnown(it) }
@Provides
@Singleton
fun getSoneLockedHandler(notificationManager: NotificationManager, @Named("soneLocked") soneLockedNotification: ListNotification<Sone>) =
SoneLockedHandler(notificationManager, soneLockedNotification, newScheduledThreadPool(1))
+ private inline fun <reified T> bind(): AnnotatedBindingBuilder<T> = bind(T::class.java)
+ private fun ScopedBindingBuilder.asSingleton() = `in`(Singleton::class.java)
+
}
import org.hamcrest.MatcherAssert.*
import org.hamcrest.Matchers.*
import java.io.*
+import java.util.function.Consumer
import kotlin.test.*
/**
private val eventBus = EventBus()
private val notificationManager = NotificationManager()
private val markedPosts = mutableListOf<Post>()
- private val handler = MarkPostKnownDuringFirstStartHandler(notificationManager) { markedPosts += it }
+ private val handler = MarkPostKnownDuringFirstStartHandler(notificationManager, Consumer { markedPosts += it })
init {
eventBus.register(handler)