| | |
| | | |
| | | import android.app.Activity; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.pm.ActivityInfo; |
| | | import android.util.Base64; |
| | | 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); |
| | | |
| | | String item = mDataList.get(position); |
| | | if (isShowAddItem) { |
| | | holder.getBinding().ivDelete.setVisibility(View.VISIBLE); |
| | | } else { |
| | | holder.getBinding().ivDelete.setVisibility(View.GONE); |
| | | } |
| | | |
| | | if (isShowDeleteIcon) { |
| | | holder.getBinding().ivDelete.setVisibility(View.VISIBLE); |
| | | } else { |
| | | holder.getBinding().ivDelete.setVisibility(View.GONE); |
| | | } |
| | | |
| | | if (isShowSelectIcon) { |
| | | holder.getBinding().ivSelect.setVisibility(View.VISIBLE); |
| | | if (selectedItems.contains(item)){ |
| | | holder.getBinding().ivSelect.setBackgroundResource(R.drawable.ic_checked); |
| | | } else { |
| | | holder.getBinding().ivSelect.setBackgroundResource(R.drawable.ic_unchecked); |
| | | } |
| | | } else { |
| | | holder.getBinding().ivSelect.setVisibility(View.GONE); |
| | | } |
| | | |
| | | //非预览状态下,点击item 调用 mItemAndAddClickListener.onItemClick |
| | | //预览状态下,点击item 调用 相应的 文件预览 |
| | | if (!isPreview){ |
| | |
| | | } |
| | | } |
| | | }); |
| | | }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(); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | 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")) { |
| | |
| | | // .setVideoSource(item) |
| | | // .setActivityOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) |
| | | // .start(mContext); |
| | | PlayActivity.start((Activity) mContext, item,holder.itemView,true); |
| | | |
| | | PlayerActivity.startWrapUrl((Activity) mContext, item,holder.itemView,true); |
| | | } |
| | | }); |
| | | } |
| | |
| | | } else { |
| | | holder.getBinding().ivImage.setImageResource(R.drawable.ic_others); |
| | | } |
| | | } |
| | | |
| | | if (isShowAddItem) { |
| | | holder.getBinding().ivDelete.setVisibility(View.VISIBLE); |
| | | } else { |
| | | holder.getBinding().ivDelete.setVisibility(View.GONE); |
| | | } |
| | | |
| | | if (isShowDeleteIcon) { |
| | | holder.getBinding().ivDelete.setVisibility(View.VISIBLE); |
| | | } else { |
| | | holder.getBinding().ivDelete.setVisibility(View.GONE); |
| | | } |
| | | |
| | | if (isShowSelectIcon) { |
| | | holder.getBinding().ivSelect.setVisibility(View.VISIBLE); |
| | | if (selectedItems.contains(item)){ |
| | | holder.getBinding().ivSelect.setBackgroundResource(R.drawable.ic_checked); |
| | | } else { |
| | | holder.getBinding().ivSelect.setBackgroundResource(R.drawable.ic_unchecked); |
| | | } |
| | | } else { |
| | | holder.getBinding().ivSelect.setVisibility(View.GONE); |
| | | } |
| | | |
| | | } |