| | |
| | | package com.dayu.pipirrapp.activity; |
| | | |
| | | import android.app.NotificationManager; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.text.TextUtils; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | |
| | | import androidx.activity.result.ActivityResultLauncher; |
| | | import androidx.activity.result.contract.ActivityResultContracts; |
| | | import androidx.annotation.Nullable; |
| | | import androidx.core.content.res.ResourcesCompat; |
| | | import androidx.recyclerview.widget.GridLayoutManager; |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | import androidx.recyclerview.widget.SimpleItemAnimator; |
| | | |
| | | import com.dayu.pipirrapp.MyApplication; |
| | | import com.dayu.pipirrapp.R; |
| | | import com.dayu.pipirrapp.adapter.ImageAdapter; |
| | | import com.dayu.pipirrapp.bean.ImageBean; |
| | | import com.dayu.pipirrapp.bean.net.DealDetailResult; |
| | | import com.dayu.pipirrapp.bean.net.ImageResult; |
| | | import com.dayu.pipirrapp.bean.net.OrderDetailResult; |
| | | import com.dayu.pipirrapp.bean.net.UplodFileState; |
| | | import com.dayu.pipirrapp.databinding.ActivityOrderDetailBinding; |
| | | import com.dayu.pipirrapp.fragment.OrderFragment; |
| | | import com.dayu.pipirrapp.net.ApiManager; |
| | | import com.dayu.pipirrapp.net.BaseResponse; |
| | | import com.dayu.pipirrapp.net.Constants; |
| | | import com.dayu.pipirrapp.net.subscribers.SubscriberListener; |
| | | import com.dayu.pipirrapp.tool.BigimageUtils; |
| | | import com.dayu.pipirrapp.tool.FullyGridLayoutManager; |
| | | import com.dayu.pipirrapp.utils.CommonKeyName; |
| | | import com.dayu.pipirrapp.utils.ToastUtil; |
| | | import com.dayu.pipirrapp.view.ConfirmDialog; |
| | | import com.dayu.pipirrapp.view.TitleBar; |
| | | import com.jeremyliao.liveeventbus.LiveEventBus; |
| | | import com.luck.picture.lib.decoration.GridSpacingItemDecoration; |
| | | import com.luck.picture.lib.utils.DensityUtil; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import cc.shinichi.library.bean.ImageInfo; |
| | | import cc.shinichi.library.bean.Type; |
| | | |
| | | /** |
| | | * OrderDetailActivity - |
| | |
| | | public class OrderDetailActivity extends BaseActivity { |
| | | ActivityOrderDetailBinding binding; |
| | | String workOrderId; |
| | | String proResultId; |
| | | ImageAdapter mAdapter; |
| | | List<ImageBean> images = new ArrayList<>(); |
| | | RecyclerView mRecyclerView; |
| | | List<ImageInfo> imageInfoList = new ArrayList<>(); |
| | | int ProResultStateId; |
| | | private ActivityResultLauncher<Intent> activityResultLauncher = |
| | | registerForActivityResult( |
| | | new ActivityResultContracts.StartActivityForResult(), |
| | | result -> { |
| | | if (result.getResultCode() == OrderFragment.RESULT_REFRESH) { |
| | | setResult(OrderFragment.RESULT_REFRESH); |
| | | finish(); |
| | | } |
| | | }); |
| | | |
| | | @Override |
| | | protected void onCreate(@Nullable Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | binding = ActivityOrderDetailBinding.inflate(LayoutInflater.from(this)); |
| | | setContentView(binding.getRoot()); |
| | | |
| | | new TitleBar(this).setTitleText("工单详情").setLeftIco().setLeftIcoListening(v -> OrderDetailActivity.this.finish()); |
| | | initView(); |
| | | getData(this.getIntent()); |
| | | } |
| | | |
| | | void initView() { |
| | | workOrderId = this.getIntent().getStringExtra("workOrderId"); |
| | | @Override |
| | | protected void onNewIntent(Intent intent) { |
| | | super.onNewIntent(intent); |
| | | getData(intent); |
| | | } |
| | | |
| | | private void getData(Intent intent) { |
| | | |
| | | workOrderId = intent.getStringExtra("workOrderId"); |
| | | NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); |
| | | notificationManager.cancel(workOrderId.hashCode()); |
| | | if (this.getIntent().hasExtra("proResultId")) { |
| | | binding.orderDealLL.setVisibility(View.VISIBLE); |
| | | proResultId = this.getIntent().getStringExtra("proResultId"); |
| | | getHandleData(proResultId); |
| | | } else { |
| | | binding.orderDealLL.setVisibility(View.GONE); |
| | | } |
| | | if (!TextUtils.isEmpty(workOrderId)) { |
| | | getMarkerData(workOrderId); |
| | | } else { |
| | | this.finish(); |
| | | ToastUtil.showToastLong(this, "当前workOrderId为空"); |
| | | } |
| | | binding.setItemclidk(OrderDetailActivity.this); |
| | | } |
| | | |
| | | |
| | | void initView() { |
| | | binding.setItemclidk(OrderDetailActivity.this); |
| | | mRecyclerView = binding.recyclerView; |
| | | FullyGridLayoutManager manager = new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false); |
| | | mRecyclerView.setLayoutManager(manager); |
| | | RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator(); |
| | | if (itemAnimator != null) { |
| | | ((SimpleItemAnimator) itemAnimator).setSupportsChangeAnimations(false); |
| | | } |
| | | // 添加间距装饰,确保图片有合适的间隔 |
| | | mRecyclerView.addItemDecoration(new GridSpacingItemDecoration(4, DensityUtil.dip2px(this, 8), false)); |
| | | mAdapter = new ImageAdapter(this, images, (v, position) -> { |
| | | BigimageUtils.showImages(this, position, imageInfoList); |
| | | |
| | | }); |
| | | mRecyclerView.setAdapter(mAdapter); |
| | | } |
| | | |
| | | /** |
| | |
| | | private void getMarkerData(String workOrderId) { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("workOrderId", workOrderId); |
| | | ApiManager.getInstance().requestGetHideLoading(this, Constants.BASE_URL + "/app/workOrder/getOneWorkOrder", OrderDetailResult.class, params, new SubscriberListener<BaseResponse<OrderDetailResult>>() { |
| | | ApiManager.getInstance().requestGet(this, Constants.BASE_URL + "/app/workOrder/getOneWorkOrder", OrderDetailResult.class, params, new SubscriberListener<BaseResponse<OrderDetailResult>>() { |
| | | @Override |
| | | public void onNext(BaseResponse<OrderDetailResult> t) { |
| | | if (t.isSuccess()) { |
| | | LiveEventBus.get(CommonKeyName.RedLotRefresh).post(workOrderId); |
| | | if (t.getContent() != null) { |
| | | OrderDetailResult orderDetailResult = t.getContent(); |
| | | binding.setData(orderDetailResult); |
| | | if (!TextUtils.isEmpty(t.getContent().getProResultId()) && TextUtils.isEmpty(proResultId)) { |
| | | getHandleData(orderDetailResult.getProResultId()); |
| | | } |
| | | ProResultStateId = orderDetailResult.getProResultStateId(); |
| | | switch (ProResultStateId) { |
| | | case 0://未上报 |
| | | binding.stateText.setTextColor(OrderDetailActivity.this.getResources().getColor(R.color.black, null)); |
| | | binding.stateText.setBackground(ResourcesCompat.getDrawable(OrderDetailActivity.this.getResources(), R.drawable.order_state_no_bg, null)); |
| | | binding.dealButton.setBackground(getResources().getDrawable(R.drawable.bottom_butten_blue_ripple, null)); |
| | | binding.dealButton.setVisibility(View.VISIBLE); |
| | | break; |
| | | case 1://已上报 |
| | | binding.stateText.setTextColor(OrderDetailActivity.this.getResources().getColor(R.color.white, null)); |
| | | binding.stateText.setBackground(ResourcesCompat.getDrawable(OrderDetailActivity.this.getResources(), R.drawable.order_state_wait_bg, null)); |
| | | binding.dealButton.setBackground(getResources().getDrawable(R.drawable.bottom_butten_red_ripple, null)); |
| | | binding.dealButton.setVisibility(View.VISIBLE); |
| | | binding.dealButton.setText("删除处理结果"); |
| | | break; |
| | | case 2://已完成 |
| | | binding.stateText.setTextColor(OrderDetailActivity.this.getResources().getColor(R.color.white, null)); |
| | | binding.stateText.setBackground(ResourcesCompat.getDrawable(OrderDetailActivity.this.getResources(), R.drawable.order_state_finish_bg, null)); |
| | | binding.dealButton.setVisibility(View.GONE); |
| | | break; |
| | | case 3://被驳回 |
| | | binding.stateText.setTextColor(OrderDetailActivity.this.getResources().getColor(R.color.white, null)); |
| | | binding.stateText.setBackground(ResourcesCompat.getDrawable(OrderDetailActivity.this.getResources(), R.drawable.order_state_reject_bg, null)); |
| | | binding.dealButton.setBackground(getResources().getDrawable(R.drawable.bottom_butten_blue_ripple, null)); |
| | | binding.dealButton.setVisibility(View.VISIBLE); |
| | | break; |
| | | |
| | | } |
| | | } else { |
| | | ToastUtil.showToast(OrderDetailActivity.this, t.getMsg()); |
| | | } |
| | | } else if (t.DATA_NULL.equals(t.getCode())) { |
| | | //工单已被删除 |
| | | ToastUtil.showToast(OrderDetailActivity.this, "订单已被删除!"); |
| | | setResult(OrderFragment.RESULT_REFRESH); |
| | | OrderDetailActivity.this.finish(); |
| | | |
| | | } else { |
| | | |
| | | ToastUtil.showToast(OrderDetailActivity.this, t.getMsg()); |
| | | OrderDetailActivity.this.finish(); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onCloose() { |
| | | super.onCloose(); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(Throwable e) { |
| | | super.onError(e); |
| | | ToastUtil.showToastLong(OrderDetailActivity.this, "获取详情失败,请稍后再试"); |
| | | OrderDetailActivity.this.finish(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取处理详情 |
| | | */ |
| | | private void getHandleData(String proResultId) { |
| | | |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("proResultId", proResultId); |
| | | ApiManager.getInstance().requestGet(this, Constants.BASE_URL + "/app/workOrder/getProResult", DealDetailResult.class, params, new SubscriberListener<BaseResponse<DealDetailResult>>() { |
| | | @Override |
| | | public void onNext(BaseResponse<DealDetailResult> t) { |
| | | if (t.isSuccess()) { |
| | | if (t.isSuccess()) { |
| | | if (t.getContent() != null) { |
| | | binding.setData(t.getContent()); |
| | | binding.orderDealLL.setVisibility(View.VISIBLE); |
| | | binding.setDealData(t.getContent()); |
| | | |
| | | if (!t.getContent().getImages().isEmpty()) { |
| | | for (ImageResult imageResult : t.getContent().getImages()) { |
| | | ImageBean imageBean = new ImageBean(); |
| | | imageBean.setId(imageResult.getId()); |
| | | imageBean.setWebPath(imageResult.getWebPathZip()); |
| | | imageBean.setType(UplodFileState.IMG_TYPE); |
| | | images.add(imageBean); |
| | | ImageInfo info = new ImageInfo(); |
| | | info.setOriginUrl(imageResult.getWebPath()); |
| | | info.setType(Type.IMAGE); |
| | | if (imageResult.getWebPathZip() != null) { |
| | | info.setThumbnailUrl(imageResult.getWebPathZip()); |
| | | } |
| | | |
| | | imageInfoList.add(info); |
| | | } |
| | | } |
| | | if (!t.getContent().getVideos().isEmpty()) { |
| | | for (ImageResult imageResult : t.getContent().getVideos()) { |
| | | ImageBean imageBean = new ImageBean(); |
| | | imageBean.setId(imageResult.getId()); |
| | | imageBean.setWebPath(imageResult.getWebPathZip()); |
| | | imageBean.setType(UplodFileState.VIDEO_TYPE); |
| | | images.add(imageBean); |
| | | ImageInfo info = new ImageInfo(); |
| | | info.setOriginUrl(imageResult.getWebPath()); |
| | | info.setThumbnailUrl(imageResult.getWebPath()); |
| | | if (imageResult.getWebPathZip() != null) { |
| | | info.setThumbnailUrl(imageResult.getWebPathZip()); |
| | | } |
| | | info.setType(Type.VIDEO); |
| | | imageInfoList.add(info); |
| | | } |
| | | } |
| | | mAdapter.notifyDataSetChanged(); |
| | | } else { |
| | | ToastUtil.showToast(OrderDetailActivity.this, t.getMsg()); |
| | | } |
| | |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 删除处理详情 |
| | | */ |
| | | private void deleteDealData() { |
| | | |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("proResultId", proResultId); |
| | | params.put("inspectorId", MyApplication.myApplication.userId); |
| | | ApiManager.getInstance().requestPost(this, Constants.BASE_URL + "/app/workOrder/deleteProResult", DealDetailResult.class, params, new SubscriberListener<BaseResponse<DealDetailResult>>() { |
| | | @Override |
| | | public void onNext(BaseResponse<DealDetailResult> t) { |
| | | if (t.isSuccess()) { |
| | | if (t.isSuccess()) { |
| | | ToastUtil.showToastLong(OrderDetailActivity.this, "删除成功!"); |
| | | setResult(OrderFragment.RESULT_REFRESH); |
| | | OrderDetailActivity.this.finish(); |
| | | } |
| | | } else { |
| | | ToastUtil.showToast(OrderDetailActivity.this, t.getMsg()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onCloose() { |
| | | super.onCloose(); |
| | | } |
| | | |
| | | }); |
| | | } |
| | | |
| | | public void startDealActivity() { |
| | | Intent intent = new Intent(this, OrderDealActivity.class); |
| | | intent.putExtra("workOrderId", workOrderId); |
| | | startActivity(intent); |
| | | |
| | | switch (ProResultStateId) { |
| | | case 0: |
| | | case 3: |
| | | Intent intent = new Intent(this, OrderDealActivity.class); |
| | | intent.putExtra("workOrderId", workOrderId); |
| | | activityResultLauncher.launch(intent); |
| | | break; |
| | | case 1: |
| | | ConfirmDialog confirmDialog = new ConfirmDialog(this, "确认删除该处理结果吗?", (confirmDialog1, v) -> { |
| | | confirmDialog1.dismiss(); |
| | | deleteDealData(); |
| | | }); |
| | | confirmDialog.show(); |
| | | break; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } |