|
|
@@ -1,6 +1,7 @@
|
|
|
package com.miekir.eden.ui.home.goods;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
import android.text.TextUtils;
|
|
|
@@ -9,6 +10,7 @@ import android.widget.ImageView;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.annotation.Nullable;
|
|
|
+import androidx.appcompat.app.AlertDialog;
|
|
|
|
|
|
import com.bumptech.glide.Glide;
|
|
|
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
|
|
@@ -21,7 +23,7 @@ import com.makeramen.roundedimageview.RoundedImageView;
|
|
|
import com.miekir.common.utils.ToastTool;
|
|
|
import com.miekir.eden.BuildConfig;
|
|
|
import com.miekir.eden.R;
|
|
|
-import com.miekir.eden.base.ItemLongClickListener;
|
|
|
+import com.miekir.eden.base.BaseBeiActivity;
|
|
|
import com.miekir.eden.constant.ConstantString;
|
|
|
import com.miekir.eden.manager.UserInfoManager;
|
|
|
import com.miekir.eden.tool.StringTool;
|
|
|
@@ -35,6 +37,36 @@ import rx_activity_result2.RxActivityResult;
|
|
|
|
|
|
import static android.app.Activity.RESULT_OK;
|
|
|
|
|
|
+//View fl_video_play = holder.getView(R.id.fl_video_play);
|
|
|
+//View iv_video_play = holder.getView(R.id.iv_video_play);
|
|
|
+//if (!TextUtils.isEmpty(goodsBean.videoUrl)) {
|
|
|
+// iv_video_play.setVisibility(View.VISIBLE);
|
|
|
+// fl_video_play.setOnClickListener(new View.OnClickListener() {
|
|
|
+// @Override
|
|
|
+// public void onClick(View v) {
|
|
|
+// if (!UserInfoManager.getInstance().getBeiUser().vip) {
|
|
|
+// ToastTool.showShort("请先激活会员");
|
|
|
+// if (mContext instanceof TabActivity) {
|
|
|
+// ((TabActivity) mContext).setCurrentPage(2);
|
|
|
+// }
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (!goodsBean.enable) {
|
|
|
+// ToastTool.showShort("敬请期待");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 全屏播放视频
|
|
|
+// Intent playIntent = new Intent(mContext, VideoPlayActivity.class);
|
|
|
+// playIntent.putExtra(VideoPlayActivity.KEY_URL, goodsBean.videoUrl);
|
|
|
+// playIntent.putExtra(VideoPlayActivity.KEY_TITLE, goodsBean.title);
|
|
|
+// mContext.startActivity(playIntent);
|
|
|
+// }
|
|
|
+// });
|
|
|
+//} else {
|
|
|
+// iv_video_play.setVisibility(View.GONE);
|
|
|
+//}
|
|
|
/**
|
|
|
*
|
|
|
*
|
|
|
@@ -45,6 +77,7 @@ import static android.app.Activity.RESULT_OK;
|
|
|
public class GoodsAdapter extends BaseQuickAdapter<GoodsBean, BaseViewHolder> {
|
|
|
private Activity mContext;
|
|
|
private int mRadius;
|
|
|
+ private GoodsPresenter mGoodsPresenter;
|
|
|
|
|
|
public GoodsAdapter(Activity context, @Nullable List<GoodsBean> data) {
|
|
|
super(R.layout.item_goods, data);
|
|
|
@@ -54,8 +87,17 @@ public class GoodsAdapter extends BaseQuickAdapter<GoodsBean, BaseViewHolder> {
|
|
|
|
|
|
@Override
|
|
|
protected void convert(@NonNull BaseViewHolder holder, GoodsBean goodsBean) {
|
|
|
- holder.setText(R.id.tv_title, goodsBean.title);
|
|
|
- holder.setText(R.id.tv_good_comment, StringTool.getPercent(goodsBean.dingNum, goodsBean.dingNum+goodsBean.caiNum));
|
|
|
+ if (goodsBean.enable) {
|
|
|
+ holder.setText(R.id.tv_title, goodsBean.title);
|
|
|
+ } else {
|
|
|
+ if (TextUtils.equals(ConstantString.NAME_ADMIN, UserInfoManager.getInstance().getBeiUser().email)) {
|
|
|
+ holder.setText(R.id.tv_title, goodsBean.title + "(已禁用)");
|
|
|
+ } else {
|
|
|
+ holder.setText(R.id.tv_title, "已被禁用");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //holder.setText(R.id.tv_good_comment, StringTool.getPercent(goodsBean.dingNum, goodsBean.dingNum+goodsBean.caiNum));
|
|
|
if (goodsBean.favNum < 0) {
|
|
|
goodsBean.favNum = 0;
|
|
|
}
|
|
|
@@ -106,72 +148,43 @@ public class GoodsAdapter extends BaseQuickAdapter<GoodsBean, BaseViewHolder> {
|
|
|
|
|
|
setDefaultView(aciv_goods);
|
|
|
aciv_goods.setTag(R.id.aciv_goods, goodsBean.coverImageUrl);
|
|
|
- Glide.with(mContext).load(goodsBean.coverImageUrl)
|
|
|
- .apply(RequestOptions.bitmapTransform(new RoundedCorners(mRadius)))
|
|
|
- //.apply(new RequestOptions()
|
|
|
- // .skipMemoryCache(true)
|
|
|
- // .diskCacheStrategy(DiskCacheStrategy.NONE))
|
|
|
- //先加载原图大小的十分之一
|
|
|
- .thumbnail(0.1f)
|
|
|
- .into(new SimpleTarget<Drawable>() {
|
|
|
- @Override
|
|
|
- public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
|
|
|
- if (resource == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (goodsBean.enable) {
|
|
|
+ Glide.with(mContext).load(goodsBean.coverImageUrl)
|
|
|
+ .apply(RequestOptions.bitmapTransform(new RoundedCorners(mRadius)))
|
|
|
+ //.apply(new RequestOptions()
|
|
|
+ // .skipMemoryCache(true)
|
|
|
+ // .diskCacheStrategy(DiskCacheStrategy.NONE))
|
|
|
+ //先加载原图大小的十分之一
|
|
|
+ .thumbnail(0.1f)
|
|
|
+ .into(new SimpleTarget<Drawable>() {
|
|
|
+ @Override
|
|
|
+ public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
|
|
|
+ if (resource == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- String coverUrl = null;
|
|
|
- try {
|
|
|
- coverUrl = (String) aciv_goods.getTag(R.id.aciv_goods);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- if (!TextUtils.isEmpty(coverUrl) && TextUtils.equals(coverUrl, goodsBean.coverImageUrl)) {
|
|
|
- aciv_goods.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
|
|
- aciv_goods.setImageDrawable(resource);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- /*View fl_video_play = holder.getView(R.id.fl_video_play);
|
|
|
- View iv_video_play = holder.getView(R.id.iv_video_play);
|
|
|
- if (!TextUtils.isEmpty(goodsBean.videoUrl)) {
|
|
|
- iv_video_play.setVisibility(View.VISIBLE);
|
|
|
- fl_video_play.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- if (!UserInfoManager.getInstance().getBeiUser().vip) {
|
|
|
- ToastTool.showShort("请先激活会员");
|
|
|
- if (mContext instanceof TabActivity) {
|
|
|
- ((TabActivity) mContext).setCurrentPage(2);
|
|
|
+ String coverUrl = null;
|
|
|
+ try {
|
|
|
+ coverUrl = (String) aciv_goods.getTag(R.id.aciv_goods);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (!TextUtils.isEmpty(coverUrl) && TextUtils.equals(coverUrl, goodsBean.coverImageUrl)) {
|
|
|
+ aciv_goods.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
|
|
+ aciv_goods.setImageDrawable(resource);
|
|
|
+ }
|
|
|
}
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (!goodsBean.enable) {
|
|
|
- ToastTool.showShort("敬请期待");
|
|
|
- return;
|
|
|
- }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- // 全屏播放视频
|
|
|
- Intent playIntent = new Intent(mContext, VideoPlayActivity.class);
|
|
|
- playIntent.putExtra(VideoPlayActivity.KEY_URL, goodsBean.videoUrl);
|
|
|
- playIntent.putExtra(VideoPlayActivity.KEY_TITLE, goodsBean.title);
|
|
|
- mContext.startActivity(playIntent);
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- iv_video_play.setVisibility(View.GONE);
|
|
|
- }*/
|
|
|
|
|
|
- // 暂时不需要长按弹出操作
|
|
|
+ // 长按弹出操作
|
|
|
if (UserInfoManager.getInstance().isLogin() &&
|
|
|
TextUtils.equals(ConstantString.NAME_ADMIN, UserInfoManager.getInstance().getBeiUser().email)) {
|
|
|
View view = holder.getView(R.id.cv_goods);
|
|
|
view.setOnLongClickListener(v -> {
|
|
|
- if (goodsLongClickListener != null) {
|
|
|
- goodsLongClickListener.onItemLongClick(holder.getLayoutPosition());
|
|
|
- }
|
|
|
+ // 长按
|
|
|
+ showAdminDialog(goodsBean, holder.getLayoutPosition());
|
|
|
return false;
|
|
|
});
|
|
|
}
|
|
|
@@ -182,12 +195,50 @@ public class GoodsAdapter extends BaseQuickAdapter<GoodsBean, BaseViewHolder> {
|
|
|
aciv_goods.setImageResource(R.mipmap.logo_gray);
|
|
|
}
|
|
|
|
|
|
- private ItemLongClickListener goodsLongClickListener;
|
|
|
- public ItemLongClickListener getGoodsLongClickListener() {
|
|
|
- return goodsLongClickListener;
|
|
|
+ /**
|
|
|
+ * 修改商品或者删除商品
|
|
|
+ */
|
|
|
+ private void showAdminDialog(GoodsBean goodsBean, int position) {
|
|
|
+ AlertDialog alertDialog = new AlertDialog.Builder(mContext)
|
|
|
+ .setMessage("选择操作")
|
|
|
+ .setNeutralButton("取消", (dialog, which) -> {
|
|
|
+ dialog.dismiss();
|
|
|
+ })
|
|
|
+ .setNegativeButton("禁用", (DialogInterface dialog, int which) -> {
|
|
|
+ dialog.dismiss();
|
|
|
+ if (mContext instanceof BaseBeiActivity) {
|
|
|
+ ((BaseBeiActivity) mContext).showLoading();
|
|
|
+ }
|
|
|
+ mGoodsPresenter.revertGoodsEnable(position, goodsBean.id);
|
|
|
+ })
|
|
|
+ .setPositiveButton("删除", (DialogInterface dialog, int which) -> {
|
|
|
+ dialog.dismiss();
|
|
|
+ showDeleteDialog(goodsBean, position);
|
|
|
+ }).create();
|
|
|
+ alertDialog.setCanceledOnTouchOutside(false);
|
|
|
+ alertDialog.setCancelable(false);
|
|
|
+ alertDialog.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否删除商品
|
|
|
+ */
|
|
|
+ private void showDeleteDialog(GoodsBean goodsBean, int position) {
|
|
|
+ AlertDialog alertDialog = new AlertDialog.Builder(mContext)
|
|
|
+ .setMessage("确定删除商品:" + goodsBean.title)
|
|
|
+ .setNegativeButton("取消", (dialog, which) -> dialog.dismiss())
|
|
|
+ .setPositiveButton("确定", (DialogInterface dialog, int which) -> {
|
|
|
+ dialog.dismiss();
|
|
|
+ if (mContext instanceof BaseBeiActivity) {
|
|
|
+ ((BaseBeiActivity) mContext).showLoading();
|
|
|
+ }
|
|
|
+ // 删除商品
|
|
|
+ mGoodsPresenter.deleteGoodsById(position, goodsBean.id);
|
|
|
+ }).create();
|
|
|
+ alertDialog.show();
|
|
|
}
|
|
|
|
|
|
- public void setGoodsLongClickListener(ItemLongClickListener goodsLongClickListener) {
|
|
|
- this.goodsLongClickListener = goodsLongClickListener;
|
|
|
+ public void setGoodsPresenter(GoodsPresenter goodsPresenter) {
|
|
|
+ this.mGoodsPresenter = goodsPresenter;
|
|
|
}
|
|
|
}
|