diff --git a/common/src/main/java/com/yunbao/common/adapter/ImagePreviewAdapter.java b/common/src/main/java/com/yunbao/common/adapter/ImagePreviewAdapter.java new file mode 100644 index 000000000..bc22ba76c --- /dev/null +++ b/common/src/main/java/com/yunbao/common/adapter/ImagePreviewAdapter.java @@ -0,0 +1,112 @@ +package com.yunbao.common.adapter; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.PagerSnapHelper; +import androidx.recyclerview.widget.RecyclerView; + +import com.yunbao.common.R; + + +/** + * Created by cxf on 2018/11/28. + */ + +public class ImagePreviewAdapter extends RecyclerView.Adapter { + + private LayoutInflater mInflater; + private ActionListener mActionListener; + private int mPageCount; + private LinearLayoutManager mLayoutManager; + private int mCurPosition; + + public ImagePreviewAdapter(Context context, int pageCount) { + mPageCount = pageCount; + mInflater = LayoutInflater.from(context); + } + + @NonNull + @Override + public Vh onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new Vh(mInflater.inflate(R.layout.item_preview_img, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull Vh vh, int position) { + vh.setData(position); + } + + @Override + public int getItemCount() { + return mPageCount; + } + + + class Vh extends RecyclerView.ViewHolder { + + ImageView mImg; + + public Vh(View itemView) { + super(itemView); + mImg = (ImageView) itemView; + } + + void setData(int position) { + if (mActionListener != null) { + mActionListener.loadImage(mImg, position); + } + } + } + + public void setActionListener(ActionListener actionListener) { + mActionListener = actionListener; + } + + public void setCurPosition(int curPosition) { + mCurPosition = curPosition; + if (mActionListener != null) { + mActionListener.onPageChanged(curPosition); + } + } + + public int getCurPosition(){ + return mCurPosition; + } + + @Override + public void onAttachedToRecyclerView(RecyclerView recyclerView) { + super.onAttachedToRecyclerView(recyclerView); + mLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager(); + PagerSnapHelper pagerSnapHelper = new PagerSnapHelper(); + pagerSnapHelper.attachToRecyclerView(recyclerView); + recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(RecyclerView recyclerView, int newState) { + } + + @Override + public void onScrolled(RecyclerView recyclerView, int dx, int dy) { + int position = mLayoutManager.findFirstCompletelyVisibleItemPosition(); + if (position >= 0 && mCurPosition != position) { + mCurPosition = position; + if (mActionListener != null) { + mActionListener.onPageChanged(position); + } + } + } + }); + } + + + public interface ActionListener { + void onPageChanged(int position); + + void loadImage(ImageView imageView, int position); + } +} diff --git a/common/src/main/java/com/yunbao/common/dialog/ImagePreviewDialog.java b/common/src/main/java/com/yunbao/common/dialog/ImagePreviewDialog.java new file mode 100644 index 000000000..a19449066 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/dialog/ImagePreviewDialog.java @@ -0,0 +1,160 @@ +package com.yunbao.common.dialog; + +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.animation.ValueAnimator; +import android.os.Bundle; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; +import android.view.animation.AccelerateDecelerateInterpolator; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.yunbao.common.R; +import com.yunbao.common.adapter.ImagePreviewAdapter; +import com.yunbao.common.utils.StringUtil; + +/** + * Created by Martin on 2024/3/15. + * 图片预览弹窗 + */ + +public class ImagePreviewDialog extends AbsDialogFragment implements View.OnClickListener { + + private View mBg; + private RecyclerView mRecyclerView; + private ValueAnimator mAnimator; + private int mPosition; + private int mPageCount; + private ActionListener mActionListener; + private TextView mCount; + private ImagePreviewAdapter mAdapter; + private boolean mNeedDelete; + + + @Override + protected int getLayoutId() { + return R.layout.view_preview_image; + } + + @Override + protected int getDialogStyle() { + return R.style.dialog2; + } + + @Override + protected boolean canCancel() { + return true; + } + + @Override + protected void setWindowAttributes(Window window) { + WindowManager.LayoutParams params = window.getAttributes(); + params.width = WindowManager.LayoutParams.MATCH_PARENT; + params.height = WindowManager.LayoutParams.MATCH_PARENT; + window.setAttributes(params); + } + + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + mBg = mRootView.findViewById(R.id.bg); + mCount = (TextView) findViewById(R.id.count); + findViewById(R.id.btn_close).setOnClickListener(this); + if (mNeedDelete) { + View btnDelete = findViewById(R.id.btn_delete); + btnDelete.setVisibility(View.VISIBLE); + btnDelete.setOnClickListener(this); + } + mRecyclerView = mRootView.findViewById(R.id.recyclerView); + mRecyclerView.setHasFixedSize(true); + mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false)); + mAnimator = ValueAnimator.ofFloat(0, 1); + mAnimator.setDuration(150); + mAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); + mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + float v = (float) animation.getAnimatedValue(); + mBg.setAlpha(v); + } + }); + mAnimator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + if (mRecyclerView != null && mPageCount > 0) { + ImagePreviewAdapter adapter = new ImagePreviewAdapter(mContext, mPageCount); + mAdapter = adapter; + adapter.setActionListener(new ImagePreviewAdapter.ActionListener() { + @Override + public void onPageChanged(int position) { + if (mCount != null) { + mCount.setText(StringUtil.contact(String.valueOf(position + 1), "/", String.valueOf(mPageCount))); + } + } + + @Override + public void loadImage(ImageView imageView, int position) { + if (mActionListener != null) { + mActionListener.loadImage(imageView, position); + } + } + }); + mRecyclerView.setAdapter(adapter); + if (mPosition >= 0 && mPosition < mPageCount) { + adapter.setCurPosition(mPosition); + mRecyclerView.scrollToPosition(mPosition); + } + } + } + }); + mAnimator.start(); + } + + public void setImageInfo(int pageCount, int position, boolean needDelete, ActionListener actionListener) { + mActionListener = actionListener; + mPageCount = pageCount; + mPosition = position; + mNeedDelete = needDelete; + } + + + @Override + public void onDestroy() { + if (mAnimator != null) { + mAnimator.cancel(); + } + mContext = null; + mActionListener = null; + super.onDestroy(); + } + + @Override + public void onClick(View v) { + int i = v.getId(); + if (i == R.id.btn_close) { + dismiss(); + } else if (i == R.id.btn_delete) { + delete(); + } + } + + private void delete() { + if (mAdapter != null && mActionListener != null) { + mActionListener.onDeleteClick(mAdapter.getCurPosition()); + } + dismiss(); + } + + public interface ActionListener { + void loadImage(ImageView imageView, int position); + + void onDeleteClick(int position); + } + +} diff --git a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java index bd5f82b96..2a981f8fc 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -1206,4 +1206,8 @@ public interface PDLiveApi { @GET("/api/public/?service=User.userFeedback") Observable>> feedback(@Query("problem_description") String content, @Query("problem_image") String images, @Query("contact_information") String ci); + + + @GET("/api/public/?service=User.userFeedbackRestrict") + Observable>> checkFeedback(); } diff --git a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java index 31e79f49d..9448c17c8 100644 --- a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java +++ b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java @@ -3219,6 +3219,32 @@ public class LiveNetManager { }).isDisposed(); } + public void checkFeedback( + HttpCallback callback) { + API.get().pdLiveApi(mContext) + .checkFeedback() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Consumer>>() { + @Override + public void accept(ResponseModel> responseModel) { + if (callback != null) { + HttpCallbackModel model = new HttpCallbackModel(); + model.setCode(responseModel.getData().getCode()); + model.setMsg(responseModel.getData().getMsg()); + callback.onSuccess(model); + } + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(mContext.getString(com.yunbao.common.R.string.net_error)); + } + } + }).isDisposed(); + } + private MultipartBody.Part createUploadFile(File file) { RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); return MultipartBody.Part.createFormData("file", file.getName(), requestBody); diff --git a/common/src/main/res/layout/item_preview_img.xml b/common/src/main/res/layout/item_preview_img.xml new file mode 100644 index 000000000..5fca97d21 --- /dev/null +++ b/common/src/main/res/layout/item_preview_img.xml @@ -0,0 +1,8 @@ + + diff --git a/common/src/main/res/layout/view_preview_image.xml b/common/src/main/res/layout/view_preview_image.xml new file mode 100644 index 000000000..997875235 --- /dev/null +++ b/common/src/main/res/layout/view_preview_image.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/src/main/java/com/yunbao/main/activity/FeedbackActivity.java b/main/src/main/java/com/yunbao/main/activity/FeedbackActivity.java index 66e2242b5..cf96343a8 100644 --- a/main/src/main/java/com/yunbao/main/activity/FeedbackActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/FeedbackActivity.java @@ -2,8 +2,11 @@ package com.yunbao.main.activity; import com.alibaba.android.arouter.facade.annotation.Route; import com.yunbao.common.activity.AbsActivity; +import com.yunbao.common.bean.HttpCallbackModel; import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.utils.RouteUtil; +import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.common.views.weight.ViewClicksAntiShake; import com.yunbao.main.R; @@ -41,7 +44,23 @@ public class FeedbackActivity extends AbsActivity { @Override public void onViewClicks() { //TODO 意见反馈 - RouteUtil.forwardActivity(RouteUtil.PATH_FEEDBACK_EDIT_ACTIVITY); + LiveNetManager.get(mContext) + .checkFeedback(new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(HttpCallbackModel data) { + if (data.getCode() == 0) { + RouteUtil.forwardActivity(RouteUtil.PATH_FEEDBACK_EDIT_ACTIVITY); + } else { + ToastUtil.show(R.string.activity_feedback_edit_submit_tip3); + } + } + + @Override + public void onError(String error) { + ToastUtil.show(error); + } + }); + } }); } diff --git a/main/src/main/java/com/yunbao/main/activity/FeedbackEditActivity.java b/main/src/main/java/com/yunbao/main/activity/FeedbackEditActivity.java index 60febc607..0e5639408 100644 --- a/main/src/main/java/com/yunbao/main/activity/FeedbackEditActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/FeedbackEditActivity.java @@ -16,6 +16,7 @@ import com.alibaba.android.arouter.facade.annotation.Route; import com.alibaba.fastjson.JSONArray; import com.yunbao.common.activity.AbsActivity; import com.yunbao.common.bean.HttpCallbackModel; +import com.yunbao.common.dialog.ImagePreviewDialog; import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.http.live.LiveNetManager; @@ -42,6 +43,8 @@ public class FeedbackEditActivity extends AbsActivity { ProcessImageUtil imageUtil; Dialog loadingDialog = null; int clickImage = 0; + View img1Layout, img2Layout, img3Layout; + View img1Del, img2Del, img3Del; @Override protected int getLayoutId() { @@ -79,100 +82,84 @@ public class FeedbackEditActivity extends AbsActivity { } }); - ViewClicksAntiShake.clicksAntiShake(img1, new ViewClicksAntiShake.ViewClicksCallBack() { - @Override - public void onViewClicks() { - SparseArray list; - if (img1.getTag() == null) { - list = getImageType1(100); - } else { - list = getImageType2(110); - } - showUploadImage(list); + ViewClicksAntiShake.clicksAntiShake(img1, () -> { + clickImage = 101; + if (img1.getTag() == null) { + uploadImage(img1); + } else { + showImage(img1); } }); - ViewClicksAntiShake.clicksAntiShake(img2, new ViewClicksAntiShake.ViewClicksCallBack() { - @Override - public void onViewClicks() { - SparseArray list; - if (img2.getTag() == null) { - list = getImageType1(200); - } else { - list = getImageType2(210); - } - showUploadImage(list); + ViewClicksAntiShake.clicksAntiShake(img2, () -> { + clickImage = 201; + if (img2.getTag() == null) { + uploadImage(img2); + } else { + showImage(img2); } }); - ViewClicksAntiShake.clicksAntiShake(img3, new ViewClicksAntiShake.ViewClicksCallBack() { - @Override - public void onViewClicks() { - SparseArray list; - if (img3.getTag() == null) { - list = getImageType1(300); - } else { - list = getImageType2(310); - } - showUploadImage(list); - + ViewClicksAntiShake.clicksAntiShake(img3, () -> { + clickImage = 301; + if (img3.getTag() == null) { + uploadImage(img3); + } else { + showImage(img3); } }); - ViewClicksAntiShake.clicksAntiShake(submit, new ViewClicksAntiShake.ViewClicksCallBack() { - @Override - public void onViewClicks() { - if (feedbackEdit.getText().length() == 0) { - ToastUtil.show(R.string.activity_feedback_edit_submit_tip1); - return; - } - JSONArray images = new JSONArray(); - if (img1.getTag() != null) { - images.add((String) img1.getTag()); - } - if (img2.getTag() != null) { - images.add((String) img2.getTag()); - } - if (img3.getTag() != null) { - images.add((String) img3.getTag()); - } - LiveNetManager.get(mContext) - .feedback(feedbackEdit.getText().toString(), - images, - ciEdit.getText().toString(), - new HttpCallback() { - @Override - public void onSuccess(HttpCallbackModel data) { - finish(); - RouteUtil.forwardActivity(RouteUtil.PATH_FEEDBACK_SUCCESS_ACTIVITY); - } - - @Override - public void onError(String error) { - ToastUtil.show(error); - } + ViewClicksAntiShake.clicksAntiShake(img1Del, () -> { + deleteImage(1); + }); + ViewClicksAntiShake.clicksAntiShake(img2Del, () -> { + deleteImage(2); + }); + ViewClicksAntiShake.clicksAntiShake(img3Del, () -> { + deleteImage(3); + }); + ViewClicksAntiShake.clicksAntiShake(submit, () -> { + if (feedbackEdit.getText().length() == 0) { + ToastUtil.show(R.string.activity_feedback_edit_submit_tip1); + return; + } + JSONArray images = new JSONArray(); + if (img1.getTag() != null) { + images.add((String) img1.getTag()); + } + if (img2.getTag() != null) { + images.add((String) img2.getTag()); + } + if (img3.getTag() != null) { + images.add((String) img3.getTag()); + } + LiveNetManager.get(mContext) + .feedback(feedbackEdit.getText().toString(), + images, + ciEdit.getText().toString(), + new HttpCallback() { + @Override + public void onSuccess(HttpCallbackModel data) { + finish(); + RouteUtil.forwardActivity(RouteUtil.PATH_FEEDBACK_SUCCESS_ACTIVITY); } - ); - } + @Override + public void onError(String error) { + ToastUtil.show(error); + } + } + ); + }); - img1.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - ToastUtil.show("1"); - return true; - } + img1.setOnLongClickListener(view -> { + ToastUtil.show("1"); + return true; }); - img2.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - ToastUtil.show("2"); - return true; - } + img2.setOnLongClickListener(view -> { + ToastUtil.show("2"); + return true; }); - img3.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - ToastUtil.show("3"); - return true; - } + img3.setOnLongClickListener(view -> { + ToastUtil.show("3"); + return true; }); imageUtil.setImageResultCallback(new ImageResultCallback() { @@ -190,29 +177,23 @@ public class FeedbackEditActivity extends AbsActivity { switch (clickImage) { case 101: case 112: - ImgLoader.display(mContext, bean, img1); - img1.setTag(bean); + setShowImage(img1,img1Del,bean); if (img2.getTag() == null) { - img2.setImageResource(R.mipmap.icon_activity_feedback_edit_img_add); - img2.setVisibility(View.VISIBLE); + setDefImage(img2, img2Del, img2Layout); } else if (img3.getTag() == null) { - img3.setVisibility(View.VISIBLE); - img3.setImageResource(R.mipmap.icon_activity_feedback_edit_img_add); + setDefImage(img3, img3Del, img3Layout); } break; case 201: case 212: - ImgLoader.display(mContext, bean, img2); - img2.setTag(bean); + setShowImage(img2,img2Del,bean); if (img3.getTag() == null) { - img3.setVisibility(View.VISIBLE); - img3.setImageResource(R.mipmap.icon_activity_feedback_edit_img_add); + setDefImage(img3, img3Del, img3Layout); } break; case 301: case 312: - ImgLoader.display(mContext, bean, img3); - img3.setTag(bean); + setShowImage(img3,img3Del,bean); break; } } @@ -230,6 +211,22 @@ public class FeedbackEditActivity extends AbsActivity { }); } + private void showImage(ImageView iv) { + ImagePreviewDialog dialog = new ImagePreviewDialog(); + dialog.setImageInfo(1, 1, false, new ImagePreviewDialog.ActionListener() { + @Override + public void loadImage(ImageView imageView, int position) { + ImgLoader.display(mContext, (String) iv.getTag(), imageView); + } + + @Override + public void onDeleteClick(int position) { + + } + }); + + } + private void showUploadImage(SparseArray list) { DialogUitl.showStringArrayDialog(mContext, list, new DialogUitl.StringArrayDialogCallback() { @Override @@ -286,41 +283,50 @@ public class FeedbackEditActivity extends AbsActivity { if (img3.getTag() != null) { img2.setTag(img3.getTag()); ImgLoader.display(mContext, (String) img2.getTag(), img2); - img3.setTag(null); - img3.setImageResource(R.mipmap.icon_activity_feedback_edit_img_add); + setDefImage(img3, img3Del, img3Layout); } else { - img2.setTag(null); - img2.setImageResource(R.mipmap.icon_activity_feedback_edit_img_add); - img3.setTag(null); - img3.setVisibility(View.GONE); + setDefImage(img2, img2Del, img2Layout); + setGoneImage(img3, img3Del, img3Layout); } } else { - img1.setTag(null); - img1.setImageResource(R.mipmap.icon_activity_feedback_edit_img_add); - img2.setTag(null); - img2.setVisibility(View.GONE); - img3.setTag(null); - img3.setVisibility(View.GONE); + setDefImage(img1, img1Del, img1Layout); + setGoneImage(img2, img2Del, img2Layout); + setGoneImage(img3, img3Del, img3Layout); } } else if (index == 2) { if (img3.getTag() != null) { img2.setTag(img3.getTag()); ImgLoader.display(mContext, (String) img2.getTag(), img2); - img3.setTag(null); - img3.setImageResource(R.mipmap.icon_activity_feedback_edit_img_add); + setDefImage(img3, img3Del, img3Layout); } else { - img2.setTag(null); - img2.setImageResource(R.mipmap.icon_activity_feedback_edit_img_add); - img3.setTag(null); - img3.setVisibility(View.GONE); + setDefImage(img2, img2Del, img2Layout); + setGoneImage(img3, img3Del, img3Layout); } } else if (index == 3) { - img3.setTag(null); - img3.setImageResource(R.mipmap.icon_activity_feedback_edit_img_add); + setDefImage(img3, img3Del, img3Layout); } } + private void setDefImage(ImageView iv, View ivDel, View ivLayout) { + iv.setTag(null); + ivDel.setVisibility(View.GONE); + iv.setImageResource(R.mipmap.icon_activity_feedback_edit_img_add); + ivLayout.setVisibility(View.VISIBLE); + } + + private void setGoneImage(ImageView iv, View ivDel, View ivLayout) { + iv.setTag(null); + ivDel.setVisibility(View.GONE); + ivLayout.setVisibility(View.GONE); + } + + private void setShowImage(ImageView iv, View ivDel, String url) { + iv.setTag(url); + ImgLoader.display(mContext, url, iv); + ivDel.setVisibility(View.VISIBLE); + } + private void changeImage(ImageView imageView) { uploadImage(imageView); } @@ -344,6 +350,12 @@ public class FeedbackEditActivity extends AbsActivity { img1 = findViewById(R.id.img1); img2 = findViewById(R.id.img2); img3 = findViewById(R.id.img3); + img1Layout = findViewById(R.id.img1Layout); + img2Layout = findViewById(R.id.img2Layout); + img3Layout = findViewById(R.id.img3Layout); + img1Del = findViewById(R.id.img1_del); + img2Del = findViewById(R.id.img2_del); + img3Del = findViewById(R.id.img3_del); submit = findViewById(R.id.btn_sub); editNumber = findViewById(R.id.tv_number); editNumber.setTextColor(Color.parseColor("#333333")); diff --git a/main/src/main/res/layout/activity_feedback_edit.xml b/main/src/main/res/layout/activity_feedback_edit.xml index 58f206433..a46603825 100644 --- a/main/src/main/res/layout/activity_feedback_edit.xml +++ b/main/src/main/res/layout/activity_feedback_edit.xml @@ -1,198 +1,258 @@ - - - + android:background="#FFFFFF"> + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - + android:layout_marginStart="15dp" + android:layout_marginTop="10dp" + android:orientation="horizontal"> - + - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - -