| | |
| | | |
| | | 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.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.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.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.List; |
| | | import java.util.Set; |
| | | |
| | | 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 Observer<Object> locationObserver = new Observer<Object>() { |
| | | @Override |
| | | public void onChanged(Object o) { |
| | | MyLog.d("OrderDealActivity>>>locationObserver>>"); |
| | | latLonBean = (LatLonBean) o; |
| | | } |
| | | }; |
| | |
| | | public void openPicture() { |
| | | //添加图片 |
| | | mOpenPicture(); |
| | | } |
| | | |
| | | @Override |
| | | public void onDeleteClick(int position) { |
| | | deleteItem(position); |
| | | } |
| | | }); |
| | | binding.dealButton.setOnClickListener(v -> { |
| | |
| | | |
| | | @Override |
| | | public void onPreviewDelete(int position) { |
| | | deleteItem(position); |
| | | mAdapter.remove(position); |
| | | mAdapter.notifyItemRemoved(position); |
| | | } |
| | |
| | | * @param result |
| | | */ |
| | | private void analyticalSelectResults(ArrayList<LocalMedia> result) { |
| | | //获取当前uplodFileStates所有的图片地址 |
| | | Set<String> existingPaths = new HashSet<>(); |
| | | for (UplodFileState uplodData : uplodFileStates) { |
| | | existingPaths.add(uplodData.getFilePath()); |
| | | } |
| | | //获取在PictureSelector的相册时取消选中的图片 |
| | | Set<String> resultPaths = new HashSet<>(); |
| | | for (LocalMedia media : result) { |
| | | if (media.getWidth() == 0 || media.getHeight() == 0) { |
| | | if (PictureMimeType.isHasImage(media.getMimeType())) { |
| | |
| | | //判断是否有这个路径,没有的话上传该图片 |
| | | if (!existingPaths.contains(compressPath)) { |
| | | UplodFileState uplodFileState = new UplodFileState(); |
| | | uplodFileState.setFilePath(media.getRealPath()); |
| | | uplodFileState.setFilePath(compressPath); |
| | | uplodFileStates.add(uplodFileState); |
| | | // 执行上传图片的操作 |
| | | uplodeImg(uplodFileState); |
| | | } |
| | | |
| | | |
| | | resultPaths.add(media.getCompressPath()); |
| | | } |
| | | 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()); |
| | | |
| | | //处理从相册返回时取消的图片处理 |
| | | existingPaths.removeAll(resultPaths); |
| | | if (!existingPaths.isEmpty()) { |
| | | List<UplodFileState> toRemove = new ArrayList<>(); |
| | | for (String path : existingPaths) { |
| | | for (UplodFileState uplodFileState : uplodFileStates) { |
| | | if (path.equals(uplodFileState.getFilePath())) { |
| | | uplodFileState.getThisCall().cancel(); |
| | | toRemove.add(uplodFileState); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 自定义图片压缩 |
| | | */ |
| | | 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(); |
| | | uplodFileStates.removeAll(toRemove); |
| | | } |
| | | runOnUiThread(() -> { |
| | | 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()); |
| | | |
| | | }); |
| | | } |
| | | |
| | | |
| | |
| | | * 开始定位相关逻辑 |
| | | */ |
| | | 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); |
| | | } |
| | |
| | | super.onDestroy(); |
| | | LiveEventBus.get(CommonKeyName.locationData).removeObserver(locationObserver); |
| | | } |
| | | |
| | | /** |
| | | * 预览和图片列表删除图片时处理删除事件 |
| | | */ |
| | | private void deleteItem(int position) { |
| | | try { |
| | | Call<BaseResponse> mCall = uplodFileStates.get(position).getThisCall(); |
| | | if (mCall != null) { |
| | | mCall.cancel(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | uplodFileStates.remove(position); |
| | | } |
| | | } |