package com.tejia.lijin.app.ui.dialog;
|
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.ViewGroup;
|
import android.widget.BaseAdapter;
|
import android.widget.FrameLayout;
|
import android.widget.TextView;
|
|
import com.tejia.lijin.app.ShoppingApplication;
|
import com.tejia.lijin.app.util.user.UserUtil;
|
import com.wpc.library.util.SystemCommon;
|
import com.wpc.library.widget.MyGridView;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.ShoppingApi;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* Created by weikou2015 on 2017/2/28.
|
*/
|
|
public class NotLikeGoodsDialog extends Dialog {
|
|
public NotLikeGoodsDialog(Context context) {
|
super(context);
|
this.setCancelable(false);
|
}
|
|
public NotLikeGoodsDialog(Context context, int theme) {
|
super(context, theme);
|
this.setCancelable(false);
|
}
|
|
|
public static class Builder {
|
private Context mContext;
|
private String goodsId;
|
private int goodsType;
|
List<String> reasons;
|
private String positiveButtonText;
|
private String negativeButtonText;
|
private OnClickListener positiveButtonClickListener;
|
private OnClickListener negativeButtonClickListener;
|
|
public Builder(Context context) {
|
this.mContext = context;
|
}
|
|
public Builder setReasons(List<String> message) {
|
this.reasons = message;
|
return this;
|
}
|
|
public Builder setGoodsId(String goodsId) {
|
this.goodsId = goodsId;
|
return this;
|
}
|
|
public Builder setGoodsType(int goodsType) {
|
this.goodsType = goodsType;
|
return this;
|
}
|
|
/**
|
* Set the positive button resource and it's listener
|
*
|
* @param positiveButtonText
|
* @return
|
*/
|
public Builder setPositiveButton(int positiveButtonText,
|
OnClickListener listener) {
|
this.positiveButtonText = (String) mContext
|
.getText(positiveButtonText);
|
this.positiveButtonClickListener = listener;
|
return this;
|
}
|
|
public Builder setPositiveButton(String positiveButtonText,
|
OnClickListener listener) {
|
this.positiveButtonText = positiveButtonText;
|
this.positiveButtonClickListener = listener;
|
return this;
|
}
|
|
public Builder setNegativeButton(int negativeButtonText,
|
OnClickListener listener) {
|
this.negativeButtonText = (String) mContext
|
.getText(negativeButtonText);
|
this.negativeButtonClickListener = listener;
|
return this;
|
}
|
|
public Builder setNegativeButton(String negativeButtonText,
|
OnClickListener listener) {
|
this.negativeButtonText = negativeButtonText;
|
this.negativeButtonClickListener = listener;
|
return this;
|
}
|
|
public NotLikeGoodsDialog create() {
|
LayoutInflater inflater = (LayoutInflater) mContext
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
// instantiate the dialog with the custom Theme
|
final NotLikeGoodsDialog dialog = new NotLikeGoodsDialog(mContext, R.style.Dialog);
|
View layout = inflater.inflate(R.layout.dialog_not_like_goods, null);
|
dialog.addContentView(layout, new FrameLayout.LayoutParams(
|
FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
|
FrameLayout fl_confirm = layout.findViewById(R.id.fl_confirm);
|
MyGridView gv_reason = layout.findViewById(R.id.gv_reason);
|
|
final ReasonAdapter adapter = new ReasonAdapter();
|
gv_reason.setAdapter(adapter);
|
|
// set the confirm button
|
if (positiveButtonClickListener != null) {
|
fl_confirm.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
positiveButtonClickListener.onClick(dialog,
|
DialogInterface.BUTTON_POSITIVE);
|
|
String reason = "";
|
for (int i = 0; i < adapter.chooseReasons.size(); i++) {
|
reason += adapter.chooseReasons.get(i) + ",";
|
}
|
ShoppingApi.deleteRecommendGoods(mContext, goodsId, UserUtil.getUid(ShoppingApplication.application), reason, goodsType, null);
|
}
|
});
|
}
|
dialog.setContentView(layout);
|
|
android.view.WindowManager.LayoutParams params = dialog.getWindow()
|
.getAttributes();
|
params.width = (int) ((SystemCommon.getScreenWidth(mContext) * 6) / 7);
|
params.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
|
dialog.getWindow().setAttributes(params);
|
dialog.setCanceledOnTouchOutside(true);
|
return dialog;
|
}
|
|
public class ReasonAdapter extends BaseAdapter {
|
private List<String> chooseReasons = new ArrayList<>();
|
|
@Override
|
public int getCount() {
|
return reasons == null ? 0 : reasons.size();
|
}
|
|
@Override
|
public Object getItem(int position) {
|
return reasons.get(position);
|
}
|
|
@Override
|
public long getItemId(int position) {
|
return position;
|
}
|
|
@Override
|
public View getView(final int position, View view, ViewGroup parent) {
|
final Holder holder;
|
if (view == null) {
|
holder = new Holder();
|
view = LayoutInflater.from(mContext).inflate(R.layout.dialog_item_not_like_goods, null);
|
holder.tv_not_like_reason = view.findViewById(R.id.tv_not_like_reason);
|
view.setTag(holder);
|
} else {
|
holder = (Holder) view.getTag();
|
}
|
holder.tv_not_like_reason.setTextColor(mContext.getResources().getColor(R.color.text_black_1));
|
holder.tv_not_like_reason.setText(reasons.get(position));
|
|
holder.tv_not_like_reason.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (holder.tv_not_like_reason.isActivated()) {
|
holder.tv_not_like_reason.setActivated(false);
|
holder.tv_not_like_reason.setTextColor(mContext.getResources().getColor(R.color.text_black_1));
|
chooseReasons.remove(reasons.get(position));
|
} else {
|
holder.tv_not_like_reason.setActivated(true);
|
holder.tv_not_like_reason.setTextColor(mContext.getResources().getColor(R.color.main_text_color));
|
chooseReasons.add(reasons.get(position));
|
}
|
}
|
});
|
return view;
|
}
|
|
class Holder {
|
TextView tv_not_like_reason;
|
}
|
}
|
}
|
|
|
}
|