有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在Firestore中构建跟踪系统

我从Firebase实时数据库切换到Firestore 在实时数据库中,我将此代码用于以下系统:

checkFollowingStatus(user.getUID(), holder.followButton)
holder.followButton.setOnClickListener {
            if(holder.followButton.text.toString() == "Follow")
            {
                firebaseUser?.uid.let { it1 ->
                    FirebaseDatabase.getInstance().reference
                            .child("Follow").child(it1.toString())
                            .child("Following").child(user.getUID())
                            .setValue(true).addOnCompleteListener { task ->
                                if (task.isSuccessful) {
                                    firebaseUser?.uid.let { it ->
                                        FirebaseDatabase.getInstance().reference
                                                .child("Follow").child(user.getUID())
                                                .child("Followers").child(it.toString())
                                                .setValue(true).addOnCompleteListener { task ->
                                                    if (task.isSuccessful) {

                                                    }
                                                }
                                    }
                                }
                            }
                }
            }
            else
            {
                firebaseUser?.uid.let { it1 ->
                    FirebaseDatabase.getInstance().reference
                            .child("Follow").child(it1.toString())
                            .child("Following").child(user.getUID())
                            .removeValue().addOnCompleteListener { task ->
                                if (task.isSuccessful) {
                                    firebaseUser?.uid.let { it1 ->
                                        FirebaseDatabase.getInstance().reference
                                                .child("Follow").child(user.getUID())
                                                .child("Followers").child(it1.toString())
                                                .removeValue().addOnCompleteListener { task ->
                                                    if (task.isSuccessful) {

                                                    }
                                                }
                                    }
                                }
                            }
                }
            } }
       private fun checkFollowingStatus(uid: String, followButton: Button) {
    val followingRef = firebaseUser?.uid.let { it1 ->
        FirebaseDatabase.getInstance().reference
                .child("Follow").child(it1.toString())
                .child("Following")
    }

    followingRef.addValueEventListener(object : ValueEventListener {
        override fun onDataChange(datasnapshot: DataSnapshot) {
            if (datasnapshot.child(uid).exists()) {
                followButton.text = "Unfollow"
            } else {
                followButton.text = "Follow"
            }
        }

        override fun onCancelled(p0: DatabaseError) {

        }
    })

}

它在实时数据库中看起来像这样
+跟随
+用户ID
+以下内容
+usersId
+追随者
+usersId
如何将其转换为Firestore,或者如何在Firestore数据库中构建跟踪系统


共 (1) 个答案

  1. # 1 楼答案

    var hashMap : HashMap<String, Object> 
               = HashMap<String, Object> () 
    
    hashMap.put("someName", true);
    
    
    

    并将此哈希映射传递给set方法

    databaseRefernce.addSnapshotListener(new EventListener<DocumentSnapshot or QuerySnapshot>() {
    
        @Override
        public void onEvent(@Nullable DocumentSnapshot value, @Nullable FirebaseFirestoreException error) {
          if (value.exists())  {
          }
        }
    
    });