VancedManager/app/src/main/java/com/vanced/manager/ui/events/Event.kt

24 lines
497 B
Kotlin

package com.vanced.manager.ui.events
open class Event<out T>(private val content: T) {
private var hasBeenHandled = false
/**
* Returns the content and prevents its use again.
*/
fun getContentIfNotHandled(): T? {
return if (hasBeenHandled) {
null
} else {
hasBeenHandled = true
content
}
}
/**
* Returns the content, even if it's already been handled.
*/
fun peekContent(): T = content
}