2023-11-23 15:45:55 +03:00
|
|
|
package org.amnezia.vpn.protocol
|
|
|
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
|
2023-12-05 16:10:29 +03:00
|
|
|
private const val STATE_KEY = "state"
|
2023-11-23 15:45:55 +03:00
|
|
|
|
|
|
|
|
@Suppress("DataClassPrivateConstructor")
|
|
|
|
|
data class Status private constructor(
|
2023-12-05 16:10:29 +03:00
|
|
|
val state: ProtocolState
|
2023-11-23 15:45:55 +03:00
|
|
|
) {
|
2023-12-05 16:10:29 +03:00
|
|
|
private constructor(builder: Builder) : this(builder.state)
|
2023-11-23 15:45:55 +03:00
|
|
|
|
|
|
|
|
class Builder {
|
2023-12-05 16:10:29 +03:00
|
|
|
lateinit var state: ProtocolState
|
2023-11-23 15:45:55 +03:00
|
|
|
private set
|
|
|
|
|
|
2023-12-05 16:10:29 +03:00
|
|
|
fun setState(state: ProtocolState) = apply { this.state = state }
|
2023-11-23 15:45:55 +03:00
|
|
|
|
|
|
|
|
fun build(): Status = Status(this)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
inline fun build(block: Builder.() -> Unit): Status = Builder().apply(block).build()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-05 16:10:29 +03:00
|
|
|
fun Bundle.putStatus(status: Status) {
|
|
|
|
|
putInt(STATE_KEY, status.state.ordinal)
|
2023-11-23 15:45:55 +03:00
|
|
|
}
|
|
|
|
|
|
2024-03-04 18:08:55 +03:00
|
|
|
fun Bundle.putStatus(state: ProtocolState) {
|
|
|
|
|
putInt(STATE_KEY, state.ordinal)
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-23 15:45:55 +03:00
|
|
|
fun Bundle.getStatus(): Status =
|
|
|
|
|
Status.build {
|
2023-12-05 16:10:29 +03:00
|
|
|
setState(ProtocolState.entries[getInt(STATE_KEY)])
|
2023-11-23 15:45:55 +03:00
|
|
|
}
|