Implemented in the application firebase authentication. As well as the ability to add and delete records. But when I go with another account, the records are the same everywhere.
Q: how can I create my own records for each authorized user?
Now have smth like this:
As I understood from the comment I need to add another field to my structure: "users". And ultimately get type target-list - > users - > targets
But for example in my main activity I select as follows:
databaseReference = FirebaseDatabase.getInstance().getReference("targets")
How do I understand here I have to change the structure?
UPD: I tried to to next:
private fun updateListData() {
val uid = FirebaseAuth.getInstance().currentUser?.uid ?: ""
databaseReference = FirebaseDatabase.getInstance().getReference("targets").child(uid)
getTargetsFromDb()
}
and in getTargetsFromDb():
private fun getTargetsFromDb() {
databaseReference?.addValueEventListener(object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
for (targetSnapshot in dataSnapshot.children) {
val target = targetSnapshot.getValue(Target::class.java)
target?.let { targetList.add(it) }
}
recyclerView?.adapter = adapter
}
override fun onCancelled(databaseError: DatabaseError) {
Log.d("some", "Error trying to get targets for ${databaseError.message}")
}
})
}
And get next structure: