1
0
mirror of https://github.com/dzeiocom/OpenHealth.git synced 2025-04-23 03:12:14 +00:00

feat: Project cleanup (#146)

This commit is contained in:
Florian Bouillon 2023-02-16 00:58:00 +01:00 committed by GitHub
parent 1f780ae2c4
commit bcf8004497
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 285 additions and 567 deletions

View File

@ -145,14 +145,14 @@ android {
}
}
// Compile using JAVA 8
// Compile using JAVA 11
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = JavaVersion.VERSION_11.toString()
}
// Enable View Binding and Data Binding

View File

@ -1,5 +0,0 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#000000" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M15.41,7.41L14,6l-6,6 6,6 1.41,-1.41L10.83,12z"/>
</vector>

View File

@ -1,5 +0,0 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#000000" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M10,6L8.59,7.41 13.17,12l-4.58,4.59L10,18l6,-6z"/>
</vector>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/vector_logo_background" />
<background android:drawable="@drawable/logo_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

View File

@ -34,4 +34,7 @@ object Settings {
* Goal number of steps each days
*/
const val STEPS_GOAL = "com.dzeio.open-health.steps.goal-daily"
const val WATER_INTAKE_SIZE = "com.dzeio.open-health.water.size"
const val WATER_INTAKE_SIZE_DEFAULT = 250
}

View File

@ -1,45 +0,0 @@
package com.dzeio.openhealth.adapters
import android.view.LayoutInflater
import android.view.ViewGroup
import com.dzeio.openhealth.R
import com.dzeio.openhealth.core.BaseAdapter
import com.dzeio.openhealth.core.BaseViewHolder
import com.dzeio.openhealth.data.food.Food
import com.dzeio.openhealth.databinding.ItemFoodBinding
import com.dzeio.openhealth.utils.NetworkUtils
import kotlin.math.roundToInt
class FoodAdapter : BaseAdapter<Food, ItemFoodBinding>() {
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> ItemFoodBinding
get() = ItemFoodBinding::inflate
var onItemClick: ((weight: Food) -> Unit)? = null
override fun onBindData(
holder: BaseViewHolder<ItemFoodBinding>,
item: Food,
position: Int
) {
// Download remote picture
if (item.image != null) {
NetworkUtils.getImageInBackground(holder.binding.productImage, item.image!!)
}
// set the food name
holder.binding.foodName.text = item.name + " ${item.id}"
// set the food description
holder.binding.foodDescription.text = holder.itemView.context.getString(
R.string.food_description,
item.quantity.roundToInt().toString() + item.serving.replace(Regex("\\d+"), ""),
(item.energy / 100 * item.quantity)
)
// set the callback
holder.binding.edit.setOnClickListener {
onItemClick?.invoke(item)
}
}
}

View File

@ -1,46 +0,0 @@
package com.dzeio.openhealth.adapters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.dzeio.openhealth.R
import com.dzeio.openhealth.core.BaseAdapter
import com.dzeio.openhealth.core.BaseViewHolder
import com.dzeio.openhealth.data.step.Step
import com.dzeio.openhealth.databinding.LayoutItemListBinding
class StepsAdapter() : BaseAdapter<Step, LayoutItemListBinding>() {
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> LayoutItemListBinding
get() = LayoutItemListBinding::inflate
var onItemClick: ((weight: Step) -> Unit)? = null
var isDay = false
override fun onBindData(
holder: BaseViewHolder<LayoutItemListBinding>,
item: Step,
position: Int
) {
// set the number of steps taken
holder.binding.value.text = holder.itemView.context.getString(
R.string.steps_count,
item.value
)
// set the datetime
holder.binding.datetime.text = item.formatTimestamp(!isDay)
if (isDay) {
holder.binding.iconRight.visibility = View.GONE
} else {
holder.binding.iconRight.setImageResource(R.drawable.ic_zoom_out_map)
}
// set the callback
holder.binding.edit.setOnClickListener {
onItemClick?.invoke(item)
}
}
}

View File

@ -1,40 +0,0 @@
package com.dzeio.openhealth.adapters
import android.view.LayoutInflater
import android.view.ViewGroup
import com.dzeio.openhealth.core.BaseAdapter
import com.dzeio.openhealth.core.BaseViewHolder
import com.dzeio.openhealth.data.water.Water
import com.dzeio.openhealth.databinding.LayoutItemListBinding
import com.dzeio.openhealth.units.Units
class WaterAdapter : BaseAdapter<Water, LayoutItemListBinding>() {
/**
* The unit the adapter will be using
*/
var unit: Units.Volume = Units.Volume.MILLILITER
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> LayoutItemListBinding
get() = LayoutItemListBinding::inflate
var onItemClick: ((weight: Water) -> Unit)? = null
override fun onBindData(
holder: BaseViewHolder<LayoutItemListBinding>,
item: Water,
position: Int
) {
// set the wate intake text
holder.binding.value.text =
holder.itemView.context.getString(unit.unit, unit.formatToString(item.value))
// set the datetime
holder.binding.datetime.text = item.formatTimestamp()
// set the callback
holder.binding.edit.setOnClickListener {
onItemClick?.invoke(item)
}
}
}

View File

@ -1,40 +0,0 @@
package com.dzeio.openhealth.adapters
import android.view.LayoutInflater
import android.view.ViewGroup
import com.dzeio.openhealth.core.BaseAdapter
import com.dzeio.openhealth.core.BaseViewHolder
import com.dzeio.openhealth.data.weight.Weight
import com.dzeio.openhealth.databinding.LayoutItemListBinding
import com.dzeio.openhealth.units.Units
class WeightAdapter : BaseAdapter<Weight, LayoutItemListBinding>() {
/**
* The unit the adapter will be using
*/
var unit: Units.Mass = Units.Mass.KILOGRAM
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> LayoutItemListBinding
get() = LayoutItemListBinding::inflate
var onItemClick: ((weight: Weight) -> Unit)? = null
override fun onBindData(
holder: BaseViewHolder<LayoutItemListBinding>,
item: Weight,
position: Int
) {
// set the weight text
holder.binding.value.text =
holder.itemView.context.getString(unit.unit, unit.formatToString(item.weight))
// set the datetime
holder.binding.datetime.text = item.formatTimestamp()
// set the callback
holder.binding.edit.setOnClickListener {
onItemClick?.invoke(item)
}
}
}

View File

@ -75,17 +75,21 @@ data class Food(
}
// try to know how much was eaten by the user if not said
var eaten = quantity ?: food.servingQuantity ?: food.productQuantity ?: 0f
var eaten = quantity ?: food.productQuantity ?: food.servingQuantity ?: 0f
if (eaten == 0f) {
if (food.servingQuantity != null && food.servingQuantity != 0f) {
eaten = food.servingQuantity!!
} else if (food.productQuantity != null && food.productQuantity != 0f) {
if (food.productQuantity != null && food.productQuantity != 0f) {
eaten = food.productQuantity!!
} else if (food.servingQuantity != null && food.servingQuantity != 0f) {
eaten = food.servingQuantity!!
} else if (food.servingSize != null || food.quantity != null) {
eaten = (food.servingSize ?: food.quantity)!!.trim().replace(
Regex(" +\\w+$"),
eaten = try {
(food.quantity ?: food.servingSize)!!.trim().replace(
Regex(" +\\w+"),
""
).toInt().toFloat()
} catch (e: NumberFormatException) {
0f
}
}
}
Log.d("Food", "$food")

View File

@ -10,6 +10,7 @@ import com.dzeio.openhealth.databinding.DialogFoodProductBinding
import com.dzeio.openhealth.utils.NetworkUtils
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import kotlin.math.roundToInt
/**
* Dialog that display to the user a spcific product and it's consumption
@ -66,6 +67,7 @@ class FoodDialog :
)
}
binding.quantity.setText(it.quantity.toString())
dialog?.setTitle(it.name)
}
binding.quantity.addTextChangedListener {
@ -77,17 +79,17 @@ class FoodDialog :
quantity = newQuantity
viewModel.items.value?.let {
val transformer = newQuantity ?: it.quantity
val energy = it.energy / 100 * transformer
binding.energyTxt.text = "${energy.toInt()} / 2594kcal"
val energy = it.energy * transformer / 100
binding.energyTxt.text = "${energy.roundToInt()} / 2594kcal"
binding.energyBar.progress = (100 * energy / 2594).toInt()
val proteins = it.proteins / 100 * transformer
binding.proteinsTxt.text = "${proteins.toInt()} / 130g"
val proteins = it.proteins * transformer / 100
binding.proteinsTxt.text = "${proteins.roundToInt()} / 130g"
binding.proteinsBar.progress = (100 * proteins / 130).toInt()
val carbohydrates = it.carbohydrates / 100 * transformer
binding.carbsTxt.text = "${carbohydrates.toInt()} / 324g"
val carbohydrates = it.carbohydrates * transformer / 100
binding.carbsTxt.text = "${carbohydrates.roundToInt()} / 324g"
binding.carbsBar.progress = (100 * carbohydrates / 324).toInt()
val fat = it.fat / 100 * transformer
binding.fatTxt.text = "${fat.toInt()} / 87g"
val fat = it.fat * transformer / 100
binding.fatTxt.text = "${fat.roundToInt()} / 87g"
binding.fatBar.progress = (100 * fat / 87).toInt()
}
}

View File

@ -41,11 +41,6 @@ class FoodDialogViewModel @Inject internal constructor(
return
}
val transformer = quantity / it.quantity
it.energy = it.energy * transformer
it.proteins = it.proteins * transformer
it.carbohydrates = it.carbohydrates * transformer
it.fat = it.fat * transformer
it.quantity = quantity
viewModelScope.launch {

View File

@ -1,5 +1,6 @@
package com.dzeio.openhealth.ui.food
import android.content.res.ColorStateList
import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu
@ -10,12 +11,15 @@ import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.dzeio.openhealth.Application
import com.dzeio.openhealth.R
import com.dzeio.openhealth.adapters.FoodAdapter
import com.dzeio.openhealth.adapters.ItemAdapter
import com.dzeio.openhealth.core.BaseFragment
import com.dzeio.openhealth.data.food.Food
import com.dzeio.openhealth.databinding.FragmentFoodHomeBinding
import com.dzeio.openhealth.ui.steps.FoodHomeViewModel
import com.google.android.material.color.MaterialColors
import dagger.hilt.android.AndroidEntryPoint
import java.util.Calendar
import kotlin.math.roundToInt
@AndroidEntryPoint
class FoodHomeFragment :
@ -41,11 +45,11 @@ class FoodHomeFragment :
val manager = LinearLayoutManager(requireContext())
recycler.layoutManager = manager
val adapter = FoodAdapter()
val adapter = ItemAdapter<Food>()
adapter.onItemClick = {
findNavController().navigate(
FoodHomeFragmentDirections.actionFoodHomeFragmentToNavDialogFoodProduct(
it.id,
it.value.id,
false
)
)
@ -53,7 +57,24 @@ class FoodHomeFragment :
recycler.adapter = adapter
viewModel.items.observe(viewLifecycleOwner) {
adapter.set(it)
adapter.set(
it!!.map { food ->
ItemAdapter.Item(
food,
food.name,
getString(
R.string.food_description,
food.quantity.roundToInt().toString() + food.serving.replace(
Regex("\\d+"),
""
),
(food.energy / 100 * food.quantity)
),
food.image,
R.drawable.ic_outline_edit_24
)
}
)
var energy = 0f
var proteins = 0f
@ -65,14 +86,47 @@ class FoodHomeFragment :
carbohydrates += food.carbohydrates / 100 * food.quantity
fat += food.fat / 100 * food.quantity
}
binding.energyTxt.text = "${energy.toInt()} / 2594kcal"
binding.energyBar.progress = (100 * energy / 2594).toInt()
if (binding.energyBar.progress >= 100) {
binding.energyBar.progressTintList = ColorStateList.valueOf(
MaterialColors.getColor(
view,
com.google.android.material.R.attr.colorError
)
)
}
binding.proteinsTxt.text = "${proteins.toInt()} / 130g"
binding.proteinsBar.progress = (100 * proteins / 130).toInt()
if (binding.proteinsBar.progress >= 100) {
binding.proteinsBar.progressTintList = ColorStateList.valueOf(
MaterialColors.getColor(
view,
com.google.android.material.R.attr.colorError
)
)
}
binding.carbsTxt.text = "${carbohydrates.toInt()} / 324g"
binding.carbsBar.progress = (100 * carbohydrates / 324).toInt()
if (binding.carbsBar.progress >= 100) {
binding.carbsBar.progressTintList = ColorStateList.valueOf(
MaterialColors.getColor(
view,
com.google.android.material.R.attr.colorError
)
)
}
binding.fatTxt.text = "${fat.toInt()} / 87g"
binding.fatBar.progress = (100 * fat / 87).toInt()
if (binding.fatBar.progress >= 100) {
binding.fatBar.progressTintList = ColorStateList.valueOf(
MaterialColors.getColor(
view,
com.google.android.material.R.attr.colorError
)
)
}
}
binding.next.setOnClickListener {

View File

@ -7,22 +7,24 @@ import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.dzeio.openhealth.R
import com.dzeio.openhealth.adapters.FoodAdapter
import com.dzeio.openhealth.adapters.ItemAdapter
import com.dzeio.openhealth.core.BaseDialog
import com.dzeio.openhealth.databinding.DialogFoodSearchProductBinding
import com.dzeio.openhealth.data.food.Food
import com.dzeio.openhealth.databinding.DialogSearchBinding
import com.dzeio.openhealth.utils.NetworkResult
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import kotlin.math.roundToInt
@AndroidEntryPoint
class SearchFoodDialog :
BaseDialog<SearchFoodDialogViewModel, DialogFoodSearchProductBinding>(
BaseDialog<SearchFoodDialogViewModel, DialogSearchBinding>(
SearchFoodDialogViewModel::class.java
) {
override val bindingInflater: (LayoutInflater) -> DialogFoodSearchProductBinding =
DialogFoodSearchProductBinding::inflate
override val bindingInflater: (LayoutInflater) -> DialogSearchBinding =
DialogSearchBinding::inflate
override fun onBuilderInit(builder: MaterialAlertDialogBuilder) {
super.onBuilderInit(builder)
@ -43,7 +45,7 @@ class SearchFoodDialog :
dialog.setOnShowListener {
val btn = dialog.getButton(AlertDialog.BUTTON_NEUTRAL)
btn.setOnClickListener {
viewModel.search(binding.input.text.toString())
viewModel.search(binding.search.text.toString())
binding.loading.visibility = View.VISIBLE
}
}
@ -57,10 +59,10 @@ class SearchFoodDialog :
val manager = LinearLayoutManager(requireContext())
recycler.layoutManager = manager
val adapter = FoodAdapter()
val adapter = ItemAdapter<Food>()
adapter.onItemClick = {
lifecycleScope.launch {
val id = viewModel.addProduct(it)
val id = viewModel.addProduct(it.value)
findNavController().navigate(
SearchFoodDialogDirections.actionNavDialogFoodSearchToNavDialogFoodProduct(
id,
@ -72,7 +74,25 @@ class SearchFoodDialog :
recycler.adapter = adapter
viewModel.items.observe(this) {
adapter.set(it.data ?: arrayListOf())
if (it.data != null) {
adapter.set(
it.data!!.map { food ->
ItemAdapter.Item(
food,
food.name,
getString(
R.string.food_description,
food.quantity.roundToInt().toString() + food.serving.replace(
Regex("\\d+"),
""
),
(food.energy / 100 * food.quantity)
),
food.image
)
}
)
}
if (it.status == NetworkResult.NetworkStatus.FINISHED) {
binding.loading.visibility = View.GONE
} else if (it.status == NetworkResult.NetworkStatus.ERRORED) {

View File

@ -12,7 +12,8 @@ import com.dzeio.charts.Entry
import com.dzeio.charts.axis.Line
import com.dzeio.charts.series.BarSerie
import com.dzeio.openhealth.Application
import com.dzeio.openhealth.adapters.StepsAdapter
import com.dzeio.openhealth.R
import com.dzeio.openhealth.adapters.ItemAdapter
import com.dzeio.openhealth.core.BaseFragment
import com.dzeio.openhealth.data.step.Step
import com.dzeio.openhealth.databinding.FragmentStepsHomeBinding
@ -50,16 +51,14 @@ class StepsHomeFragment :
val manager = LinearLayoutManager(requireContext())
recycler.layoutManager = manager
val adapter = StepsAdapter().apply {
this.isDay = isDay
}
val adapter = ItemAdapter<Step>()
if (!isDay) {
adapter.onItemClick = {
findNavController().navigate(
StepsHomeFragmentDirections.actionNavStepsHomeSelf().apply {
day = it.timestamp
title = "Steps from " + it.formatTimestamp(true)
day = it.value.timestamp
title = "Steps from " + it.value.formatTimestamp(true)
}
)
}
@ -137,7 +136,18 @@ class StepsHomeFragment :
}
}
if (isDay) {
adapter.set(filtered)
adapter.set(
filtered.map {
ItemAdapter.Item(
it,
getString(
R.string.steps_count,
it.value
),
it.formatTimestamp(false)
)
}
)
serie.entries = filtered.map {
Entry(
it.timestamp.toDouble(),
@ -172,6 +182,17 @@ class StepsHomeFragment :
adapter.set(
entries.map { Step(value = it.value.y.toInt(), timestamp = it.key) }
.sortedByDescending { it.timestamp }
.map {
ItemAdapter.Item(
it,
getString(
R.string.steps_count,
it.value
),
it.formatTimestamp(true),
icon = R.drawable.ic_zoom_out_map
)
}
)
serie.entries = ArrayList(entries.values)

View File

@ -8,9 +8,12 @@ import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.dzeio.charts.Entry
import com.dzeio.charts.series.BarSerie
import com.dzeio.openhealth.adapters.WaterAdapter
import com.dzeio.openhealth.R
import com.dzeio.openhealth.adapters.ItemAdapter
import com.dzeio.openhealth.core.BaseFragment
import com.dzeio.openhealth.data.water.Water
import com.dzeio.openhealth.databinding.FragmentMainWaterHomeBinding
import com.dzeio.openhealth.units.Units
import com.dzeio.openhealth.utils.ChartUtils
import dagger.hilt.android.AndroidEntryPoint
import java.text.SimpleDateFormat
@ -34,15 +37,16 @@ class WaterHomeFragment :
val manager = LinearLayoutManager(requireContext())
recycler.layoutManager = manager
val adapter = WaterAdapter()
adapter.onItemClick = {
val adapter = ItemAdapter<Water>().apply {
onItemClick = {
findNavController().navigate(
WaterHomeFragmentDirections.actionNavWaterHomeToNavWaterEdit(
it.id
it.value.id
)
)
}
recycler.adapter = adapter
recycler.adapter = this
}
val chart = binding.chart
@ -58,6 +62,7 @@ class WaterHomeFragment :
xAxis.apply {
dataWidth = 604800000.0
textPaint.textSize = 32f
scrollEnabled = true
onValueFormat = onValueFormat@{
return@onValueFormat SimpleDateFormat(
"yyyy-MM-dd",
@ -74,7 +79,20 @@ class WaterHomeFragment :
}
viewModel.items.observe(viewLifecycleOwner) { list ->
adapter.set(list)
val unit = Units.Volume.MILLILITER
adapter.set(
list.map {
ItemAdapter.Item(
it,
getString(
unit.unit,
unit.formatToString(it.value)
),
it.formatTimestamp(),
icon = R.drawable.ic_outline_edit_24
)
}
)
if (list.isEmpty()) {
return@observe
@ -88,7 +106,9 @@ class WaterHomeFragment :
}
serie.entries = dataset as ArrayList<Entry>
chart.xAxis.x = dataset[0].x
chart.xAxis.x = chart.xAxis.getXMin()
chart.xAxis.x =
chart.xAxis.getXMax() - chart.xAxis.dataWidth!! + chart.xAxis.dataWidth!! / 7
chart.refresh()
}
}

View File

@ -1,12 +1,12 @@
package com.dzeio.openhealth.ui.water
import android.view.LayoutInflater
import android.view.View
import androidx.core.widget.doOnTextChanged
import com.dzeio.openhealth.R
import com.dzeio.openhealth.Settings
import com.dzeio.openhealth.core.BaseDialog
import com.dzeio.openhealth.databinding.DialogWaterSizeSelectorBinding
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
@ -30,50 +30,47 @@ class WaterSizeSelectorDialog :
}
viewModel.cupSize.observe(this) {
var real = it ?: Settings.WATER_INTAKE_SIZE_DEFAULT
binding.customSize.text = String.format(
getString(R.string.custom_amount),
"${it}ml"
"${real}ml"
)
if (binding.inputParent.visibility == View.GONE) {
binding.input.setText(real.toString())
}
}
binding.size100ml.setOnClickListener {
setTextFieldStatus()
viewModel.setCupSize(100)
}
binding.size250ml.setOnClickListener {
setTextFieldStatus()
viewModel.setCupSize(250)
}
binding.size500ml.setOnClickListener {
setTextFieldStatus()
viewModel.setCupSize(500)
}
binding.size1000ml.setOnClickListener {
setTextFieldStatus()
viewModel.setCupSize(1000)
}
binding.customSize.setOnClickListener {
val editTextLayout = TextInputLayout(requireContext())
setTextFieldStatus(true)
}
val editText = TextInputEditText(requireContext())
editText.setText(viewModel.cupSize.value.toString())
binding.input.doOnTextChanged { text, start, before, count ->
val newSize = text.toString().toIntOrNull()
if (newSize != null) {
viewModel.setCupSize(newSize)
}
}
}
editTextLayout.addView(editText)
MaterialAlertDialogBuilder(requireContext())
.setView(editTextLayout)
.setTitle("Custom Cup Size")
.setOnCancelListener {
it.dismiss()
}
.setNegativeButton(R.string.cancel) { dialog, _ ->
dialog.dismiss()
}
.setPositiveButton(
R.string.validate
) { dialog, _ ->
viewModel.setCupSize(editText.text.toString().toInt())
dismiss()
dialog.dismiss()
}
.show()
}
private fun setTextFieldStatus(displayed: Boolean = false) {
binding.inputParent.visibility = if (displayed) View.VISIBLE else View.GONE
binding.customSize.visibility = if (displayed) View.GONE else View.VISIBLE
}
}

View File

@ -1,32 +1,19 @@
package com.dzeio.openhealth.ui.water
import android.content.SharedPreferences
import androidx.lifecycle.MutableLiveData
import com.dzeio.openhealth.Settings
import com.dzeio.openhealth.core.BaseViewModel
import com.dzeio.openhealth.utils.Configuration
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
@HiltViewModel
class WaterSizeSelectorViewModel @Inject constructor(
private val settings: SharedPreferences
private val settings: Configuration
) : BaseViewModel() {
private val _cupSize = MutableLiveData(0)
val cupSize = _cupSize
init {
val cup = settings.getInt("water_cup_size", -1)
if (cup != -1) {
_cupSize.value = cup
}
}
val cupSize = settings.getInt(Settings.WATER_INTAKE_SIZE).toLiveData()
fun setCupSize(value: Int) {
settings.edit()
.putInt("water_cup_size", value)
.apply()
_cupSize.value = value
settings.getInt(Settings.WATER_INTAKE_SIZE).value = value
}
}

View File

@ -21,10 +21,11 @@ import com.dzeio.charts.axis.Line
import com.dzeio.charts.series.LineSerie
import com.dzeio.openhealth.BuildConfig
import com.dzeio.openhealth.R
import com.dzeio.openhealth.adapters.WeightAdapter
import com.dzeio.openhealth.adapters.ItemAdapter
import com.dzeio.openhealth.core.BaseFragment
import com.dzeio.openhealth.data.weight.Weight
import com.dzeio.openhealth.databinding.FragmentListWeightBinding
import com.dzeio.openhealth.units.Units
import com.dzeio.openhealth.utils.PermissionsManager
import com.google.android.material.color.MaterialColors
import dagger.hilt.android.AndroidEntryPoint
@ -113,11 +114,11 @@ class ListWeightFragment :
)
}
val adapter = WeightAdapter().apply {
val adapter = ItemAdapter<Weight>().apply {
onItemClick = {
findNavController().navigate(
ListWeightFragmentDirections.actionNavListWeightToNavEditWeight(
it.id
it.value.id
)
)
}
@ -129,16 +130,23 @@ class ListWeightFragment :
this.adapter = adapter
}
viewModel.massUnit.observe(viewLifecycleOwner) {
adapter.unit = it
}
viewModel.weights.observe(viewLifecycleOwner) {
if (it != null) {
val itt = it.toMutableList()
itt.sortWith { o1, o2 -> if (o1.timestamp > o2.timestamp) -1 else 1 }
adapter.set(itt)
updateGraph(it)
viewModel.weights.observe(viewLifecycleOwner) { list ->
if (list != null) {
val unit = viewModel.massUnit.value ?: Units.Mass.KILOGRAM
adapter.set(
list.map {
ItemAdapter.Item(
it,
getString(
unit.unit,
unit.formatToString(it.weight)
),
it.formatTimestamp(),
icon = R.drawable.ic_outline_edit_24
)
}.reversed()
)
updateGraph(list)
}
}

View File

@ -54,10 +54,10 @@ class Configuration(
return cache[key] as BooleanField
}
fun getInt(key: String): IntField {
fun getInt(key: String, defaultValue: Int? = null): IntField {
if (cache[key] == null) {
// Log.d(TAG, "$key is not cache, creating new instance")
cache[key] = IntField(key)
cache[key] = IntField(key, defaultValue)
} else {
// Log.d(TAG, "$key in cache")
}
@ -141,10 +141,15 @@ class Configuration(
inner class IntField(
private val key: String,
private val defaultValue: Int = -1
private val defaultValue: Int? = null
) : Field<Int?>(defaultValue) {
override fun exists(): Boolean = prefs.contains(key)
override fun internalGet(): Int = prefs.getInt(key, defaultValue)
override fun internalGet(): Int? {
if (exists()) {
return prefs.getInt(key, 0)
}
return defaultValue
}
override fun internalSet(value: Int?) =
prefs.edit { if (value == null) remove(key) else putInt(key, value) }
}

View File

@ -1,10 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
</vector>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

View File

@ -18,7 +18,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.widget.NumberPicker
<NumberPicker
android:id="@+id/layout_dialog_edit_weight_kg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -26,7 +26,7 @@
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="0dp" />
<android.widget.NumberPicker
<NumberPicker
android:id="@+id/layout_dialog_edit_weight_gram"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@ -10,6 +10,7 @@
<ImageView
android:id="@+id/image"
android:layout_marginTop="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:srcCompat="@tools:sample/avatars" />

View File

@ -1,39 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:paddingHorizontal="16dp"
android:nestedScrollingEnabled="true"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ProgressBar
android:id="@+id/loading"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/error_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:text="@string/connectivity_error" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:itemCount="5"
tools:listitem="@layout/item_food">
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>

View File

@ -87,11 +87,24 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="visible"
android:text="@string/custom_amount"
style="@style/Widget.Material3.Button.TextButton"
tools:text="Custom amount: 1234ml"
/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/input_parent"
android:layout_width="match_parent"
android:visibility="gone"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<LinearLayout

View File

@ -172,7 +172,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/layout_item_list"
tools:listitem="@layout/item_list"
tools:context=".ui.weight.ListWeightFragment" />
</LinearLayout>

View File

@ -5,6 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:context=".ui.home.HomeFragment">
<Button
@ -12,6 +13,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_marginBottom="16dp"
android:text="Goto Tests" />
<LinearLayout
@ -23,9 +25,9 @@
<com.google.android.material.card.MaterialCardView
style="?attr/materialCardViewFilledStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="16dp"
android:layout_marginRight="8dp"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
@ -143,10 +145,8 @@
<com.google.android.material.card.MaterialCardView
style="?attr/materialCardViewFilledStyle"
android:layout_width="0dp"
android:layout_marginLeft="8dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_weight="1">
<LinearLayout
@ -264,7 +264,6 @@
style="?attr/materialCardViewFilledStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="16dp">
<LinearLayout
@ -314,8 +313,7 @@
android:id="@+id/weight_graph"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_margin="8dp"
android:minHeight="200dp" />
android:layout_margin="8dp" />
</LinearLayout>

View File

@ -19,43 +19,32 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingHorizontal="12dp"
android:paddingVertical="16dp">
android:padding="16dp"
>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:paddingVertical="8dp"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_bluetooth"
android:background="@drawable/shape_circle"
app:tint="?colorOnPrimary" />
<LinearLayout
android:layout_width="wrap_content"
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="4dp"
android:text="Bluetooth Scale Status" />
</LinearLayout>
android:layout_marginHorizontal="16dp"
android:text="@string/bluetooth_scale" />
<Button
android:id="@+id/bluetooth_button"
android:text="@string/add_goal"
android:text="@string/sync"
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>
@ -139,14 +128,14 @@
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"
android:clipToPadding="false"
android:padding="16dp"
tools:listitem="@layout/layout_item_list"
tools:context=".ui.weight.ListWeightFragment" />
tools:context=".ui.weight.ListWeightFragment"
tools:listitem="@layout/item_list" />
</LinearLayout>

View File

@ -1,6 +1,5 @@
<?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:layout_height="match_parent"
@ -56,6 +55,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
tools:listitem="@layout/layout_item_list" />
tools:listitem="@layout/item_list" />
</LinearLayout>

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
@ -56,6 +55,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
tools:listitem="@layout/layout_item_list" />
tools:listitem="@layout/item_list" />
</LinearLayout>

View File

@ -1,59 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="?attr/materialCardViewFilledStyle"
android:layout_marginBottom="8dp"
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:id="@+id/edit"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="1">
<ImageView
android:id="@+id/product_image"
android:layout_width="43dp"
android:layout_height="match_parent"
android:layout_marginEnd="16dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
tools:srcCompat="@tools:sample/avatars" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/food_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name of food" />
<TextView
android:id="@+id/food_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="250g (800kcal)" />
</LinearLayout>
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_baseline_edit_24" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>

View File

@ -55,7 +55,7 @@
android:id="@+id/icon_right"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_baseline_edit_24" />
android:src="@drawable/ic_outline_edit_24" />
</LinearLayout>

View File

@ -1,63 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView
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"
style="?attr/materialCardViewFilledStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:id="@+id/card"
android:layout_marginEnd="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="40dp"
android:id="@+id/logo"
android:layout_height="40dp"
android:layout_marginHorizontal="16dp"
android:layout_marginVertical="16dp"
android:src="@drawable/ic_logo_fit" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="54dp"
android:layout_marginVertical="16dp"
android:gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
style="@style/TextAppearance.Material3.TitleMedium"
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Google Fit" />
<TextView
android:id="@+id/status"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Last Sync: Yesterday" />
</LinearLayout>
<ImageView
android:id="@+id/icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginHorizontal="16dp"
android:layout_marginVertical="16dp"
android:src="@drawable/ic_baseline_extension_24" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>

View File

@ -1,49 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
style="?attr/materialCardViewFilledStyle"
android:layout_marginBottom="8dp"
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:id="@+id/edit"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="xkg" />
<TextView
android:id="@+id/datetime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="Taken: yyyy-mm-dd" />
</LinearLayout>
<ImageView
android:id="@+id/icon_right"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_baseline_edit_24" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/vector_logo_background"/>
<background android:drawable="@drawable/logo_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
<monochrome android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>

View File

@ -183,7 +183,7 @@
<dialog
android:id="@+id/nav_dialog_food_search"
android:name="com.dzeio.openhealth.ui.food.SearchFoodDialog"
tools:layout="@layout/dialog_food_search_product"
tools:layout="@layout/dialog_search"
>
<action
android:id="@+id/action_nav_dialog_food_search_to_nav_dialog_food_product"

View File

@ -55,5 +55,7 @@
<string name="error_reporter_crash">Erreur lors de la géneration d\'un rapport d\'erreur</string>
<string name="steps_count">%1$d pas</string>
<string name="connectivity_error">Il semplerais que nous ne pouvons pas communiquer avec OpenFoodFact, Merci de re-essayer plus tard</string>
<string name="bluetooth_scale">Balance bluetooth</string>
<string name="sync">Synchroniser</string>
<string name="searching_scales">Recherche de balances connecté...</string>
</resources>

View File

@ -68,5 +68,7 @@
<string name="food_description" translatable="false">%1$s (%2$.0f kcal)</string>
<string name="steps_count">%1$d steps</string>
<string name="connectivity_error">It seems that we can\'t communicate with OpenFoodFact, please retry later</string>
<string name="searching_scales">Searchin Scales</string>
<string name="searching_scales">Searching Scales</string>
<string name="sync">Sync</string>
<string name="bluetooth_scale">Bluetooth Scale</string>
</resources>

View File

@ -15,9 +15,9 @@ buildscript {
plugins {
// android app plugin ? (tbh idk what thoses "plugins" does)
id("com.android.application") version "7.4.0" apply false
id("com.android.application") version "7.4.1" apply false
// is it a lib? no, do I need it? IDK
id("com.android.library") version "7.4.0" apply false
id("com.android.library") version "7.4.1" apply false
// add kotlin compatibility :>
id("org.jetbrains.kotlin.android") version "1.8.10" apply false