mirror of
https://github.com/dzeiocom/OpenHealth.git
synced 2025-04-23 11:22:10 +00:00
feat: Continue work on Browse and Weight
This commit is contained in:
parent
3e5d10d817
commit
14102f65ae
@ -12,13 +12,16 @@ import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import androidx.navigation.ui.*
|
||||
import androidx.navigation.ui.AppBarConfiguration
|
||||
import androidx.navigation.ui.NavigationUI
|
||||
import androidx.navigation.ui.navigateUp
|
||||
import androidx.navigation.ui.setupActionBarWithNavController
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import androidx.work.WorkManager
|
||||
import com.dzeio.openhealth.core.BaseActivity
|
||||
import com.dzeio.openhealth.databinding.ActivityMainBinding
|
||||
import com.dzeio.openhealth.interfaces.NotificationChannels
|
||||
import com.dzeio.openhealth.services.WaterReminderService
|
||||
import com.dzeio.openhealth.ui.home.HomeFragmentDirections
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
@ -81,7 +84,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
NavigationUI.onNavDestinationSelected(item, navController) || super.onOptionsItemSelected(item)
|
||||
NavigationUI.onNavDestinationSelected(item, navController) ||
|
||||
super.onOptionsItemSelected(item)
|
||||
|
||||
override fun onRequestPermissionsResult(
|
||||
requestCode: Int,
|
||||
@ -125,5 +129,4 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,14 +6,16 @@ import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import com.dzeio.openhealth.data.water.Water
|
||||
import com.dzeio.openhealth.data.water.WaterDao
|
||||
import com.dzeio.openhealth.data.weight.WeightDao
|
||||
import com.dzeio.openhealth.data.weight.Weight
|
||||
import com.dzeio.openhealth.data.weight.WeightDao
|
||||
|
||||
@Database(
|
||||
entities = [
|
||||
Weight::class,
|
||||
Water::class
|
||||
], version = 1, exportSchema = false
|
||||
],
|
||||
version = 1,
|
||||
exportSchema = false
|
||||
)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
abstract fun weightDao(): WeightDao
|
||||
|
@ -5,7 +5,8 @@ import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import java.sql.Date
|
||||
import java.text.DateFormat.getDateInstance
|
||||
import java.util.*
|
||||
import java.util.Calendar
|
||||
import java.util.TimeZone
|
||||
|
||||
@Entity()
|
||||
data class Water(
|
||||
@ -16,7 +17,7 @@ data class Water(
|
||||
var source: String = "OpenHealth"
|
||||
) {
|
||||
init {
|
||||
if (timestamp == (0).toLong()) {
|
||||
if (timestamp == 0L) {
|
||||
val cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
|
||||
cal.set(Calendar.HOUR_OF_DAY, 0)
|
||||
cal.set(Calendar.MINUTE, 0)
|
||||
|
@ -14,7 +14,6 @@ interface WaterDao : BaseDao<Water> {
|
||||
@Query("SELECT * FROM Water where id = :weightId")
|
||||
fun getOne(weightId: Long): Flow<Water?>
|
||||
|
||||
|
||||
@Query("Select count(*) from Water")
|
||||
fun getCount(): Flow<Int>
|
||||
|
||||
|
@ -5,6 +5,7 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.dzeio.openhealth.core.BaseFragment
|
||||
import com.dzeio.openhealth.databinding.FragmentBrowseBinding
|
||||
@ -23,5 +24,13 @@ class BrowseFragment :
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding.weight.setOnClickListener {
|
||||
findNavController().navigate(BrowseFragmentDirections.actionNavBrowseToNavListWeight())
|
||||
}
|
||||
|
||||
binding.waterIntake.setOnClickListener {
|
||||
findNavController().navigate(BrowseFragmentDirections.actionNavBrowseToNavWaterHome())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ import com.dzeio.openhealth.core.BaseFragment
|
||||
import com.dzeio.openhealth.data.weight.Weight
|
||||
import com.dzeio.openhealth.databinding.FragmentListWeightBinding
|
||||
import com.dzeio.openhealth.graphs.WeightChart
|
||||
import com.dzeio.openhealth.ui.home.HomeViewModel
|
||||
import com.dzeio.openhealth.units.WeightUnit
|
||||
import com.dzeio.openhealth.utils.GraphUtils
|
||||
import com.google.android.material.color.MaterialColors
|
||||
@ -26,10 +25,10 @@ import kotlinx.coroutines.flow.collectLatest
|
||||
|
||||
@AndroidEntryPoint
|
||||
class ListWeightFragment :
|
||||
BaseFragment<HomeViewModel, FragmentListWeightBinding>(HomeViewModel::class.java) {
|
||||
BaseFragment<ListWeightViewModel, FragmentListWeightBinding>(ListWeightViewModel::class.java) {
|
||||
|
||||
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> FragmentListWeightBinding =
|
||||
FragmentListWeightBinding::inflate
|
||||
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) ->
|
||||
FragmentListWeightBinding = FragmentListWeightBinding::inflate
|
||||
|
||||
val settings: SharedPreferences by lazy {
|
||||
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
@ -40,6 +39,10 @@ class ListWeightFragment :
|
||||
|
||||
setHasOptionsMenu(true)
|
||||
|
||||
if (viewModel.goalWeight != null) {
|
||||
binding.goalButton.setText(R.string.edit_goal)
|
||||
}
|
||||
|
||||
val recycler = binding.list
|
||||
|
||||
val manager = LinearLayoutManager(requireContext())
|
||||
@ -103,7 +106,9 @@ class ListWeightFragment :
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.action_add -> {
|
||||
findNavController().navigate(ListWeightFragmentDirections.actionNavListWeightToNavAddWeightDialog())
|
||||
findNavController().navigate(
|
||||
ListWeightFragmentDirections.actionNavListWeightToNavAddWeightDialog()
|
||||
)
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
|
@ -0,0 +1,23 @@
|
||||
package com.dzeio.openhealth.ui.weight
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import com.dzeio.openhealth.core.BaseViewModel
|
||||
import com.dzeio.openhealth.data.weight.WeightRepository
|
||||
import com.dzeio.openhealth.units.UnitFactory
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class ListWeightViewModel @Inject internal constructor(
|
||||
private val weightRepository: WeightRepository,
|
||||
settings: SharedPreferences
|
||||
) : BaseViewModel() {
|
||||
|
||||
var weightUnit =
|
||||
UnitFactory.mass(settings.getString("weight_unit", "kilogram") ?: "kilogram")
|
||||
|
||||
val goalWeight: Float? =
|
||||
(settings.getString("weight_goal", null)?.toFloatOrNull())
|
||||
|
||||
fun fetchWeights() = weightRepository.getWeights()
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
<vector android:height="24dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
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="M19,3H5C3.9,3 3,3.9 3,5v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2V5C21,3.9 20.1,3 19,3zM19,19H5V5h14V19zM12,6c-1.66,0 -3,1.34 -3,3s1.34,3 3,3s3,-1.34 3,-3S13.66,6 12,6zM11,9.5h-1v-1h1V9.5zM12.5,9.5h-1v-1h1V9.5zM14,9.5h-1v-1h1V9.5z"/>
|
||||
</vector>
|
@ -34,6 +34,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/steps"
|
||||
style="?attr/materialCardViewFilledStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -73,7 +74,7 @@
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="4500 of 5000 steps" />
|
||||
android:text="xxxx of xxxx steps" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@ -98,11 +99,12 @@
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:text="Heart"
|
||||
android:text="Vitals"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/heart_rate"
|
||||
style="?attr/materialCardViewFilledStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -163,6 +165,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/weight"
|
||||
style="?attr/materialCardViewFilledStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -183,7 +186,7 @@
|
||||
android:layout_height="40dp"
|
||||
android:paddingVertical="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:src="@drawable/ic_baseline_add_24"
|
||||
android:src="@drawable/ic_outline_monitor_weight_24"
|
||||
android:background="@drawable/shape_circle"
|
||||
app:tint="?colorOnPrimary" />
|
||||
|
||||
@ -203,6 +206,7 @@
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/height"
|
||||
style="?attr/materialCardViewFilledStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -269,6 +273,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/water_intake"
|
||||
style="?attr/materialCardViewFilledStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -309,6 +314,7 @@
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/food_calories"
|
||||
style="?attr/materialCardViewFilledStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -14,11 +14,63 @@
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp">
|
||||
|
||||
<com.github.mikephil.charting.charts.LineChart
|
||||
android:id="@+id/chart"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp"
|
||||
android:minHeight="200dp" />
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
|
||||
android:paddingHorizontal="12dp"
|
||||
android:paddingVertical="16dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:paddingVertical="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:src="@drawable/ic_outline_monitor_weight_24"
|
||||
android:background="@drawable/shape_circle"
|
||||
app:tint="?colorOnPrimary" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="4dp"
|
||||
android:text="History" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.github.mikephil.charting.charts.LineChart
|
||||
android:id="@+id/chart"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp"
|
||||
android:minHeight="200dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/goal_button"
|
||||
android:text="@string/add_goal"
|
||||
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>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
|
@ -35,5 +35,7 @@
|
||||
<string name="menu_dashboard">Dashboard</string>
|
||||
<string name="menu_browse">Browse</string>
|
||||
<string name="menu_activity">Activity</string>
|
||||
<string name="add_goal">Ajouter un objectif</string>
|
||||
<string name="edit_goal">Modifier l\'objectif</string>
|
||||
|
||||
</resources>
|
||||
|
@ -45,4 +45,7 @@
|
||||
<string name="menu_dashboard">Dashboard</string>
|
||||
<string name="menu_browse">Browse</string>
|
||||
<string name="menu_activity">Activity</string>
|
||||
|
||||
<string name="add_goal">Add Goal</string>
|
||||
<string name="edit_goal">Modify Goal</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user