InterfaceLock

class InterfaceLock(lifecycle: Lifecycle, group: InterfaceLock.Group = Group())

Locking for user interface operations.

Use an instance of this class to ensure user interactions are ignored while a user-initiated operation is already running.

Each instance of InterfaceLock is a member of a Group and if no group parameter is provided to the constructor a new group is created by default. Only a single operation can be running across all InterfaceLock instances in the same group. Additional operations are not run until the currently running one completes.

Since the runExclusively is not blocking or suspending, you can monitor the progress using the state and observeState properties.

Constructors

Link copied to clipboard
fun InterfaceLock(lifecycle: Lifecycle, group: InterfaceLock.Group = Group())

Types

Link copied to clipboard
class Group

Exclusive access lock group. Multiple locks in the same group are competing with each other.

Link copied to clipboard
sealed class State

State of the lock.

Functions

Link copied to clipboard
fun resetFailedState(): Boolean

Resets the current state to Idle if it's currently Failed.

Link copied to clipboard
fun runExclusively(work: suspend () -> Unit)

While the supplied work is running, this lock is considered taken and all other invocations of this method will just return, doing nothing.

Properties

Link copied to clipboard
val isLocked: Boolean

Whether the lock is currently executing work and is locked.

Link copied to clipboard
val observeIsLocked: ObservableProperty<Boolean>
Link copied to clipboard
val observeState: ObservableProperty<InterfaceLock.State>
Link copied to clipboard
var state: InterfaceLock.State