1.图片上传进度相关代码。
2.修复地图定位图标不居中问题。
| | |
| | | JPUSH_APPKEY : "375adbd599ceb9977566b929", |
| | | //暂时填写默认值即可. |
| | | JPUSH_CHANNEL : "developer-default", |
| | | |
| | | //若不集成厂商通道,可直接跳过以下配置 |
| | | MEIZU_APPKEY : "MZ-魅族的APPKEY", |
| | | MEIZU_APPID : "MZ-魅族的APPID", |
| | |
| | | exclude group: 'androidx.core'; |
| | | } |
| | | |
| | | //进度加载 |
| | | implementation 'com.github.jenly1314:circleprogressview:1.1.3' |
| | | |
| | | } |
| | |
| | | function locationOverLay(lng, lag) { |
| | | console.log("function》》》》》locationOverLay"); |
| | | map.centerAndZoom(new T.LngLat(lng, lag), map.getZoom()); |
| | | |
| | | let icon = new T.Icon({ |
| | | iconUrl: CONFIG.IMAGES.LOCATION, |
| | | iconSize: new T.Point(20, 20), |
| | | iconAnchor: new T.Point(10, 10) |
| | | }); |
| | | let marker = new T.Marker( |
| | | new T.LngLat(lng, lag), |
| | | { icon: createIcon(CONFIG.IMAGES.LOCATION, 27) } |
| | | { icon: icon } |
| | | ); |
| | | map.addOverLay(marker); |
| | | } |
| | |
| | | map.removeOverLay(locationMarker); |
| | | } |
| | | var newPoint = new T.LngLat(log, lat); |
| | | let icon = new T.Icon({ |
| | | iconUrl: CONFIG.IMAGES.LOCATION, |
| | | iconSize: new T.Point(20, 20), |
| | | iconAnchor: new T.Point(10, 10) |
| | | }); |
| | | |
| | | locationMarker = new T.Marker( |
| | | newPoint, |
| | | { icon: createIcon(CONFIG.IMAGES.LOCATION, 20) } |
| | | { icon: icon } |
| | | ); |
| | | map.addOverLay(locationMarker); |
| | | map.panTo(newPoint); |
| | | } |
| | | //保存定位坐标生成轨迹 |
| | | var path = []; |
| | | var lineLayer = new T.Polyline([], { color: '#ff4500', weight: 3, opacity: 0.8 }); |
| | | var lineLayer = new T.Polyline([], { color: '#E9900A', weight: 3, opacity: 0.8 }); |
| | | let locationMarker; |
| | | function updateInspectionLocation(log, lat) { |
| | | var lastLat = lat; |
| | |
| | | } |
| | | |
| | | var aginPath = []; |
| | | var oldLineLayer = new T.Polyline([], { color: '#ff4500', weight: 3, opacity: 0.8 }); |
| | | var oldLineLayer = new T.Polyline([], { color: '#E9900A', weight: 3, opacity: 0.8 }); |
| | | //显示因异常关闭的巡检记录 |
| | | function aginShowLocation(lng, lat) { |
| | | // 调用 Android 提供的接口,获取数据 |
| | |
| | | import com.tencent.bugly.crashreport.CrashReport; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | import retrofit2.Call; |
| | |
| | | private final List<LocalMedia> mData = new ArrayList<>(); |
| | | private ActivityResultLauncher<Intent> launcherResult; |
| | | private ImageEngine imageEngine; |
| | | List<UplodFileState> uplodFileStates = new ArrayList<>(); |
| | | Map<String, UplodFileState> uplodFileStates = new HashMap<>(); |
| | | // List<UplodFileState> uplodFileStates = new ArrayList<>(); |
| | | LatLonBean latLonBean; |
| | | |
| | | /** |
| | |
| | | } |
| | | mRecyclerView.addItemDecoration(new GridSpacingItemDecoration(4, |
| | | DensityUtil.dip2px(this, 8), false)); |
| | | mAdapter = new AddPictureAdapter(this, mData); |
| | | mAdapter = new AddPictureAdapter(this, mData, uplodFileStates); |
| | | mAdapter.setSelectMax(maxSelectNum + maxSelectVideoNum); |
| | | mRecyclerView.setAdapter(mAdapter); |
| | | imageEngine = GlideEngine.createGlideEngine(); |
| | |
| | | }); |
| | | binding.dealButton.setOnClickListener(v -> { |
| | | boolean isAllPost = true; |
| | | for (UplodFileState imgData : uplodFileStates) { |
| | | for (UplodFileState imgData : uplodFileStates.values()) { |
| | | if (imgData.getState() == 0) { |
| | | isAllPost = false; |
| | | } |
| | |
| | | private void analyticalSelectResults(ArrayList<LocalMedia> result) { |
| | | //获取当前uplodFileStates所有的图片地址 |
| | | Set<String> existingPaths = new HashSet<>(); |
| | | for (UplodFileState uplodData : uplodFileStates) { |
| | | for (UplodFileState uplodData : uplodFileStates.values()) { |
| | | existingPaths.add(uplodData.getFilePath()); |
| | | } |
| | | //获取在PictureSelector的相册时取消选中的图片 |
| | |
| | | if (!existingPaths.contains(compressPath)) { |
| | | UplodFileState uplodFileState = new UplodFileState(); |
| | | uplodFileState.setFilePath(compressPath); |
| | | uplodFileStates.add(uplodFileState); |
| | | uplodFileStates.put(compressPath, uplodFileState); |
| | | // 执行上传图片的操作 |
| | | uplodeImg(uplodFileState); |
| | | } |
| | |
| | | if (!existingPaths.isEmpty()) { |
| | | List<UplodFileState> toRemove = new ArrayList<>(); |
| | | for (String path : existingPaths) { |
| | | for (UplodFileState uplodFileState : uplodFileStates) { |
| | | for (UplodFileState uplodFileState : uplodFileStates.values()) { |
| | | if (path.equals(uplodFileState.getFilePath())) { |
| | | uplodFileState.getThisCall().cancel(); |
| | | toRemove.add(uplodFileState); |
| | | } |
| | | } |
| | | } |
| | | uplodFileStates.removeAll(toRemove); |
| | | for (UplodFileState removeFile : toRemove) { |
| | | uplodFileStates.remove(removeFile.getFilePath()); |
| | | } |
| | | } |
| | | runOnUiThread(new Runnable() { |
| | | @Override |
| | |
| | | ApiManager.getInstance().uploadFile(this, uplodFileState, new UploadFileListener() { |
| | | @Override |
| | | public void onBack(UplodFileState state) { |
| | | for (UplodFileState uplodFile : uplodFileStates) { |
| | | if (uplodFile.getFilePath().equals(state.getFilePath())) { |
| | | int index = uplodFileStates.indexOf(uplodFile); |
| | | if (index != -1) { |
| | | uplodFileStates.set(index, uplodFile); // 更新对应的项 |
| | | } |
| | | } |
| | | |
| | | } |
| | | uplodFileStates.replace(state.getFilePath(), state); |
| | | mAdapter.updateProgress(uplodFileState); |
| | | } |
| | | }); |
| | | }, mAdapter); |
| | | } |
| | | |
| | | /** |
| | |
| | | import com.tencent.bugly.crashreport.CrashReport; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | import retrofit2.Call; |
| | |
| | | private final List<LocalMedia> mData = new ArrayList<>(); |
| | | private ActivityResultLauncher<Intent> launcherResult; |
| | | private ImageEngine imageEngine; |
| | | List<UplodFileState> uplodFileStates = new ArrayList<>(); |
| | | // List<UplodFileState> uplodFileStates = new ArrayList<>(); |
| | | Map<String, UplodFileState> uplodFileStates = new HashMap<>(); |
| | | String workOrderId; |
| | | LatLonBean latLonBean; |
| | | |
| | |
| | | } |
| | | mRecyclerView.addItemDecoration(new GridSpacingItemDecoration(4, |
| | | DensityUtil.dip2px(this, 8), false)); |
| | | mAdapter = new AddPictureAdapter(this, mData); |
| | | mAdapter = new AddPictureAdapter(this, mData, uplodFileStates); |
| | | mAdapter.setSelectMax(maxSelectNum + maxSelectVideoNum); |
| | | mRecyclerView.setAdapter(mAdapter); |
| | | imageEngine = GlideEngine.createGlideEngine(); |
| | |
| | | }); |
| | | binding.dealButton.setOnClickListener(v -> { |
| | | boolean isAllPost = true; |
| | | for (UplodFileState imgData : uplodFileStates) { |
| | | for (UplodFileState imgData : uplodFileStates.values()) { |
| | | if (imgData.getState() == 0) { |
| | | isAllPost = false; |
| | | } |
| | |
| | | private void analyticalSelectResults(ArrayList<LocalMedia> result) { |
| | | //获取当前uplodFileStates所有的图片地址 |
| | | Set<String> existingPaths = new HashSet<>(); |
| | | for (UplodFileState uplodData : uplodFileStates) { |
| | | for (UplodFileState uplodData : uplodFileStates.values()) { |
| | | existingPaths.add(uplodData.getFilePath()); |
| | | } |
| | | //获取在PictureSelector的相册时取消选中的图片 |
| | |
| | | if (!existingPaths.contains(compressPath)) { |
| | | UplodFileState uplodFileState = new UplodFileState(); |
| | | uplodFileState.setFilePath(compressPath); |
| | | uplodFileStates.add(uplodFileState); |
| | | uplodFileStates.put(compressPath, uplodFileState); |
| | | // 执行上传图片的操作 |
| | | uplodeImg(uplodFileState); |
| | | } |
| | |
| | | if (!existingPaths.isEmpty()) { |
| | | List<UplodFileState> toRemove = new ArrayList<>(); |
| | | for (String path : existingPaths) { |
| | | for (UplodFileState uplodFileState : uplodFileStates) { |
| | | for (UplodFileState uplodFileState : uplodFileStates.values()) { |
| | | if (path.equals(uplodFileState.getFilePath())) { |
| | | uplodFileState.getThisCall().cancel(); |
| | | toRemove.add(uplodFileState); |
| | | } |
| | | } |
| | | } |
| | | uplodFileStates.removeAll(toRemove); |
| | | for (UplodFileState removeFile : toRemove) { |
| | | uplodFileStates.remove(removeFile.getFilePath()); |
| | | } |
| | | } |
| | | runOnUiThread(() -> { |
| | | boolean isMaxSize = result.size() == mAdapter.getSelectMax(); |
| | |
| | | ApiManager.getInstance().uploadFile(this, uplodFileState, new UploadFileListener() { |
| | | @Override |
| | | public void onBack(UplodFileState state) { |
| | | for (UplodFileState uplodFile : uplodFileStates) { |
| | | if (uplodFile.getFilePath().equals(state.getFilePath())) { |
| | | int index = uplodFileStates.indexOf(uplodFile); |
| | | if (index != -1) { |
| | | uplodFileStates.set(index, uplodFile); // 更新对应的项 |
| | | } |
| | | } |
| | | |
| | | } |
| | | uplodFileStates.replace(state.getFilePath(), state); |
| | | mAdapter.updateProgress(uplodFileState); |
| | | } |
| | | }); |
| | | }, mAdapter); |
| | | } |
| | | |
| | | /** |
| | |
| | | * 开始定位相关逻辑 |
| | | */ |
| | | private void startLocation() { |
| | | ServiceUtils.startLocationService(this,true); |
| | | ServiceUtils.startLocationService(this, true); |
| | | //获取定位服务传过来的坐标点 |
| | | LiveEventBus.get(CommonKeyName.locationData).observeForever(locationObserver); |
| | | } |
| | |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.ImageView; |
| | | import android.widget.RelativeLayout; |
| | | import android.widget.TextView; |
| | | |
| | | import androidx.annotation.NonNull; |
| | |
| | | import com.bumptech.glide.Glide; |
| | | import com.bumptech.glide.load.engine.DiskCacheStrategy; |
| | | import com.dayu.pipirrapp.R; |
| | | import com.dayu.pipirrapp.bean.net.UplodFileState; |
| | | import com.dayu.pipirrapp.listener.OnItemLongClickListener; |
| | | import com.dayu.pipirrapp.utils.MyLog; |
| | | import com.king.view.circleprogressview.CircleProgressView; |
| | | import com.luck.picture.lib.config.PictureMimeType; |
| | | import com.luck.picture.lib.config.SelectMimeType; |
| | | import com.luck.picture.lib.entity.LocalMedia; |
| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * AddPictureAdapter - |
| | |
| | | public static final int TYPE_PICTURE = 2; |
| | | private final LayoutInflater mInflater; |
| | | private final ArrayList<LocalMedia> list = new ArrayList<>(); |
| | | Map<String, UplodFileState> fileStates; |
| | | private int selectMax = 9; |
| | | private Context mContext; |
| | | |
| | | /** |
| | | * 删除 |
| | | */ |
| | | public void delete(int position) { |
| | | try { |
| | | if (position != RecyclerView.NO_POSITION && list.size() > position) { |
| | | list.remove(position); |
| | | notifyItemRemoved(position); |
| | | notifyItemRangeChanged(position, list.size()); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public AddPictureAdapter(Context context, List<LocalMedia> result) { |
| | | public AddPictureAdapter(Context context, List<LocalMedia> result, Map<String, UplodFileState> fileStates) { |
| | | this.mInflater = LayoutInflater.from(context); |
| | | this.list.addAll(result); |
| | | this.mContext = context; |
| | | this.fileStates = fileStates; |
| | | } |
| | | |
| | | public void setSelectMax(int selectMax) { |
| | |
| | | } |
| | | } |
| | | |
| | | public static class ViewHolder extends RecyclerView.ViewHolder { |
| | | |
| | | ImageView mImg; |
| | | ImageView mIvDel; |
| | | TextView tvDuration; |
| | | |
| | | public ViewHolder(View view) { |
| | | super(view); |
| | | mImg = view.findViewById(R.id.fiv); |
| | | mIvDel = view.findViewById(R.id.iv_del); |
| | | tvDuration = view.findViewById(R.id.tv_duration); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public int getItemCount() { |
| | |
| | | //少于MaxSize张,显示继续添加的图标 |
| | | if (getItemViewType(position) == TYPE_CAMERA) { |
| | | viewHolder.mImg.setImageResource(R.mipmap.ic_add_image); |
| | | viewHolder.mImg.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View view) { |
| | | if (mItemClickListener != null) { |
| | | mItemClickListener.openPicture(); |
| | | } |
| | | viewHolder.mImg.setOnClickListener(view -> { |
| | | if (mItemClickListener != null) { |
| | | mItemClickListener.openPicture(); |
| | | } |
| | | }); |
| | | viewHolder.mIvDel.setVisibility(View.INVISIBLE); |
| | | viewHolder.circleProgressView.setVisibility(View.GONE); |
| | | } else { |
| | | //删除图片 |
| | | viewHolder.mIvDel.setVisibility(View.VISIBLE); |
| | | viewHolder.mIvDel.setOnClickListener(view -> { |
| | | int index = viewHolder.getAbsoluteAdapterPosition(); |
| | |
| | | .diskCacheStrategy(DiskCacheStrategy.ALL) |
| | | .into(viewHolder.mImg); |
| | | } |
| | | |
| | | // 更新进度 |
| | | UplodFileState uplodFileState = fileStates.get(media.getCompressPath()); |
| | | uplodFileState.setAdapterPosition(position); |
| | | MyLog.d("progressRequestBodyHolder>>>" + "State:" + uplodFileState.getState() + ">>>position:" + position + ">>>Progress: " + uplodFileState.getProgress()); |
| | | |
| | | if (uplodFileState.getState() == UplodFileState.STATE_UPDING) { |
| | | if (uplodFileState.getProgress() < 100) { |
| | | viewHolder.maskLayerBg.setVisibility(View.VISIBLE); |
| | | viewHolder.circleProgressView.setVisibility(View.VISIBLE); |
| | | viewHolder.circleProgressView.setProgress(uplodFileState.getProgress()); |
| | | |
| | | } else { |
| | | viewHolder.circleProgressView.setVisibility(View.GONE); |
| | | viewHolder.maskLayerBg.setVisibility(View.GONE); |
| | | } |
| | | } else if (fileStates.get(media.getCompressPath()).getState() == UplodFileState.STATE_DONE) { |
| | | viewHolder.maskLayerBg.setVisibility(View.GONE); |
| | | viewHolder.circleProgressView.setVisibility(View.GONE); |
| | | } else { |
| | | viewHolder.maskLayerBg.setVisibility(View.VISIBLE); |
| | | } |
| | | |
| | | //itemView 的点击事件 |
| | | if (mItemClickListener != null) { |
| | | viewHolder.itemView.setOnClickListener(v -> { |
| | |
| | | return true; |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 更新进度 |
| | | * |
| | | * @param uplodFileState |
| | | */ |
| | | public void updateProgress(UplodFileState uplodFileState) { |
| | | MyLog.d("updateProgress>>>" + "State:" + uplodFileState.getState() + ">>>position:" + uplodFileState.getAdapterPosition() + ">>>Progress: " + uplodFileState.getProgress()); |
| | | |
| | | // 更新进度参数 |
| | | if (fileStates.containsKey(uplodFileState.getFilePath())) { |
| | | if (uplodFileState.getState()==0){ |
| | | // 获取已有的 UplodFileState 对象并更新进度 |
| | | UplodFileState existingState = fileStates.get(uplodFileState.getFilePath()); |
| | | existingState.setProgress(uplodFileState.getProgress()); // 更新进度 |
| | | // 获取进度更新项的位置 |
| | | int position = existingState.getAdapterPosition(); |
| | | if (position != RecyclerView.NO_POSITION) { |
| | | // 通知适配器刷新指定位置的项 |
| | | notifyItemChanged(position); |
| | | } |
| | | }else if (uplodFileState.getState()==2){ |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | public void setItemLongClickListener(OnItemLongClickListener l) { |
| | | this.mItemLongClickListener = l; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 删除 |
| | | */ |
| | | public void delete(int position) { |
| | | try { |
| | | if (position != RecyclerView.NO_POSITION && list.size() > position) { |
| | | list.remove(position); |
| | | notifyItemRemoved(position); |
| | | notifyItemRangeChanged(position, list.size()); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public static class ViewHolder extends RecyclerView.ViewHolder { |
| | | |
| | | ImageView mImg; |
| | | ImageView mIvDel; |
| | | ImageView postError; |
| | | TextView tvDuration; |
| | | RelativeLayout maskLayerBg; |
| | | CircleProgressView circleProgressView; |
| | | |
| | | |
| | | public ViewHolder(View view) { |
| | | super(view); |
| | | mImg = view.findViewById(R.id.fiv); |
| | | mIvDel = view.findViewById(R.id.iv_del); |
| | | tvDuration = view.findViewById(R.id.tv_duration); |
| | | circleProgressView = view.findViewById(R.id.cpv); |
| | | maskLayerBg=view.findViewById(R.id.mask_layer_bg); |
| | | postError=view.findViewById(R.id.postError); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * AddIssueRequest - |
| | |
| | | * @version 1.0 |
| | | * @since 2024-12-09 |
| | | */ |
| | | public class AddIssueRequest extends BaseRequest{ |
| | | public class AddIssueRequest extends BaseRequest { |
| | | String workOrderId;//工单ID |
| | | String inspectorId;//巡检员ID |
| | | String content;//结果内容 |
| | |
| | | return images; |
| | | } |
| | | |
| | | public void setImages(List<UplodFileState> states) { |
| | | public void setImages(Map<String, UplodFileState> states) { |
| | | images.clear(); |
| | | for (UplodFileState data : states) { |
| | | for (UplodFileState data : states.values()) { |
| | | ImageRequest image = new ImageRequest(); |
| | | image.setWebPath(data.getWebPath()); |
| | | image.setId(data.getId()); |
| | | image.setId(data.getPostId()); |
| | | images.add(image); |
| | | } |
| | | } |
| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * AddProcessingResult -上报处理结果 |
| | |
| | | return images; |
| | | } |
| | | |
| | | public void setImages(List<UplodFileState> states) { |
| | | public void setImages(Map<String, UplodFileState> states) { |
| | | images.clear(); |
| | | for (UplodFileState data : states) { |
| | | for (UplodFileState data : states.values()) { |
| | | ImageRequest image = new ImageRequest(); |
| | | image.setWebPath(data.getWebPath()); |
| | | image.setId(data.getId()); |
| | | image.setId(data.getPostId()); |
| | | images.add(image); |
| | | } |
| | | } |
| | |
| | | package com.dayu.pipirrapp.bean.net; |
| | | |
| | | import com.dayu.pipirrapp.net.BaseResponse; |
| | | import com.luck.picture.lib.entity.LocalMedia; |
| | | |
| | | import retrofit2.Call; |
| | | |
| | |
| | | * Date: 2023-04-15 8:15 |
| | | * Description: |
| | | */ |
| | | public class UplodFileState { |
| | | int state = 0;//0正在上传 1上传完成 2上传失败 |
| | | String filePath;//上传的文件 |
| | | int number;//失败后重试的次数 |
| | | String id;//上传后的id |
| | | String webPath;//上传后的地址 |
| | | Call<BaseResponse> thisCall;//当前请求 |
| | | public class UplodFileState extends LocalMedia { |
| | | //正在上传 |
| | | public final static int STATE_UPDING = 0; |
| | | //上传完成 |
| | | public final static int STATE_DONE = 1; |
| | | //上传失败 |
| | | public final static int STATE_ERROR = 2; |
| | | |
| | | //0正在上传 1上传完成 2上传失败 |
| | | int state = 0; |
| | | //上传的文件 |
| | | String filePath; |
| | | //失败后重试的次数 |
| | | int number; |
| | | //上传后的id |
| | | String postId; |
| | | //上传后的地址 |
| | | String webPath; |
| | | //当前请求 |
| | | Call<BaseResponse> thisCall; |
| | | //图片上传进度 |
| | | int progress; |
| | | //adapter中的position |
| | | int adapterPosition = -1; |
| | | |
| | | public int getAdapterPosition() { |
| | | return adapterPosition; |
| | | } |
| | | |
| | | public void setAdapterPosition(int adapterPosition) { |
| | | this.adapterPosition = adapterPosition; |
| | | } |
| | | |
| | | public int getProgress() { |
| | | return progress; |
| | | } |
| | | |
| | | public void setProgress(int progress) { |
| | | this.progress = progress; |
| | | } |
| | | |
| | | |
| | | public Call<BaseResponse> getThisCall() { |
| | | return thisCall; |
| | |
| | | this.filePath = filePath; |
| | | } |
| | | |
| | | public String getId() { |
| | | return id; |
| | | public String getPostId() { |
| | | return postId; |
| | | } |
| | | |
| | | public void setId(String id) { |
| | | this.id = id; |
| | | public void setPostId(String postId) { |
| | | this.postId = postId; |
| | | } |
| | | |
| | | public String getWebPath() { |
| | |
| | | import android.annotation.SuppressLint; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.text.TextUtils; |
| | | import android.util.Log; |
| | | |
| | | import com.dayu.pipirrapp.MyApplication; |
| | | import com.dayu.pipirrapp.activity.LoginActivity; |
| | | import com.dayu.pipirrapp.adapter.AddPictureAdapter; |
| | | import com.dayu.pipirrapp.bean.net.CodeResult; |
| | | import com.dayu.pipirrapp.bean.net.UplodFileState; |
| | | import com.dayu.pipirrapp.bean.net.WeatherResponse; |
| | |
| | | import com.dayu.pipirrapp.net.subscribers.CodeListener; |
| | | import com.dayu.pipirrapp.net.subscribers.ProgressSubscriber; |
| | | import com.dayu.pipirrapp.net.subscribers.SubscriberListener; |
| | | import com.dayu.pipirrapp.net.upload.IMGProgressLisener; |
| | | import com.dayu.pipirrapp.net.upload.ProgressListener; |
| | | import com.dayu.pipirrapp.net.upload.ProgressRequestBody; |
| | | import com.dayu.pipirrapp.net.upload.UploadFileListener; |
| | |
| | | } |
| | | BaseResponse<T> response = new BaseResponse<>(); |
| | | response.setCode(tem.getCode()); |
| | | response.setMsg(tem.getMsg()); |
| | | if (!TextUtils.isEmpty(tem.getMsg())){ |
| | | response.setMsg(tem.getMsg()); |
| | | }else { |
| | | response.setMsg(""); |
| | | } |
| | | |
| | | |
| | | if (tClass != null) { |
| | | if (tem.getContent() instanceof Map) { |
| | |
| | | } |
| | | |
| | | |
| | | // public void uploadFile(final Context context, final UplodFileState uplodData, final UploadFileListener listener) { |
| | | // uploadFile(context, uplodData, listener, null); |
| | | // } |
| | | |
| | | /** |
| | | * 上传文件 |
| | | * |
| | |
| | | * @param uplodData |
| | | * @param listener |
| | | */ |
| | | public void uploadFile(final Context context, final UplodFileState uplodData, final UploadFileListener listener) { |
| | | |
| | | public void uploadFile(final Context context, final UplodFileState uplodData, final UploadFileListener listener, final AddPictureAdapter adapter) { |
| | | MyLog.d("progressRequestBody>>>" + "path:" + uplodData.getFilePath() ); |
| | | File file = new File(uplodData.getFilePath()); |
| | | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
| | | ProgressRequestBody progressRequestBody = new ProgressRequestBody(requestBody, new ProgressListener() { |
| | | @Override |
| | | public void onProgress(long bytesWritten, long contentLength, boolean done) { |
| | | // 更新进度条或进行其他操作 |
| | | int progress = (int) (100 * bytesWritten / contentLength); |
| | | // 例如:更新 ProgressBar 或显示进度 |
| | | runOnUiThread(() -> { |
| | | // 进度条更新代码 |
| | | // progressBar.setProgress(progress); |
| | | MyLog.d("progressRequestBody>>>" + "上传进度: " + progress + "%"); |
| | | }); |
| | | } |
| | | ProgressRequestBody progressRequestBody = new ProgressRequestBody(requestBody, (bytesWritten, contentLength, done) -> { |
| | | // MyLog.d("progressRequestBody>>>" + "bytesWritten:" + bytesWritten + ">>>contentLength: " + contentLength ); |
| | | // 更新进度条或进行其他操作 |
| | | int progress = (int) (100 * bytesWritten / contentLength); |
| | | // 例如:更新 ProgressBar 或显示进度 |
| | | runOnUiThread(() -> { |
| | | uplodData.setProgress(progress); |
| | | // 进度条更新代码 |
| | | if (adapter != null && uplodData.getAdapterPosition() != -1) { |
| | | adapter.updateProgress(uplodData); |
| | | } |
| | | MyLog.d("progressRequestBody>>>" + "adapterPosition:" + uplodData.getAdapterPosition() + ">>>上传进度: " + progress + "%"); |
| | | }); |
| | | |
| | | }); |
| | | MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), progressRequestBody); |
| | | RequestBody description = RequestBody.create(MediaType.parse("text/plain"), "file description"); |
| | |
| | | if (response.body() != null) { |
| | | if (response.body().isSuccess()) { |
| | | uplodData.setState(1); |
| | | uplodData.setId(((LinkedTreeMap) response.body().getContent()).get("id").toString()); |
| | | uplodData.setPostId(((LinkedTreeMap) response.body().getContent()).get("id").toString()); |
| | | uplodData.setWebPath(((LinkedTreeMap) response.body().getContent()).get("webPath").toString()); |
| | | listener.onBack(uplodData); |
| | | } else { |
| | | if (uplodData.getNumber() <= uplodFilerepeatSize) { |
| | | uplodData.setNumber(uplodData.getNumber() + 1); |
| | | uplodData.setState(2); |
| | | uploadFile(context, uplodData, listener); |
| | | uploadFile(context, uplodData, listener, adapter); |
| | | } else { |
| | | listener.onBack(uplodData); |
| | | } |
| | |
| | | if (uplodData.getNumber() <= uplodFilerepeatSize) { |
| | | uplodData.setNumber(uplodData.getNumber() + 1); |
| | | uplodData.setState(2); |
| | | uploadFile(context, uplodData, listener); |
| | | uploadFile(context, uplodData, listener, adapter); |
| | | } else { |
| | | listener.onBack(uplodData); |
| | | } |
| | |
| | | }); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | */ |
| | | public class Constants { |
| | | // public static final String BASE_URL = "http://192.168.10.52:8088"; |
| | | //public static final String BASE_URL = "https://no253541tf71.vicp.fun"; |
| | | public static final String BASE_URL = "http://fve2iz.natappfree.cc"; |
| | | public static final String BASE_URL = "https://no253541tf71.vicp.fun"; |
| | | //public static final String BASE_URL = "http://fve2iz.natappfree.cc"; |
| | | /** |
| | | * 代表请求成功 |
| | | */ |
| | |
| | | //添加日志拦截器 |
| | | //添加数据请求统一处理拦截器 |
| | | // if (BuildConfig.DEBUG) { |
| | | builder.addInterceptor(loggingInterceptor); |
| | | // builder.addInterceptor(loggingInterceptor); |
| | | // } |
| | | |
| | | OkHttpClient client = builder.build(); |
New file |
| | |
| | | package com.dayu.pipirrapp.net.upload; |
| | | |
| | | /** |
| | | * IMGProgressLisener - |
| | | * |
| | | * @author zuoxiao |
| | | * @version 1.0 |
| | | * @since 2024-12-24 |
| | | */ |
| | | public interface IMGProgressLisener { |
| | | void onProgress(int progress); |
| | | } |
| | |
| | | package com.dayu.pipirrapp.net.upload; |
| | | |
| | | public interface ProgressListener { |
| | | void onProgress(long bytesWritten, long totalBytes, boolean done); |
| | | void onProgress(long progress, long totalBytes, boolean done); |
| | | } |
| | |
| | | MyLog.i("原生定位没有权限>>>>"); |
| | | return; |
| | | } |
| | | locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, listener); |
| | | locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, listener); |
| | | } catch (Exception e) { |
| | | CrashReport.postCatchedException(e); |
| | | } |
New file |
| | |
| | | <vector xmlns:android="http://schemas.android.com/apk/res/android" |
| | | android:width="24dp" |
| | | android:height="24dp" |
| | | android:viewportWidth="48" |
| | | android:viewportHeight="48"> |
| | | <path |
| | | android:pathData="M44,23.994C44,22.89 43.105,21.994 42,21.994C40.895,21.994 40,22.89 40,23.994H44ZM24,7.994C25.105,7.994 26,7.099 26,5.994C26,4.89 25.105,3.994 24,3.994V7.994ZM39,39.994H9V43.994H39V39.994ZM8,38.994V8.994H4V38.994H8ZM40,23.994V38.994H44V23.994H40ZM9,7.994H24V3.994H9V7.994ZM9,39.994C8.448,39.994 8,39.546 8,38.994H4C4,41.756 6.239,43.994 9,43.994V39.994ZM39,43.994C41.761,43.994 44,41.756 44,38.994H40C40,39.546 39.552,39.994 39,39.994V43.994ZM8,8.994C8,8.442 8.448,7.994 9,7.994V3.994C6.239,3.994 4,6.233 4,8.994H8Z" |
| | | android:fillColor="#ff0000"/> |
| | | <path |
| | | android:pathData="M6,35L16.693,25.198C17.439,24.514 18.578,24.495 19.346,25.154L32,36" |
| | | android:strokeLineJoin="round" |
| | | android:strokeWidth="4" |
| | | android:fillColor="#00000000" |
| | | android:strokeColor="#ff0000" |
| | | android:strokeLineCap="round"/> |
| | | <path |
| | | android:pathData="M28,31L32.773,26.226C33.477,25.523 34.591,25.444 35.388,26.041L42,31" |
| | | android:strokeLineJoin="round" |
| | | android:strokeWidth="4" |
| | | android:fillColor="#00000000" |
| | | android:strokeColor="#ff0000" |
| | | android:strokeLineCap="round"/> |
| | | <path |
| | | android:pathData="M33,7L41,15" |
| | | android:strokeLineJoin="round" |
| | | android:strokeWidth="4" |
| | | android:fillColor="#00000000" |
| | | android:strokeColor="#ff0000" |
| | | android:strokeLineCap="round"/> |
| | | <path |
| | | android:pathData="M41,7L33,15" |
| | | android:strokeLineJoin="round" |
| | | android:strokeWidth="4" |
| | | android:fillColor="#00000000" |
| | | android:strokeColor="#ff0000" |
| | | android:strokeLineCap="round"/> |
| | | </vector> |
| | |
| | | android:id="@+id/ScrollView" |
| | | android:layout_width="match_parent" |
| | | android:layout_height="match_parent" |
| | | android:layout_above="@+id/delete_button" |
| | | |
| | | android:layout_below="@+id/title" |
| | | android:layout_marginTop="5dp" |
| | | android:layout_marginBottom="5dp"> |
| | |
| | | <?xml version="1.0" encoding="utf-8"?> |
| | | <com.luck.picture.lib.widget.SquareRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| | | xmlns:app="http://schemas.android.com/apk/res-auto" |
| | | xmlns:tools="http://schemas.android.com/tools" |
| | | android:layout_width="match_parent" |
| | | android:layout_height="wrap_content"> |
| | |
| | | android:textSize="11sp" |
| | | android:visibility="gone" |
| | | tools:visibility="visible" /> |
| | | |
| | | |
| | | <RelativeLayout |
| | | android:id="@+id/mask_layer_bg" |
| | | android:layout_width="match_parent" |
| | | android:layout_height="match_parent" |
| | | android:background="@color/mask_layer_bg"> |
| | | |
| | | <com.king.view.circleprogressview.CircleProgressView |
| | | android:id="@+id/cpv" |
| | | android:layout_width="wrap_content" |
| | | android:layout_height="wrap_content" |
| | | android:layout_centerHorizontal="true" |
| | | android:layout_centerVertical="true" |
| | | app:cpvShowTick="false" |
| | | app:cpvStrokeWidth="2dp" /> |
| | | |
| | | <ImageView |
| | | android:id="@+id/postError" |
| | | android:layout_width="match_parent" |
| | | android:layout_height="match_parent" |
| | | android:layout_margin="40dp" |
| | | android:src="@drawable/ic_error_picture" /> |
| | | </RelativeLayout> |
| | | |
| | | |
| | | </com.luck.picture.lib.widget.SquareRelativeLayout> |
| | |
| | | <color name="delete_color">#ff0000</color> |
| | | <color name="item_bg_color">#F9F9F9</color> |
| | | <color name="item_name_text_color">#828282</color> |
| | | <color name="mask_layer_bg">#BF828282</color> |
| | | </resources> |