From 3101839b05347545a963c67df2b0d0506dc476d9 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Wed, 29 May 2019 12:53:47 +0200 Subject: Refactor battery api classes. --- .../kotlin/pl/treksoft/kvision/cordova/Battery.kt | 38 +++++++++++++--------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'kvision-modules/kvision-cordova') diff --git a/kvision-modules/kvision-cordova/src/main/kotlin/pl/treksoft/kvision/cordova/Battery.kt b/kvision-modules/kvision-cordova/src/main/kotlin/pl/treksoft/kvision/cordova/Battery.kt index 5d9b8e93..84a7eb2e 100644 --- a/kvision-modules/kvision-cordova/src/main/kotlin/pl/treksoft/kvision/cordova/Battery.kt +++ b/kvision-modules/kvision-cordova/src/main/kotlin/pl/treksoft/kvision/cordova/Battery.kt @@ -24,15 +24,6 @@ package pl.treksoft.kvision.cordova import kotlin.browser.window -/** - * Battery status event types. - */ -enum class BatteryEvent(internal val type: String) { - BATTERY_STATUS("batterystatus"), - BATTERY_LOW("batterylow"), - BATTERY_CRITICAL("batterycritical") -} - /** * Battery status. */ @@ -42,13 +33,28 @@ external class BatteryStatus { } /** - * Add listeners for battery status Cordova events. + * Main object for Cordova battery. */ -fun addBatteryStatusListener(event: BatteryEvent, listener: (BatteryStatus) -> Unit) { - addDeviceReadyListener { - window.addEventListener(event.type, { status -> - @Suppress("UnsafeCastFromDynamic") - listener(status.asDynamic()) - }, false) +object Battery { + + /** + * Battery status event types. + */ + enum class BatteryEvent(internal val type: String) { + BATTERY_STATUS("batterystatus"), + BATTERY_LOW("batterylow"), + BATTERY_CRITICAL("batterycritical") + } + + /** + * Add listeners for battery status Cordova events. + */ + fun addStatusListener(event: BatteryEvent, listener: (BatteryStatus) -> Unit) { + addDeviceReadyListener { + window.addEventListener(event.type, { status -> + @Suppress("UnsafeCastFromDynamic") + listener(status.asDynamic()) + }, false) + } } } -- cgit