我有一些片段,我被绑定数据所困,我想绑定一次数据,就像在textview中缓存数据一样,因为当我从另一个片段中对片段进行概要分析时,视图总是像从firestore一样重载请求数据这个:
这是我的代码:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val user = FirebaseAuth.getInstance().currentUser
val email = user?.email
FirestoreUtil.getCurrentUser { users ->
view.profil_name.text = users.name
view.profil_email.text = email
view.text_bio.text = users.bio
if(users.status != "santri"){
view.button_menjadi_pengajar.visibility = View.VISIBLE
view.floating_action_button.visibility = View.INVISIBLE
}
if(users.profilePicturePath!=null){
GlideApp.with(this)
.load(users.profilePicturePath)
.placeholder(R.mipmap.default_profile)
.into(view.profil_picture)
}
}
}
和firestoreutil:
fun getCurrentUser(onSuccess: (Users) -> Unit){
currentUserDocRef.get()
.addOnSuccessListener {
onSuccess(it.toObject(Users::class.java)!!)
}
}
如果您有任何建议,我很乐意实施
谢谢。