use of com.tutuanle.chatapp.models.UserStatus 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.models.UserStatus in project Chat-app by TuTuanLe.
the class MainActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (data != null) {
if (data.getData() != null) {
dialog.show();
FirebaseStorage storage = FirebaseStorage.getInstance();
Date date = new Date();
StorageReference reference = storage.getReference().child("status").child(date.getTime() + "");
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) {
UserStatus userStatus = new UserStatus();
userStatus.setName(user.getName());
userStatus.setProfileImage(user.getProfileImage());
userStatus.setLastUpdated(date.getTime());
userStatuses.add(userStatus);
HashMap<String, Object> obj = new HashMap<>();
obj.put("name", userStatus.getName());
obj.put("profileImage", userStatus.getProfileImage());
obj.put("lastUpdate", userStatus.getLastUpdated());
String imageUrl = uri.toString();
Status status = new Status(imageUrl, userStatus.getLastUpdated());
database.getReference().child("stories").child(FirebaseAuth.getInstance().getUid()).updateChildren(obj);
database.getReference().child("stories").child(FirebaseAuth.getInstance().getUid()).child("statuses").push().setValue(status);
dialog.dismiss();
}
});
}
}
});
}
}
}
use of com.tutuanle.chatapp.models.UserStatus 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();
}
use of com.tutuanle.chatapp.models.UserStatus in project Chat-app by TuTuanLe.
the class TopStatusAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull TopStatusViewHolder holder, int position) {
UserStatus userStatus = userStatuses.get(position);
Status lastStatus = userStatus.getStatuses().get(userStatus.getStatuses().size() - 1);
Glide.with(context).load(lastStatus.getImageUrl()).into(holder.binding.image);
Glide.with(context).load(lastStatus.getImageUrl()).into(holder.binding.imageUserStatus);
holder.binding.circularStatusView.setPortionsCount(userStatus.getStatuses().size());
holder.binding.circularStatusView.setOnClickListener(view -> {
ArrayList<MyStory> myStories = new ArrayList<>();
for (Status status : userStatus.getStatuses()) {
myStories.add(new MyStory(status.getImageUrl()));
}
new StoryView.Builder(((MainScreenActivity) context).getSupportFragmentManager()).setStoriesList(// Required
myStories).setStoryDuration(// Default is 2000 Millis (2 Seconds)
5000).setTitleText(// Default is Hidden
userStatus.getName()).setSubtitleText(// Default is Hidden
"").setTitleLogoUrl(// Default is Hidden
userStatus.getProfileImage()).setStoryClickListeners(new StoryClickListeners() {
@Override
public void onDescriptionClickListener(int position1) {
// your action
}
@Override
public void onTitleIconClickListener(int position1) {
// your action
}
}).build().show();
});
}
use of com.tutuanle.chatapp.models.UserStatus in project Chat-app by TuTuanLe.
the class StoryFragment method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 2 && resultCode == -1 && data != null) {
dialog.show();
FirebaseStorage storage = FirebaseStorage.getInstance();
Date date = new Date();
StorageReference reference = storage.getReference().child("status").child(date.getTime() + "");
reference.putFile(data.getData()).addOnCompleteListener(task -> {
if (task.isSuccessful()) {
reference.getDownloadUrl().addOnSuccessListener(uri -> {
UserStatus userStatus = new UserStatus();
userStatus.setName(preferenceManager.getString(Constants.KEY_NAME));
userStatus.setProfileImage(preferenceManager.getString(Constants.KEY_IMAGE));
userStatus.setLastUpdated(date.getTime());
userStatuses.add(userStatus);
HashMap<String, Object> obj = new HashMap<>();
obj.put("name", userStatus.getName());
obj.put("profileImage", userStatus.getProfileImage());
obj.put("lastUpdate", userStatus.getLastUpdated());
String imageUrl = uri.toString();
Status status = new Status(imageUrl, userStatus.getLastUpdated());
database.collection(Constants.KEY_COLLECTION_STORIES).document(preferenceManager.getString(Constants.KEY_USER_ID)).collection(Constants.KEY_COLLECTION_STATUSES).add(status);
database.collection(Constants.KEY_COLLECTION_STORIES).document(preferenceManager.getString(Constants.KEY_USER_ID)).set(obj);
;
dialog.dismiss();
});
}
});
}
}
Aggregations