private int getDisabled() { int disabled = 0; for (final Link link : links) { if (!link.isEnabled()) { disabled++; } } return disabled; }
@Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater layoutInflater = LayoutInflater.from(activity.getApplicationContext()); ViewHolder holder; final int type = getItemViewType(position); if (convertView == null) { convertView = layoutInflater.inflate(type == PRESSABLE_TYPE ? itemLayout : dividerLayout, null); if (type == DIVIDER_TYPE) { convertView.setOnClickListener(null); } holder = new ViewHolder(); holder.textView = (TextView) convertView.findViewById(R.id.title); holder.imageView = (ImageView) convertView.findViewById(R.id.imageView); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } if (type == DIVIDER_TYPE) { return convertView; } switch (typeForPosition(position)) { case CHANNEL: Link link = (Link) getItem(position); holder.textView.setText(link.getTitle()); holder.imageView.setImageDrawable(iconForPosition(position)); break; case SETTINGS: holder.textView.setText("Settings"); holder.imageView.setImageDrawable(iconForPosition(position)); break; case ABOUT: holder.textView.setText("About"); holder.imageView.setImageDrawable(iconForPosition(position)); break; default: holder.textView.setText("Bookmarks"); holder.imageView.setImageDrawable(iconForPosition(position)); } return convertView; }
@Override public Object getItem(int i) { if (positionIsChannel(i)) { int j = 0; for (final Link link : links) { if (j == i && link.isEnabled()) { return link; } else if (link.isEnabled()) { j++; } } throw new IndexOutOfBoundsException(); } else if (positionIsSettings(i)) { return SettingsActivity.class; } else if (positionIsBookmarks(i)) { return BookmarksDisplay.class; } else if (positionIsAbout(i)) { return AboutDisplay.class; } return null; }