diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-05-29 12:53:47 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-05-29 12:53:47 +0200 |
commit | 3101839b05347545a963c67df2b0d0506dc476d9 (patch) | |
tree | 50d87753867cd284dbbe3b74f7ea20be5f6f1bdc /kvision-modules/kvision-cordova | |
parent | ba0faac18b6641e90866d108f49bfc42148b4085 (diff) | |
download | kvision-3101839b05347545a963c67df2b0d0506dc476d9.tar.gz kvision-3101839b05347545a963c67df2b0d0506dc476d9.tar.bz2 kvision-3101839b05347545a963c67df2b0d0506dc476d9.zip |
Refactor battery api classes.
Diffstat (limited to 'kvision-modules/kvision-cordova')
-rw-r--r-- | kvision-modules/kvision-cordova/src/main/kotlin/pl/treksoft/kvision/cordova/Battery.kt | 38 |
1 files changed, 22 insertions, 16 deletions
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 @@ -25,15 +25,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. */ external class BatteryStatus { @@ -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) + } } } |