private void calculateAdapterList() { Vector<String> recents = MessageStorage.getInstance().getConversationsAddresses(); recentStartPos = (recents.size() == 0) ? -1 : 0; recentUsers = User.convertAddressesToUsers(getActivity(), recents); recentUsers = User.orderUsers(recentUsers, User.ORDER_DATE_DESC); neighboursStartPos = recentUsers.size(); IService service = ((BluetoothTestActivity) getActivity()).getService(); if (service != null) { neighbourUsers = User.convertNeighboursToUsers(getActivity(), service.getNeighbours()); neighbourUsers = User.removeDuplicates(neighbourUsers, recentUsers); neighbourUsers = User.orderUsers(neighbourUsers, User.ORDER_ALPHANUMERIC_ASC); } else { neighbourUsers = new Vector<User>(); } friendsStartPos = neighboursStartPos + neighbourUsers.size(); friendUsers = UserStorage.getInstance().getUsers(); friendUsers = User.removeDuplicates(friendUsers, neighbourUsers); friendUsers = User.removeDuplicates(friendUsers, recentUsers); friendUsers = User.orderUsers(friendUsers, User.ORDER_ALPHANUMERIC_ASC); }
@Override public View getAmazingView(int position, View convertView, ViewGroup parent) { User u = (User) getItem(position); convertView = LayoutInflater.from(getActivity()).inflate(R.layout.user_row, null); ((FrameLayout) convertView.findViewById(R.id.badge)).addView(u.getBadge(getActivity())); ((TextView) convertView.findViewById(R.id.txt_name)).setText(u.name); IService service = ((BluetoothTestActivity) getActivity()).getService(); if (service != null && u.inRange(service.getNeighbours())) { ((ImageView) convertView.findViewById(R.id.img_available)) .setImageResource(android.R.drawable.presence_online); } int unread = MessageStorage.getInstance().getMessagesUnreadCount(u); if (unread > 0) { ((TextView) convertView.findViewById(R.id.txt_unread_count)) .setText(String.valueOf(unread)); } if (getSectionForPosition(position) == SECTION_RECENT) { String last = MessageStorage.getInstance().getLastMessageFromConversation(u).text; convertView.findViewById(R.id.txt_last_message).setVisibility(View.VISIBLE); ((TextView) convertView.findViewById(R.id.txt_last_message)).setText(last); } return convertView; }