use of com.macbitsgoa.ard.models.UserItem in project ARD by MobileApplicationsClub.
the class NewChatActivity method getUsersEventListener.
private ValueEventListener getUsersEventListener() {
return new ValueEventListener() {
@Override
public void onDataChange(final DataSnapshot dataSnapshot) {
usersList.clear();
for (final DataSnapshot child : dataSnapshot.getChildren()) {
if (child.getValue() == null)
continue;
final String uid = child.getKey();
if (uid == null || uid.equals(getUser().getUid()))
continue;
final String name = child.child(UserItemKeys.NAME).getValue(String.class);
final String email = child.child(UserItemKeys.EMAIL).getValue(String.class);
final String photoUrl = child.child(UserItemKeys.PHOTO_URL).getValue(String.class);
UserItem ui = new UserItem(uid, name, email, photoUrl, "User");
usersList.add(ui);
}
AHC.logd(TAG, "All users are " + usersList.toString());
Collections.sort(usersList);
if (usersList.removeAll(adminsList))
AHC.logd(TAG, "Final non admin users are " + usersList.toString());
else
AHC.logd(TAG, "No admins were removed from userlist");
adapter.notifyDataSetChanged();
}
@Override
public void onCancelled(final DatabaseError databaseError) {
AHC.logd(TAG, "Database error for users in " + NewChatActivity.class.getSimpleName());
AHC.logd(TAG, databaseError.toString());
}
};
}
use of com.macbitsgoa.ard.models.UserItem in project ARD by MobileApplicationsClub.
the class NewChatActivity method getAdminEventListener.
private ValueEventListener getAdminEventListener() {
return new ValueEventListener() {
@Override
public void onDataChange(final DataSnapshot dataSnapshot) {
adminsList.clear();
for (final DataSnapshot child : dataSnapshot.getChildren()) {
final String uid = child.getKey();
if (uid == null || uid.equals(getUser().getUid()))
continue;
final String name = child.child(UserItemKeys.NAME).getValue(String.class);
final String email = child.child(UserItemKeys.EMAIL).getValue(String.class);
final String photoUrl = child.child(UserItemKeys.PHOTO_URL).getValue(String.class);
final String desc = child.child(UserItemKeys.DESC).getValue(String.class);
UserItem ui = new UserItem(uid, name, email, photoUrl, desc);
adminsList.add(ui);
}
Collections.sort(adminsList);
AHC.logd(TAG, "Admins are " + adminsList.toString());
adapter.notifyDataSetChanged();
progressBar.setVisibility(View.GONE);
}
@Override
public void onCancelled(final DatabaseError databaseError) {
AHC.logd(TAG, "Database error for admins in " + NewChatActivity.class.getSimpleName());
AHC.logd(TAG, databaseError.toString());
Toast.makeText(NewChatActivity.this, "Could not get admin data. Try again later!", Toast.LENGTH_SHORT).show();
}
};
}
use of com.macbitsgoa.ard.models.UserItem in project ARD by MobileApplicationsClub.
the class NewChatAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder generalHolder, final int position) {
if (generalHolder.getItemViewType() == TEXT) {
final TextViewHolder holder = (TextViewHolder) generalHolder;
if (position == admins.size() + 1)
holder.setText("Users");
else
holder.setText("Admins");
} else {
final NewChatViewHolder holder = (NewChatViewHolder) generalHolder;
UserItem ui;
if (position <= admins.size())
ui = admins.get(position - 1);
else
ui = users.get(position - admins.size() - 2);
holder.setUi(ui);
}
}
Aggregations