InterfaceLock

class InterfaceLock(lifecycle: Lifecycle, group: InterfaceLock.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

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

Types

Group
Link copied to clipboard
class Group
Exclusive access lock group.
State
Link copied to clipboard
sealed class State
State of the lock.

Functions

resetFailedState
Link copied to clipboard
fun resetFailedState(): Boolean
Resets the current state to Idle if it's currently Failed.
runExclusively
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

isLocked
Link copied to clipboard
val isLocked: Boolean
Whether the lock is currently executing work and is locked.
observeIsLocked
Link copied to clipboard
val observeIsLocked: ObservableProperty<Boolean>
observeState
Link copied to clipboard
val observeState: ObservableProperty<InterfaceLock.State>
state
Link copied to clipboard
var state: InterfaceLock.State