Search in sources :

Example 1 with UserItem

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());
        }
    };
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot) UserItem(com.macbitsgoa.ard.models.UserItem)

Example 2 with UserItem

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();
        }
    };
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot) UserItem(com.macbitsgoa.ard.models.UserItem)

Example 3 with UserItem

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);
    }
}
Also used : NewChatViewHolder(com.macbitsgoa.ard.viewholders.NewChatViewHolder) TextViewHolder(com.macbitsgoa.ard.viewholders.TextViewHolder) UserItem(com.macbitsgoa.ard.models.UserItem)

Aggregations

UserItem (com.macbitsgoa.ard.models.UserItem)3 DataSnapshot (com.google.firebase.database.DataSnapshot)2 DatabaseError (com.google.firebase.database.DatabaseError)2 ValueEventListener (com.google.firebase.database.ValueEventListener)2 NewChatViewHolder (com.macbitsgoa.ard.viewholders.NewChatViewHolder)1 TextViewHolder (com.macbitsgoa.ard.viewholders.TextViewHolder)1