GenericPanel

abstract class GenericPanel<C : PanelContext>(val frontendContext: FrontendContext) : PanelContextProvider<C> , LifecycleOwner

A panel to visually represent a Frontend. Panels are intended to be presented to the user by the system UI, which does this by attaching the IviFragment returned by createInitialFragment to its layout. The created fragment will internally instantiate a ViewModel (FrontendViewModel) with a reference to this panel.

The system UI may choose to show and stop showing the panel more than once. E.g., a panel may be temporarily removed from the system UI if a similar panel with higher priority is offered to the system UI. Each time, a new fragment, along with its ViewModel, is created and destroyed. As such, it's important to consider whether data should be stored in the panel or the ViewModel. Data that is solely used by the fragment's view typically belongs in in the ViewModel, but note that it will be cleared when the panel is removed and presented again. Data that is important to persist should be kept in the panel instead.

Service connections for presenting data are commonly in the ViewModel rather than the panel to avoid keeping services alive for panels that are not presented. (Note that if the service requested in the ViewModel is already alive, creating another connection to it is a cheap operation.) It can however be beneficial for the panel to ask for a service connection in its constructor, allowing the service connection to be created by the Frontend and thus stay alive after the panel is destroyed. This allows panel contents to be populated immediately upon showing and is important when a service call must be performed upon the destruction of the panel or ViewModel, as those calls may fail when the service is closed as a result of the panel's or ViewModel's destruction. Similarly, if a call is needed when the panel is removed, it is not sufficient to perform it within ViewModel.onCleared because the ViewModel may never have been created during the panel's lifespan.

The panel starts as detached with the lifecycle in Lifecycle.State.CREATED. The lifecycle changes state to Lifecycle.State.STARTED when it is attached to the system UI. The panel can be detached and then attached again.

If the panel is dismissed or removed from the frontend, its lifecycle transitions to Lifecycle.State.DESTROYED after which it may not be added to a frontend again.

A panel instance can only be added to a single Frontend instance. The frontendContext must be the same Frontend.frontendContext instance of the frontend to which this panel will be added.

Parameters

frontendContext

An entry point for this GenericPanel to communicate with the rest of the system.

Constructors

Link copied to clipboard
fun GenericPanel(frontendContext: FrontendContext)

Properties

Link copied to clipboard
val frontendContext: FrontendContext
Link copied to clipboard
val id: Long

Unique identifier of a GenericPanel. Each ID is an increment of the previously created panel's ID, allowing this value to be used for sorting purposes.

Link copied to clipboard
val isOccluded: LiveData<Boolean?>

Whether the panel is partially or fully occluded:

Link copied to clipboard
override val panelContext: LiveData<C?>

The PanelContext given when the panel is attached to the system UI.

Link copied to clipboard
val tag: String

The tag to recognise this panel with. Useful in combination with fragment tags to detect which fragment belongs to which panel.

Link copied to clipboard
var transitionDestination: PanelTransitionDestination? = null

A destination that the information contained by this panel transitions to when this panel closes. By default it is null, indicating the information does not transition anywhere.

Link copied to clipboard
var transitionSource: PanelTransitionSource? = null

The source of the information contained by this panel when the information transitions from another panel to this one. By default it is null, indicating the information does not transition from any other particular panel.

Functions

Link copied to clipboard
fun createInitialFragment(): Fragment

The fragment used when initially showing the panel. The fragment may be recreated by the system UI upon configuration changes.

Link copied to clipboard
operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun getLifecycle(): Lifecycle
Link copied to clipboard
override fun hashCode(): Int
Link copied to clipboard
open fun onAddedToFrontend()

Called when this panel is added to Frontend.panels, allowing it to be shown in the system UI.

Link copied to clipboard
open fun onAttached(panelContext: C)

Called when the panel is attached to the system UI. The panel may be detached and attached multiple times, for example on configuration changes. However, a panel will never be attached multiple times at once.

Link copied to clipboard
open fun onDetached()

Called when the panel has been detached from the system UI. The panel may be attached again later, for example when the configuration changes.

Link copied to clipboard
open fun onRemovedFromFrontend()

Called when this panel is removed from Frontend.panels, preventing it from being shown in the system UI.

Link copied to clipboard
open override fun toString(): String

Inheritors

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard