mirror of
https://github.com/dzeiocom/OpenHealth.git
synced 2025-06-13 09:29:19 +00:00
feat: Change inner work to allow more depictions of datas
This commit is contained in:
94
app/src/debug/res/layout/fragment_list_weight.xml
Normal file
94
app/src/debug/res/layout/fragment_list_weight.xml
Normal file
@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
style="?attr/materialCardViewFilledStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
|
||||
android:paddingHorizontal="12dp"
|
||||
android:paddingVertical="16dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:paddingVertical="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:src="@drawable/ic_outline_monitor_weight_24"
|
||||
android:background="@drawable/shape_circle"
|
||||
app:tint="?colorOnPrimary" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="4dp"
|
||||
android:text="History" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.dzeio.charts.ChartView
|
||||
android:id="@+id/chart"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp"
|
||||
android:minHeight="200dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/goal_button"
|
||||
android:text="@string/add_goal"
|
||||
style="?materialButtonOutlinedStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginVertical="16dp"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<Button
|
||||
android:id="@+id/debug_random_values"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Generate random values" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:clipToPadding="false"
|
||||
android:id="@+id/list"
|
||||
android:padding="16dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
tools:listitem="@layout/layout_item_list"
|
||||
tools:context=".ui.weight.ListWeightFragment" />
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -88,9 +88,7 @@ class StepsHomeFragment :
|
||||
}
|
||||
|
||||
xAxis.apply {
|
||||
increment = 86400000.0
|
||||
// displayCount = 168
|
||||
// displayCount = 10
|
||||
dataWidth = 604800000.0
|
||||
textPaint.color = MaterialColors.getColor(
|
||||
requireView(),
|
||||
com.google.android.material.R.attr.colorOnPrimaryContainer
|
||||
|
@ -10,15 +10,18 @@ import android.view.ViewGroup
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.dzeio.charts.Entry
|
||||
import com.dzeio.charts.series.LineSerie
|
||||
import com.dzeio.openhealth.R
|
||||
import com.dzeio.openhealth.adapters.WeightAdapter
|
||||
import com.dzeio.openhealth.core.BaseFragment
|
||||
import com.dzeio.openhealth.data.weight.Weight
|
||||
import com.dzeio.openhealth.databinding.FragmentListWeightBinding
|
||||
import com.dzeio.openhealth.graphs.WeightChart
|
||||
import com.dzeio.openhealth.utils.GraphUtils
|
||||
import com.google.android.material.color.MaterialColors
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import java.text.DateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
@AndroidEntryPoint
|
||||
class ListWeightFragment :
|
||||
@ -57,7 +60,7 @@ class ListWeightFragment :
|
||||
}
|
||||
}
|
||||
|
||||
val recycler = binding.list.apply {
|
||||
binding.list.apply {
|
||||
val manager = LinearLayoutManager(requireContext())
|
||||
layoutManager = manager
|
||||
this.adapter = adapter
|
||||
@ -65,7 +68,6 @@ class ListWeightFragment :
|
||||
|
||||
viewModel.massUnit.observe(viewLifecycleOwner) {
|
||||
adapter.unit = it
|
||||
// adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
viewModel.weights.observe(viewLifecycleOwner) {
|
||||
@ -77,28 +79,88 @@ class ListWeightFragment :
|
||||
}
|
||||
}
|
||||
|
||||
GraphUtils.lineChartSetup(
|
||||
binding.chart,
|
||||
MaterialColors.getColor(
|
||||
val chart = binding.chart
|
||||
|
||||
val serie = LineSerie(chart).apply {
|
||||
linePaint.color = MaterialColors.getColor(
|
||||
requireView(),
|
||||
com.google.android.material.R.attr.colorPrimary
|
||||
),
|
||||
MaterialColors.getColor(
|
||||
requireView(),
|
||||
com.google.android.material.R.attr.colorOnBackground
|
||||
)
|
||||
)
|
||||
textPaint.color = MaterialColors.getColor(
|
||||
requireView(),
|
||||
com.google.android.material.R.attr.colorOnPrimary
|
||||
)
|
||||
}
|
||||
|
||||
chart.apply {
|
||||
series = arrayListOf(serie)
|
||||
|
||||
yAxis.apply {
|
||||
textLabel.color = MaterialColors.getColor(
|
||||
requireView(),
|
||||
com.google.android.material.R.attr.colorOnPrimaryContainer
|
||||
)
|
||||
linePaint.color = MaterialColors.getColor(
|
||||
requireView(),
|
||||
com.google.android.material.R.attr.colorOnPrimaryContainer
|
||||
)
|
||||
|
||||
onValueFormat = { value -> "${value.toInt()}" }
|
||||
}
|
||||
|
||||
xAxis.apply {
|
||||
// 7 day history
|
||||
// increment = (7 * 24 * 60 * 60 * 1000).toDouble()
|
||||
textPaint.color = MaterialColors.getColor(
|
||||
requireView(),
|
||||
com.google.android.material.R.attr.colorOnPrimaryContainer
|
||||
)
|
||||
textPaint.textSize = 32f
|
||||
onValueFormat = onValueFormat@{
|
||||
val formatter = DateFormat.getDateTimeInstance(
|
||||
DateFormat.SHORT,
|
||||
DateFormat.SHORT,
|
||||
Locale.getDefault()
|
||||
)
|
||||
return@onValueFormat formatter.format(Date(it.toLong()))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Debug button
|
||||
if (binding.debugRandomValues != null) {
|
||||
binding.debugRandomValues.setOnClickListener {
|
||||
viewModel.generateRandomValues()
|
||||
}
|
||||
binding.debugRandomValues.setOnLongClickListener {
|
||||
viewModel.delete(viewModel.weights.value!!)
|
||||
return@setOnLongClickListener true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateGraph(list: List<Weight>) {
|
||||
WeightChart.setup(
|
||||
binding.chart,
|
||||
requireView(),
|
||||
list,
|
||||
viewModel.massUnit.value!!,
|
||||
viewModel.goalWeight.value,
|
||||
false
|
||||
)
|
||||
val chart = binding.chart
|
||||
val serie = chart.series[0] as LineSerie
|
||||
|
||||
val entries: ArrayList<Entry> = arrayListOf()
|
||||
|
||||
list.forEach {
|
||||
entries.add(Entry(
|
||||
it.timestamp.toDouble(),
|
||||
it.weight
|
||||
))
|
||||
}
|
||||
serie.entries = entries
|
||||
|
||||
if (list.isEmpty()) {
|
||||
chart.xAxis.x = 0.0
|
||||
} else {
|
||||
chart.xAxis.x = list[0].timestamp.toDouble()
|
||||
}
|
||||
|
||||
chart.refresh()
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
|
@ -13,6 +13,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
import kotlin.random.Random
|
||||
|
||||
@HiltViewModel
|
||||
class ListWeightViewModel @Inject internal constructor(
|
||||
@ -48,4 +49,20 @@ class ListWeightViewModel @Inject internal constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun generateRandomValues(): Unit {
|
||||
viewModelScope.launch {
|
||||
weightRepository.addWeight(
|
||||
Weight(
|
||||
weight = Random.nextInt(0, 100).toFloat()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun delete(list: List<Weight>) {
|
||||
viewModelScope.launch {
|
||||
for (item in list) weightRepository.deleteWeight(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ object Units {
|
||||
);
|
||||
|
||||
fun formatToString(value: Int): String {
|
||||
return String.format("%d", value * modifier)
|
||||
return String.format("%.0f", (value * modifier))
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<array name="health_permissions">
|
||||
<item>androidx.health.permission.HeartRate.READ</item>
|
||||
<item>androidx.health.permission.HeartRate.WRITE</item>
|
||||
<item>androidx.health.permission.Steps.READ</item>
|
||||
<item>androidx.health.permission.Steps.WRITE</item>
|
||||
</array>
|
||||
</resources>
|
Reference in New Issue
Block a user