@Override public void onBindViewHolder(final PictureViewHolder holder, final int position) { final Picture picture = pictures.get(position); String picUrl = picture.getPics()[0]; if (picUrl.endsWith(".gif")) { holder.img_gif.setVisibility(View.VISIBLE); // 非WIFI网络情况下,GIF图只加载缩略图,详情页才加载真实图片 if (!isWifiConnected) { picUrl = picUrl.replace("mw600", "small").replace("mw1200", "small").replace("large", "small"); } } else { holder.img_gif.setVisibility(View.GONE); } holder.progress.setProgress(0); holder.progress.setVisibility(View.VISIBLE); ImageLoadProxy.displayImageList( picUrl, holder.img, R.drawable.ic_loading_large, new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { super.onLoadingComplete(imageUri, view, loadedImage); holder.progress.setVisibility(View.GONE); } }, new ImageLoadingProgressListener() { @Override public void onProgressUpdate(String imageUri, View view, int current, int total) { holder.progress.setProgress((int) (current * 100f / total)); } }); if (TextUtil.isNull(picture.getText_content().trim())) { holder.tv_content.setVisibility(View.GONE); } else { holder.tv_content.setVisibility(View.VISIBLE); holder.tv_content.setText(picture.getText_content().trim()); } holder.img.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(mActivity, ImageDetailActivity.class); intent.putExtra(BaseActivity.DATA_IMAGE_AUTHOR, picture.getComment_author()); intent.putExtra(BaseActivity.DATA_IMAGE_URL, picture.getPics()); intent.putExtra(BaseActivity.DATA_IMAGE_ID, picture.getComment_ID()); intent.putExtra(BaseActivity.DATA_THREAD_KEY, "comment-" + picture.getComment_ID()); if (picture.getPics()[0].endsWith(".gif")) { intent.putExtra(BaseActivity.DATA_IS_NEED_WEBVIEW, true); } mActivity.startActivity(intent); } }); holder.tv_author.setText(picture.getComment_author()); holder.tv_time.setText( String2TimeUtil.dateString2GoodExperienceFormat(picture.getComment_date())); holder.tv_like.setText(picture.getVote_positive()); holder.tv_comment_count.setText(picture.getComment_counts()); // 用于恢复默认的文字 holder.tv_like.setTypeface(Typeface.DEFAULT); holder.tv_like.setTextColor( mActivity.getResources().getColor(R.color.secondary_text_default_material_light)); holder.tv_support_des.setTextColor( mActivity.getResources().getColor(R.color.secondary_text_default_material_light)); holder.tv_unlike.setText(picture.getVote_negative()); holder.tv_unlike.setTypeface(Typeface.DEFAULT); holder.tv_unlike.setTextColor( mActivity.getResources().getColor(R.color.secondary_text_default_material_light)); holder.tv_un_support_des.setTextColor( mActivity.getResources().getColor(R.color.secondary_text_default_material_light)); holder.img_share.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { new MaterialDialog.Builder(mActivity) .items(R.array.picture_dialog) .backgroundColor(mActivity.getResources().getColor(JDApplication.COLOR_OF_DIALOG)) .contentColor(JDApplication.COLOR_OF_DIALOG_CONTENT) .itemsCallback( new MaterialDialog.ListCallback() { @Override public void onSelection( MaterialDialog dialog, View view, int which, CharSequence text) { switch (which) { // 分享 case 0: ShareUtil.sharePicture(mActivity, picture.getPics()[0]); break; // 保存 case 1: FileUtil.savePicture( mActivity, picture.getPics()[0], mSaveFileCallBack); break; } } }) .show(); } }); holder.ll_comment.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(mActivity, CommentListActivity.class); intent.putExtra(BaseActivity.DATA_THREAD_KEY, "comment-" + picture.getComment_ID()); mActivity.startActivity(intent); } }); setAnimation(holder.card, position); }
@Override public void onDestroy() { super.onDestroy(); JDApplication.getRefWatcher(getActivity()).watch(this); ImageLoadProxy.getImageLoader().clearMemoryCache(); }