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:
commit
e7ae2e53ba
1
.github/workflows/build.yml
vendored
1
.github/workflows/build.yml
vendored
@ -50,4 +50,3 @@ jobs:
|
||||
github_token: ${{ secrets.github_token }}
|
||||
android: true
|
||||
reporter: github-pr-review # Change reporter
|
||||
|
||||
|
@ -7,10 +7,11 @@ import com.dzeio.openhealth.core.BaseViewHolder
|
||||
import com.dzeio.openhealth.databinding.LayoutExtensionItemBinding
|
||||
import com.dzeio.openhealth.extensions.Extension
|
||||
|
||||
class ExtensionAdapter() : BaseAdapter<Extension, LayoutExtensionItemBinding>() {
|
||||
|
||||
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> LayoutExtensionItemBinding
|
||||
get() = LayoutExtensionItemBinding::inflate
|
||||
class ExtensionAdapter : BaseAdapter<Extension, LayoutExtensionItemBinding>() {
|
||||
|
||||
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) ->
|
||||
LayoutExtensionItemBinding = LayoutExtensionItemBinding::inflate
|
||||
|
||||
var onItemClick: ((weight: Extension) -> Unit)? = null
|
||||
|
||||
|
@ -25,4 +25,4 @@ class WaterAdapter() : BaseAdapter<Water, LayoutItemListBinding>() {
|
||||
onItemClick?.invoke(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +129,6 @@ class GoogleFit() : Extension() {
|
||||
arrayOf(startTime, endTime)
|
||||
}
|
||||
|
||||
|
||||
private fun startImport(data: Data) {
|
||||
Log.d("GoogleFitImporter", "Importing for ${data.name}")
|
||||
|
||||
@ -151,9 +150,9 @@ class GoogleFit() : Extension() {
|
||||
DataReadRequest.Builder()
|
||||
.read(type)
|
||||
.setTimeRange(timeRange[0], timeRange[1], timeUnit)
|
||||
.build(), data
|
||||
.build(),
|
||||
data
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
private fun runRequest(request: DataReadRequest, data: Data) {
|
||||
@ -209,7 +208,8 @@ class GoogleFit() : Extension() {
|
||||
Data.WEIGHT -> {
|
||||
weightLiveData.value =
|
||||
ImportState(
|
||||
States.DONE, weightLiveData.value?.list
|
||||
States.DONE,
|
||||
weightLiveData.value?.list
|
||||
?: ArrayList()
|
||||
)
|
||||
}
|
||||
@ -258,5 +258,4 @@ class GoogleFit() : Extension() {
|
||||
|
||||
return weightLiveData
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.dzeio.openhealth.ui.home
|
||||
import android.animation.ValueAnimator
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.RectF
|
||||
import android.os.Bundle
|
||||
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.utils.DrawUtils
|
||||
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.LineData
|
||||
import com.github.mikephil.charting.data.LineDataSet
|
||||
@ -50,7 +53,7 @@ class HomeFragment : BaseFragment<HomeViewModel, FragmentHomeBinding>(HomeViewMo
|
||||
AddWeightDialog().show(requireActivity().supportFragmentManager, null)
|
||||
}
|
||||
|
||||
binding.fragmentHomeWaterAdd.setOnClickListener { _ ->
|
||||
binding.fragmentHomeWaterAdd.setOnClickListener {
|
||||
|
||||
val water = viewModel.water.value
|
||||
|
||||
@ -98,7 +101,6 @@ class HomeFragment : BaseFragment<HomeViewModel, FragmentHomeBinding>(HomeViewMo
|
||||
viewModel.updateWater(item)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,7 +117,8 @@ class HomeFragment : BaseFragment<HomeViewModel, FragmentHomeBinding>(HomeViewMo
|
||||
MaterialColors.getColor(
|
||||
requireView(),
|
||||
com.google.android.material.R.attr.colorPrimary
|
||||
), MaterialColors.getColor(
|
||||
),
|
||||
MaterialColors.getColor(
|
||||
requireView(),
|
||||
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))
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
// Apply new dataset
|
||||
|
||||
data = LineData(dataSet)
|
||||
|
||||
// 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
|
||||
)
|
||||
|
||||
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... :(
|
||||
// Also it invalidate the view so I don't have to call invalidate
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun updateWater(water: Int) {
|
||||
@ -231,7 +272,8 @@ class HomeFragment : BaseFragment<HomeViewModel, FragmentHomeBinding>(HomeViewMo
|
||||
MaterialColors.getColor(
|
||||
requireView(),
|
||||
com.google.android.material.R.attr.colorPrimary
|
||||
), 6f
|
||||
),
|
||||
6f
|
||||
)
|
||||
canvas.save()
|
||||
binding.background.setImageBitmap(graph)
|
||||
@ -239,4 +281,4 @@ class HomeFragment : BaseFragment<HomeViewModel, FragmentHomeBinding>(HomeViewMo
|
||||
start()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,18 @@
|
||||
package com.dzeio.openhealth.ui.settings
|
||||
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import androidx.preference.EditTextPreference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import com.dzeio.openhealth.R
|
||||
|
||||
class SettingsFragment : PreferenceFragmentCompat() {
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.preferences, rootKey)
|
||||
|
||||
val weightGoal = findPreference<EditTextPreference>("weight_goal")
|
||||
weightGoal?.setOnBindEditTextListener {
|
||||
it.inputType = InputType.TYPE_CLASS_NUMBER
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
package com.dzeio.openhealth.ui.water
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.dzeio.openhealth.Application.Companion.TAG
|
||||
import com.dzeio.openhealth.adapters.WaterAdapter
|
||||
import com.dzeio.openhealth.core.BaseFragment
|
||||
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.google.android.material.color.MaterialColors
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import java.util.*
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
import java.util.TimeZone
|
||||
|
||||
@AndroidEntryPoint
|
||||
class WaterHomeFragment :
|
||||
@ -47,26 +51,26 @@ class WaterHomeFragment :
|
||||
val chart = binding.chart
|
||||
|
||||
GraphUtils.barChartSetup(
|
||||
chart, MaterialColors.getColor(
|
||||
chart,
|
||||
MaterialColors.getColor(
|
||||
requireView(),
|
||||
com.google.android.material.R.attr.colorPrimary
|
||||
), MaterialColors.getColor(
|
||||
),
|
||||
MaterialColors.getColor(
|
||||
requireView(),
|
||||
com.google.android.material.R.attr.colorOnBackground
|
||||
)
|
||||
)
|
||||
|
||||
chart.xAxis.valueFormatter = GraphUtils.DateValueFormatter(1000 * 60 * 60 * 24)
|
||||
|
||||
viewModel.items.observe(viewLifecycleOwner) { list ->
|
||||
adapter.set(list)
|
||||
|
||||
val dataset = BarDataSet(
|
||||
list.map {
|
||||
val epoch = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
|
||||
epoch.time = Date(0)
|
||||
epoch.add(Calendar.MILLISECOND, it.timestamp.toInt())
|
||||
return@map BarEntry(
|
||||
(epoch.timeInMillis / 1000 / 60 / 60).toFloat(),
|
||||
(it.timestamp / 1000 / 60 / 60 / 24).toFloat(),
|
||||
it.value.toFloat()
|
||||
)
|
||||
},
|
||||
@ -77,4 +81,4 @@ class WaterHomeFragment :
|
||||
chart.invalidate()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.dzeio.openhealth.ui.water
|
||||
|
||||
import com.dzeio.openhealth.core.BaseViewModel
|
||||
|
||||
class WaterSizeSelectorViewModel : BaseViewModel() {
|
||||
}
|
@ -11,12 +11,14 @@ import com.github.mikephil.charting.data.Entry
|
||||
import com.github.mikephil.charting.formatter.ValueFormatter
|
||||
import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
object GraphUtils {
|
||||
|
||||
fun lineChartSetup(chart: LineChart, mainColor: Int, textColor: Int) {
|
||||
barLineChartSetup(chart, mainColor, textColor)
|
||||
// chart.isAutoScaleMinMaxEnabled = true
|
||||
}
|
||||
|
||||
fun barChartSetup(chart: BarChart, mainColor: Int, textColor: Int) {
|
||||
@ -32,47 +34,40 @@ object GraphUtils {
|
||||
chart.apply {
|
||||
|
||||
// Setup
|
||||
legend.isEnabled = false
|
||||
legend.isEnabled = true
|
||||
description = Description().apply { isEnabled = false }
|
||||
|
||||
xAxis.apply {
|
||||
valueFormatter = object : ValueFormatter() {
|
||||
override fun getAxisLabel(value: Float, axis: AxisBase?): String {
|
||||
return SimpleDateFormat(
|
||||
"yyyy-MM-dd",
|
||||
Locale.getDefault()
|
||||
).format(Date(value.toLong()))
|
||||
//return super.getAxisLabel(value, axis)
|
||||
}
|
||||
}
|
||||
valueFormatter = DateValueFormatter()
|
||||
position = XAxis.XAxisPosition.BOTTOM
|
||||
setDrawGridLines(false)
|
||||
setLabelCount(3, true)
|
||||
this.textColor = textColor
|
||||
//setDrawGridLines(false)
|
||||
//setDrawZeroLine(false)
|
||||
// setDrawGridLines(false)
|
||||
// setDrawZeroLine(false)
|
||||
setDrawAxisLine(false)
|
||||
disableGridDashedLine()
|
||||
invalidateOutline()
|
||||
}
|
||||
|
||||
axisLeft.apply {
|
||||
isEnabled = false
|
||||
axisLineColor = mainColor
|
||||
this.textColor = textColor
|
||||
// setDrawZeroLine(false)
|
||||
setDrawZeroLine(false)
|
||||
setLabelCount(0, true)
|
||||
setDrawGridLines(false)
|
||||
setDrawBorders(false)
|
||||
}
|
||||
axisRight.apply {
|
||||
this.textColor = textColor
|
||||
setLabelCount(4, true)
|
||||
}
|
||||
setNoDataTextColor(textColor)
|
||||
|
||||
|
||||
isAutoScaleMinMaxEnabled = true
|
||||
legend.isEnabled = false
|
||||
isDragEnabled = true
|
||||
isScaleYEnabled = false
|
||||
// isScaleYEnabled = false
|
||||
description = Description().apply { isEnabled = false }
|
||||
isScaleXEnabled = true
|
||||
setPinchZoom(false)
|
||||
@ -80,4 +75,16 @@ object GraphUtils {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
7
app/src/main/res/layout/dialog_water_size_selector.xml
Normal file
7
app/src/main/res/layout/dialog_water_size_selector.xml
Normal 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>
|
@ -16,6 +16,14 @@
|
||||
android:selectAllOnFocus="true"
|
||||
android:singleLine="true"
|
||||
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 android:title="Water Settings">
|
||||
|
||||
@ -37,4 +45,4 @@
|
||||
android:inputType="number"
|
||||
android:title="Daily Water intake" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
</PreferenceScreen>
|
||||
|
@ -10,12 +10,12 @@ buildscript {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.android.application' version '7.1.0-beta05' apply false
|
||||
id 'com.android.library' 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-rc01' apply false
|
||||
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
delete project.buildDir
|
||||
}
|
||||
}
|
||||
|
BIN
private_key.pepk
Normal file
BIN
private_key.pepk
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user