Skip to content

Commit

Permalink
refactor : 유저 생년월일 데이터 타입 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jordan-comlinee committed Nov 28, 2024
1 parent 92f582c commit baf6972
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 36 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions app/src/main/java/com/dna/beyoureyes/AssignActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,7 +21,7 @@ class AssignActivity : AppCompatActivity(), FragmentNavigationListener {
private var currentStep = 0
private var disease : ArrayList<String> = ArrayList<String>()
private var allergy : ArrayList<String> = ArrayList<String>()
private var profilr : String? = null
private var profile : String = ""

override fun onNavigateToFragment(fragment: Fragment) {
replaceFragment(fragment)
Expand Down Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dna.beyoureyes

import android.util.Log
import com.dna.beyoureyes.model.Gender

//========================================================================
// 섭취 범위 관리를 위한 enum 객체들
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/dna/beyoureyes/SplashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -58,6 +59,7 @@ class SplashActivity : AppCompatActivity() {
}
updateUI(currentUser)


}
// [END on_start_check_user]

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class FirebaseHelper {
private val firestore: FirebaseFirestore = FirebaseFirestore.getInstance()

// 데이터를 Firestore에 추가
fun sendData(userInfo: HashMap<String, Serializable?>, collectionName: String) {
fun sendData(userInfo: HashMap<String, Any?>, collectionName: String) {
firestore.collection(collectionName)
.add(userInfo)
.addOnSuccessListener { documentReference ->
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/dna/beyoureyes/model/Protein.kt
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,7 +16,7 @@ enum class Gender {
class UserInfo (
var name : String, // 사용자 나이
var gender : Int, // 사용자 성별
var birth : String, // 사용자 생일
var birth : Timestamp, // 사용자 생일
var disease : MutableSet<String>, // 사용자 질병 정보(nullable - 해당사항 없을 수 있으므로)
var allergic : MutableSet<String>, // 사용자 알레르기 정보(nullable - 해당사항 없을 수 있으므로
var age : Int,
Expand All @@ -24,15 +25,15 @@ class UserInfo (
init {
age = getAge(birth)
}
constructor(name:String, gender:Int, birth: String, disease:ArrayList<String>, allergy:ArrayList<String>, age:Int)
constructor(name:String, gender:Int, birth: Timestamp, disease:ArrayList<String>, allergy:ArrayList<String>, age:Int)
:this(name, gender, birth, disease.toMutableSet(), allergy.toMutableSet(), age)
constructor(name:String, gender:Int, birth: String, disease:ArrayList<String>, allergy:ArrayList<String>)
constructor(name:String, gender:Int, birth: Timestamp, disease:ArrayList<String>, allergy:ArrayList<String>)
:this(name, gender, birth, disease.toMutableSet(), allergy.toMutableSet(), getAge(birth))

constructor(name:String, gender:Int, birth: String, disease:ArrayList<String>, allergy:ArrayList<String>, profile:String)
constructor(name:String, gender:Int, birth: Timestamp, disease:ArrayList<String>, allergy:ArrayList<String>, 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 메소드
Expand Down Expand Up @@ -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)
Expand All @@ -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<String>
val allergicList = document.data.get("userAllergy") as ArrayList<String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>)
fun onAllergyInputRecieved(userAllergyList : ArrayList<String>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Nutrition>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/dna/beyoureyes/userId.kt
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down

0 comments on commit baf6972

Please sign in to comment.