Reputation: 98
In my Firebase chat app am inserting data for user name and profile photo using setValue on user sign up after they have logged in with google, email and password or facebook. Then in my profile activity i then use valueEventListener to show user photo and and user name, am able to update if I use the setValue method again in my profile activity. But the problem is that it only updates the current data, all places where the user has posted something or comment, the user name and profile photo remains the same. is there a way to update everything in my database when user updates his info in profile activity?
Here is how am inserting data
StorageReference filepath = mStorageImage.child(mImageUri.getLastPathSegment());
filepath.putFile(mImageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
String downloadUri = taskSnapshot.getDownloadUrl().toString();
mDatabaseUsers.child(user_id).child("name").setValue(name);
mDatabaseUsers.child(user_id).child("timestampjoined").setValue(timestamp);
mDatabaseUsers.child(user_id).child("image").setValue(downloadUri);
mProgress.dismiss();
Then in my profile activity I get the data
mDatabaseUser.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String timestampjoined = (String) dataSnapshot.child("timestampjoined").getValue();
String profilename = (String) dataSnapshot.child("name").getValue();
String profilepicture = (String) dataSnapshot.child("image").getValue();
Glide.with(DDiaryProfileActivity.this).load(profilepicture)
.fitCenter().diskCacheStrategy(DiskCacheStrategy.ALL).into(mProfilePicture);
((CollapsingToolbarLayout) findViewById(R.id.toolbar_profile)).setCollapsedTitleTextAppearance(R.style.CollapsingToolBar);;
((CollapsingToolbarLayout) findViewById(R.id.toolbar_profile)).setTitle(profilename);
mTimeJoined.setText("Date joined : " + timestampjoined);
mProfileName.setText(profilename);
How do I update in all places where this data is saved?
Upvotes: 0
Views: 185
Reputation: 196
The problem is not clear. Please explain in some more details. Post your database structure.
To get the same data everywhere just create a child say for example
user
-userid
-name:username
-photo:url
-timestamp:12:30
with the users name,photo,time stamp etc and then fetch these details wherever you want the user details.Also update this child in your profile activity. So basically what you are doing is fetching and updating all the values from the same child.
Upvotes: 1