Skip to content

Commit

Permalink
과거 기록 상세 보기 화면 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
moon0900 committed Dec 2, 2024
1 parent b6afff5 commit 6aeb696
Show file tree
Hide file tree
Showing 30 changed files with 703 additions and 431 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ plugins {
id("org.jetbrains.kotlin.android")
//Google Firebase plugin
id("com.google.gms.google-services")
// navigation safeargs, classpath
id("androidx.navigation.safeargs.kotlin")


}

Expand Down
3 changes: 0 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@
<activity
android:name=".CameraFailActivity"
android:exported="false" />
<activity
android:name=".MyPastDetailActivity"
android:exported="false" />
<activity
android:name=".OnboardingActivity"
android:exported="false" />
Expand Down
164 changes: 8 additions & 156 deletions app/src/main/java/com/dna/beyoureyes/EnergyChart.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.View
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import com.dna.beyoureyes.model.Nutrition
import com.github.mikephil.charting.animation.Easing
import com.github.mikephil.charting.charts.BarChart
import com.github.mikephil.charting.charts.PieChart
Expand All @@ -27,20 +28,20 @@ import com.github.mikephil.charting.formatter.ValueFormatter
// primary 생성자 - 액티비티 내 바 차트 객체 및 관련 텍스트뷰를 전달
class NutriIntakeBarDisplay(
val barChart : BarChart,
val nameTextView: TextView,
val massTextView: TextView,
val dvTextView : TextView) {

fun hide(){
barChart.visibility = View.GONE
dvTextView.visibility = View.GONE
}

fun setZero(context: Context, unit: UnitOfMass, dv: DailyValue) {
setBarValue(context, Nutrition(0, unit), dv)
}

fun setBarValue(context: Context, nutri: Nutrition, dv: DailyValue) {
val milliIntake = nutri.getMilliGram()
val percentIntake = nutri.getPercentageOfDailyValue(dv.dailyValue)
fun set(context: Context, nutri: Nutrition) {
nameTextView.text = nutri.name
massTextView.text = nutri.massString
dvTextView.text = "권장 섭취량 " + nutri.getDailyValueText()
val percentIntake = nutri.percentageOfDailyValue
val entries = arrayListOf<BarEntry>()
entries.add(BarEntry(0f, percentIntake.toFloat()))
applyBarChart(context, entries, 100f)
Expand Down Expand Up @@ -111,104 +112,6 @@ class NutriIntakeBarDisplay(
}
}

// set All Bar Chart
class AllIntakeBarDisplay(
val natriumBar: NutriIntakeBarDisplay,
val carbsBar: NutriIntakeBarDisplay,
val sugarBar: NutriIntakeBarDisplay,
val proteinBar: NutriIntakeBarDisplay,
val fatBar: NutriIntakeBarDisplay,
val satFatBar: NutriIntakeBarDisplay,
val cholBar: NutriIntakeBarDisplay,
val lackIntakeReview : TextView,
val overIntakeReview : TextView
) {


fun hide(context: Context, userDVs: NutrientDailyValues?) {

userDVs?.let { // 사용자 맞춤 권장량 O
setNoDataValues(context, it)
}?:run{ // 사용자 맞춤 권장량 객체 null 일때 바 차트 다 숨김
natriumBar.hide()
carbsBar.hide()
sugarBar.hide()
proteinBar.hide()
fatBar.hide()
satFatBar.hide()
cholBar.hide()
}

lackIntakeReview.visibility = View.GONE
overIntakeReview.visibility = View.GONE
}

fun setNoDataValues(context: Context, userDVs: NutrientDailyValues) {
natriumBar.setZero(context, UnitOfMass.MILLIGRAM, userDVs.natrium)
carbsBar.setZero(context, UnitOfMass.GRAM, userDVs.carbs)
sugarBar.setZero(context, UnitOfMass.GRAM, userDVs.sugar)
proteinBar.setZero(context, UnitOfMass.GRAM, userDVs.protein)
fatBar.setZero(context, UnitOfMass.GRAM, userDVs.fat)
satFatBar.setZero(context, UnitOfMass.GRAM, userDVs.satFat)
cholBar.setZero(context, UnitOfMass.MILLIGRAM, userDVs.chol)
}
fun setAll(context: Context, totalIntake:NutritionFacts, userDVs: NutrientDailyValues?) {
userDVs?.let { userDVs ->
totalIntake.natrium?.let {
natriumBar.setBarValue(context, it, userDVs.natrium)
} ?: run {
natriumBar.setBarValue(context, Nutrition(0, UnitOfMass.MILLIGRAM), userDVs.natrium)
}

totalIntake.carbs?.let {
carbsBar.setBarValue(context, it, userDVs.carbs)
} ?: run {
carbsBar.setBarValue(context, Nutrition(0, UnitOfMass.GRAM), userDVs.carbs)
}

totalIntake.sugar?.let {
sugarBar.setBarValue(context, it, userDVs.sugar)
} ?: run {
sugarBar.setBarValue(context, Nutrition(0, UnitOfMass.GRAM), userDVs.sugar)
}

totalIntake.protein?.let {
proteinBar.setBarValue(context, it, userDVs.protein)
} ?: run {
proteinBar.setBarValue(context, Nutrition(0, UnitOfMass.GRAM), userDVs.protein)
}

totalIntake.fat?.let {
fatBar.setBarValue(context, it, userDVs.fat)
} ?: run {
fatBar.setBarValue(context, Nutrition(0, UnitOfMass.GRAM), userDVs.fat)
}

totalIntake.satFat?.let {
satFatBar.setBarValue(context, it, userDVs.satFat)
} ?: run {
satFatBar.setBarValue(context, Nutrition(0, UnitOfMass.GRAM), userDVs.satFat)
}

totalIntake.chol?.let {
cholBar.setBarValue(context, it, userDVs.chol)
} ?: run {
cholBar.setBarValue(context, Nutrition(0, UnitOfMass.MILLIGRAM), userDVs.chol)
}
}?:run{
// 사용자 맞춤 권장량 객체 null 일때 바 차트 다 숨김
natriumBar.hide()
carbsBar.hide()
sugarBar.hide()
proteinBar.hide()
fatBar.hide()
satFatBar.hide()
cholBar.hide()
}
}

}

// PieChartSetting
class EnergyChart(private val chart : PieChart) {

Expand Down Expand Up @@ -309,57 +212,6 @@ class EnergyChart(private val chart : PieChart) {
}
}



class NaIntakeBarDisplay(
val natriumBar: NutriIntakeBarDisplay
) {


fun hide(context: Context, userDVs: NutrientDailyValues?) {

userDVs?.let { // 사용자 맞춤 권장량 O
setNoDataValues(context, it)
}?:run{ // 사용자 맞춤 권장량 객체 null 일때 바 차트 다 숨김
natriumBar.hide()
}
}

fun setNoDataValues(context: Context, userDVs: NutrientDailyValues) {
natriumBar.setZero(context, UnitOfMass.MILLIGRAM, userDVs.natrium)
}

fun setReviews(context: Context, intake:NutritionFacts, userDVs: NutrientDailyValues){
var overNutris = arrayListOf<String>()
var lackNutris = arrayListOf<String>()

intake.natrium?.let {
userDVs.natrium.getIntakeStatus(it.getMilliGram())?.let { range ->
when (range) {
IntakeRange.LACK -> lackNutris.add("나트륨")
IntakeRange.OVER -> overNutris.add("나트륨")
else -> {}
}
}
}
}

fun setAll(context: Context, totalIntake:NutritionFacts, userDVs: NutrientDailyValues?) {
userDVs?.let { userDVs ->
totalIntake.natrium?.let {
natriumBar.setBarValue(context, it, userDVs.natrium)
} ?: run {
natriumBar.setBarValue(context, Nutrition(100, UnitOfMass.MILLIGRAM), userDVs.natrium)
}
setReviews(context, totalIntake, userDVs)
}?:run{
// 사용자 맞춤 권장량 객체 null 일때 바 차트 다 숨김
natriumBar.hide()
}
}

}

// calculate dp for unify ratio
fun dpToPx(context: Context, dp: Float): Float {
val density = context.resources.displayMetrics.density
Expand Down
26 changes: 24 additions & 2 deletions app/src/main/java/com/dna/beyoureyes/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import android.content.Context
import android.os.Bundle
import android.util.Log
import android.util.TypedValue
import android.view.View
import android.view.animation.AnimationUtils
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.navigation.ui.setupWithNavController
import com.dna.beyoureyes.databinding.ActivityMainBinding
Expand All @@ -18,6 +21,7 @@ import java.util.Calendar
class MainActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding
private lateinit var navController: NavController

val foodHistoryItems = mutableListOf<FoodHistory>() // 음식 기록 리스트

Expand All @@ -33,9 +37,23 @@ class MainActivity : AppCompatActivity() {

// 프래그먼트 뷰에 네비게이션 컨트롤러 연결
// -> 네비게이션 파일에 설정한대로 처리할 수 있게
val navController = findNavController(R.id.nav_host_fragment_activity_main)
navController = findNavController(R.id.nav_host_fragment_activity_main)
navView.setupWithNavController(navController)

// 프래그먼트 교체 시 하단 네비게이션 바를 숨겨야 할 때
navController.addOnDestinationChangedListener { _, destination, _ ->
if (destination.id == R.id.navigation_past_detail) { // 과거 기록 뷰는 하단 바 숨김
navView.visibility = View.GONE
} else {
// 그 외는 표시. 사라졌다가 등장시킬 시 애니메이션 효과 추가
if (navView.visibility == View.GONE) {
val slideIn = AnimationUtils.loadAnimation(this, R.anim.slide_in_bottom)
navView.startAnimation(slideIn)
navView.visibility = View.VISIBLE
}
}
}

// 오늘의 시작 시간 (자정)
val calendar = Calendar.getInstance()
calendar.set(Calendar.HOUR_OF_DAY, 0)
Expand Down Expand Up @@ -78,10 +96,14 @@ class MainActivity : AppCompatActivity() {
Log.w("HOME", "Error getting documents.", exception)
}.addOnCompleteListener {
// 데이터 로드를 마친 후 프래그먼트 화면 갱신
navController.navigate(R.id.navigation_home)
navigateToHomeFragment()
}
}

fun navigateToHomeFragment() {
navController.navigate(R.id.navigation_home)
}

private fun Float.toDp(context: Context): Float {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this, context.resources.displayMetrics)
}
Expand Down
11 changes: 0 additions & 11 deletions app/src/main/java/com/dna/beyoureyes/MyPastDetailActivity.kt

This file was deleted.

36 changes: 36 additions & 0 deletions app/src/main/java/com/dna/beyoureyes/ResultKcalFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.dna.beyoureyes

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.dna.beyoureyes.databinding.FragmentResultCalBinding

class ResultKcalFragment : Fragment() {

private var _binding: FragmentResultCalBinding? = null
private val binding get() = _binding!!

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
// Inflate the layout for this fragment
_binding = FragmentResultCalBinding.inflate(inflater, container, false)

return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// 외부에서 Bundle로 전달받은 칼로리 데이터
val kcal : Int? = arguments?.getInt("kcal")
kcal?.let { binding.kcalTextView.text = "${it}kcal" }
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
Loading

0 comments on commit 6aeb696

Please sign in to comment.