A Kotlin library that simplifies the implementation of a dynamic heart rate zone component
HZone
HZone is a Kotlin library that demonstrates how to implement a component that draws five different zones based on a BPM (heart rate beats per minute) value provided to it.
Getting Started
To use HZone in your project, you need to add the following configuration to your settings.gradle
file.
Kotlin DSL
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven {
url = uri("https://jitpack.io")
}
}
}
Groovy
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Next, add the library dependency to your app module's build.gradle
.
Kotlin DSL
dependencies {
implementation("com.github.gastsail:hzone:[latest]")
}
Groovy
dependencies {
implementation 'com.github.gastsail:hzone:[latest]'
}
Usage
To use HZone
in your application, import the HZone
method and provide the necessary parameters.
val averageBpm = 75 // Replace with your actual average BPM
HZone(averageBpm) {
// Zone clicked
}
You can also specify the onZoneClick
parameter to handle zone click events.
HZone(averageBpm = averageBpm, onZoneClick = {
// Zone clicked
})
The averageBpm
parameter is used to calculate the average BPM from the values you provide using the calculateAverageBpm
function.
val bpmValues = viewModel.bpmValues.collectAsStateWithLifecycle()
val averageBpm = calculateAverageBpm(bpmValues)
Remember that the bpmValues
should be a stream that comes from a data source, this can be modeled in a viewmodel that emits each bpm to the view and the view collect it as state.
Feel free to customize and integrate HZone
into your project to visualize heart rate zones dynamically.
If you like this repo please don't forget to leave a ⭐️