| | |
| | | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.net.Uri; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.text.TextUtils; |
| | | import android.util.Log; |
| | |
| | | import com.dayu.pipirrapp.net.ApiManager; |
| | | 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.FileUploadUtils; |
| | | 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.MyLog; |
| | | 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.loper7.date_time_picker.DateTimeConfig; |
| | | import com.loper7.date_time_picker.dialog.CardDatePickerDialog; |
| | | import com.luck.picture.lib.basic.PictureSelectionModel; |
| | | import com.luck.picture.lib.basic.PictureSelector; |
| | | import com.luck.picture.lib.config.PictureMimeType; |
| | | import com.luck.picture.lib.config.SelectMimeType; |
| | | import com.luck.picture.lib.decoration.GridSpacingItemDecoration; |
| | | import com.luck.picture.lib.engine.CompressFileEngine; |
| | | import com.luck.picture.lib.engine.ImageEngine; |
| | | import com.luck.picture.lib.entity.LocalMedia; |
| | | import com.luck.picture.lib.entity.MediaExtraInfo; |
| | | import com.luck.picture.lib.interfaces.OnExternalPreviewEventListener; |
| | | import com.luck.picture.lib.interfaces.OnKeyValueResultCallbackListener; |
| | | import com.luck.picture.lib.utils.DateUtils; |
| | | import com.luck.picture.lib.utils.DensityUtil; |
| | | import com.luck.picture.lib.utils.MediaUtils; |
| | | import com.luck.picture.lib.utils.PictureFileUtils; |
| | | import com.tencent.bugly.crashreport.CrashReport; |
| | | |
| | | import java.io.File; |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.Map; |
| | | |
| | | import top.zibin.luban.CompressionPredicate; |
| | | import top.zibin.luban.Luban; |
| | | import top.zibin.luban.OnNewCompressListener; |
| | | import top.zibin.luban.OnRenameListener; |
| | | import retrofit2.Call; |
| | | |
| | | /** |
| | | * OrderDealDetailActivity - |
| | |
| | | * @since 2024-11-27 |
| | | */ |
| | | public class OrderDealActivity extends BaseActivity { |
| | | private String TAG = "OrderDealActivity"; |
| | | private final String TAG = "OrderDealActivity"; |
| | | ActivityOrderDealBinding binding; |
| | | RecyclerView mRecyclerView; |
| | | AddPictureAdapter mAdapter; |
| | |
| | | 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; |
| | | String strCompleteTime; |
| | | |
| | | /** |
| | | * 定位监听 |
| | |
| | | private Observer<Object> locationObserver = new Observer<Object>() { |
| | | @Override |
| | | public void onChanged(Object o) { |
| | | MyLog.d("OrderDealActivity>>>locationObserver>>"); |
| | | latLonBean = (LatLonBean) o; |
| | | } |
| | | }; |
| | |
| | | |
| | | void initView() { |
| | | new TitleBar(this).setTitleText("处理工单").setLeftIco().setLeftIcoListening(v -> OrderDealActivity.this.finish()); |
| | | binding.timeLL.setOnClickListener(v -> { |
| | | long time = System.currentTimeMillis(); |
| | | List<Integer> list = new ArrayList<>(); |
| | | list.add(DateTimeConfig.YEAR); |
| | | list.add(DateTimeConfig.MONTH); |
| | | list.add(DateTimeConfig.DAY); |
| | | list.add(DateTimeConfig.HOUR); |
| | | list.add(DateTimeConfig.MIN); |
| | | new CardDatePickerDialog.Builder(this) |
| | | .setTitle("选择处理时间") |
| | | .setOnChoose("确定", aLong -> { |
| | | //aLong = millisecond |
| | | strCompleteTime = com.dayu.pipirrapp.utils.DateUtils.formatTimestamp(aLong); |
| | | binding.timeData.setText(strCompleteTime); |
| | | return null; |
| | | }) |
| | | .showBackNow(true) |
| | | .setDefaultTime(time) |
| | | .setMaxTime(time) |
| | | .setMinTime(time - 365L * 24 * 60 * 60 * 1000) // 设置最小时间为一年前 |
| | | .setDisplayType(list) |
| | | .build().show(); |
| | | }); |
| | | mRecyclerView = binding.recycler; |
| | | FullyGridLayoutManager manager = new FullyGridLayoutManager(this, |
| | | 4, GridLayoutManager.VERTICAL, false); |
| | |
| | | } |
| | | 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(); |
| | |
| | | //添加图片 |
| | | mOpenPicture(); |
| | | } |
| | | |
| | | @Override |
| | | public void onDeleteClick(int position) { |
| | | deleteItem(position); |
| | | } |
| | | |
| | | @Override |
| | | public void onReUpload(UplodFileState uplodFileState) { |
| | | FileUploadUtils.uploadFile(OrderDealActivity.this, uplodFileState, uplodFileStates, mAdapter); |
| | | } |
| | | }); |
| | | binding.dealButton.setOnClickListener(v -> { |
| | | boolean isAllPost = true; |
| | | for (UplodFileState imgData : uplodFileStates) { |
| | | for (UplodFileState imgData : uplodFileStates.values()) { |
| | | if (imgData.getState() == 0) { |
| | | isAllPost = false; |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void onPreviewDelete(int position) { |
| | | deleteItem(position); |
| | | mAdapter.remove(position); |
| | | mAdapter.notifyItemRemoved(position); |
| | | } |
| | |
| | | * @param result |
| | | */ |
| | | private void analyticalSelectResults(ArrayList<LocalMedia> result) { |
| | | Set<String> existingPaths = new HashSet<>(); |
| | | for (UplodFileState uplodData : uplodFileStates) { |
| | | existingPaths.add(uplodData.getFilePath()); |
| | | } |
| | | for (LocalMedia media : result) { |
| | | if (media.getWidth() == 0 || media.getHeight() == 0) { |
| | | if (PictureMimeType.isHasImage(media.getMimeType())) { |
| | |
| | | Log.i(TAG, "裁剪宽高: " + media.getCropImageWidth() + "x" + media.getCropImageHeight()); |
| | | Log.i(TAG, "文件大小: " + PictureFileUtils.formatAccurateUnitFileSize(media.getSize())); |
| | | Log.i(TAG, "文件时长: " + media.getDuration()); |
| | | String compressPath = media.getCompressPath(); |
| | | //判断是否有这个路径,没有的话上传该图片 |
| | | if (!existingPaths.contains(compressPath)) { |
| | | UplodFileState uplodFileState = new UplodFileState(); |
| | | uplodFileState.setFilePath(media.getRealPath()); |
| | | uplodFileStates.add(uplodFileState); |
| | | // 执行上传图片的操作 |
| | | uplodeImg(uplodFileState); |
| | | } |
| | | |
| | | |
| | | Log.i(TAG, "扩展名: " + media.getMimeType()); |
| | | FileUploadUtils.creatAndUploadFile(this, media, uplodFileStates, mAdapter); |
| | | } |
| | | runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | boolean isMaxSize = result.size() == mAdapter.getSelectMax(); |
| | | int oldSize = mAdapter.getData().size(); |
| | | mAdapter.notifyItemRangeRemoved(0, isMaxSize ? oldSize + 1 : oldSize); |
| | | mAdapter.getData().clear(); |
| | | |
| | | mAdapter.getData().addAll(result); |
| | | mAdapter.notifyItemRangeInserted(0, result.size()); |
| | | |
| | | } |
| | | }); |
| | | // 获取 result 中没有而 uplodFileStates 中有的地址 |
| | | FileUploadUtils.cancelRemovedUploads(result, uplodFileStates); |
| | | // 更新UI |
| | | FileUploadUtils.updateUI(result, mAdapter); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 自定义图片压缩 |
| | | */ |
| | | private static class ImageFileCompressEngine implements CompressFileEngine { |
| | | |
| | | @Override |
| | | public void onStartCompress(Context context, ArrayList<Uri> source, OnKeyValueResultCallbackListener call) { |
| | | Luban.with(context).load(source).ignoreBy(100).setRenameListener(new OnRenameListener() { |
| | | @Override |
| | | public String rename(String filePath) { |
| | | int indexOf = filePath.lastIndexOf("."); |
| | | String postfix = indexOf != -1 ? filePath.substring(indexOf) : ".jpg"; |
| | | return DateUtils.getCreateFileName("CMP_") + postfix; |
| | | } |
| | | }).filter(new CompressionPredicate() { |
| | | @Override |
| | | public boolean apply(String path) { |
| | | if (PictureMimeType.isUrlHasImage(path) && !PictureMimeType.isHasHttp(path)) { |
| | | return true; |
| | | } |
| | | return !PictureMimeType.isUrlHasGif(path); |
| | | } |
| | | }).setCompressListener(new OnNewCompressListener() { |
| | | @Override |
| | | public void onStart() { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onSuccess(String source, File compressFile) { |
| | | if (call != null) { |
| | | call.onCallback(source, compressFile.getAbsolutePath()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onError(String source, Throwable e) { |
| | | if (call != null) { |
| | | call.onCallback(source, null); |
| | | } |
| | | } |
| | | }).launch(); |
| | | } |
| | | } |
| | | |
| | | |
| | | //上传图片 |
| | | 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); // 更新对应的项 |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 上报处理结果 |
| | |
| | | result.setContent(binding.contentET.getText().toString()); |
| | | result.setInspectorId(MyApplication.myApplication.userId); |
| | | result.setWorkOrderId(workOrderId); |
| | | result.setCompleteTime(com.dayu.pipirrapp.utils.DateUtils.getNowDateToMMStr()); |
| | | result.setCompleteTime(strCompleteTime); |
| | | if (latLonBean != null) { |
| | | result.setLat(String.valueOf(latLonBean.getLatitude())); |
| | | result.setLng(String.valueOf(latLonBean.getLongitude())); |
| | |
| | | * 开始定位相关逻辑 |
| | | */ |
| | | 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); |
| | | } |
| | |
| | | protected void onDestroy() { |
| | | super.onDestroy(); |
| | | LiveEventBus.get(CommonKeyName.locationData).removeObserver(locationObserver); |
| | | FileUploadUtils.cancelAllCall(uplodFileStates); |
| | | } |
| | | |
| | | /** |
| | | * 预览和图片列表删除图片时处理删除事件 |
| | | */ |
| | | private void deleteItem(int position) { |
| | | LocalMedia localMedia = mAdapter.getData().get(position); |
| | | String path; |
| | | UplodFileState uplodFileState; |
| | | if (TextUtils.isEmpty(localMedia.getCompressPath())) { |
| | | uplodFileState = uplodFileStates.get(localMedia.getRealPath()); |
| | | } else { |
| | | uplodFileState = uplodFileStates.get(localMedia.getCompressPath()); |
| | | } |
| | | if (uplodFileState != null) { |
| | | path = uplodFileState.getFilePath(); |
| | | try { |
| | | Call mCall = uplodFileStates.get(path).getThisCall(); |
| | | if (mCall != null) { |
| | | mCall.cancel(); |
| | | MyLog.d("progressRequestBody>>>" + "cancel》》》path:" + path); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | uplodFileStates.remove(path); |
| | | } |
| | | } |
| | | } |