mirror of
https://github.com/dzeiocom/OpenHealth.git
synced 2025-04-23 03:12:14 +00:00
misc: Started cleaning up UI
This commit is contained in:
parent
86e127f0bd
commit
c7a0917e29
@ -15,6 +15,9 @@ import com.dzeio.openhealth.core.BaseStaticFragment
|
||||
import com.dzeio.openhealth.databinding.FragmentAboutBinding
|
||||
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
|
||||
|
||||
/**
|
||||
* Fragment for the About page
|
||||
*/
|
||||
class AboutFragment : BaseStaticFragment<FragmentAboutBinding>() {
|
||||
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> FragmentAboutBinding
|
||||
get() = FragmentAboutBinding::inflate
|
||||
@ -23,22 +26,29 @@ class AboutFragment : BaseStaticFragment<FragmentAboutBinding>() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// set the version number
|
||||
binding.version.text =
|
||||
resources.getString(R.string.version_number, BuildConfig.VERSION_NAME)
|
||||
|
||||
// handle contact US button
|
||||
binding.contactUs.setOnClickListener {
|
||||
openLink("mailto:contact.openhealth@dze.io")
|
||||
}
|
||||
|
||||
// handle Github button
|
||||
binding.github.setOnClickListener {
|
||||
openLink("https://github.com/dzeiocom/OpenHealth")
|
||||
}
|
||||
|
||||
// send the user to the Google OSS licenses page when clicked
|
||||
binding.licenses.setOnClickListener {
|
||||
startActivity(Intent(requireContext(), OssLicensesMenuActivity::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* simple function that try to open a link.
|
||||
*/
|
||||
private fun openLink(url: String) {
|
||||
try {
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
|
@ -10,6 +10,9 @@ import com.dzeio.openhealth.core.BaseFragment
|
||||
import com.dzeio.openhealth.databinding.FragmentActivityBinding
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
/**
|
||||
* Fragment for the Activity page
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class ActivityFragment :
|
||||
BaseFragment<ActivityViewModel, FragmentActivityBinding>(ActivityViewModel::class.java) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.dzeio.openhealth.ui.browse
|
||||
|
||||
import android.Manifest
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
@ -10,7 +9,6 @@ import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.dzeio.openhealth.R
|
||||
import com.dzeio.openhealth.core.BaseFragment
|
||||
import com.dzeio.openhealth.databinding.FragmentBrowseBinding
|
||||
@ -25,10 +23,6 @@ class BrowseFragment :
|
||||
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> FragmentBrowseBinding
|
||||
get() = FragmentBrowseBinding::inflate
|
||||
|
||||
private val settings: SharedPreferences by lazy {
|
||||
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
}
|
||||
|
||||
private lateinit var button: MaterialCardView
|
||||
private val activityResult = registerForActivityResult(
|
||||
ActivityResultContracts.RequestMultiplePermissions()
|
||||
@ -45,25 +39,32 @@ class BrowseFragment :
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// handle clicking on the weight card
|
||||
binding.weight.setOnClickListener {
|
||||
findNavController().navigate(BrowseFragmentDirections.actionNavBrowseToNavListWeight())
|
||||
}
|
||||
|
||||
// handle clicking on the water intake card
|
||||
binding.waterIntake.setOnClickListener {
|
||||
findNavController().navigate(BrowseFragmentDirections.actionNavBrowseToNavWaterHome())
|
||||
}
|
||||
|
||||
// handle clicking on the food calories card
|
||||
binding.foodCalories.setOnClickListener {
|
||||
findNavController().navigate(BrowseFragmentDirections.actionNavBrowseToFoodHomeFragment())
|
||||
}
|
||||
|
||||
// handle clicking on the steps card
|
||||
binding.steps.setOnClickListener {
|
||||
// since Android Q We need additionnal permissions
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
// check for activity permission
|
||||
val activityPermission = PermissionsManager.hasPermission(
|
||||
requireContext(),
|
||||
Manifest.permission.ACTIVITY_RECOGNITION
|
||||
)
|
||||
|
||||
// check for notification permission
|
||||
val notificationPermission =
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && PermissionsManager.hasPermission(
|
||||
requireContext(),
|
||||
@ -72,33 +73,41 @@ class BrowseFragment :
|
||||
|
||||
val permissionsToAsk = arrayListOf<String>()
|
||||
|
||||
// add missing permission to list
|
||||
if (!activityPermission) {
|
||||
permissionsToAsk.add(Manifest.permission.ACTIVITY_RECOGNITION)
|
||||
}
|
||||
|
||||
// add missing permission to list only if necessary
|
||||
if (!notificationPermission && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
permissionsToAsk.add(Manifest.permission.POST_NOTIFICATIONS)
|
||||
}
|
||||
|
||||
// ask for permissions
|
||||
if (permissionsToAsk.isNotEmpty()) {
|
||||
button = binding.steps
|
||||
activityResult.launch(permissionsToAsk.toTypedArray())
|
||||
return@setOnClickListener
|
||||
}
|
||||
}
|
||||
|
||||
// navigate user to the Steps home fragment
|
||||
findNavController().navigate(
|
||||
BrowseFragmentDirections.actionNavBrowseToStepsHomeFragment()
|
||||
)
|
||||
}
|
||||
|
||||
// display the number of steps the user made today
|
||||
viewModel.steps.observe(viewLifecycleOwner) {
|
||||
updateStepsText(it, viewModel.stepsGoal.value)
|
||||
}
|
||||
|
||||
// display the number of steps the user should do today
|
||||
viewModel.stepsGoal.observe(viewLifecycleOwner) {
|
||||
updateStepsText(viewModel.steps.value, it)
|
||||
}
|
||||
|
||||
// display the current user's weight
|
||||
viewModel.weight.observe(viewLifecycleOwner) {
|
||||
binding.weightText.setText(
|
||||
String.format(
|
||||
|
@ -23,8 +23,7 @@ class BrowseViewModel @Inject internal constructor(
|
||||
private val _steps = MutableLiveData(0)
|
||||
val steps: LiveData<Int> = _steps
|
||||
|
||||
private val _stepsGoal: MutableLiveData<Int?> = MutableLiveData()
|
||||
val stepsGoal: LiveData<Int?> = _stepsGoal
|
||||
val stepsGoal = config.getInt(Settings.STEPS_GOAL).toLiveData()
|
||||
|
||||
private val _weight = MutableLiveData(0f)
|
||||
val weight: LiveData<Float> = _weight
|
||||
@ -43,8 +42,5 @@ class BrowseViewModel @Inject internal constructor(
|
||||
}
|
||||
}
|
||||
|
||||
this._stepsGoal.postValue(
|
||||
config.getInt(Settings.STEPS_GOAL).value
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,9 @@ import com.dzeio.openhealth.utils.DownloadImageTask
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
/**
|
||||
* Dialog that display to the user a spcific product and it's consumption
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class FoodDialog :
|
||||
BaseDialog<FoodDialogViewModel, DialogFoodProductBinding>(FoodDialogViewModel::class.java) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user