| | |
| | | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.text.TextUtils; |
| | | import android.util.Log; |
| | |
| | | import com.dayu.pipirrapp.net.BaseResponse; |
| | | import com.dayu.pipirrapp.net.subscribers.SubscriberListener; |
| | | import com.dayu.pipirrapp.net.upload.UploadFileListener; |
| | | import com.dayu.pipirrapp.service.MyLocationService; |
| | | import com.dayu.pipirrapp.tool.FullyGridLayoutManager; |
| | | import com.dayu.pipirrapp.tool.GlideEngine; |
| | | import com.dayu.pipirrapp.tool.ImageFileCompressEngine; |
| | | import com.dayu.pipirrapp.utils.CommonKeyName; |
| | | import com.dayu.pipirrapp.utils.ServiceUtils; |
| | | import com.dayu.pipirrapp.utils.ToastUtil; |
| | | import com.dayu.pipirrapp.view.TitleBar; |
| | | import com.jeremyliao.liveeventbus.LiveEventBus; |
| | |
| | | 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; |
| | |
| | | RecyclerView mRecyclerView; |
| | | AddPictureAdapter mAdapter; |
| | | int maxSelectNum = 10;//最大照片 |
| | | int maxSelectVideoNum = 0;//最大视频 |
| | | int maxSelectVideoNum = 3;//最大视频 |
| | | |
| | | int videoMaxSecond = 60; |
| | | 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; |
| | | |
| | | /** |
| | | * 定位监听 |
| | | */ |
| | | private Observer<Object> locationObserver = new Observer<Object>() { |
| | | private final Observer<Object> locationObserver = new Observer<Object>() { |
| | | @Override |
| | | public void onChanged(Object o) { |
| | | latLonBean = (LatLonBean) o; |
| | |
| | | } |
| | | 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; |
| | | } |
| | |
| | | |
| | | if (!TextUtils.isEmpty(binding.contentET.getText().toString())) { |
| | | if (isAllPost) { |
| | | if (uplodFileStates.size() > 0) { |
| | | if (!uplodFileStates.isEmpty()) { |
| | | postData(); |
| | | } else { |
| | | ToastUtil.showToast(AddIssueActivity.this, "请上传图片"); |
| | |
| | | private void mOpenPicture() { |
| | | // 进入相册 |
| | | PictureSelectionModel selectionModel = PictureSelector.create(this) |
| | | .openGallery(SelectMimeType.ofImage()) |
| | | .openGallery(SelectMimeType.ofAll()) |
| | | .setMaxSelectNum(maxSelectNum) |
| | | .setMaxVideoSelectNum(maxSelectVideoNum) |
| | | .setImageEngine(imageEngine) |
| | | //设置图片压缩 |
| | | .setCompressEngine(new ImageFileCompressEngine()) |
| | | //设置视频图片一起在相册选择 |
| | | .isWithSelectVideoImage(true) |
| | | //设置最大视频时长 |
| | | .setRecordVideoMaxSecond(videoMaxSecond) |
| | | // 过滤视频最大时长 |
| | | .setFilterVideoMaxSecond(videoMaxSecond) |
| | | // 拍照是否纠正旋转图片 |
| | | .isCameraRotateImage(true) |
| | | .setSelectedData(mAdapter.getData()); |
| | | |
| | | selectionModel.forResult(launcherResult); |
| | |
| | | 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的相册时取消选中的图片 |
| | | Set<String> resultPaths = new HashSet<>(); |
| | | |
| | | for (LocalMedia media : result) { |
| | | if (media.getWidth() == 0 || media.getHeight() == 0) { |
| | |
| | | Log.i(TAG, "文件时长: " + media.getDuration()); |
| | | String compressPath = media.getCompressPath(); |
| | | //判断是否有这个路径,没有的话上传该图片并添加uplodFileStates中 |
| | | if (TextUtils.isEmpty(compressPath)) { |
| | | compressPath = media.getRealPath(); |
| | | } |
| | | if (!existingPaths.contains(compressPath)) { |
| | | UplodFileState uplodFileState = new UplodFileState(); |
| | | uplodFileState.setFilePath(compressPath); |
| | | uplodFileStates.add(uplodFileState); |
| | | uplodFileStates.put(compressPath, uplodFileState); |
| | | // 执行上传图片的操作 |
| | | uplodeImg(uplodFileState); |
| | | } |
| | | |
| | | |
| | | resultPaths.add(media.getCompressPath()); |
| | | } |
| | | //处理从相册返回时取消的图片处理 |
| | | existingPaths.removeAll(resultPaths); |
| | | if (!existingPaths.isEmpty()) { |
| | | List<UplodFileState> toRemove = new ArrayList<>(); |
| | | for (String path : existingPaths) { |
| | | for (UplodFileState uplodFileState : uplodFileStates.values()) { |
| | | if (path.equals(uplodFileState.getFilePath())) { |
| | | uplodFileState.getThisCall().cancel(); |
| | | toRemove.add(uplodFileState); |
| | | } |
| | | } |
| | | } |
| | | for (UplodFileState removeFile : toRemove) { |
| | | uplodFileStates.remove(removeFile.getFilePath()); |
| | | } |
| | | } |
| | | runOnUiThread(new Runnable() { |
| | | @Override |
| | |
| | | |
| | | //上传图片 |
| | | private void uplodeImg(UplodFileState uplodFileState) { |
| | | 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); // 更新对应的项 |
| | | } |
| | | } |
| | | ApiManager.getInstance().uploadFile(this, uplodFileState, state -> { |
| | | |
| | | } |
| | | } |
| | | }); |
| | | uplodFileStates.replace(state.getFilePath(), state); |
| | | mAdapter.updateProgress(uplodFileState); |
| | | }, mAdapter); |
| | | } |
| | | |
| | | /** |
| | |
| | | * 开始定位相关逻辑 |
| | | */ |
| | | private void startLocation() { |
| | | Intent location = new Intent(this, MyLocationService.class); |
| | | location.putExtra("isSingle", true); |
| | | //开启定位 |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
| | | startForegroundService(location); |
| | | } else { |
| | | startService(location); |
| | | } |
| | | ServiceUtils.startLocationService(this, true); |
| | | //获取定位服务传过来的坐标点 |
| | | LiveEventBus.get(CommonKeyName.locationData).observeForever(locationObserver); |
| | | } |