admin
2021-05-13 4a8f1bec26519a25f073739534e653a4f7c9e11d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
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.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 uid = mContext.getSharedPreferences("user", Context.MODE_PRIVATE).getString("uid", "");
                        String reason = "";
                        for (int i = 0; i < adapter.chooseReasons.size(); i++) {
                            reason += adapter.chooseReasons.get(i) + ",";
                        }
                        ShoppingApi.deleteRecommendGoods(mContext, goodsId, uid, 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;
            }
        }
    }
 
 
}