app/src/main/java/org/weibeld/nytexplore/adapter/ArticleAdapter.java
@Override
    public void onBindViewHolder(ViewHolder vh, int position) {
        Doc article = mData.get(position);

        vh.tvTitle.setText(getSafeString(article.getHeadline().getMain()));

        if (article.getPubDate() != null) {
            vh.tvDate.setVisibility(View.VISIBLE);
            MyDate date = new MyDate(article.getPubDate());
            vh.tvDate.setText(date.format1());
        } else
            vh.tvDate.setVisibility(View.GONE);

        ArrayList<Multimedium> multimedia = (ArrayList<Multimedium>) article.getMultimedia();
        String thumbUrl = "";
        for (Multimedium m : multimedia) {
            if (m.getType().equals("image") && m.getSubtype().equals("thumbnail")) {
                thumbUrl = ApiService.API_IMAGE_BASE_URL + m.getUrl();
                break;
            }
        }
        if (!thumbUrl.isEmpty())
            // TODO: Glide seems to not cache most of these images but load them from the URL each time
            Glide.with(mContext)
                    .load(thumbUrl)
                    // Save original image in cache (less fetching from server)
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    .placeholder(R.drawable.placeholder_thumb)
                    .error(R.drawable.error_thumb)
                    .into(vh.ivThumb);

    }
// the item at the specified position.
the item at the specified position.
the item at the specified position .
@Override
    public void onBindViewHolder(ViewHolder vh, int position) {
        Doc article = mData.get(position);
        vh.tvTitle.setText(getSafeString(article.getHeadline().getMain()));
        if (article.getPubDate() != null) {
            vh.tvDate.setVisibility(View.VISIBLE);
            MyDate date = new MyDate(article.getPubDate());
            vh.tvDate.setText(date.format1());
        } else
            vh.tvDate.setVisibility(View.GONE);
        ArrayList<Multimedium> multimedia = (ArrayList<Multimedium>) article.getMultimedia();
        String thumbUrl = "";
        for (Multimedium m : multimedia) {
            if (m.getType().equals("image") && m.getSubtype().equals("thumbnail")) {
                thumbUrl = ApiService.API_IMAGE_BASE_URL + m.getUrl();
                break;
            }
        }
        if (!thumbUrl.isEmpty())
            Glide.with(mContext)
                    .load(thumbUrl)
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    .placeholder(R.drawable.placeholder_thumb)
                    .error(R.drawable.error_thumb)
                    .into(vh.ivThumb);
    }
@ Override public void onBindViewHolder ( ViewHolder vh , int position ) { Doc article = mData . get ( position ) ; vh . tvTitle . setText ( getSafeString ( article . getHeadline ( ) . getMain ( ) ) ) ; if ( article . getPubDate ( ) != null ) { vh . tvDate . setVisibility ( View . VISIBLE ) ; MyDate date = new MyDate ( article . getPubDate ( ) ) ; vh . tvDate . setText ( date . format1 ( ) ) ; } else vh . tvDate . setVisibility ( View . GONE ) ; ArrayList < Multimedium > multimedia = ( ArrayList < Multimedium > ) article . getMultimedia ( ) ; String thumbUrl = "" ; for ( Multimedium m : multimedia ) { if ( m . getType ( ) . equals ( "image" ) && m . getSubtype ( ) . equals ( "thumbnail" ) ) { thumbUrl = ApiService . API_IMAGE_BASE_URL + m . getUrl ( ) ; break ; } } if ( ! thumbUrl . isEmpty ( ) ) Glide . with ( mContext ) . load ( thumbUrl ) . diskCacheStrategy ( DiskCacheStrategy . SOURCE ) . placeholder ( R . drawable . placeholder_thumb ) . error ( R . drawable . error_thumb ) . into ( vh . ivThumb ) ; }
the item at the specified position.
the item at the specified position .
// TODO: Glide seems to not cache most of these images but load them from the URL each time // Save original image in cache (less fetching from server)