use of com.tutuanle.chatapp.adapters.TopStatusAdapter 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;
}
});
}
use of com.tutuanle.chatapp.adapters.TopStatusAdapter in project Chat-app by TuTuanLe.
the class HomeFragment method getUserStatus.
@SuppressLint("NotifyDataSetChanged")
private void getUserStatus() {
userStatuses = new ArrayList<>();
statusAdapter = new TopStatusAdapter(mainScreenActivity, userStatuses);
RecyclerView temp = view.findViewById(R.id.statusList);
temp.setAdapter(statusAdapter);
ArrayList<Status> statuses = new ArrayList<>();
statuses.add(new Status("https://firebasestorage.googleapis.com/v0/b/chatsapp-4b8d6.appspot.com/o/status%2F1648451488181?alt=media&token=9e1f4eb7-8825-43c2-8220-106c92409620", 164845148));
statuses.add(new Status("https://firebasestorage.googleapis.com/v0/b/chatsapp-4b8d6.appspot.com/o/status%2F1648451488181?alt=media&token=9e1f4eb7-8825-43c2-8220-106c92409620", 164853774));
ArrayList<Status> statuses1 = new ArrayList<>();
statuses1.add(new Status("hhttps://images.unsplash.com/photo-1453728013993-6d66e9c9123a?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8dmlld3xlbnwwfHwwfHw%3D&w=1000&q=80", 164845148));
statuses1.add(new Status("https://www.w3schools.com/w3images/fjords.jpg", 164853774));
statuses1.add(new Status("https://st.depositphotos.com/1006706/2671/i/600/depositphotos_26715369-stock-photo-which-way-to-choose-3d.jpg", 164853774));
ArrayList<Status> statuses2 = new ArrayList<>();
statuses2.add(new Status("https://www.perma-horti.com/wp-content/uploads/2019/02/image-2.jpg", 164845148));
userStatuses.add(new UserStatus("Tuan Anh", "https://firebasestorage.googleapis.com/v0/b/chatsapp-4b8d6.appspot.com/o/status%2F1648537741702?alt=media&token=685fb7d8-a05d-429d-9834-1db74b41ff0e", 164853810, statuses));
userStatuses.add(new UserStatus("TuTuanLe", "https://www.w3schools.com/w3images/fjords.jpg", 174853810, statuses1));
userStatuses.add(new UserStatus("TAnh", "https://images.unsplash.com/photo-1453728013993-6d66e9c9123a?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8dmlld3xlbnwwfHwwfHw%3D&w=1000&q=80", 184853810, statuses2));
statusAdapter.notifyDataSetChanged();
}
Aggregations