Skip to content

Commit

Permalink
refactor: create and use zoneOffsetToJsMap util
Browse files Browse the repository at this point in the history
  • Loading branch information
Minishlink committed Aug 1, 2024
1 parent 695d863 commit d6f3fd0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,12 @@ class ReactExerciseSessionRecord : ReactHealthRecordImpl<ExerciseSessionRecord>
override fun parseRecord(record: ExerciseSessionRecord): WritableNativeMap {
return WritableNativeMap().apply {
putString("startTime", record.startTime.toString())
putMap("startZoneOffset", zoneOffsetToJsMap(record.startZoneOffset))
putString("endTime", record.endTime.toString())
putMap("endZoneOffset", zoneOffsetToJsMap(record.endZoneOffset))
putString("notes", record.notes)
putString("title", record.title)
putInt("exerciseType", record.exerciseType)

if (record.startZoneOffset != null) {
putMap("startZoneOffset", WritableNativeMap().apply {
putString("id", record.startZoneOffset!!.id)
putInt("totalSeconds", record.startZoneOffset!!.totalSeconds)
})
}

if (record.endZoneOffset != null) {
putMap("endZoneOffset", WritableNativeMap().apply {
putString("id", record.endZoneOffset!!.id)
putInt("totalSeconds", record.endZoneOffset!!.totalSeconds)
})
}

putArray("laps", WritableNativeArray().apply {
record.laps.map {
val map = WritableNativeMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.facebook.react.bridge.WritableNativeArray
import com.facebook.react.bridge.WritableNativeMap
import dev.matinzd.healthconnect.records.*
import java.time.Instant
import java.time.ZoneOffset
import kotlin.reflect.KClass

fun <T : Record> convertReactRequestOptionsFromJS(
Expand Down Expand Up @@ -258,6 +259,17 @@ fun lengthToJsMap(length: Length?): WritableNativeMap {
}
}

fun zoneOffsetToJsMap(zoneOffset: ZoneOffset?): WritableNativeMap? {
if (zoneOffset == null) {
return null
}

return WritableNativeMap().apply {
putString("id", zoneOffset.id)
putInt("totalSeconds", zoneOffset.totalSeconds)
}
}

fun getVolumeFromJsMap(volume: ReadableMap?): Volume {
if (volume == null) {
throw InvalidLength()
Expand Down

0 comments on commit d6f3fd0

Please sign in to comment.