use of com.tutuanle.chatapp.adapters.UsersAdapter in project Chat-app by TuTuanLe.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
dialog = new ProgressDialog(this);
dialog.setMessage("upLoading Image ...");
dialog.setCancelable(false);
database = FirebaseDatabase.getInstance();
users = new ArrayList<User>();
usersAdapter = new UsersAdapter(this, users);
userStatuses = new ArrayList<>();
database.getReference().child("users").child(FirebaseAuth.getInstance().getUid()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
user = snapshot.getValue(User.class);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
statusAdapter = new TopStatusAdapter(this, userStatuses);
// binding.statusList.setLayoutManager((new LinearLayoutManager(this)));
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(RecyclerView.HORIZONTAL);
binding.statusList.setLayoutManager(layoutManager);
// binding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
binding.statusList.setAdapter(statusAdapter);
binding.recyclerView.setAdapter(usersAdapter);
database.getReference().child("users").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
users.clear();
for (DataSnapshot snapshot1 : snapshot.getChildren()) {
User user = snapshot1.getValue(User.class);
Log.d("log", user.toString());
users.add(user);
}
usersAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
database.getReference().child("stories").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.exists()) {
userStatuses.clear();
for (DataSnapshot storySnapshot : snapshot.getChildren()) {
UserStatus status = new UserStatus();
status.setName(storySnapshot.child("name").getValue(String.class));
status.setProfileImage(storySnapshot.child("profileImage").getValue(String.class));
status.setLastUpdated(storySnapshot.child("lastUpdate").getValue(Long.class));
ArrayList<Status> statuses = new ArrayList<>();
for (DataSnapshot statusSnapshot : storySnapshot.child("statuses").getChildren()) {
Status sampleStatus = statusSnapshot.getValue(Status.class);
statuses.add(sampleStatus);
}
status.setStatuses(statuses);
userStatuses.add(status);
}
statusAdapter.notifyDataSetChanged();
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
binding.BottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch(item.getItemId()) {
case R.id.status:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, 75);
break;
}
;
return false;
}
});
}
Aggregations