public class statusFragment extends Fragment {
//StatusfragmentBinding binding;
TopStatusAdapter statusAdapter;
ArrayList<UserStatus> userStatuses;
///we are creating customize fragment where first layut is created then class creat to attach then to the activities by creating classes while in simple activities creation both layout and activity is created at same time
ImageButton camerastatus;
RecyclerView statusList;
ProgressDialog dialog;
// for uploading
FirebaseDatabase database;
private FirebaseStorage firebaseStorage;
private StorageReference storageReference;
private FirebaseAuth firebaseAuth;
private static int PICK_IMAGE = 123;
private Uri imagepath;
private String ImageUriAcessToken;
userprofile user; //user obj
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.statusfragment,container,false);
dialog = new ProgressDialog(getContext());
dialog.setMessage("Uploading Image...");
dialog.setCancelable(false);
//like specific
database= FirebaseDatabase.getInstance();
userStatuses= new ArrayList<>();//need to remove from TopstatusAdapter
statusList = view.findViewById(R.id.statusList);
camerastatus= view.findViewById(R.id.camerastatus);
statusAdapter= new TopStatusAdapter(getContext(),userStatuses);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
layoutManager.setOrientation(RecyclerView.VERTICAL);
statusList.setLayoutManager(layoutManager);
statusList.setAdapter(statusAdapter);
StorageReference reference = storage.getReference().child("SImages").child(firebaseAuth.getUid()).child("Status Pic");
//before like video
database.getReference().child("status").child(firebaseAuth.getUid())
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
user = snapshot.getValue(userprofile.class);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
camerastatus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//before:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, 75);
}
});
return view;
}
@Override
public void onActivityResult(int requestCode, int resultCode,@Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(data != null) {
if(data.getData() != null) {
//firebase to upload data
FirebaseStorage storage = FirebaseStorage.getInstance();
Date date = new Date();
StorageReference reference = storage.getReference().child("SImages").child(firebaseAuth.getUid()).child("Status Pic");
reference.putFile(data.getData()).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if(task.isSuccessful()) {
reference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
//dialog.dismiss();
UserStatus userStatus = new UserStatus();
userStatus.setName(user.getUsername());
userStatus.setLastUpdated(date.getTime());
HashMap<String,Object> obj=new HashMap<>();
obj.put("name", userStatus.getName());
obj.put("lastUpdated", userStatus.getLastUpdated());
String imageUrl = uri.toString();
Status status = new Status(imageUrl, userStatus.getLastUpdated());
database.getReference().child("status").child("stories").updateChildren(obj);
database.getReference().child("stories").child("status")
.child("stories")
.push()
.setValue(status);
}
});
}
}
});
}
}
}
}[image1[\]\[1\]][1]
[1]: https://i.stack.imgur.com/6eCEz.jpg
this is a status fragment , i want to make a module like WhatsApp status, here in the code above i am uploading the image on firebase storage that is working fine , image is being uploaded but in real-time database the image is not being uploaded.
I have attached the screenshot of my storage where data is being uploaded and also the screenshot of real time database where image is not being uploaded .