| | |
| | | import android.app.Activity; |
| | | import android.content.Context; |
| | | import android.util.Base64; |
| | | import android.util.TypedValue; |
| | | import android.view.View; |
| | | |
| | | import androidx.annotation.Nullable; |
| | |
| | | |
| | | if (item != null) { |
| | | //非图片视频,打开文件预览 |
| | | |
| | | if (item.endsWith(".pdf")) { |
| | | holder.getBinding().ivImage.setImageResource(R.drawable.ic_pdf); |
| | | } else if (item.endsWith(".zip") || item.endsWith(".aar") || item.endsWith(".7z")) { |
| | | holder.getBinding().ivImage.setImageResource(R.drawable.ic_zip); |
| | | } else if (item.endsWith(".doc") || item.endsWith(".docx")) { |
| | | holder.getBinding().ivImage.setImageResource(R.drawable.ic_word); |
| | | } else if (item.endsWith(".xls") || item.endsWith(".xlsx")) { |
| | | holder.getBinding().ivImage.setImageResource(R.drawable.ic_excel); |
| | | } else if (item.endsWith(".ppt") || item.endsWith(".pptx")) { |
| | | holder.getBinding().ivImage.setImageResource(R.drawable.ic_ppt); |
| | | } else if (item.endsWith(".txt")) { |
| | | holder.getBinding().ivImage.setImageResource(R.drawable.ic_txt); |
| | | } else if (item.endsWith(".jpg") || item.endsWith(".jpeg") || item.endsWith(".png") || item.endsWith(".gif")) { |
| | | if (item.endsWith(".pdf") || item.endsWith(".PDF")) { |
| | | TypedValue icPdf = new TypedValue(); |
| | | mContext.getTheme().resolveAttribute(R.attr.icPdf, icPdf, true); |
| | | holder.getBinding().ivImage.setImageResource(icPdf.resourceId); |
| | | } else if (item.endsWith(".zip") || item.endsWith(".ZIP") || item.endsWith(".aar") || item.endsWith(".AAR") || item.endsWith(".7z")) { |
| | | TypedValue icZip = new TypedValue(); |
| | | mContext.getTheme().resolveAttribute(R.attr.icZip, icZip, true); |
| | | holder.getBinding().ivImage.setImageResource(icZip.resourceId); |
| | | } else if (item.endsWith(".doc") || item.endsWith(".docx") || item.endsWith(".DOC") || item.endsWith(".DOCX") || item.endsWith(".wps") || item.endsWith(".WPS")) { |
| | | TypedValue icWord = new TypedValue(); |
| | | mContext.getTheme().resolveAttribute(R.attr.icWord, icWord, true); |
| | | holder.getBinding().ivImage.setImageResource(icWord.resourceId); |
| | | } else if (item.endsWith(".xls") || item.endsWith(".xlsx") || item.endsWith(".XLS") || item.endsWith(".XLSX")) { |
| | | TypedValue icExcel = new TypedValue(); |
| | | mContext.getTheme().resolveAttribute(R.attr.icExcel, icExcel, true); |
| | | holder.getBinding().ivImage.setImageResource(icExcel.resourceId); |
| | | } else if (item.endsWith(".ppt") || item.endsWith(".PPT") || item.endsWith(".pptx") || item.endsWith(".PPTX")) { |
| | | TypedValue icPpt = new TypedValue(); |
| | | mContext.getTheme().resolveAttribute(R.attr.icPpt, icPpt, true); |
| | | holder.getBinding().ivImage.setImageResource(icPpt.resourceId); |
| | | } else if (item.endsWith(".txt") || item.endsWith(".TXT")) { |
| | | TypedValue icTxt = new TypedValue(); |
| | | mContext.getTheme().resolveAttribute(R.attr.icTxt, icTxt, true); |
| | | holder.getBinding().ivImage.setImageResource(icTxt.resourceId); |
| | | } else if (item.endsWith(".jpg") || item.endsWith(".JPG") || item.endsWith(".jpeg") || item.endsWith(".JPEG") || item.endsWith(".png") || item.endsWith(".PNG") || item.endsWith(".gif") || item.endsWith(".GIF") || item.endsWith(".bmp") || item.endsWith(".BMP")) { |
| | | holder.getBinding().setUrl(item); |
| | | if (isPreview) { |
| | | holder.itemView.setOnClickListener(new View.OnClickListener() { |
| | |
| | | } |
| | | }); |
| | | } |
| | | } else if (item.endsWith(".mp4")) { |
| | | } else if (item.endsWith(".mp4") || item.endsWith(".MP4") ) { |
| | | holder.getBinding().flPlay.setVisibility(View.VISIBLE); |
| | | holder.getBinding().setUrl(item); |
| | | if (isPreview) { |
| | |
| | | }); |
| | | } |
| | | |
| | | } else if (item.endsWith(".mp3") || item.endsWith(".m4a")) { |
| | | } else if (item.endsWith(".mp3") || item.endsWith(".m4a") || item.endsWith(".MP3") || item.endsWith(".M4A")) { |
| | | // holder.getBinding().flPlay.setVisibility(View.VISIBLE); |
| | | holder.getBinding().ivImage.setImageResource(R.drawable.ic_audio); |
| | | TypedValue icAudio = new TypedValue(); |
| | | mContext.getTheme().resolveAttribute(R.attr.icAudio, icAudio, true); |
| | | holder.getBinding().ivImage.setImageResource(icAudio.resourceId); |
| | | } else { |
| | | holder.getBinding().ivImage.setImageResource(R.drawable.ic_others); |
| | | TypedValue icOther = new TypedValue(); |
| | | mContext.getTheme().resolveAttribute(R.attr.icOther, icOther, true); |
| | | holder.getBinding().ivImage.setImageResource(icOther.resourceId); |
| | | } |
| | | } |
| | | |