TorServiceUI

Core androidMain abstraction which enables implementors the ability to create a fully customized notification for the running instances of TorRuntime as they operate within TorService.

This class' API is designed as follows:

NOTE: This is currently an ExperimentalKmpTorApi when extending to create your own implementation. Things may change (as the annotation states), so use at your own risk! Prefer using the stable implementation via the kmp-tor:runtime-service-ui dependency.

See also

io.matthewnelson.kmp.tor.runtime.service.ui.KmpTorServiceUI

Throws

IllegalStateException

on instantiation if args were not those which were passed to Factory.create. See Args.

Constructors

Link copied to clipboard
@ExperimentalKmpTorApi
protected constructor(args: TorServiceUI.Args)

Types

Link copied to clipboard

androidMain implementation for passing arguments in an encapsulated manner when instantiating new instances of TorServiceUI implementations.

Link copied to clipboard
protected object Companion
Link copied to clipboard
abstract class Factory<C : AbstractTorServiceUI.Config, IS : AbstractTorServiceUI.InstanceState<C>, UI : TorServiceUI<C, IS>> @ExperimentalKmpTorApi constructor(defaultConfig: C, val info: TorServiceUI.NotificationInfo) : AbstractTorServiceUI.Factory<TorServiceUI.Args, C, IS, UI>

Core androidMain abstraction for a Factory class which is responsible for instantiating new instances of TorServiceUI when requested by TorService.

Link copied to clipboard
class NotificationInfo @JvmOverloads constructor(val notificationId: Short, val channelId: String, val channelName: Int, val channelDescription: Int, val channelShowBadge: Boolean = false, val channelImportanceLow: Boolean = false)

Holder for Foreground Service Notification and NotificationChannel configuration info used to instantiate Factory. Is validated upon invocation of TorServiceConfig.Foreground.Companion.Builder.

Link copied to clipboard
protected fun interface Receiver

Callback for creating BroadcastReceiver that belong to the Service context, without exposing the Service to implementors of TorServiceUI.

Properties

Link copied to clipboard
@JvmField
protected val appContext: Context

Application Context for resolving android resources and creating Notification.Builder. This MUST NOT be utilized when posting Notification updates and registering BroadcastReceiver. Use post and register functions which will be executed within the context of the android.app.Service.

Link copied to clipboard
@JvmField
protected val channelId: String
Link copied to clipboard
@JvmField
protected val defaultConfig: C

The default Config that was defined for Factory.defaultConfig

Link copied to clipboard
@get:JvmName(name = "displayed")
protected val displayed: IS?

Returns the currently displayed InstanceState.

Link copied to clipboard
@get:JvmName(name = "instanceStates")
protected val instanceStates: Collection<IS>

All InstanceState currently operating within this UI "container".

Link copied to clipboard
@JvmField
protected val serviceChildScope: CoroutineScope

A CoroutineScope which is configured as a child to the service object's CoroutineScope which utilizes Dispatchers.Main

Functions

Link copied to clipboard

Implementors MUST utilize args to instantiate a new instance of the InstanceState implementation. If args were not consumed by the returned instance of InstanceState, an exception will be thrown by createProtected.

Link copied to clipboard
operator override fun equals(other: Any?): Boolean
Link copied to clipboard
override fun hashCode(): Int
Link copied to clipboard
fun isDestroyed(): Boolean
Link copied to clipboard
Link copied to clipboard
protected open fun onDestroy()
Link copied to clipboard
protected abstract fun onRender(displayed: IS, hasPrevious: Boolean, hasNext: Boolean)

Indicates there was a stateful change that requires an update to the UI.

Link copied to clipboard
protected fun Notification.post()

Posts the Notification to NotificationManager. This MUST be called upon first onRender invocation (or sooner) to ensure that the call to Service.startForeground is had, otherwise an ANR will result for Android API 26+.

Link copied to clipboard
@JvmOverloads
protected fun TorServiceUI.Receiver.register(filter: IntentFilter, permission: String?, scheduler: Handler?, exported: Boolean?, flags: Int = 0): Disposable.Once?

Registers a BroadcastReceiver with the Service context and pipes the Intent from BroadcastReceiver.onReceive to Receiver.onReceive.

Link copied to clipboard
protected fun selectNext()

Shifts the pointer to the "right" and calls onRender with the new parameters. If no next InstanceState is available, then nothing occurs.

Link copied to clipboard
protected fun selectPrevious()

Shifts the pointer to the "left" and calls onRender with the new parameters. If no previous InstanceState is available, then nothing occurs.