|
@@ -0,0 +1,300 @@
|
|
|
+package com.zkjc.policedemo.mvp.ui.activity;
|
|
|
+
|
|
|
+import android.content.Intent;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.Button;
|
|
|
+import android.widget.EditText;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
+import androidx.recyclerview.widget.RecyclerView;
|
|
|
+
|
|
|
+import com.google.gson.JsonObject;
|
|
|
+import com.google.gson.JsonParser;
|
|
|
+import com.hjq.toast.ToastUtils;
|
|
|
+import com.jess.arms.base.BaseActivity;
|
|
|
+import com.jess.arms.di.component.AppComponent;
|
|
|
+import com.jess.arms.utils.ArmsUtils;
|
|
|
+
|
|
|
+import com.lzy.imagepicker.ImagePicker;
|
|
|
+import com.lzy.imagepicker.bean.ImageItem;
|
|
|
+import com.lzy.imagepicker.ui.ImageGridActivity;
|
|
|
+import com.lzy.imagepicker.ui.ImagePreviewDelActivity;
|
|
|
+import com.lzy.imagepicker.view.CropImageView;
|
|
|
+import com.zkjc.common.base.ZkjcBaseActivity;
|
|
|
+import com.zkjc.common.utils.ApkUtils;
|
|
|
+import com.zkjc.common.utils.BitmapUtils;
|
|
|
+import com.zkjc.common.utils.Utils;
|
|
|
+import com.zkjc.common.view.CommonTitleBarV3;
|
|
|
+import com.zkjc.policedemo.app.utils.CommonInterFace;
|
|
|
+import com.zkjc.policedemo.app.utils.GlideImageLoader;
|
|
|
+import com.zkjc.policedemo.app.utils.UploadUtil;
|
|
|
+import com.zkjc.policedemo.di.component.DaggerAqffxcComponent;
|
|
|
+import com.zkjc.policedemo.mvp.contract.AqffxcContract;
|
|
|
+import com.zkjc.policedemo.mvp.model.entity.Aqffxc;
|
|
|
+import com.zkjc.policedemo.mvp.model.entity.RhzfEntity;
|
|
|
+import com.zkjc.policedemo.mvp.model.entity.Wtfy;
|
|
|
+import com.zkjc.policedemo.mvp.presenter.AqffxcPresenter;
|
|
|
+
|
|
|
+import com.zkjc.policedemo.R;
|
|
|
+import com.zkjc.policedemo.mvp.ui.adapter.WtfyAdapter;
|
|
|
+
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.Serializable;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import butterknife.BindView;
|
|
|
+
|
|
|
+import static com.jess.arms.utils.Preconditions.checkNotNull;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * ================================================
|
|
|
+ * Description:
|
|
|
+ * <p>
|
|
|
+ * Created by MVPArmsTemplate on 11/15/2024 14:52
|
|
|
+ * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
|
|
|
+ * <a href="https://github.com/JessYanCoding">Follow me</a>
|
|
|
+ * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
|
|
|
+ * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
|
|
|
+ * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
|
|
|
+ * ================================================
|
|
|
+ */
|
|
|
+public class AqffxcActivity extends ZkjcBaseActivity<AqffxcPresenter> implements AqffxcContract.View, WtfyAdapter.OnRecyclerViewItemClickListener {
|
|
|
+
|
|
|
+ private static final int IMAGE_ITEM_ADD = -1;
|
|
|
+ @BindView(R.id.title_bar)
|
|
|
+ CommonTitleBarV3 titleBar;
|
|
|
+ @BindView(R.id.wtfy_zp)
|
|
|
+ RecyclerView wtfyZp;
|
|
|
+ @BindView(R.id.et_fynr)
|
|
|
+ EditText etFynr;
|
|
|
+ @BindView(R.id.bt_commit)
|
|
|
+ Button btCommit;
|
|
|
+
|
|
|
+ private int maxImgCount = 9;
|
|
|
+ private List<String> urls = new ArrayList<>();
|
|
|
+ private ArrayList<ImageItem> wtlImageList; //当前选择的所有图片
|
|
|
+ private WtfyAdapter wtfyAdapter;
|
|
|
+ public static final int REQUEST_CODE_SELECT_WT = 1002;
|
|
|
+ public static final int REQUEST_CODE_PREVIEW_WT = 1003;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setupActivityComponent(@NonNull AppComponent appComponent) {
|
|
|
+ DaggerAqffxcComponent //如找不到该类,请编译一下项目
|
|
|
+ .builder()
|
|
|
+ .appComponent(appComponent)
|
|
|
+ .view(this)
|
|
|
+ .build()
|
|
|
+ .inject(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int initView(@Nullable Bundle savedInstanceState) {
|
|
|
+ return R.layout.activity_aqffxc; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initData(@Nullable Bundle savedInstanceState) {
|
|
|
+ titleBar.setTitle("安全防范宣传");
|
|
|
+ initImagePicker();
|
|
|
+ wtlImageList = new ArrayList<>();
|
|
|
+ wtfyAdapter = new WtfyAdapter(this, wtlImageList, maxImgCount);
|
|
|
+ wtfyAdapter.setOnItemClickListener(this);
|
|
|
+ wtfyZp.setLayoutManager(new GridLayoutManager(this, 3));
|
|
|
+ wtfyZp.setHasFixedSize(true);
|
|
|
+ wtfyZp.setAdapter(wtfyAdapter);
|
|
|
+ btCommit.setOnClickListener(v -> {
|
|
|
+ if (urls.size() < wtlImageList.size()) {
|
|
|
+ ToastUtils.show("正在上传图片,请稍后保存");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (TextUtils.isEmpty(etFynr.getText().toString())) {
|
|
|
+ ToastUtils.show("请填写宣传内容");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("id", getIntent().getStringExtra("id"));
|
|
|
+ map.put("dzbm", getIntent().getStringExtra("dzbm"));
|
|
|
+ Aqffxc aqffxc = new Aqffxc();
|
|
|
+ aqffxc.setXcnr(etFynr.getText().toString());
|
|
|
+ StringBuffer sbzp = new StringBuffer();
|
|
|
+ for (int i = 0; i < urls.size(); i++) {
|
|
|
+
|
|
|
+ if (i == urls.size() - 1) {
|
|
|
+ sbzp.append(urls.get(i));
|
|
|
+ } else {
|
|
|
+ sbzp.append(urls.get(i)).append(",");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ aqffxc.setFj(sbzp.toString());
|
|
|
+ map.put("aqxcff", aqffxc);
|
|
|
+ Utils.getInstances().showDialog(AqffxcActivity.this, "上传中");
|
|
|
+ mPresenter.commitRhxx(map);
|
|
|
+ });
|
|
|
+ Aqffxc aqffxc = (Aqffxc) getIntent().getSerializableExtra("aqffxc");
|
|
|
+ if (aqffxc != null) {
|
|
|
+ btCommit.setVisibility(View.GONE);
|
|
|
+ etFynr.setText(aqffxc.getXcnr());
|
|
|
+ String imgs = aqffxc.getFj();
|
|
|
+ if (!TextUtils.isEmpty(imgs)) {
|
|
|
+ String[] split = imgs.split(",");
|
|
|
+ for (String str: split) {
|
|
|
+ ImageItem imageItem = new ImageItem();
|
|
|
+ imageItem.path = str;
|
|
|
+ wtlImageList.add(imageItem);
|
|
|
+ urls.add(str);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ wtfyAdapter.setImages(wtlImageList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initImagePicker() {
|
|
|
+ ImagePicker imagePicker = ImagePicker.getInstance();
|
|
|
+ imagePicker.setImageLoader(new GlideImageLoader()); //设置图片加载器
|
|
|
+ imagePicker.setShowCamera(true); //显示拍照按钮
|
|
|
+ imagePicker.setCrop(true); //允许裁剪(单选才有效)
|
|
|
+ imagePicker.setSaveRectangle(true); //是否按矩形区域保存
|
|
|
+ imagePicker.setSelectLimit(maxImgCount); //选中数量限制
|
|
|
+ imagePicker.setMultiMode(false); //多选
|
|
|
+ imagePicker.setStyle(CropImageView.Style.RECTANGLE); //裁剪框的形状
|
|
|
+ imagePicker.setFocusWidth(1000); //裁剪框的宽度。单位像素(圆形自动取宽高最小值)
|
|
|
+ imagePicker.setFocusHeight(1600); //裁剪框的高度。单位像素(圆形自动取宽高最小值)
|
|
|
+ imagePicker.setOutPutX(1000); //保存文件的宽度。单位像素
|
|
|
+ imagePicker.setOutPutY(1000); //保存文件的高度。单位像素
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void showLoading() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void hideLoading() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showMessage(@NonNull String message) {
|
|
|
+ checkNotNull(message);
|
|
|
+ ArmsUtils.snackbarText(message);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void launchActivity(@NonNull Intent intent) {
|
|
|
+ checkNotNull(intent);
|
|
|
+ ArmsUtils.startActivity(intent);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void killMyself() {
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+
|
|
|
+
|
|
|
+ if (resultCode == ImagePicker.RESULT_CODE_ITEMS) {
|
|
|
+ //添加图片返回
|
|
|
+ if (data != null && requestCode == REQUEST_CODE_SELECT_WT) {
|
|
|
+ ArrayList<ImageItem> images = (ArrayList<ImageItem>) data.getSerializableExtra(ImagePicker.EXTRA_RESULT_ITEMS);
|
|
|
+ if (images != null) {
|
|
|
+ wtlImageList.addAll(images);
|
|
|
+ for (int i = 0; i < wtlImageList.size(); i++) {
|
|
|
+ String path = wtlImageList.get(i).path;
|
|
|
+ System.out.println(i + "图片路径" + path);
|
|
|
+ String s = BitmapUtils.fileToBase64(new File(path));
|
|
|
+ // photos.add("data:image/jpeg;base64," + s);
|
|
|
+ }
|
|
|
+ wtfyAdapter.setImages(wtlImageList);
|
|
|
+ uploadImage(wtlImageList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (resultCode == ImagePicker.RESULT_CODE_BACK) {
|
|
|
+ //预览图片返回
|
|
|
+
|
|
|
+ if (data != null && requestCode == REQUEST_CODE_PREVIEW_WT) {
|
|
|
+ ArrayList<ImageItem> images = (ArrayList<ImageItem>) data.getSerializableExtra(ImagePicker.EXTRA_IMAGE_ITEMS);
|
|
|
+ if (images != null) {
|
|
|
+ wtlImageList.clear();
|
|
|
+ urls.clear();
|
|
|
+ wtlImageList.addAll(images);
|
|
|
+ wtfyAdapter.setImages(wtlImageList);
|
|
|
+ uploadImage(wtlImageList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ private void uploadImage(ArrayList<ImageItem> wtlImageList) {
|
|
|
+ urls.clear();
|
|
|
+ if (wtlImageList.size() > 0) {
|
|
|
+ for (int i = 0; i < wtlImageList.size(); i++) {
|
|
|
+ if (wtlImageList.get(i).path.contains("http")) {
|
|
|
+ urls.add(wtlImageList.get(i).path);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ UploadUtil.getInstance().init(AqffxcActivity.this).getRequest(wtlImageList.get(i).path, new CommonInterFace() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(String result) {
|
|
|
+
|
|
|
+ JsonObject jsonObject1 = new JsonParser().parse(result).getAsJsonObject();
|
|
|
+ JsonObject jsonObject = jsonObject1.get("data").getAsJsonObject();
|
|
|
+ if (jsonObject.has("link")) {
|
|
|
+ String url = jsonObject.get("link").getAsString();
|
|
|
+ urls.add(url);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(Throwable throwable) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFinsh() {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void onItemClickwtfy(View view, int position) {
|
|
|
+ switch (position) {
|
|
|
+ case IMAGE_ITEM_ADD:
|
|
|
+ ImagePicker.getInstance().setSelectLimit(maxImgCount - wtlImageList.size());
|
|
|
+ Intent intent = new Intent(this, ImageGridActivity.class);
|
|
|
+ //intent.putExtra(ImageGridActivity.EXTRAS_IMAGES,(ArrayList<ImageItem>) adapter.getImages());
|
|
|
+ // intent.putExtra(ImageGridActivity.EXTRAS_TAKE_PICKERS, true);
|
|
|
+ intent.putExtra(ImageGridActivity.EXTRAS_IMAGES, (ArrayList<ImageItem>) wtfyAdapter.getImages());
|
|
|
+
|
|
|
+ startActivityForResult(intent, REQUEST_CODE_SELECT_WT);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ //打开预览
|
|
|
+ Intent intentPreview = new Intent(this, ImagePreviewDelActivity.class);
|
|
|
+ intentPreview.putExtra(ImagePicker.EXTRA_IMAGE_ITEMS, (ArrayList<ImageItem>) wtfyAdapter.getImages());
|
|
|
+ intentPreview.putExtra(ImagePicker.EXTRA_SELECTED_IMAGE_POSITION, position);
|
|
|
+ intentPreview.putExtra(ImagePicker.EXTRA_FROM_ITEMS, true);
|
|
|
+ startActivityForResult(intentPreview, REQUEST_CODE_PREVIEW_WT);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCommitSuccess(RhzfEntity.Room data) {
|
|
|
+ setResult(RESULT_OK);
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+}
|