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

misc: Started cleaning up UI

This commit is contained in:
Florian Bouillon 2023-01-08 00:13:49 +01:00
parent 86e127f0bd
commit c7a0917e29
Signed by: Florian Bouillon
GPG Key ID: BEEAF3722D0EBF64
5 changed files with 32 additions and 11 deletions

View File

@ -15,6 +15,9 @@ import com.dzeio.openhealth.core.BaseStaticFragment
import com.dzeio.openhealth.databinding.FragmentAboutBinding import com.dzeio.openhealth.databinding.FragmentAboutBinding
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
/**
* Fragment for the About page
*/
class AboutFragment : BaseStaticFragment<FragmentAboutBinding>() { class AboutFragment : BaseStaticFragment<FragmentAboutBinding>() {
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> FragmentAboutBinding override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> FragmentAboutBinding
get() = FragmentAboutBinding::inflate get() = FragmentAboutBinding::inflate
@ -23,22 +26,29 @@ class AboutFragment : BaseStaticFragment<FragmentAboutBinding>() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
// set the version number
binding.version.text = binding.version.text =
resources.getString(R.string.version_number, BuildConfig.VERSION_NAME) resources.getString(R.string.version_number, BuildConfig.VERSION_NAME)
// handle contact US button
binding.contactUs.setOnClickListener { binding.contactUs.setOnClickListener {
openLink("mailto:contact.openhealth@dze.io") openLink("mailto:contact.openhealth@dze.io")
} }
// handle Github button
binding.github.setOnClickListener { binding.github.setOnClickListener {
openLink("https://github.com/dzeiocom/OpenHealth") openLink("https://github.com/dzeiocom/OpenHealth")
} }
// send the user to the Google OSS licenses page when clicked
binding.licenses.setOnClickListener { binding.licenses.setOnClickListener {
startActivity(Intent(requireContext(), OssLicensesMenuActivity::class.java)) startActivity(Intent(requireContext(), OssLicensesMenuActivity::class.java))
} }
} }
/**
* simple function that try to open a link.
*/
private fun openLink(url: String) { private fun openLink(url: String) {
try { try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))

View File

@ -10,6 +10,9 @@ import com.dzeio.openhealth.core.BaseFragment
import com.dzeio.openhealth.databinding.FragmentActivityBinding import com.dzeio.openhealth.databinding.FragmentActivityBinding
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
/**
* Fragment for the Activity page
*/
@AndroidEntryPoint @AndroidEntryPoint
class ActivityFragment : class ActivityFragment :
BaseFragment<ActivityViewModel, FragmentActivityBinding>(ActivityViewModel::class.java) { BaseFragment<ActivityViewModel, FragmentActivityBinding>(ActivityViewModel::class.java) {

View File

@ -1,7 +1,6 @@
package com.dzeio.openhealth.ui.browse package com.dzeio.openhealth.ui.browse
import android.Manifest import android.Manifest
import android.content.SharedPreferences
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
@ -10,7 +9,6 @@ import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.preference.PreferenceManager
import com.dzeio.openhealth.R import com.dzeio.openhealth.R
import com.dzeio.openhealth.core.BaseFragment import com.dzeio.openhealth.core.BaseFragment
import com.dzeio.openhealth.databinding.FragmentBrowseBinding import com.dzeio.openhealth.databinding.FragmentBrowseBinding
@ -25,10 +23,6 @@ class BrowseFragment :
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> FragmentBrowseBinding override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> FragmentBrowseBinding
get() = FragmentBrowseBinding::inflate get() = FragmentBrowseBinding::inflate
private val settings: SharedPreferences by lazy {
PreferenceManager.getDefaultSharedPreferences(requireContext())
}
private lateinit var button: MaterialCardView private lateinit var button: MaterialCardView
private val activityResult = registerForActivityResult( private val activityResult = registerForActivityResult(
ActivityResultContracts.RequestMultiplePermissions() ActivityResultContracts.RequestMultiplePermissions()
@ -45,25 +39,32 @@ class BrowseFragment :
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
// handle clicking on the weight card
binding.weight.setOnClickListener { binding.weight.setOnClickListener {
findNavController().navigate(BrowseFragmentDirections.actionNavBrowseToNavListWeight()) findNavController().navigate(BrowseFragmentDirections.actionNavBrowseToNavListWeight())
} }
// handle clicking on the water intake card
binding.waterIntake.setOnClickListener { binding.waterIntake.setOnClickListener {
findNavController().navigate(BrowseFragmentDirections.actionNavBrowseToNavWaterHome()) findNavController().navigate(BrowseFragmentDirections.actionNavBrowseToNavWaterHome())
} }
// handle clicking on the food calories card
binding.foodCalories.setOnClickListener { binding.foodCalories.setOnClickListener {
findNavController().navigate(BrowseFragmentDirections.actionNavBrowseToFoodHomeFragment()) findNavController().navigate(BrowseFragmentDirections.actionNavBrowseToFoodHomeFragment())
} }
// handle clicking on the steps card
binding.steps.setOnClickListener { binding.steps.setOnClickListener {
// since Android Q We need additionnal permissions
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// check for activity permission
val activityPermission = PermissionsManager.hasPermission( val activityPermission = PermissionsManager.hasPermission(
requireContext(), requireContext(),
Manifest.permission.ACTIVITY_RECOGNITION Manifest.permission.ACTIVITY_RECOGNITION
) )
// check for notification permission
val notificationPermission = val notificationPermission =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && PermissionsManager.hasPermission( Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && PermissionsManager.hasPermission(
requireContext(), requireContext(),
@ -72,33 +73,41 @@ class BrowseFragment :
val permissionsToAsk = arrayListOf<String>() val permissionsToAsk = arrayListOf<String>()
// add missing permission to list
if (!activityPermission) { if (!activityPermission) {
permissionsToAsk.add(Manifest.permission.ACTIVITY_RECOGNITION) permissionsToAsk.add(Manifest.permission.ACTIVITY_RECOGNITION)
} }
// add missing permission to list only if necessary
if (!notificationPermission && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { if (!notificationPermission && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
permissionsToAsk.add(Manifest.permission.POST_NOTIFICATIONS) permissionsToAsk.add(Manifest.permission.POST_NOTIFICATIONS)
} }
// ask for permissions
if (permissionsToAsk.isNotEmpty()) { if (permissionsToAsk.isNotEmpty()) {
button = binding.steps button = binding.steps
activityResult.launch(permissionsToAsk.toTypedArray()) activityResult.launch(permissionsToAsk.toTypedArray())
return@setOnClickListener return@setOnClickListener
} }
} }
// navigate user to the Steps home fragment
findNavController().navigate( findNavController().navigate(
BrowseFragmentDirections.actionNavBrowseToStepsHomeFragment() BrowseFragmentDirections.actionNavBrowseToStepsHomeFragment()
) )
} }
// display the number of steps the user made today
viewModel.steps.observe(viewLifecycleOwner) { viewModel.steps.observe(viewLifecycleOwner) {
updateStepsText(it, viewModel.stepsGoal.value) updateStepsText(it, viewModel.stepsGoal.value)
} }
// display the number of steps the user should do today
viewModel.stepsGoal.observe(viewLifecycleOwner) { viewModel.stepsGoal.observe(viewLifecycleOwner) {
updateStepsText(viewModel.steps.value, it) updateStepsText(viewModel.steps.value, it)
} }
// display the current user's weight
viewModel.weight.observe(viewLifecycleOwner) { viewModel.weight.observe(viewLifecycleOwner) {
binding.weightText.setText( binding.weightText.setText(
String.format( String.format(

View File

@ -23,8 +23,7 @@ class BrowseViewModel @Inject internal constructor(
private val _steps = MutableLiveData(0) private val _steps = MutableLiveData(0)
val steps: LiveData<Int> = _steps val steps: LiveData<Int> = _steps
private val _stepsGoal: MutableLiveData<Int?> = MutableLiveData() val stepsGoal = config.getInt(Settings.STEPS_GOAL).toLiveData()
val stepsGoal: LiveData<Int?> = _stepsGoal
private val _weight = MutableLiveData(0f) private val _weight = MutableLiveData(0f)
val weight: LiveData<Float> = _weight val weight: LiveData<Float> = _weight
@ -43,8 +42,5 @@ class BrowseViewModel @Inject internal constructor(
} }
} }
this._stepsGoal.postValue(
config.getInt(Settings.STEPS_GOAL).value
)
} }
} }

View File

@ -11,6 +11,9 @@ import com.dzeio.openhealth.utils.DownloadImageTask
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
/**
* Dialog that display to the user a spcific product and it's consumption
*/
@AndroidEntryPoint @AndroidEntryPoint
class FoodDialog : class FoodDialog :
BaseDialog<FoodDialogViewModel, DialogFoodProductBinding>(FoodDialogViewModel::class.java) { BaseDialog<FoodDialogViewModel, DialogFoodProductBinding>(FoodDialogViewModel::class.java) {