| | |
| | | |
| | | import android.app.Activity; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.pm.ActivityInfo; |
| | | import android.util.Base64; |
| | | import android.util.TypedValue; |
| | | import android.view.View; |
| | | |
| | | import androidx.annotation.Nullable; |
| | | import androidx.core.app.ActivityCompat; |
| | | import androidx.core.app.ActivityOptionsCompat; |
| | | import androidx.core.util.Pair; |
| | | |
| | | import com.android.app_base.base.BaseConfig; |
| | | import com.android.app_base.base.adapter.BaseRVAdapter; |
| | | import com.application.zhangshi_app_android.R; |
| | | import com.application.zhangshi_app_android.databinding.ItemElectronicFileAddBinding; |
| | | import com.application.zhangshi_app_android.ui.BrowserActivity; |
| | | import com.application.zhangshi_app_android.ui.ImagePreviewActivity; |
| | | import com.application.zhangshi_app_android.ui.PlayActivity; |
| | | import com.application.zhangshi_app_android.ui.VideoPlayActivity; |
| | | import com.application.zhangshi_app_android.ui.PlayerActivity; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | |
| | | if (getItemViewType(position) == TYPE_Add) { |
| | | holder.getBinding().flAdd.setVisibility(View.VISIBLE); |
| | | holder.getBinding().flImage.setVisibility(View.GONE); |
| | | |
| | | holder.itemView.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | |
| | | holder.getBinding().flAdd.setVisibility(View.GONE); |
| | | holder.getBinding().flImage.setVisibility(View.VISIBLE); |
| | | |
| | | //非预览状态下,点击item 调用 mItemAndAddClickListener.onItemClick |
| | | //预览状态下,点击item 调用 相应的 文件预览 |
| | | if (!isPreview){ |
| | | holder.itemView.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (mItemAndAddClickListener != null) { |
| | | mItemAndAddClickListener.onItemClick(holder.itemView,position); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | String item = mDataList.get(position); |
| | | 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")) { |
| | | holder.getBinding().setUrl(item); |
| | | if (isPreview) { |
| | | holder.itemView.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | ImagePreviewActivity.start(mContext, item); |
| | | } |
| | | }); |
| | | } |
| | | } else if (item.endsWith(".mp4")) { |
| | | holder.getBinding().flPlay.setVisibility(View.VISIBLE); |
| | | holder.getBinding().setUrl(item); |
| | | if (isPreview) { |
| | | holder.itemView.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | // new VideoPlayActivity.Builder() |
| | | // .setVideoSource(item) |
| | | // .setActivityOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) |
| | | // .start(mContext); |
| | | PlayActivity.start((Activity) mContext, item,holder.itemView,true); |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | } else if (item.endsWith(".mp3") || item.endsWith(".m4a")) { |
| | | // holder.getBinding().flPlay.setVisibility(View.VISIBLE); |
| | | holder.getBinding().ivImage.setImageResource(R.drawable.ic_audio); |
| | | } else { |
| | | holder.getBinding().ivImage.setImageResource(R.drawable.ic_others); |
| | | } |
| | | } |
| | | |
| | | if (isShowAddItem) { |
| | | holder.getBinding().ivDelete.setVisibility(View.VISIBLE); |
| | | } else { |
| | |
| | | holder.getBinding().ivSelect.setVisibility(View.GONE); |
| | | } |
| | | |
| | | //非预览状态下,点击item 调用 mItemAndAddClickListener.onItemClick |
| | | //预览状态下,点击item 调用 相应的 文件预览 |
| | | if (!isPreview){ |
| | | holder.itemView.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (mItemAndAddClickListener != null) { |
| | | mItemAndAddClickListener.onItemClick(holder.itemView,position); |
| | | } |
| | | } |
| | | }); |
| | | }else { |
| | | holder.itemView.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | String url = mDataList.get(position); |
| | | if (url.contains("profile/upload")) {//如果是上传到服务器的文件 |
| | | //只取profile/upload以后的部分 |
| | | url = url.substring(url.indexOf("profile/upload")); |
| | | url = BaseConfig.BASE_URL_DOMAIN + "/" + url; |
| | | //处理url进行Base64编码,借助 kkfileview 进行文件预览 |
| | | // URL编码Base64编码后的URL |
| | | try { |
| | | String encodedUrl = URLEncoder.encode(Base64.encodeToString(url.getBytes(), Base64.NO_WRAP), "UTF-8"); |
| | | String kkFileViewUrl = "https://www.bendudu.com:8085/preview/onlinePreview?url=" + encodedUrl; |
| | | BrowserActivity.start(mContext, kkFileViewUrl); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | if (item != null) { |
| | | //非图片视频,打开文件预览 |
| | | 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() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | ImagePreviewActivity.start(mContext, item); |
| | | } |
| | | }); |
| | | } |
| | | } else if (item.endsWith(".mp4") || item.endsWith(".MP4") ) { |
| | | holder.getBinding().flPlay.setVisibility(View.VISIBLE); |
| | | holder.getBinding().setUrl(item); |
| | | if (isPreview) { |
| | | holder.itemView.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | // new VideoPlayActivity.Builder() |
| | | // .setVideoSource(item) |
| | | // .setActivityOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) |
| | | // .start(mContext); |
| | | PlayerActivity.startWrapUrl((Activity) mContext, item,holder.itemView,true); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | } else if (item.endsWith(".mp3") || item.endsWith(".m4a") || item.endsWith(".MP3") || item.endsWith(".M4A")) { |
| | | // holder.getBinding().flPlay.setVisibility(View.VISIBLE); |
| | | TypedValue icAudio = new TypedValue(); |
| | | mContext.getTheme().resolveAttribute(R.attr.icAudio, icAudio, true); |
| | | holder.getBinding().ivImage.setImageResource(icAudio.resourceId); |
| | | } else { |
| | | TypedValue icOther = new TypedValue(); |
| | | mContext.getTheme().resolveAttribute(R.attr.icOther, icOther, true); |
| | | holder.getBinding().ivImage.setImageResource(icOther.resourceId); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |