1
0
mirror of https://github.com/dzeiocom/OpenHealth.git synced 2025-04-23 19:32:11 +00:00

Merge branch 'Aviortheking-patch-1'

Signed-off-by: Avior <github@avior.me>
This commit is contained in:
Florian Bouillon 2022-01-06 01:01:33 +01:00
commit e7ae2e53ba
Signed by: Florian Bouillon
GPG Key ID: 0A288052C94BD2C8
14 changed files with 142 additions and 49 deletions

View File

@ -50,4 +50,3 @@ jobs:
github_token: ${{ secrets.github_token }} github_token: ${{ secrets.github_token }}
android: true android: true
reporter: github-pr-review # Change reporter reporter: github-pr-review # Change reporter

View File

@ -7,10 +7,11 @@ import com.dzeio.openhealth.core.BaseViewHolder
import com.dzeio.openhealth.databinding.LayoutExtensionItemBinding import com.dzeio.openhealth.databinding.LayoutExtensionItemBinding
import com.dzeio.openhealth.extensions.Extension import com.dzeio.openhealth.extensions.Extension
class ExtensionAdapter() : BaseAdapter<Extension, LayoutExtensionItemBinding>() {
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> LayoutExtensionItemBinding class ExtensionAdapter : BaseAdapter<Extension, LayoutExtensionItemBinding>() {
get() = LayoutExtensionItemBinding::inflate
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) ->
LayoutExtensionItemBinding = LayoutExtensionItemBinding::inflate
var onItemClick: ((weight: Extension) -> Unit)? = null var onItemClick: ((weight: Extension) -> Unit)? = null

View File

@ -129,7 +129,6 @@ class GoogleFit() : Extension() {
arrayOf(startTime, endTime) arrayOf(startTime, endTime)
} }
private fun startImport(data: Data) { private fun startImport(data: Data) {
Log.d("GoogleFitImporter", "Importing for ${data.name}") Log.d("GoogleFitImporter", "Importing for ${data.name}")
@ -151,9 +150,9 @@ class GoogleFit() : Extension() {
DataReadRequest.Builder() DataReadRequest.Builder()
.read(type) .read(type)
.setTimeRange(timeRange[0], timeRange[1], timeUnit) .setTimeRange(timeRange[0], timeRange[1], timeUnit)
.build(), data .build(),
data
) )
} }
private fun runRequest(request: DataReadRequest, data: Data) { private fun runRequest(request: DataReadRequest, data: Data) {
@ -209,7 +208,8 @@ class GoogleFit() : Extension() {
Data.WEIGHT -> { Data.WEIGHT -> {
weightLiveData.value = weightLiveData.value =
ImportState( ImportState(
States.DONE, weightLiveData.value?.list States.DONE,
weightLiveData.value?.list
?: ArrayList() ?: ArrayList()
) )
} }
@ -258,5 +258,4 @@ class GoogleFit() : Extension() {
return weightLiveData return weightLiveData
} }
} }

View File

@ -3,6 +3,7 @@ package com.dzeio.openhealth.ui.home
import android.animation.ValueAnimator import android.animation.ValueAnimator
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.Canvas import android.graphics.Canvas
import android.graphics.Color
import android.graphics.RectF import android.graphics.RectF
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
@ -20,6 +21,8 @@ import com.dzeio.openhealth.databinding.FragmentHomeBinding
import com.dzeio.openhealth.ui.weight.AddWeightDialog import com.dzeio.openhealth.ui.weight.AddWeightDialog
import com.dzeio.openhealth.utils.DrawUtils import com.dzeio.openhealth.utils.DrawUtils
import com.dzeio.openhealth.utils.GraphUtils import com.dzeio.openhealth.utils.GraphUtils
import com.github.mikephil.charting.components.LimitLine
import com.github.mikephil.charting.components.YAxis
import com.github.mikephil.charting.data.Entry import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.data.LineData import com.github.mikephil.charting.data.LineData
import com.github.mikephil.charting.data.LineDataSet import com.github.mikephil.charting.data.LineDataSet
@ -50,7 +53,7 @@ class HomeFragment : BaseFragment<HomeViewModel, FragmentHomeBinding>(HomeViewMo
AddWeightDialog().show(requireActivity().supportFragmentManager, null) AddWeightDialog().show(requireActivity().supportFragmentManager, null)
} }
binding.fragmentHomeWaterAdd.setOnClickListener { _ -> binding.fragmentHomeWaterAdd.setOnClickListener {
val water = viewModel.water.value val water = viewModel.water.value
@ -98,7 +101,6 @@ class HomeFragment : BaseFragment<HomeViewModel, FragmentHomeBinding>(HomeViewMo
viewModel.updateWater(item) viewModel.updateWater(item)
} }
} }
} }
} }
@ -115,7 +117,8 @@ class HomeFragment : BaseFragment<HomeViewModel, FragmentHomeBinding>(HomeViewMo
MaterialColors.getColor( MaterialColors.getColor(
requireView(), requireView(),
com.google.android.material.R.attr.colorPrimary com.google.android.material.R.attr.colorPrimary
), MaterialColors.getColor( ),
MaterialColors.getColor(
requireView(), requireView(),
com.google.android.material.R.attr.colorOnBackground com.google.android.material.R.attr.colorOnBackground
) )
@ -129,11 +132,17 @@ class HomeFragment : BaseFragment<HomeViewModel, FragmentHomeBinding>(HomeViewMo
entries.add(Entry(item.timestamp.toFloat(), item.weight)) entries.add(Entry(item.timestamp.toFloat(), item.weight))
} }
val dataSet = LineDataSet(entries, "Label") val dataSet = LineDataSet(entries, "Label").apply {
axisDependency = YAxis.AxisDependency.RIGHT
setDrawCircles(false)
setDrawCircleHole(false)
mode = LineDataSet.Mode.HORIZONTAL_BEZIER
}
binding.weightGraph.apply { binding.weightGraph.apply {
// Apply new dataset // Apply new dataset
data = LineData(dataSet) data = LineData(dataSet)
// idk what I did but it works lol // idk what I did but it works lol
@ -141,9 +150,42 @@ class HomeFragment : BaseFragment<HomeViewModel, FragmentHomeBinding>(HomeViewMo
0f, entries[entries.size - 1].x / 1000f 0f, entries[entries.size - 1].x / 1000f
) )
val goal = PreferenceManager.getDefaultSharedPreferences(requireContext())
.getString("weight_goal", null)?.toFloatOrNull()
// legend.apply {
// isEnabled = true
// form = Legend.LegendForm.LINE
//
// if (goal != null) {
// val legendEntry = LegendEntry().apply {
// label = "Weight Goal"
// formColor = Color.RED
// }
// setCustom(arrayOf(legendEntry))
// }
// }
setDrawBorders(false)
// BIS... :( // BIS... :(
// Also it invalidate the view so I don't have to call invalidate // Also it invalidate the view so I don't have to call invalidate
moveViewToX(entries[entries.size - 1].x - 1600000000f) moveViewToX(entries[entries.size - 1].x - 1600000000f)
if (goal != null) {
axisRight.axisMinimum = goal
val limit = LimitLine(goal)
limit.lineColor = Color.RED
val dash = 30f
limit.enableDashedLine(dash, dash, 0f)
limit.lineWidth = 1f
limit.textColor = Color.BLACK
limit.textSize = 12f
axisRight.addLimitLine(limit)
} else {
isAutoScaleMinMaxEnabled = true
}
} }
} }
} }
@ -167,7 +209,6 @@ class HomeFragment : BaseFragment<HomeViewModel, FragmentHomeBinding>(HomeViewMo
updateWater(0) updateWater(0)
} }
} }
} }
private fun updateWater(water: Int) { private fun updateWater(water: Int) {
@ -231,7 +272,8 @@ class HomeFragment : BaseFragment<HomeViewModel, FragmentHomeBinding>(HomeViewMo
MaterialColors.getColor( MaterialColors.getColor(
requireView(), requireView(),
com.google.android.material.R.attr.colorPrimary com.google.android.material.R.attr.colorPrimary
), 6f ),
6f
) )
canvas.save() canvas.save()
binding.background.setImageBitmap(graph) binding.background.setImageBitmap(graph)

View File

@ -1,11 +1,18 @@
package com.dzeio.openhealth.ui.settings package com.dzeio.openhealth.ui.settings
import android.os.Bundle import android.os.Bundle
import android.text.InputType
import androidx.preference.EditTextPreference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import com.dzeio.openhealth.R import com.dzeio.openhealth.R
class SettingsFragment : PreferenceFragmentCompat() { class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.preferences, rootKey) setPreferencesFromResource(R.xml.preferences, rootKey)
val weightGoal = findPreference<EditTextPreference>("weight_goal")
weightGoal?.setOnBindEditTextListener {
it.inputType = InputType.TYPE_CLASS_NUMBER
}
} }
} }

View File

@ -1,11 +1,13 @@
package com.dzeio.openhealth.ui.water package com.dzeio.openhealth.ui.water
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.dzeio.openhealth.Application.Companion.TAG
import com.dzeio.openhealth.adapters.WaterAdapter import com.dzeio.openhealth.adapters.WaterAdapter
import com.dzeio.openhealth.core.BaseFragment import com.dzeio.openhealth.core.BaseFragment
import com.dzeio.openhealth.databinding.FragmentMainWaterHomeBinding import com.dzeio.openhealth.databinding.FragmentMainWaterHomeBinding
@ -15,7 +17,9 @@ import com.github.mikephil.charting.data.BarDataSet
import com.github.mikephil.charting.data.BarEntry import com.github.mikephil.charting.data.BarEntry
import com.google.android.material.color.MaterialColors import com.google.android.material.color.MaterialColors
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import java.util.* import java.util.Calendar
import java.util.Date
import java.util.TimeZone
@AndroidEntryPoint @AndroidEntryPoint
class WaterHomeFragment : class WaterHomeFragment :
@ -47,26 +51,26 @@ class WaterHomeFragment :
val chart = binding.chart val chart = binding.chart
GraphUtils.barChartSetup( GraphUtils.barChartSetup(
chart, MaterialColors.getColor( chart,
MaterialColors.getColor(
requireView(), requireView(),
com.google.android.material.R.attr.colorPrimary com.google.android.material.R.attr.colorPrimary
), MaterialColors.getColor( ),
MaterialColors.getColor(
requireView(), requireView(),
com.google.android.material.R.attr.colorOnBackground com.google.android.material.R.attr.colorOnBackground
) )
) )
chart.xAxis.valueFormatter = GraphUtils.DateValueFormatter(1000 * 60 * 60 * 24)
viewModel.items.observe(viewLifecycleOwner) { list -> viewModel.items.observe(viewLifecycleOwner) { list ->
adapter.set(list) adapter.set(list)
val dataset = BarDataSet( val dataset = BarDataSet(
list.map { list.map {
val epoch = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
epoch.time = Date(0)
epoch.add(Calendar.MILLISECOND, it.timestamp.toInt())
return@map BarEntry( return@map BarEntry(
(epoch.timeInMillis / 1000 / 60 / 60).toFloat(), (it.timestamp / 1000 / 60 / 60 / 24).toFloat(),
it.value.toFloat() it.value.toFloat()
) )
}, },

View File

@ -0,0 +1,13 @@
package com.dzeio.openhealth.ui.water
import android.view.LayoutInflater
import com.dzeio.openhealth.core.BaseDialog
import com.dzeio.openhealth.databinding.DialogWaterSizeSelectorBinding
class WaterSizeSelectorDialog :
BaseDialog<WaterSizeSelectorViewModel, DialogWaterSizeSelectorBinding>(
WaterSizeSelectorViewModel::class.java
) {
override val bindingInflater: (LayoutInflater) -> DialogWaterSizeSelectorBinding
get() = DialogWaterSizeSelectorBinding::inflate
}

View File

@ -0,0 +1,6 @@
package com.dzeio.openhealth.ui.water
import com.dzeio.openhealth.core.BaseViewModel
class WaterSizeSelectorViewModel : BaseViewModel() {
}

View File

@ -11,12 +11,14 @@ import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.formatter.ValueFormatter import com.github.mikephil.charting.formatter.ValueFormatter
import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.Date
import java.util.Locale
object GraphUtils { object GraphUtils {
fun lineChartSetup(chart: LineChart, mainColor: Int, textColor: Int) { fun lineChartSetup(chart: LineChart, mainColor: Int, textColor: Int) {
barLineChartSetup(chart, mainColor, textColor) barLineChartSetup(chart, mainColor, textColor)
// chart.isAutoScaleMinMaxEnabled = true
} }
fun barChartSetup(chart: BarChart, mainColor: Int, textColor: Int) { fun barChartSetup(chart: BarChart, mainColor: Int, textColor: Int) {
@ -32,47 +34,40 @@ object GraphUtils {
chart.apply { chart.apply {
// Setup // Setup
legend.isEnabled = false legend.isEnabled = true
description = Description().apply { isEnabled = false } description = Description().apply { isEnabled = false }
xAxis.apply { xAxis.apply {
valueFormatter = object : ValueFormatter() { valueFormatter = DateValueFormatter()
override fun getAxisLabel(value: Float, axis: AxisBase?): String {
return SimpleDateFormat(
"yyyy-MM-dd",
Locale.getDefault()
).format(Date(value.toLong()))
//return super.getAxisLabel(value, axis)
}
}
position = XAxis.XAxisPosition.BOTTOM position = XAxis.XAxisPosition.BOTTOM
setDrawGridLines(false) setDrawGridLines(false)
setLabelCount(3, true) setLabelCount(3, true)
this.textColor = textColor this.textColor = textColor
//setDrawGridLines(false) // setDrawGridLines(false)
//setDrawZeroLine(false) // setDrawZeroLine(false)
setDrawAxisLine(false) setDrawAxisLine(false)
disableGridDashedLine() disableGridDashedLine()
invalidateOutline() invalidateOutline()
} }
axisLeft.apply { axisLeft.apply {
isEnabled = false
axisLineColor = mainColor axisLineColor = mainColor
this.textColor = textColor this.textColor = textColor
// setDrawZeroLine(false) setDrawZeroLine(false)
setLabelCount(0, true) setLabelCount(0, true)
setDrawGridLines(false) setDrawGridLines(false)
setDrawBorders(false)
} }
axisRight.apply { axisRight.apply {
this.textColor = textColor this.textColor = textColor
setLabelCount(4, true)
} }
setNoDataTextColor(textColor) setNoDataTextColor(textColor)
isAutoScaleMinMaxEnabled = true
legend.isEnabled = false legend.isEnabled = false
isDragEnabled = true isDragEnabled = true
isScaleYEnabled = false // isScaleYEnabled = false
description = Description().apply { isEnabled = false } description = Description().apply { isEnabled = false }
isScaleXEnabled = true isScaleXEnabled = true
setPinchZoom(false) setPinchZoom(false)
@ -80,4 +75,16 @@ object GraphUtils {
setDrawBorders(false) setDrawBorders(false)
} }
} }
class DateValueFormatter(
private val transformer: Int = 1
) : ValueFormatter() {
override fun getAxisLabel(value: Float, axis: AxisBase?): String {
return SimpleDateFormat(
"yyyy-MM-dd",
Locale.getDefault()
).format(Date(value.toLong() * transformer))
// return super.getAxisLabel(value, axis)
}
}
} }

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
</LinearLayout>

View File

@ -16,6 +16,14 @@
android:selectAllOnFocus="true" android:selectAllOnFocus="true"
android:singleLine="true" android:singleLine="true"
android:title="Height" /> android:title="Height" />
<EditTextPreference
android:key="weight_goal"
android:selectAllOnFocus="true"
android:singleLine="true"
android:digits="0123456789"
android:inputType="numberDecimal"
android:title="Goal Weight" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="Water Settings"> <PreferenceCategory android:title="Water Settings">

View File

@ -10,8 +10,8 @@ buildscript {
} }
plugins { plugins {
id 'com.android.application' version '7.1.0-beta05' apply false id 'com.android.application' version '7.1.0-rc01' apply false
id 'com.android.library' version '7.1.0-beta05' apply false id 'com.android.library' version '7.1.0-rc01' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
} }

BIN
private_key.pepk Normal file

Binary file not shown.