| | |
| | | package com.dayu.pipirrapp.activity; |
| | | |
| | | import static com.dayu.pipirrapp.net.Constants.BASE_URL; |
| | | |
| | | 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 android.view.LayoutInflater; |
| | | import android.view.View; |
| | | |
| | | import androidx.activity.result.ActivityResultLauncher; |
| | | import androidx.activity.result.contract.ActivityResultContracts; |
| | | import androidx.lifecycle.Observer; |
| | | import androidx.recyclerview.widget.GridLayoutManager; |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | import androidx.recyclerview.widget.SimpleItemAnimator; |
| | | |
| | | import com.dayu.pipirrapp.MyApplication; |
| | | import com.dayu.pipirrapp.adapter.AddPictureAdapter; |
| | | import com.dayu.pipirrapp.bean.db.LatLonBean; |
| | | import com.dayu.pipirrapp.bean.net.AddProcessingResult; |
| | | import com.dayu.pipirrapp.bean.net.InsectionResult; |
| | | import com.dayu.pipirrapp.bean.net.UplodFileState; |
| | | import com.dayu.pipirrapp.databinding.ActivityOrderDealBinding; |
| | | 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.FullyGridLayoutManager; |
| | | import com.dayu.pipirrapp.tool.GlideEngine; |
| | | import com.dayu.pipirrapp.utils.CommonKeyName; |
| | | import com.dayu.pipirrapp.utils.ToastUtil; |
| | | import com.dayu.pipirrapp.view.TitleBar; |
| | | import com.jeremyliao.liveeventbus.LiveEventBus; |
| | | 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.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.List; |
| | | import java.util.Set; |
| | | |
| | | import top.zibin.luban.CompressionPredicate; |
| | | import top.zibin.luban.Luban; |
| | |
| | | private final List<LocalMedia> mData = new ArrayList<>(); |
| | | private ActivityResultLauncher<Intent> launcherResult; |
| | | private ImageEngine imageEngine; |
| | | List<UplodFileState> uplodFileStates = new ArrayList<>(); |
| | | String workOrderId; |
| | | LatLonBean latLonBean; |
| | | |
| | | /** |
| | | * 定位监听 |
| | | */ |
| | | private Observer<Object> locationObserver = new Observer<Object>() { |
| | | @Override |
| | | public void onChanged(Object o) { |
| | | latLonBean = (LatLonBean) o; |
| | | } |
| | | }; |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | binding = ActivityOrderDealBinding.inflate(LayoutInflater.from(this)); |
| | | setContentView(binding.getRoot()); |
| | | workOrderId = this.getIntent().getStringExtra("workOrderId"); |
| | | launcherResult = createActivityResultLauncher(); |
| | | initView(); |
| | | startLocation(); |
| | | } |
| | | |
| | | |
| | |
| | | public void openPicture() { |
| | | //添加图片 |
| | | mOpenPicture(); |
| | | } |
| | | }); |
| | | binding.dealButton.setOnClickListener(v -> { |
| | | boolean isAllPost = true; |
| | | for (UplodFileState imgData : uplodFileStates) { |
| | | if (imgData.getState() == 0) { |
| | | isAllPost = false; |
| | | } |
| | | } |
| | | |
| | | if (!TextUtils.isEmpty(binding.contentET.getText().toString())) { |
| | | if (isAllPost) { |
| | | if (uplodFileStates.size() > 0) { |
| | | postData(); |
| | | } else { |
| | | ToastUtil.showToast(OrderDealActivity.this, "请上传图片"); |
| | | } |
| | | } else { |
| | | ToastUtil.showToast(OrderDealActivity.this, "图片正在上传请稍后提交"); |
| | | } |
| | | } else { |
| | | ToastUtil.showToast(OrderDealActivity.this, "请输入反馈内容"); |
| | | } |
| | | }); |
| | | } |
| | |
| | | * @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); |
| | | } |
| | | |
| | | |
| | | } |
| | | runOnUiThread(new Runnable() { |
| | | @Override |
| | |
| | | |
| | | mAdapter.getData().addAll(result); |
| | | mAdapter.notifyItemRangeInserted(0, result.size()); |
| | | |
| | | } |
| | | }); |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | //上传图片 |
| | | 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); // 更新对应的项 |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 上报处理结果 |
| | | */ |
| | | private void postData() { |
| | | AddProcessingResult result = new AddProcessingResult(); |
| | | result.setImages(uplodFileStates); |
| | | result.setContent(binding.contentET.getText().toString()); |
| | | result.setInspectorId(MyApplication.myApplication.userId); |
| | | result.setWorkOrderId(workOrderId); |
| | | result.setCompleteTime(com.dayu.pipirrapp.utils.DateUtils.getNowDateToMMStr()); |
| | | if (latLonBean != null) { |
| | | result.setLat(String.valueOf(latLonBean.getLatitude())); |
| | | result.setLng(String.valueOf(latLonBean.getLongitude())); |
| | | } |
| | | ApiManager.getInstance().requestPostHideLoading(this, BASE_URL + "/app/workOrder/addProcessingResult", InsectionResult.class, result.toMap(result), new SubscriberListener<BaseResponse<List<InsectionResult>>>() { |
| | | @Override |
| | | public void onNext(BaseResponse<List<InsectionResult>> t) { |
| | | try { |
| | | if (t.isSuccess()) { |
| | | ToastUtil.showToastLong(OrderDealActivity.this, "上报成功"); |
| | | OrderDealActivity.this.finish(); |
| | | } else { |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | CrashReport.postCatchedException(e); |
| | | } |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 开始定位相关逻辑 |
| | | */ |
| | | 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); |
| | | } |
| | | //获取定位服务传过来的坐标点 |
| | | LiveEventBus.get(CommonKeyName.locationData).observeForever(locationObserver); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | protected void onDestroy() { |
| | | super.onDestroy(); |
| | | LiveEventBus.get(CommonKeyName.locationData).removeObserver(locationObserver); |
| | | } |
| | | } |