1.修复上传文件取消上传还会上传bug
2.添加上传视频功能
3.添加关闭activity时关闭上传功能。
| | |
| | | } |
| | | |
| | | buildTypes { |
| | | debug{ |
| | | buildConfigField "boolean", "DEBUG", "true" |
| | | } |
| | | release { |
| | | buildConfigField "boolean", "DEBUG", "false" |
| | | minifyEnabled false |
| | | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
| | | } |
| | |
| | | sourceCompatibility JavaVersion.VERSION_1_8 |
| | | targetCompatibility JavaVersion.VERSION_1_8 |
| | | } |
| | | |
| | | // 启用 buildConfig 特性 |
| | | buildFeatures { |
| | | buildConfig true |
| | | } |
| | | dataBinding { |
| | | enabled = true; |
| | | } |
| | |
| | | import com.dayu.pipirrapp.net.BaseResponse; |
| | | import com.dayu.pipirrapp.net.subscribers.SubscriberListener; |
| | | import com.dayu.pipirrapp.net.upload.UploadFileListener; |
| | | 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; |
| | |
| | | @Override |
| | | public void onDeleteClick(int position) { |
| | | deleteItem(position); |
| | | } |
| | | |
| | | @Override |
| | | public void onReUpload(UplodFileState uplodFileState) { |
| | | uplodeImg(uplodFileState); |
| | | } |
| | | }); |
| | | binding.dealButton.setOnClickListener(v -> { |
| | |
| | | Log.i(TAG, "裁剪宽高: " + media.getCropImageWidth() + "x" + media.getCropImageHeight()); |
| | | Log.i(TAG, "文件大小: " + PictureFileUtils.formatAccurateUnitFileSize(media.getSize())); |
| | | Log.i(TAG, "文件时长: " + media.getDuration()); |
| | | Log.i(TAG, "扩展名: " + media.getMimeType()); |
| | | String compressPath = media.getCompressPath(); |
| | | //判断是否有这个路径,没有的话上传该图片并添加uplodFileStates中 |
| | | if (TextUtils.isEmpty(compressPath)) { |
| | |
| | | if (!existingPaths.contains(compressPath)) { |
| | | UplodFileState uplodFileState = new UplodFileState(); |
| | | uplodFileState.setFilePath(compressPath); |
| | | if (compressPath.toLowerCase().endsWith(".mp4") || compressPath.toLowerCase().endsWith(".avi") || compressPath.toLowerCase().endsWith(".mkv") || compressPath.toLowerCase().endsWith(".mov")) { |
| | | // 这是视频文件 |
| | | uplodFileState.setUploadType(UplodFileState.VIDEO_TYPE); |
| | | } else { |
| | | uplodFileState.setUploadType(UplodFileState.IMG_TYPE); |
| | | } |
| | | uplodFileState.setExtName(media.getMimeType()); |
| | | uplodFileStates.put(compressPath, uplodFileState); |
| | | // 执行上传图片的操作 |
| | | uplodeImg(uplodFileState); |
| | |
| | | |
| | | //上传图片 |
| | | private void uplodeImg(UplodFileState uplodFileState) { |
| | | ApiManager.getInstance().uploadFile(this, uplodFileState, state -> { |
| | | |
| | | uplodFileStates.replace(state.getFilePath(), state); |
| | | mAdapter.updateProgress(uplodFileState); |
| | | }, mAdapter); |
| | | FileUploadUtils.uploadFile(this, uplodFileState, uplodFileStates, mAdapter); |
| | | } |
| | | |
| | | /** |
| | |
| | | protected void onDestroy() { |
| | | super.onDestroy(); |
| | | LiveEventBus.get(CommonKeyName.locationData).removeObserver(locationObserver); |
| | | FileUploadUtils.cancelAllCall(uplodFileStates); |
| | | } |
| | | |
| | | /** |
| | | * 预览和图片列表删除图片时处理删除事件 |
| | | */ |
| | | private void deleteItem(int position) { |
| | | try { |
| | | Call<BaseResponse> mCall = uplodFileStates.get(position).getThisCall(); |
| | | if (mCall != null) { |
| | | mCall.cancel(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | 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()); |
| | | } |
| | | uplodFileStates.remove(position); |
| | | if (uplodFileState != null) { |
| | | path = uplodFileState.getFilePath(); |
| | | try { |
| | | Call<BaseResponse> mCall = uplodFileStates.get(path).getThisCall(); |
| | | if (mCall != null) { |
| | | mCall.cancel(); |
| | | MyLog.d("progressRequestBody>>>" + "cancel》》》path:" + path); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | uplodFileStates.remove(path); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | import com.dayu.pipirrapp.net.BaseResponse; |
| | | import com.dayu.pipirrapp.net.subscribers.SubscriberListener; |
| | | import com.dayu.pipirrapp.net.upload.UploadFileListener; |
| | | import com.dayu.pipirrapp.tool.FileUploadUtils; |
| | | import com.dayu.pipirrapp.tool.FullyGridLayoutManager; |
| | | import com.dayu.pipirrapp.tool.GlideEngine; |
| | | import com.dayu.pipirrapp.tool.ImageFileCompressEngine; |
| | |
| | | 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<>(); |
| | | Map<String, UplodFileState> uplodFileStates = new HashMap<>(); |
| | | String workOrderId; |
| | | LatLonBean latLonBean; |
| | | |
| | |
| | | @Override |
| | | public void onDeleteClick(int position) { |
| | | deleteItem(position); |
| | | } |
| | | |
| | | @Override |
| | | public void onReUpload(UplodFileState uplodFileState) { |
| | | uplodFileState.setState(UplodFileState.STATE_UPDING); |
| | | uplodeImg(uplodFileState); |
| | | } |
| | | }); |
| | | binding.dealButton.setOnClickListener(v -> { |
| | |
| | | Log.i(TAG, "文件时长: " + media.getDuration()); |
| | | String compressPath = media.getCompressPath(); |
| | | //判断是否有这个路径,没有的话上传该图片 |
| | | if (TextUtils.isEmpty(compressPath)) { |
| | | compressPath = media.getRealPath(); |
| | | } |
| | | if (!existingPaths.contains(compressPath)) { |
| | | UplodFileState uplodFileState = new UplodFileState(); |
| | | uplodFileState.setFilePath(compressPath); |
| | | if (compressPath.toLowerCase().endsWith(".mp4") || compressPath.toLowerCase().endsWith(".avi") || compressPath.toLowerCase().endsWith(".mkv") || compressPath.toLowerCase().endsWith(".mov")) { |
| | | // 这是视频文件 |
| | | uplodFileState.setUploadType(UplodFileState.VIDEO_TYPE); |
| | | }else { |
| | | uplodFileState.setUploadType(UplodFileState.IMG_TYPE); |
| | | } |
| | | uplodFileStates.put(compressPath, uplodFileState); |
| | | // 执行上传图片的操作 |
| | | uplodeImg(uplodFileState); |
| | |
| | | |
| | | //上传图片 |
| | | private void uplodeImg(UplodFileState uplodFileState) { |
| | | ApiManager.getInstance().uploadFile(this, uplodFileState, new UploadFileListener() { |
| | | @Override |
| | | public void onBack(UplodFileState state) { |
| | | uplodFileStates.replace(state.getFilePath(), state); |
| | | mAdapter.updateProgress(uplodFileState); |
| | | } |
| | | }, mAdapter); |
| | | FileUploadUtils.uploadFile(this, uplodFileState, uplodFileStates, mAdapter); |
| | | } |
| | | |
| | | /** |
| | |
| | | protected void onDestroy() { |
| | | super.onDestroy(); |
| | | LiveEventBus.get(CommonKeyName.locationData).removeObserver(locationObserver); |
| | | FileUploadUtils.cancelAllCall(uplodFileStates); |
| | | } |
| | | |
| | | /** |
| | | * 预览和图片列表删除图片时处理删除事件 |
| | | */ |
| | | private void deleteItem(int position) { |
| | | try { |
| | | Call<BaseResponse> mCall = uplodFileStates.get(position).getThisCall(); |
| | | if (mCall != null) { |
| | | mCall.cancel(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | 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()); |
| | | } |
| | | uplodFileStates.remove(position); |
| | | if (uplodFileState != null) { |
| | | path = uplodFileState.getFilePath(); |
| | | try { |
| | | Call<BaseResponse> mCall = uplodFileStates.get(path).getThisCall(); |
| | | if (mCall != null) { |
| | | mCall.cancel(); |
| | | MyLog.d("progressRequestBody>>>" + "cancel》》》path:" + path); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | uplodFileStates.remove(path); |
| | | } |
| | | } |
| | | } |
| | |
| | | }); |
| | | viewHolder.mIvDel.setVisibility(View.INVISIBLE); |
| | | viewHolder.circleProgressView.setVisibility(View.GONE); |
| | | viewHolder.maskLayerBg.setVisibility(View.GONE); |
| | | } else { |
| | | //删除图片 |
| | | viewHolder.mIvDel.setVisibility(View.VISIBLE); |
| | |
| | | } |
| | | |
| | | // 更新进度 |
| | | UplodFileState uplodFileState; |
| | | if (TextUtils.isEmpty(media.getCompressPath())) { |
| | | uplodFileState = fileStates.get(media.getRealPath()); |
| | | } else { |
| | | uplodFileState = fileStates.get(media.getCompressPath()); |
| | | } |
| | | |
| | | |
| | | UplodFileState uplodFileState = TextUtils.isEmpty(media.getCompressPath()) |
| | | ? fileStates.get(media.getRealPath()) |
| | | : fileStates.get(media.getCompressPath()); |
| | | if (uplodFileState != null) { |
| | | uplodFileState.setAdapterPosition(position); |
| | | MyLog.d("progressRequestBodyHolder>>>" + "State:" + uplodFileState.getState() + ">>>position:" + position + ">>>Progress: " + uplodFileState.getProgress()); |
| | | |
| | | if (uplodFileState.getState() == UplodFileState.STATE_UPDING) { |
| | | MyLog.d("progressRequestBodyHolder>>>" + "正在上传"); |
| | | viewHolder.postError.setVisibility(View.GONE); |
| | | if (uplodFileState.getProgress() < 100) { |
| | | viewHolder.maskLayerBg.setVisibility(View.VISIBLE); |
| | | viewHolder.circleProgressView.setVisibility(View.VISIBLE); |
| | |
| | | viewHolder.circleProgressView.setVisibility(View.GONE); |
| | | viewHolder.maskLayerBg.setVisibility(View.GONE); |
| | | } |
| | | } else if (fileStates.get(media.getCompressPath()).getState() == UplodFileState.STATE_DONE) { |
| | | } else if (uplodFileState.getState() == UplodFileState.STATE_DONE) { |
| | | MyLog.d("progressRequestBodyHolder>>>" + "完成"); |
| | | viewHolder.maskLayerBg.setVisibility(View.GONE); |
| | | viewHolder.circleProgressView.setVisibility(View.GONE); |
| | | } else { |
| | | MyLog.d("progressRequestBodyHolder>>>" + "错误"); |
| | | viewHolder.maskLayerBg.setVisibility(View.VISIBLE); |
| | | viewHolder.postError.setVisibility(View.VISIBLE); |
| | | viewHolder.circleProgressView.setVisibility(View.GONE); |
| | |
| | | int adapterPosition = viewHolder.getAbsoluteAdapterPosition(); |
| | | mItemClickListener.onItemClick(v, adapterPosition); |
| | | }); |
| | | viewHolder.postError.setOnClickListener(v -> { |
| | | mItemClickListener.onReUpload(uplodFileState); |
| | | }); |
| | | } |
| | | |
| | | if (mItemLongClickListener != null) { |
| | | viewHolder.itemView.setOnLongClickListener(v -> { |
| | | int adapterPosition = viewHolder.getAbsoluteAdapterPosition(); |
| | | int adapterPosition = viewHolder.getBindingAdapterPosition(); |
| | | mItemLongClickListener.onItemLongClick(viewHolder, adapterPosition, v); |
| | | return true; |
| | | }); |
| | |
| | | |
| | | // 更新进度参数 |
| | | if (fileStates.containsKey(uplodFileState.getFilePath())) { |
| | | // 获取已有的 UplodFileState 对象并更新进度 |
| | | UplodFileState existingState = fileStates.get(uplodFileState.getFilePath()); |
| | | int position = existingState.getAdapterPosition(); |
| | | existingState.setState(uplodFileState.getState()); |
| | | if (uplodFileState.getState() == 0) { |
| | | // 获取已有的 UplodFileState 对象并更新进度 |
| | | UplodFileState existingState = fileStates.get(uplodFileState.getFilePath()); |
| | | existingState.setState(uplodFileState.getState()); |
| | | existingState.setProgress(uplodFileState.getProgress()); // 更新进度 |
| | | // 获取进度更新项的位置 |
| | | int position = existingState.getAdapterPosition(); |
| | | if (position != RecyclerView.NO_POSITION) { |
| | | // 通知适配器刷新指定位置的项 |
| | | notifyItemChanged(position); |
| | | } |
| | | } else if (uplodFileState.getState() == 2) { |
| | | |
| | | } |
| | | |
| | | if (position != RecyclerView.NO_POSITION) { |
| | | notifyItemChanged(position); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | * @param position |
| | | */ |
| | | void onDeleteClick(int position); |
| | | |
| | | /** |
| | | * 上传失败后重新上传 |
| | | */ |
| | | void onReUpload(UplodFileState uplodFileState); |
| | | } |
| | | |
| | | private OnItemLongClickListener mItemLongClickListener; |
| | |
| | | public final static int STATE_DONE = 1; |
| | | //上传失败 |
| | | public final static int STATE_ERROR = 2; |
| | | //图片类型 |
| | | public final static int IMG_TYPE = 1; |
| | | //视频类型 |
| | | public final static int VIDEO_TYPE = 2; |
| | | |
| | | //0正在上传 1上传完成 2上传失败 |
| | | int state = 0; |
| | |
| | | int progress; |
| | | //adapter中的position |
| | | int adapterPosition = -1; |
| | | //上传类型 |
| | | int uploadType; |
| | | //扩展名 |
| | | String extName; |
| | | |
| | | public String getExtName() { |
| | | return extName; |
| | | } |
| | | |
| | | public void setExtName(String extName) { |
| | | this.extName = extName; |
| | | } |
| | | |
| | | public int getUploadType() { |
| | | return uploadType; |
| | | } |
| | | |
| | | public void setUploadType(int uploadType) { |
| | | this.uploadType = uploadType; |
| | | } |
| | | |
| | | public int getAdapterPosition() { |
| | | return adapterPosition; |
| | |
| | | public void setMapMarker(MarkerBean markerBean) { |
| | | if (markerBean != null) { |
| | | if (webViewIsFinished) { |
| | | mWebView.evaluateJavascript("javascript:addMarker(\"" + markerBean.getId() + "\",\"" + markerBean.getLng() + "\",\"" + markerBean.getLat() + "\",\"" + markerBean.getName() + "\")", new ValueCallback<String>() { |
| | | @Override |
| | | public void onReceiveValue(String value) { |
| | | } |
| | | }); |
| | | markerBeanSet.put(markerBean.getId(), markerBean); |
| | | |
| | | if (!TextUtils.isEmpty(markerBean.getLng()) && !TextUtils.isEmpty(markerBean.getLat())) { |
| | | mWebView.evaluateJavascript("javascript:addMarker(\"" + markerBean.getId() + "\",\"" + markerBean.getLng() + "\",\"" + markerBean.getLat() + "\",\"" + markerBean.getName() + "\")", new ValueCallback<String>() { |
| | | @Override |
| | | public void onReceiveValue(String value) { |
| | | } |
| | | }); |
| | | markerBeanSet.put(markerBean.getId(), markerBean); |
| | | } else { |
| | | MyLog.d("setMapMarker>" + markerBean.getName() + "经纬度为空"); |
| | | } |
| | | } else { |
| | | webNoFinishMarkerData.add(markerBean); |
| | | } |
| | |
| | | confirmDialog.show(); |
| | | }); |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | |
| | | package com.dayu.pipirrapp.net; |
| | | |
| | | import static com.dayu.pipirrapp.bean.net.UplodFileState.STATE_DONE; |
| | | import static com.dayu.pipirrapp.bean.net.UplodFileState.STATE_ERROR; |
| | | import static com.dayu.pipirrapp.bean.net.UplodFileState.STATE_UPDING; |
| | | import static com.luck.picture.lib.thread.PictureThreadUtils.runOnUiThread; |
| | | |
| | | import android.annotation.SuppressLint; |
| | |
| | | // } |
| | | |
| | | /** |
| | | * 上传文件 |
| | | * 上传图片文件 |
| | | * |
| | | * @param context |
| | | * @param uplodData |
| | | * @param listener |
| | | */ |
| | | public void uploadFile(final Context context, final UplodFileState uplodData, final UploadFileListener listener, final AddPictureAdapter adapter) { |
| | | MyLog.d("progressRequestBody>>>" + "path:" + uplodData.getFilePath()); |
| | | |
| | | if (!TextUtils.isEmpty(uplodData.getFilePath())) { |
| | | MyLog.d("progressRequestBody>>>" + "path:" + uplodData.getFilePath()+">>>uploadType:"+uplodData.getUploadType()); |
| | | uplodData.setState(STATE_UPDING); |
| | | File file = new File(uplodData.getFilePath()); |
| | | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
| | | ProgressRequestBody progressRequestBody = new ProgressRequestBody(requestBody, (bytesWritten, contentLength, done) -> { |
| | |
| | | }); |
| | | MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), progressRequestBody); |
| | | RequestBody description = RequestBody.create(MediaType.parse("text/plain"), "file description"); |
| | | Call<BaseResponse> uploadFile = apiService.uploadFile(body, description); |
| | | Call<BaseResponse> uploadFile = null; |
| | | switch (uplodData.getUploadType()) { |
| | | case UplodFileState.IMG_TYPE: |
| | | uploadFile = apiService.uploadImgFile(body, description); |
| | | break; |
| | | case UplodFileState.VIDEO_TYPE: |
| | | uploadFile = apiService.uploadVideoFile(body, description); |
| | | break; |
| | | default: |
| | | uploadFile = apiService.uploadImgFile(body, description); |
| | | break; |
| | | } |
| | | |
| | | uplodData.setThisCall(uploadFile); |
| | | uploadFile.enqueue(new Callback<BaseResponse>() { |
| | | @Override |
| | | public void onResponse(Call<BaseResponse> call, Response<BaseResponse> response) { |
| | | if (response.body() != null) { |
| | | if (response.body().isSuccess()) { |
| | | uplodData.setState(1); |
| | | uplodData.setState(STATE_DONE); |
| | | uplodData.setPostId(((LinkedTreeMap) response.body().getContent()).get("id").toString()); |
| | | uplodData.setWebPath(((LinkedTreeMap) response.body().getContent()).get("webPath").toString()); |
| | | listener.onBack(uplodData); |
| | | } else { |
| | | MyLog.d("progressRequestBody>>>" + response.body().getMsg()); |
| | | if (uplodData.getNumber() <= uplodFilerepeatSize) { |
| | | uplodData.setNumber(uplodData.getNumber() + 1); |
| | | uplodData.setState(2); |
| | | uplodData.setState(STATE_ERROR); |
| | | uploadFile(context, uplodData, listener, adapter); |
| | | } else { |
| | | uplodData.setState(STATE_ERROR); |
| | | uplodData.setNumber(0); |
| | | listener.onBack(uplodData); |
| | | } |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void onFailure(Call<BaseResponse> call, Throwable t) { |
| | | MyLog.d("progressRequestBody>>>" + "onFailure:"); |
| | | if (uplodData.getNumber() <= uplodFilerepeatSize) { |
| | | uplodData.setNumber(uplodData.getNumber() + 1); |
| | | uplodData.setState(2); |
| | | uploadFile(context, uplodData, listener, adapter); |
| | | } else { |
| | | listener.onBack(uplodData); |
| | | MyLog.d("progressRequestBody>>>" + "onFailure:" + t.getMessage()); |
| | | if (!t.getMessage().equals("Canceled")) { |
| | | uplodData.setState(STATE_ERROR); |
| | | if (uplodData.getNumber() <= uplodFilerepeatSize) { |
| | | uplodData.setNumber(uplodData.getNumber() + 1); |
| | | uploadFile(context, uplodData, listener, adapter); |
| | | } else { |
| | | uplodData.setNumber(0); |
| | | listener.onBack(uplodData); |
| | | } |
| | | } |
| | | |
| | | } |
| | | }); |
| | | } else { |
| | | uplodData.setState(UplodFileState.STATE_ERROR); |
| | | uplodData.setState(STATE_ERROR); |
| | | listener.onBack(uplodData); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | Observable<BaseResponse> requestPost(@Url String url, @Body Map<String, Object> params); |
| | | |
| | | @GET() |
| | | Observable<BaseResponse> requestGet(@Url String url, @QueryMap Map<String, Object> params,@Header("token") String token); |
| | | Observable<BaseResponse> requestGet(@Url String url, @QueryMap Map<String, Object> params, @Header("token") String token); |
| | | |
| | | @GET() |
| | | Observable<BaseResponse> requestGet(@Url String url); |
| | |
| | | Call<BaseResponse> uploadFiles(@PartMap Map<String, RequestBody> map); |
| | | |
| | | @Multipart |
| | | @POST(Constants.BASE_URL + "/app/webFile/upPhoto") |
| | | Call<BaseResponse> uploadFile(@Part MultipartBody.Part file,@Part("description") RequestBody description); |
| | | @POST(Constants.BASE_UPLOAD_FILE_URL + "/app/webFile/upPhoto") |
| | | Call<BaseResponse> uploadImgFile(@Part MultipartBody.Part file, @Part("description") RequestBody description); |
| | | |
| | | @Multipart |
| | | @POST(Constants.BASE_UPLOAD_FILE_URL + "/app/webFile/upVideo") |
| | | Call<BaseResponse> uploadVideoFile(@Part MultipartBody.Part file, @Part("description") RequestBody description); |
| | | |
| | | //获取验证码 |
| | | @GET(Constants.BASE_URL+"/app/captcha/get") |
| | | @GET(Constants.BASE_URL + "/app/captcha/get") |
| | | Observable<CodeResult> getCode(@QueryMap Map<String, Object> params); |
| | | |
| | | @GET() |
| | |
| | | * Description: |
| | | */ |
| | | public class Constants { |
| | | // public static final String BASE_URL = "http://192.168.10.52:8088"; |
| | | public static final String BASE_URL = "https://no253541tf71.vicp.fun"; |
| | | //public static final String BASE_URL = "http://fve2iz.natappfree.cc"; |
| | | // public static final String BASE_URL = "http://192.168.10.52:8088"; |
| | | public static final String BASE_URL = "https://no253541tf71.vicp.fun"; |
| | | //public static final String BASE_URL = "http://fve2iz.natappfree.cc"; |
| | | public static final String BASE_UPLOAD_FILE_URL = "https://no253541tf71.vicp.fun"; |
| | | /** |
| | | * 代表请求成功 |
| | | */ |
| | |
| | | package com.dayu.pipirrapp.net; |
| | | |
| | | |
| | | import com.dayu.pipirrapp.BuildConfig; |
| | | |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import okhttp3.OkHttpClient; |
| | |
| | | builder.addInterceptor(new MyIntercepterApplication()); |
| | | //添加日志拦截器 |
| | | //添加数据请求统一处理拦截器 |
| | | // if (BuildConfig.DEBUG) { |
| | | if (BuildConfig.DEBUG) { |
| | | builder.addInterceptor(loggingInterceptor); |
| | | // } |
| | | } |
| | | |
| | | OkHttpClient client = builder.build(); |
| | | // // 创建GsonBuilder并设置长整型序列化策略为字符串 |
New file |
| | |
| | | package com.dayu.pipirrapp.tool; |
| | | |
| | | import android.content.Context; |
| | | |
| | | import com.dayu.pipirrapp.adapter.AddPictureAdapter; |
| | | import com.dayu.pipirrapp.bean.net.UplodFileState; |
| | | import com.dayu.pipirrapp.net.ApiManager; |
| | | import com.dayu.pipirrapp.net.BaseResponse; |
| | | import com.dayu.pipirrapp.net.upload.UploadFileListener; |
| | | |
| | | import java.util.Map; |
| | | |
| | | import retrofit2.Call; |
| | | |
| | | /** |
| | | * FileUploadUtils - |
| | | * |
| | | * @author zuoxiao |
| | | * @version 1.0 |
| | | * @since 2025-01-03 |
| | | */ |
| | | public class FileUploadUtils { |
| | | |
| | | |
| | | /** |
| | | * 上传图片文件 |
| | | * |
| | | * @param context |
| | | * @param uplodFileState |
| | | * @param uplodFileStates |
| | | * @param adapter |
| | | */ |
| | | public static void uploadFile(Context context, UplodFileState uplodFileState, Map<String, UplodFileState> uplodFileStates, AddPictureAdapter adapter) { |
| | | ApiManager.getInstance().uploadFile(context, uplodFileState, state -> { |
| | | uplodFileStates.replace(state.getFilePath(), state); |
| | | adapter.updateProgress(uplodFileState); |
| | | }, adapter); |
| | | } |
| | | |
| | | /** |
| | | * 当关闭activity时关闭所有请求 |
| | | * @param uplodFileStates |
| | | */ |
| | | public static void cancelAllCall(Map<String, UplodFileState> uplodFileStates){ |
| | | try { |
| | | for(UplodFileState uplodFileState:uplodFileStates.values()){ |
| | | Call<BaseResponse> mCall =uplodFileState.getThisCall(); |
| | | if (mCall != null) { |
| | | mCall.cancel(); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | public static void showToastShort(Context context, String s) { |
| | | if (s != null) { |
| | | if (!TextUtils.isEmpty(s)) |
| | | makeText(context, s, Toast.LENGTH_SHORT).show(); |
| | | |
| | | if (!TextUtils.isEmpty(s)) { |
| | | if (context != null) { |
| | | if (!TextUtils.isEmpty(context.getPackageName())) { |
| | | makeText(context, s, Toast.LENGTH_SHORT).show(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | public static void showToastLong(Context context, String s) { |
| | | if (!TextUtils.isEmpty(s)) { |
| | | makeText(context, s, Toast.LENGTH_LONG).show(); |
| | | if (context != null) { |
| | | if (!TextUtils.isEmpty(context.getPackageName())) { |
| | | makeText(context, s, Toast.LENGTH_LONG).show(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static void showToast(Context context, String s) { |
| | | if (s != null) { |
| | | makeText(context, s, Toast.LENGTH_LONG).show(); |
| | | if (context != null) { |
| | | if (!TextUtils.isEmpty(context.getPackageName())) { |
| | | makeText(context, s, Toast.LENGTH_LONG).show(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | android:layout_marginTop="10dp" |
| | | android:background="@color/white" |
| | | android:hint="请输入旧密码" |
| | | android:maxLines="1" |
| | | android:paddingLeft="20dp" |
| | | android:paddingRight="20dp" /> |
| | | android:paddingRight="20dp" |
| | | android:singleLine="true" /> |
| | | |
| | | |
| | | <TextView |
| | |
| | | android:background="@color/white" |
| | | android:hint="请输入新密码" |
| | | android:inputType="textPassword" |
| | | android:maxLines="1" |
| | | android:paddingLeft="20dp" |
| | | android:paddingRight="20dp" /> |
| | | android:paddingRight="20dp" |
| | | android:singleLine="true" /> |
| | | |
| | | <EditText |
| | | android:id="@+id/newPsTwo" |
| | |
| | | android:background="@color/white" |
| | | android:hint="再次输入新密码" |
| | | android:inputType="textPassword" |
| | | android:maxLines="1" |
| | | android:paddingLeft="20dp" |
| | | android:paddingRight="20dp" /> |
| | | android:paddingRight="20dp" |
| | | android:singleLine="true" /> |
| | | |
| | | |
| | | <TextView |
| | |
| | | android:layout_height="match_parent" |
| | | tools:src="@color/app_color_f6" /> |
| | | |
| | | <ImageView |
| | | android:id="@+id/iv_del" |
| | | android:layout_width="wrap_content" |
| | | android:layout_height="wrap_content" |
| | | android:layout_alignTop="@id/fiv" |
| | | android:layout_alignRight="@id/fiv" |
| | | android:paddingLeft="10dp" |
| | | android:paddingBottom="10dp" |
| | | android:scaleType="centerInside" |
| | | android:src="@mipmap/ic_item_delete" |
| | | android:visibility="gone" |
| | | tools:visibility="visible" /> |
| | | |
| | | |
| | | <TextView |
| | | android:id="@+id/tv_duration" |
| | |
| | | android:id="@+id/mask_layer_bg" |
| | | android:layout_width="match_parent" |
| | | android:layout_height="match_parent" |
| | | android:visibility="gone" |
| | | android:background="@color/mask_layer_bg"> |
| | | |
| | | <com.king.view.circleprogressview.CircleProgressView |
| | |
| | | android:layout_height="wrap_content" |
| | | android:layout_centerHorizontal="true" |
| | | android:layout_centerVertical="true" |
| | | app:cpvLabelTextSize="15sp" |
| | | app:cpvShowTick="false" |
| | | app:cpvStrokeWidth="2dp" /> |
| | | |
| | |
| | | android:id="@+id/postError" |
| | | android:layout_width="match_parent" |
| | | android:layout_height="match_parent" |
| | | android:layout_margin="40dp" |
| | | android:padding="20dp" |
| | | android:src="@drawable/ic_error_picture" /> |
| | | </RelativeLayout> |
| | | |
| | | |
| | | <ImageView |
| | | android:id="@+id/iv_del" |
| | | android:layout_width="wrap_content" |
| | | android:layout_height="wrap_content" |
| | | android:layout_alignTop="@id/fiv" |
| | | android:layout_alignRight="@id/fiv" |
| | | android:paddingLeft="10dp" |
| | | android:paddingBottom="10dp" |
| | | android:scaleType="centerInside" |
| | | android:src="@mipmap/ic_item_delete" |
| | | android:visibility="gone" |
| | | tools:visibility="visible" /> |
| | | </com.luck.picture.lib.widget.SquareRelativeLayout> |