Страницы

Поиск по вопросам

суббота, 13 июля 2019 г.

VkApiLink приходит к своим и другим статьям

здраствуйте! VkApiLink приходит к своим и другим статьям.. Кароче когда она отображается в какой либо статье, то она потом на другие начинает напрыгивать, через 1-5 статей... как исправить неподскажите?
public class PostAdapter extends RecyclerView.Adapter {
private LayoutInflater mInflater; private int mShowStyle; private int musicShowStyle; VKPostArray obj; VKApiPhoto vkPhoto; ArrayList imgUrls1; VKApiUser mainUser; Context ctx;
public PostAdapter(Context context, VKPostArray posts, VKApiUser user) { super(); this.obj = posts; this.mainUser = user; this.mInflater = LayoutInflater.from(context); ctx = context; }
@Override public void onBindViewHolder(final PostViewHolder holder, final int position) {
final VKApiPost p = obj.get(position);
VKAttachments att = new VKAttachments(); att = p.attachments;
for (VKAttachments.VKApiAttachment attachment : p.attachments) { Log.d("TAG", "attachment getType " + attachment.getType()); switch (attachment.getType()){ case AUDIO: if (attachment.getType().equals(AUDIO)){ VKApiAudio audio = (VKApiAudio) att.get(0); Log.d("TAG", "audio title: " + audio.title); if (audio != null){ holder.layone4.setVisibility(View.VISIBLE); holder.as1.setText(audio.artist); holder.as2.setText(audio.title); //Picasso.with(ctx).load(link.image_src).into(holder.i1); } else { holder.layone4.setVisibility(View.GONE); holder.as1.setText(null); holder.as2.setText(null); //holder.i1.setImageDrawable(null); }} break; case VIDEO: if (attachment.getType().equals(VIDEO)){ VKApiVideo video = (VKApiVideo) att.get(0); Log.d("TAG", "video title: " + video.title); if (video != null){ holder.layone3.setVisibility(View.VISIBLE); holder.vs1.setText(video.title); holder.vs2.setText(video.description); //Picasso.with(ctx).load(link.image_src).into(holder.i1); } else { holder.layone3.setVisibility(View.GONE); holder.vs1.setText(null); holder.vs2.setText(null); //holder.i1.setImageDrawable(null); }} break; case DOCUMENTS: if (attachment.getType().equals(DOCUMENTS)){ VKApiDocument document = (VKApiDocument) att.get(0); Log.d("TAG", "document title: " + document.title); if (document != null){ holder.layone5.setVisibility(View.VISIBLE); holder.ds1.setText(document.title); holder.ds2.setText(document.size + " мб"); //Picasso.with(ctx).load(link.image_src).into(holder.i1); } else { holder.layone5.setVisibility(View.GONE); holder.ds1.setText(null); holder.ds2.setText(null); //holder.i1.setImageDrawable(null); }} break; case LINK: if (attachment.getType().equals(LINK)){ VKApiLink link = (VKApiLink) att.get(0); Log.d("TAG", "link description: " + link.description); if (att.get(0).getType().equals(LINK)){ holder.layone.setVisibility(View.VISIBLE); holder.s1.setText(link.title); holder.s2.setText(link.url); Picasso.with(ctx).load(link.image_src).into(holder.i1); } else { holder.layone.setVisibility(View.GONE); holder.s1.setText(null); holder.s2.setText(null); holder.i1.setImageDrawable(null); Log.d("TAG", "link description gone: " + link.description); }}else {
} break; case POOL: if (attachment.getType().equals(POOL)){ VKApiPoll poll = (VKApiPoll) att.get(0); Log.d("TAG", "pool question: " + poll.question); if (poll != null){ holder.layone2.setVisibility(View.VISIBLE); //holder.pps1.setText(poll.getType()); holder.pps2.setText(poll.question); } else { holder.layone2.setVisibility(View.GONE); //holder.pps1.setText(null); holder.pps2.setText(null); }} break; case ALBUM: if (attachment.getType().equals(ALBUM)){ VKApiPhotoAlbum photoAlbum = (VKApiPhotoAlbum) att.get(0); Log.d("TAG", "photoAlbum title: " + photoAlbum.title); if(photoAlbum != null) { holder.layone1.setVisibility(View.VISIBLE); holder.ps1.setText(photoAlbum.title); holder.ps2.setText("В альбоме " + photoAlbum.size + " фотографий"); } else { holder.layone1.setVisibility(View.GONE); holder.ps1.setText(null); holder.ps2.setText(null); }} break; default: break; } }
holder.textPost.setText(p.text); Linkify.addLinks(holder.textPost, Linkify.WEB_URLS);
int i; imgUrls1 = new ArrayList<>(att.size());
try { for (i = 0; i <= att.size(); i++) { vkPhoto = (VKApiPhoto) att.get(i); imgUrls1.add(vkPhoto.photo_807); } } catch (Exception e) { holder.mNglContent.setImagesData(imgUrls1); } } @Override public int getItemCount() { return obj.size(); }
@Override public int getItemViewType(int position) { return PHOTO; }
@Override public PostViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { switch (viewType){ case PHOTO: if (mShowStyle == NineGridImageView.STYLE_FILL) { return new PostViewHolder(mInflater.inflate(R.layout.recycler_item_wall, parent, false)); } else { return new PostViewHolder(mInflater.inflate(R.layout.recycler_item_wall, parent, false)); } case MUSIC: if (musicShowStyle == audio.getType().length()) { return new PostViewHolder(mInflater.inflate(R.layout.musicitem, parent, false)); }} return null; }
public class PostViewHolder extends RecyclerView.ViewHolder {
CardView cv; TextView textPost, news_name, textDatePost, textrepostPost, textlikePost; ImageView like, repost,i1, ppi1, pi1; CircleImageView news_ava; CheckBox like1; NineGridImageView mNglContent;
ImageView playMusic; TextView artistMusic, titleMusic, durationMusic, urlMusic;
TextView s1, s2; TextView ps1, ps2, pps1, pps2, as1, as2, vs1, vs2, ds1, ds2; LinearLayout layone, layone1, layone2, layone3, layone4, layone5;
private NineGridImageViewAdapter mAdapter = new NineGridImageViewAdapter() { @Override protected void onDisplayImage(Context context, ImageView imageView, String s) { if(imageView == null){ imageView.setImageResource(R.drawable.ic_ab_app); }else{ Picasso.with(context).load(s).into(imageView); }}
@Override protected ImageView generateImageView(Context context) { return super.generateImageView(context); }
@Override protected void onItemImageClick(Context context, int position, List list) {
} };
public PostViewHolder(View v) { super(v); cv = (CardView) v.findViewById(R.id.card_view_wall);
news_name = (TextView) v.findViewById(R.id.news_name); news_ava = (CircleImageView) v.findViewById(R.id.news_ava); textDatePost = (TextView) v.findViewById(R.id.textDatePost);
textPost = (TextView) v.findViewById(R.id.textPost);
like = (ImageView) v.findViewById(R.id.iv_like_button); textlikePost = (TextView) v.findViewById(R.id.tv_likes_count);
//like1 = (CheckBox) v.findViewById(R.id.iv_like_button); textrepostPost = (TextView) v.findViewById(R.id.tv_reposts_count); repost = (ImageView) v.findViewById(R.id.iv_repost);
mNglContent = (NineGridImageView) v.findViewById(R.id.ngl_images); mNglContent.setAdapter(mAdapter);
playMusic = (ImageView) v.findViewById(R.id.playMusic); artistMusic = (TextView) v.findViewById(R.id.artistMusic); titleMusic = (TextView) v.findViewById(R.id.albumMusic); durationMusic = (TextView) v.findViewById(R.id.durationMusic); //urlMusic = (TextView) itemView.findViewById(R.id.urlMusic);
layone = (LinearLayout) v.findViewById(R.id.link); layone1 = (LinearLayout) v.findViewById(R.id.photoAlbum); layone2 = (LinearLayout) v.findViewById(R.id.pool); layone3 = (LinearLayout) v.findViewById(R.id.video); layone4 = (LinearLayout) v.findViewById(R.id.audio); layone5 = (LinearLayout) v.findViewById(R.id.document);
as1 = (TextView) v.findViewById(R.id.as1); as2 = (TextView) v.findViewById(R.id.as2); //ai1 = (ImageView) v.findViewById(R.id.i1);
vs1 = (TextView) v.findViewById(R.id.vs1); vs2 = (TextView) v.findViewById(R.id.vs2); //ai1 = (ImageView) v.findViewById(R.id.i1);
ds1 = (TextView) v.findViewById(R.id.ds1); ds2 = (TextView) v.findViewById(R.id.ds2); //ai1 = (ImageView) v.findViewById(R.id.i1);
s1 = (TextView) v.findViewById(R.id.s1); s2 = (TextView) v.findViewById(R.id.s2); i1 = (ImageView) v.findViewById(R.id.i1);
pi1 = (ImageView) v.findViewById(R.id.pi1); ps1 = (TextView) v.findViewById(R.id.ps1); ps2 = (TextView) v.findViewById(R.id.ps2);
ppi1 = (ImageView) v.findViewById(R.id.ppi1); pps1 = (TextView) v.findViewById(R.id.pps1); pps2 = (TextView) v.findViewById(R.id.pps2); }}


Ответ

У вас пустой else в котором вам надо отобразить состояние при отсутствии ссылки. Заполните его кодом убирающим картинку, тест и прочее примерно так:
if(link != null) { holder.layone.setVisibility(View.VISIBLE); holder.s1.setText(link.title); holder.s2.setText(link.url); Picasso.with(ctx).load(link.image_src).into(holder.i1); }else{ holder.layone.setVisibility(View.GONE); holder.s1.setText(null); holder.s2.setText(null); holder.i1.setImageDrawable(null); }

Комментариев нет:

Отправить комментарий