From baf6972438b46aeb125bd1e0df6fbd2fe37265d4 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 28 Nov 2024 18:45:22 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20=EC=9C=A0=EC=A0=80=20=EC=83=9D?= =?UTF-8?q?=EB=85=84=EC=9B=94=EC=9D=BC=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 1 - .../java/com/dna/beyoureyes/AssignActivity.kt | 18 ++++++++----- .../com/dna/beyoureyes/NutrientDailyValues.kt | 1 + .../java/com/dna/beyoureyes/SplashActivity.kt | 8 +++--- .../dna/beyoureyes/model/FirebaseHelper.kt | 2 +- .../java/com/dna/beyoureyes/model/Protein.kt | 1 - .../dna/beyoureyes/{ => model}/UserInfo.kt | 26 ++++++++----------- .../ui/FragmentNavigationListener.kt | 4 --- .../dna/beyoureyes/ui/home/HomeFragment.kt | 1 - .../dna/beyoureyes/ui/home/IntakeAdapter.kt | 1 - .../beyoureyes/ui/home/IntakeNutritionBar.kt | 2 -- .../main/java/com/dna/beyoureyes/userId.kt | 2 +- 12 files changed, 31 insertions(+), 36 deletions(-) rename app/src/main/java/com/dna/beyoureyes/{ => model}/UserInfo.kt (83%) diff --git a/.idea/misc.xml b/.idea/misc.xml index f9f55b1b..0d678e42 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/app/src/main/java/com/dna/beyoureyes/AssignActivity.kt b/app/src/main/java/com/dna/beyoureyes/AssignActivity.kt index 3c49bfd6..97305402 100644 --- a/app/src/main/java/com/dna/beyoureyes/AssignActivity.kt +++ b/app/src/main/java/com/dna/beyoureyes/AssignActivity.kt @@ -3,13 +3,16 @@ package com.dna.beyoureyes import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import android.util.Log -import android.widget.Toast import androidx.fragment.app.Fragment import com.dna.beyoureyes.model.FirebaseHelper +import com.dna.beyoureyes.model.UserInfo import com.dna.beyoureyes.ui.FragmentNavigationListener import com.google.firebase.auth.ktx.auth import com.google.firebase.ktx.Firebase +import com.google.firebase.Timestamp +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale class AssignActivity : AppCompatActivity(), FragmentNavigationListener { private var name : String? = null @@ -18,7 +21,7 @@ class AssignActivity : AppCompatActivity(), FragmentNavigationListener { private var currentStep = 0 private var disease : ArrayList = ArrayList() private var allergy : ArrayList = ArrayList() - private var profilr : String? = null + private var profile : String = "" override fun onNavigateToFragment(fragment: Fragment) { replaceFragment(fragment) @@ -91,15 +94,18 @@ class AssignActivity : AppCompatActivity(), FragmentNavigationListener { } fun registInfo() { - AppUser.info = UserInfo(name?:"", gender?:0, birth!!, disease, allergy) + val dateFormat = SimpleDateFormat("yyyyMMdd", Locale.getDefault()) + val birthDate = dateFormat.parse(birth ?: "") ?: Date() + val birthTimeStamp = Timestamp(birthDate) + AppUser.info = UserInfo(name?:"", gender?:0, birthTimeStamp, disease, allergy) val userInfo = hashMapOf( "userId" to Firebase.auth.currentUser?.uid, "userName" to name!!, "userGender" to gender, - "userBirth" to birth, + "userBirth" to birthTimeStamp, "userDisease" to disease, "userAllergy" to allergy, - "userProfile" to "" + "userProfile" to profile ) FirebaseHelper.sendData(userInfo, "userInfo") } diff --git a/app/src/main/java/com/dna/beyoureyes/NutrientDailyValues.kt b/app/src/main/java/com/dna/beyoureyes/NutrientDailyValues.kt index d2ab518e..3d3b6b90 100644 --- a/app/src/main/java/com/dna/beyoureyes/NutrientDailyValues.kt +++ b/app/src/main/java/com/dna/beyoureyes/NutrientDailyValues.kt @@ -1,6 +1,7 @@ package com.dna.beyoureyes import android.util.Log +import com.dna.beyoureyes.model.Gender //======================================================================== // 섭취 범위 관리를 위한 enum 객체들 diff --git a/app/src/main/java/com/dna/beyoureyes/SplashActivity.kt b/app/src/main/java/com/dna/beyoureyes/SplashActivity.kt index 57fdc281..03abfc16 100644 --- a/app/src/main/java/com/dna/beyoureyes/SplashActivity.kt +++ b/app/src/main/java/com/dna/beyoureyes/SplashActivity.kt @@ -8,7 +8,7 @@ import android.util.Log import com.daimajia.androidanimations.library.Techniques import com.daimajia.androidanimations.library.YoYo import com.dna.beyoureyes.databinding.ActivitySplashBinding -import com.google.firebase.auth.EmailAuthProvider +import com.dna.beyoureyes.model.UserInfo import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.FirebaseUser import com.google.firebase.auth.ktx.auth @@ -47,7 +47,8 @@ class SplashActivity : AppCompatActivity() { //Toast.makeText(this@SplashActivity, "이미 가입한 유저", Toast.LENGTH_LONG).show() userId = currentUser.uid AppUser.id = userId - Log.d("GOOGLE : ", AppUser.id.toString()+" INIT") + Log.d("GOOGLE : ", AppUser.id.toString()) + //Toast.makeText(this@SplashActivity, userId, Toast.LENGTH_LONG).show() Handler().postDelayed({ startActivity(Intent(this, MainActivity::class.java)); finish(); }, 3 * 1000) } @@ -58,6 +59,7 @@ class SplashActivity : AppCompatActivity() { } updateUI(currentUser) + } // [END on_start_check_user] @@ -73,7 +75,7 @@ class SplashActivity : AppCompatActivity() { // 과연 절대로 null이 아닐까? userId = user!!.uid AppUser.id = userId - Log.d("GOOGLE : ", AppUser.id.toString()+" INIT") + Log.d("SPLASH : ", AppUser.id.toString()+" INIT") //Toast.makeText(this@SplashActivity, userId, Toast.LENGTH_LONG).show() updateUI(user) } else { diff --git a/app/src/main/java/com/dna/beyoureyes/model/FirebaseHelper.kt b/app/src/main/java/com/dna/beyoureyes/model/FirebaseHelper.kt index 107056b9..1e7b34e7 100644 --- a/app/src/main/java/com/dna/beyoureyes/model/FirebaseHelper.kt +++ b/app/src/main/java/com/dna/beyoureyes/model/FirebaseHelper.kt @@ -9,7 +9,7 @@ class FirebaseHelper { private val firestore: FirebaseFirestore = FirebaseFirestore.getInstance() // 데이터를 Firestore에 추가 - fun sendData(userInfo: HashMap, collectionName: String) { + fun sendData(userInfo: HashMap, collectionName: String) { firestore.collection(collectionName) .add(userInfo) .addOnSuccessListener { documentReference -> diff --git a/app/src/main/java/com/dna/beyoureyes/model/Protein.kt b/app/src/main/java/com/dna/beyoureyes/model/Protein.kt index a90bba83..d8f131d1 100644 --- a/app/src/main/java/com/dna/beyoureyes/model/Protein.kt +++ b/app/src/main/java/com/dna/beyoureyes/model/Protein.kt @@ -1,7 +1,6 @@ package com.dna.beyoureyes.model import com.dna.beyoureyes.AppUser -import com.dna.beyoureyes.Gender class Protein(override var milligram: Int = 0) : Nutrition { diff --git a/app/src/main/java/com/dna/beyoureyes/UserInfo.kt b/app/src/main/java/com/dna/beyoureyes/model/UserInfo.kt similarity index 83% rename from app/src/main/java/com/dna/beyoureyes/UserInfo.kt rename to app/src/main/java/com/dna/beyoureyes/model/UserInfo.kt index 2d8fe91f..0cc70f3f 100644 --- a/app/src/main/java/com/dna/beyoureyes/UserInfo.kt +++ b/app/src/main/java/com/dna/beyoureyes/model/UserInfo.kt @@ -1,7 +1,8 @@ -package com.dna.beyoureyes +package com.dna.beyoureyes.model +import com.dna.beyoureyes.NutrientDailyValues +import com.google.firebase.Timestamp import com.google.firebase.firestore.QueryDocumentSnapshot -import com.google.firebase.firestore.auth.User import java.text.SimpleDateFormat import java.util.Calendar import java.util.Locale @@ -15,7 +16,7 @@ enum class Gender { class UserInfo ( var name : String, // 사용자 나이 var gender : Int, // 사용자 성별 - var birth : String, // 사용자 생일 + var birth : Timestamp, // 사용자 생일 var disease : MutableSet, // 사용자 질병 정보(nullable - 해당사항 없을 수 있으므로) var allergic : MutableSet, // 사용자 알레르기 정보(nullable - 해당사항 없을 수 있으므로 var age : Int, @@ -24,15 +25,15 @@ class UserInfo ( init { age = getAge(birth) } - constructor(name:String, gender:Int, birth: String, disease:ArrayList, allergy:ArrayList, age:Int) + constructor(name:String, gender:Int, birth: Timestamp, disease:ArrayList, allergy:ArrayList, age:Int) :this(name, gender, birth, disease.toMutableSet(), allergy.toMutableSet(), age) - constructor(name:String, gender:Int, birth: String, disease:ArrayList, allergy:ArrayList) + constructor(name:String, gender:Int, birth: Timestamp, disease:ArrayList, allergy:ArrayList) :this(name, gender, birth, disease.toMutableSet(), allergy.toMutableSet(), getAge(birth)) - constructor(name:String, gender:Int, birth: String, disease:ArrayList, allergy:ArrayList, profile:String) + constructor(name:String, gender:Int, birth: Timestamp, disease:ArrayList, allergy:ArrayList, profile:String) :this(name, gender, birth, disease.toMutableSet(), allergy.toMutableSet(), getAge(birth), profile) - constructor(name:String, gender:Int, birth: String, profile: String) + constructor(name:String, gender:Int, birth: Timestamp, profile: String) :this(name, gender, birth, mutableSetOf(), mutableSetOf(), getAge(birth), profile) // 사용자 맞춤 권장량 정보를 제공하는 get 메소드 @@ -86,18 +87,13 @@ class UserInfo ( companion object { - fun getAge(birth: String) : Int { - // 날짜 형식 정의 - val dateFormat = SimpleDateFormat("yyyyMMdd", Locale.getDefault()) - - val birthDate = dateFormat.parse(birth) - + fun getAge(birth: Timestamp) : Int { val calendar = Calendar.getInstance() val currentYear = calendar.get(Calendar.YEAR) val currentMonth = calendar.get(Calendar.MONTH) + 1 val currentDay = calendar.get(Calendar.DAY_OF_MONTH) - calendar.time = birthDate + calendar.time = birth.toDate() val birthYear = calendar.get(Calendar.YEAR) val birthMonth = calendar.get(Calendar.MONTH) + 1 val birthDay = calendar.get(Calendar.DAY_OF_MONTH) @@ -111,7 +107,7 @@ class UserInfo ( } fun parseFirebaseDoc(document: QueryDocumentSnapshot) : UserInfo? { val name = document.data.get("userName") as? String - val birth = document.data.get("userBirth") as? String + val birth = document.data.get("userBirth") as? Timestamp val gender = document.data.get("userGender") as? Long val diseaseList = document.data.get("userDisease") as ArrayList val allergicList = document.data.get("userAllergy") as ArrayList diff --git a/app/src/main/java/com/dna/beyoureyes/ui/FragmentNavigationListener.kt b/app/src/main/java/com/dna/beyoureyes/ui/FragmentNavigationListener.kt index b535a19c..76e6fcdf 100644 --- a/app/src/main/java/com/dna/beyoureyes/ui/FragmentNavigationListener.kt +++ b/app/src/main/java/com/dna/beyoureyes/ui/FragmentNavigationListener.kt @@ -4,13 +4,9 @@ import androidx.fragment.app.Fragment interface FragmentNavigationListener { fun onNavigateToFragment(fragment: Fragment) - fun onBtnClick(currentFragment: Fragment, isNxt : Boolean) - fun onNameInputRecieved(name: String) - fun onGenderInputRecieved(gender : Int) - fun onBirthInputRecieved(birth : String) fun onDiseaseInputRecieved(userDiseaseList : ArrayList) fun onAllergyInputRecieved(userAllergyList : ArrayList) diff --git a/app/src/main/java/com/dna/beyoureyes/ui/home/HomeFragment.kt b/app/src/main/java/com/dna/beyoureyes/ui/home/HomeFragment.kt index 56584380..bad0af50 100644 --- a/app/src/main/java/com/dna/beyoureyes/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/dna/beyoureyes/ui/home/HomeFragment.kt @@ -9,7 +9,6 @@ import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.dna.beyoureyes.AppUser -import com.dna.beyoureyes.Gender import com.dna.beyoureyes.NutritionFacts import com.dna.beyoureyes.R import com.dna.beyoureyes.databinding.FragmentHomeBinding diff --git a/app/src/main/java/com/dna/beyoureyes/ui/home/IntakeAdapter.kt b/app/src/main/java/com/dna/beyoureyes/ui/home/IntakeAdapter.kt index 45a2cc29..ab6b8e6f 100644 --- a/app/src/main/java/com/dna/beyoureyes/ui/home/IntakeAdapter.kt +++ b/app/src/main/java/com/dna/beyoureyes/ui/home/IntakeAdapter.kt @@ -2,7 +2,6 @@ package com.dna.beyoureyes.ui.home import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView -import com.dna.beyoureyes.Gender import com.dna.beyoureyes.model.Nutrition class IntakeAdapter(private val items: MutableList) diff --git a/app/src/main/java/com/dna/beyoureyes/ui/home/IntakeNutritionBar.kt b/app/src/main/java/com/dna/beyoureyes/ui/home/IntakeNutritionBar.kt index dd0d17a1..5bc9b055 100644 --- a/app/src/main/java/com/dna/beyoureyes/ui/home/IntakeNutritionBar.kt +++ b/app/src/main/java/com/dna/beyoureyes/ui/home/IntakeNutritionBar.kt @@ -10,8 +10,6 @@ import android.widget.ProgressBar import android.widget.TextView import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.ContextCompat -import com.dna.beyoureyes.AppUser -import com.dna.beyoureyes.Gender import com.dna.beyoureyes.R import com.dna.beyoureyes.model.Nutrition diff --git a/app/src/main/java/com/dna/beyoureyes/userId.kt b/app/src/main/java/com/dna/beyoureyes/userId.kt index 7b3358da..2ed28793 100644 --- a/app/src/main/java/com/dna/beyoureyes/userId.kt +++ b/app/src/main/java/com/dna/beyoureyes/userId.kt @@ -1,6 +1,6 @@ package com.dna.beyoureyes -import com.dna.beyoureyes.UserInfo +import com.dna.beyoureyes.model.UserInfo import android.app.Application class userId : Application() {