|
@@ -0,0 +1,398 @@
|
|
|
+package com.cooleshow.usercenter.ui.activity.setting;
|
|
|
+
|
|
|
+import android.Manifest;
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.Intent;
|
|
|
+import android.graphics.Color;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.os.Parcelable;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.alibaba.android.arouter.facade.annotation.Route;
|
|
|
+import com.alibaba.android.arouter.launcher.ARouter;
|
|
|
+import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
|
|
|
+import com.bigkoo.pickerview.view.OptionsPickerView;
|
|
|
+import com.chad.library.adapter.base.BaseQuickAdapter;
|
|
|
+import com.chad.library.adapter.base.listener.OnItemChildClickListener;
|
|
|
+import com.chad.library.adapter.base.listener.OnItemClickListener;
|
|
|
+import com.cooleshow.base.bean.ServiceContactBean;
|
|
|
+import com.cooleshow.base.constanst.StyleConfig;
|
|
|
+import com.cooleshow.base.constanst.UploadConstants;
|
|
|
+import com.cooleshow.base.router.RouterPath;
|
|
|
+import com.cooleshow.base.ui.activity.BaseMVPActivity;
|
|
|
+import com.cooleshow.base.utils.JumpUtils;
|
|
|
+import com.cooleshow.base.utils.ToastUtil;
|
|
|
+import com.cooleshow.base.utils.helper.GlideEngine;
|
|
|
+import com.cooleshow.base.utils.helper.QMUIDeviceHelper;
|
|
|
+import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
|
|
|
+import com.cooleshow.base.utils.helper.upload.UploadHelper;
|
|
|
+import com.cooleshow.usercenter.R;
|
|
|
+import com.cooleshow.usercenter.adapter.FeedBackAddPhotoListAdapter;
|
|
|
+import com.cooleshow.usercenter.bean.FeedBackTypeBean;
|
|
|
+import com.cooleshow.usercenter.databinding.ActivityFeedbackLayoutBinding;
|
|
|
+import com.cooleshow.usercenter.presenter.FeedBackPresenter;
|
|
|
+import com.cooleshow.usercenter.presenter.contract.FeedBackContract;
|
|
|
+import com.luck.picture.lib.PictureSelector;
|
|
|
+import com.luck.picture.lib.config.PictureConfig;
|
|
|
+import com.luck.picture.lib.config.PictureMimeType;
|
|
|
+import com.luck.picture.lib.entity.LocalMedia;
|
|
|
+import com.tbruyelle.rxpermissions3.RxPermissions;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
+import androidx.recyclerview.widget.RecyclerView;
|
|
|
+
|
|
|
+
|
|
|
+ * 创建日期:2022/5/18 16:25
|
|
|
+ *
|
|
|
+ * @author Ryan
|
|
|
+ * 类说明:
|
|
|
+ */
|
|
|
+@Route(path = RouterPath.UserCenter.MINE_FEEDBACK)
|
|
|
+public class FeedBackActivity extends BaseMVPActivity<ActivityFeedbackLayoutBinding, FeedBackPresenter> implements FeedBackContract.FeedBackView, View.OnClickListener {
|
|
|
+ private OptionsPickerView pvOptions;
|
|
|
+ private int currentSelectTypePosition = -1;
|
|
|
+ private int maxSelectNum = 5;
|
|
|
+ private String currentSelectTypeId;
|
|
|
+
|
|
|
+ private ArrayList<FeedBackTypeBean.RowsBean> types = new ArrayList<>();
|
|
|
+ private FeedBackAddPhotoListAdapter mPhotoListAdapter;
|
|
|
+
|
|
|
+ List<String> urlList = new ArrayList<>();
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
+ StyleConfig.setTheme(this);
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ QMUIStatusBarHelper.setStatusBarLightMode(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ int id = view.getId();
|
|
|
+ if (id == R.id.tv_submit) {
|
|
|
+ String content = getContent();
|
|
|
+ if (TextUtils.isEmpty(content)) {
|
|
|
+ ToastUtil.getInstance().showShort("请输入您的反馈意见");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (TextUtils.isEmpty(currentSelectTypeId)) {
|
|
|
+ ToastUtil.getInstance().showShort("请选择反馈类型");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int selectSize = getSelectSize();
|
|
|
+ if (selectSize > 0) {
|
|
|
+ uploadImg(selectSize);
|
|
|
+ } else {
|
|
|
+ presenter.addSuggestion(content, "", currentSelectTypeId, "");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (id == R.id.cs_type) {
|
|
|
+ showTypeFilter();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (id == com.cooleshow.base.R.id.tv_right_text) {
|
|
|
+ ARouter.getInstance().build(RouterPath.UserCenter.MINE_FEEDBACK_RECORD)
|
|
|
+ .navigation();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initView() {
|
|
|
+ initMidTitleToolBar(viewBinding.toolbarInclude.toolbar, "意见反馈");
|
|
|
+ viewBinding.toolbarInclude.tvRightText.setVisibility(View.VISIBLE);
|
|
|
+ viewBinding.toolbarInclude.tvRightText.setText("反馈记录");
|
|
|
+ viewBinding.toolbarInclude.tvRightText.setOnClickListener(this);
|
|
|
+ viewBinding.tvSubmit.setOnClickListener(this);
|
|
|
+ viewBinding.csType.setOnClickListener(this);
|
|
|
+ mPhotoListAdapter = new FeedBackAddPhotoListAdapter();
|
|
|
+ RecyclerView.LayoutManager layoutManager;
|
|
|
+ if(QMUIDeviceHelper.isTablet(getApplicationContext())){
|
|
|
+ layoutManager =new LinearLayoutManager(this, RecyclerView.HORIZONTAL,false);
|
|
|
+ }else{
|
|
|
+ layoutManager = new GridLayoutManager(this, 4);
|
|
|
+ }
|
|
|
+ viewBinding.recyclerView.setLayoutManager(layoutManager);
|
|
|
+ addNewEmpty();
|
|
|
+ viewBinding.recyclerView.setAdapter(mPhotoListAdapter);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initData() {
|
|
|
+ super.initData();
|
|
|
+ initListener();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void uploadImg(int enableSelectSize) {
|
|
|
+ urlList.clear();
|
|
|
+ for (int i = 0; i < mPhotoListAdapter.getData().size(); i++) {
|
|
|
+ String compressPath = mPhotoListAdapter.getData().get(i).getCompressPath();
|
|
|
+ if (!TextUtils.isEmpty(compressPath)) {
|
|
|
+ upLoadVideo(this, compressPath, enableSelectSize);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initListener() {
|
|
|
+ mPhotoListAdapter.setOnItemClickListener(new OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
|
|
|
+ LocalMedia item = (LocalMedia) adapter.getItem(position);
|
|
|
+ if (item.getPath().equals("123")) {
|
|
|
+ toSelectPic();
|
|
|
+ } else {
|
|
|
+ JumpUtils.startPhotoPreview(FeedBackActivity.this,getImages(),position,100);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ mPhotoListAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemChildClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
|
|
|
+ if (position < mPhotoListAdapter.getData().size()) {
|
|
|
+ LocalMedia localMedia = mPhotoListAdapter.getData().get(position);
|
|
|
+ if (view.getId() == R.id.iv_del) {
|
|
|
+ mPhotoListAdapter.remove(localMedia);
|
|
|
+ addNewEmpty();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void toSelectPic() {
|
|
|
+ new RxPermissions(this)
|
|
|
+ .request(Manifest.permission.CAMERA,
|
|
|
+ Manifest.permission.READ_EXTERNAL_STORAGE,
|
|
|
+ Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
|
|
+ .subscribe(granted -> {
|
|
|
+ if (granted) {
|
|
|
+ goAlbum();
|
|
|
+ } else {
|
|
|
+ ToastUtil.getInstance().show(this, "请打开存储和相机权限!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void goAlbum() {
|
|
|
+ PictureSelector.create(FeedBackActivity.this)
|
|
|
+ .openGallery(PictureMimeType.ofImage())
|
|
|
+ .loadImageEngine(GlideEngine.createGlideEngine())
|
|
|
+ .theme(com.cooleshow.base.R.style.picture_daya_style)
|
|
|
+ .selectionMode(PictureConfig.MULTIPLE)
|
|
|
+ .maxSelectNum(maxSelectNum + 1 - mPhotoListAdapter.getData().size())
|
|
|
+ .compress(true)
|
|
|
+ .forResult(PictureConfig.CHOOSE_REQUEST);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public int getSelectSize() {
|
|
|
+ int count = 0;
|
|
|
+ for (int i = 0; i < mPhotoListAdapter.getData().size(); i++) {
|
|
|
+ LocalMedia localMedia = mPhotoListAdapter.getData().get(i);
|
|
|
+ if (!TextUtils.isEmpty(localMedia.getCompressPath())) {
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addNewEmpty() {
|
|
|
+ if (hasEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ LocalMedia localMedia = new LocalMedia();
|
|
|
+ localMedia.setPath("123");
|
|
|
+ mPhotoListAdapter.getData().add(localMedia);
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean hasEmpty() {
|
|
|
+ for (int i = 0; i < mPhotoListAdapter.getData().size(); i++) {
|
|
|
+ LocalMedia localMedia = mPhotoListAdapter.getData().get(i);
|
|
|
+ if (TextUtils.equals(localMedia.getPath(), "123")) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void upLoadVideo(Activity activity, String filePath, int enableSelectSize) {
|
|
|
+ UploadHelper uploadHelper = new UploadHelper(activity, UploadConstants.UPLOAD_TYPE_OTHER);
|
|
|
+ uploadHelper.uploadFile(new File(filePath));
|
|
|
+ uploadHelper.setUpLoadCallBack(new UploadHelper.UpLoadCallBack() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(String url) {
|
|
|
+ urlList.add(url);
|
|
|
+ if (urlList.size() == enableSelectSize) {
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ for (int i = 0; i < urlList.size(); i++) {
|
|
|
+ stringBuilder.append(urlList.get(i));
|
|
|
+ if (i != urlList.size() - 1) {
|
|
|
+ stringBuilder.append(",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ presenter.addSuggestion(getContent(), "", currentSelectTypeId, stringBuilder.toString());
|
|
|
+ urlList.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailure() {
|
|
|
+ ToastUtil.getInstance().showShort("上传失败,请重试");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getContent() {
|
|
|
+ return viewBinding.etContent.getText().toString().trim();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected ActivityFeedbackLayoutBinding getLayoutView() {
|
|
|
+ return ActivityFeedbackLayoutBinding.inflate(getLayoutInflater());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ presenter.getCustomerServiceContact();
|
|
|
+ presenter.getSuggestionType();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected FeedBackPresenter createPresenter() {
|
|
|
+ return new FeedBackPresenter();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addSuggestionSuccess(Object object) {
|
|
|
+ ToastUtil.getInstance().showShort("提交成功");
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getCustomerServiceContactSuccess(ServiceContactBean data) {
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (data != null) {
|
|
|
+ viewBinding.tvContactText.setText(getString(R.string.custom_service_tip, data.getPhone(), data.getEmail()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getSuggestionTypeSuccess(FeedBackTypeBean data) {
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (data != null && data.getRows() != null) {
|
|
|
+ types.clear();
|
|
|
+ types.addAll(data.getRows());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void showTypeFilter() {
|
|
|
+ if (types.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ pvOptions = new OptionsPickerBuilder(this, (options1, options2, options3, v) -> {
|
|
|
+ this.currentSelectTypePosition = options1;
|
|
|
+ FeedBackTypeBean.RowsBean rowsBean = types.get(options1);
|
|
|
+ viewBinding.tvFeedbackType.setText(rowsBean.getText());
|
|
|
+ viewBinding.tvFeedbackType.setTextColor(getResources().getColor(com.cooleshow.base.R.color.color_333333));
|
|
|
+ currentSelectTypeId = rowsBean.getId();
|
|
|
+ }).setLayoutRes(com.cooleshow.base.R.layout.pickerview_options_default_layout, v -> {
|
|
|
+
|
|
|
+ final TextView tvSubmit = (TextView) v.findViewById(com.cooleshow.base.R.id.tv_finish);
|
|
|
+ TextView ivCancel = (TextView) v.findViewById(com.cooleshow.base.R.id.tv_cancel);
|
|
|
+ tvSubmit.setOnClickListener(v12 -> {
|
|
|
+ pvOptions.returnData();
|
|
|
+ pvOptions.dismiss();
|
|
|
+ });
|
|
|
+ ivCancel.setOnClickListener(v1 -> pvOptions.dismiss());
|
|
|
+
|
|
|
+ }).setDividerColor(Color.TRANSPARENT)
|
|
|
+ .setBgColor(Color.TRANSPARENT).isDialog(false).build();
|
|
|
+
|
|
|
+ pvOptions.setPicker(types);
|
|
|
+ if (currentSelectTypePosition != -1 && currentSelectTypePosition < types.size()) {
|
|
|
+ pvOptions.setSelectOptions(currentSelectTypePosition);
|
|
|
+ }
|
|
|
+ pvOptions.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+ if (resultCode == RESULT_OK) {
|
|
|
+ switch (requestCode) {
|
|
|
+ case PictureConfig.CHOOSE_REQUEST:
|
|
|
+
|
|
|
+ List<LocalMedia> list = PictureSelector.obtainMultipleResult(data);
|
|
|
+ mPhotoListAdapter.getData().addAll(0, list);
|
|
|
+ if (mPhotoListAdapter.getData().size() > maxSelectNum) {
|
|
|
+ mPhotoListAdapter.getData().remove(maxSelectNum);
|
|
|
+ }
|
|
|
+ mPhotoListAdapter.notifyDataSetChanged();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ break;
|
|
|
+ case 100:
|
|
|
+
|
|
|
+ List<LocalMedia> list1 = data.getParcelableArrayListExtra("list");
|
|
|
+ mPhotoListAdapter.getData().clear();
|
|
|
+ mPhotoListAdapter.getData().addAll(list1);
|
|
|
+ if (mPhotoListAdapter.getData().size() < maxSelectNum) {
|
|
|
+ addNewEmpty();
|
|
|
+ }
|
|
|
+ mPhotoListAdapter.notifyDataSetChanged();
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private ArrayList<LocalMedia> getImages() {
|
|
|
+ ArrayList<LocalMedia> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < mPhotoListAdapter.getData().size(); i++) {
|
|
|
+ LocalMedia localMedia = mPhotoListAdapter.getData().get(i);
|
|
|
+ if (!TextUtils.isEmpty(localMedia.getCompressPath())) {
|
|
|
+ list.add(localMedia);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+}
|