Skip to content

Commit

Permalink
feat : Firebase로부터 유저 정보 receive 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jordan-comlinee committed Nov 28, 2024
1 parent baf6972 commit 55b0151
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
4 changes: 3 additions & 1 deletion app/src/main/java/com/dna/beyoureyes/SplashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.util.Log
import android.widget.Toast
import com.daimajia.androidanimations.library.Techniques
import com.daimajia.androidanimations.library.YoYo
import com.dna.beyoureyes.databinding.ActivitySplashBinding
import com.dna.beyoureyes.model.FirebaseHelper
import com.dna.beyoureyes.model.UserInfo
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.FirebaseUser
Expand Down Expand Up @@ -48,7 +50,7 @@ class SplashActivity : AppCompatActivity() {
userId = currentUser.uid
AppUser.id = userId
Log.d("GOOGLE : ", AppUser.id.toString())

FirebaseHelper.receiveUserData(userId)
//Toast.makeText(this@SplashActivity, userId, Toast.LENGTH_LONG).show()
Handler().postDelayed({ startActivity(Intent(this, MainActivity::class.java)); finish(); }, 3 * 1000)
}
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/dna/beyoureyes/model/FirebaseHelper.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.dna.beyoureyes.model

import android.util.Log
import androidx.camera.core.processing.SurfaceProcessorNode.In
import com.dna.beyoureyes.AppUser
import com.google.firebase.Timestamp
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.ktx.firestore
import com.google.firebase.ktx.Firebase
import java.io.Serializable

class FirebaseHelper {
Expand Down Expand Up @@ -42,5 +47,24 @@ class FirebaseHelper {
Log.d("REGISTERFIRESTORE : ", "Error deleting documents.", exception)
}
}

fun receiveUserData(userId: String) {

val db = Firebase.firestore
db.collection("userInfo")
.whereEqualTo("userId", AppUser.id!!)
.get()
.addOnSuccessListener { info ->
for (document in info) {
val userName = document.data.get("userName") as String
val userGender = document.data.get("userGender") as Long
val userBirth = document.data.get("userBirth") as Timestamp
val userDisease = document.data.get("userDisease") as ArrayList<String>
val userAllergy = document.data.get("userAllergy") as ArrayList<String>
val profile = document.data.get("userProfile") as String
AppUser.setInfo(userName, userGender.toInt(), userBirth, userDisease, userAllergy, profile)
}
}
}
}
}
2 changes: 0 additions & 2 deletions app/src/main/java/com/dna/beyoureyes/model/UserInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class UserInfo (
init {
age = getAge(birth)
}
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: Timestamp, disease:ArrayList<String>, allergy:ArrayList<String>)
:this(name, gender, birth, disease.toMutableSet(), allergy.toMutableSet(), getAge(birth))

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/dna/beyoureyes/ui/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class HomeFragment : Fragment() {
}
energyIntake = totalIntake.energy ?: 0 // 사용자의 칼로리 섭취량
Log.d("HOME", totalIntake.natrium?.getMilliGram().toString())
} else {
Log.d("TODAYINTAKE", "user did not eat today")
}
}
.addOnFailureListener { exception -> // DB 연결 실패 처리
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.dna.beyoureyes.AppUser
import com.dna.beyoureyes.R
import com.dna.beyoureyes.databinding.FragmentMyInfoBinding
import com.dna.beyoureyes.model.FoodHistory
Expand Down Expand Up @@ -63,6 +64,8 @@ class MyInfoFragment : Fragment() {
binding.privacyPolicyBtn.setOnClickListener {

}

updateProfile()
return root
}

Expand All @@ -71,4 +74,8 @@ class MyInfoFragment : Fragment() {
_binding = null
}

fun updateProfile() {
binding.profileName.setText(AppUser.info?.name?:"")
}

}
7 changes: 7 additions & 0 deletions app/src/main/java/com/dna/beyoureyes/userId.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.dna.beyoureyes

import com.dna.beyoureyes.model.UserInfo
import android.app.Application
import com.dna.beyoureyes.model.Gender
import com.google.firebase.Timestamp

class userId : Application() {
var userId: String? = null
Expand Down Expand Up @@ -29,4 +31,9 @@ object AppUser {
return false
}
}

fun setInfo(name : String, gender: Int, birth: Timestamp, disease : ArrayList<String>?, allergy : ArrayList<String>?, profile: String?) {
val info = UserInfo(name, gender, birth, disease?: ArrayList(), allergy?:ArrayList(), profile?:"")
this.info = info
}
}

0 comments on commit 55b0151

Please sign in to comment.