admin
2021-05-14 1b4b3fed2569ac21ad6feb0a3a2c051175e7c36e
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
package com.tejia.lijin.app.ui.mine;
 
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
 
import com.ali.auth.third.core.util.StringUtil;
import com.app.hubert.guide.util.ScreenUtils;
import com.google.gson.Gson;
import com.tejia.lijin.app.ShoppingApplication;
import com.wpc.library.RetainViewFragment;
import com.wpc.library.util.common.StringUtils;
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
import com.tejia.lijin.app.R;
import com.tejia.lijin.app.ShoppingApi;
import com.tejia.lijin.app.entity.Label;
import com.tejia.lijin.app.entity.user.TeamFansDetailVO;
import com.tejia.lijin.app.ui.dialog.ShapeLoadingDialog;
import com.tejia.lijin.app.ui.dialog.TeamFansLabelAddDialog;
import com.tejia.lijin.app.util.SetLabels;
import com.tejia.lijin.app.util.clipboard.ClipboardUtil;
import com.tejia.lijin.app.util.user.UserUtil;
 
import org.apache.http.Header;
import org.json.JSONObject;
 
import java.util.ArrayList;
import java.util.List;
 
public class PlayerRemarkInfoFragment extends RetainViewFragment implements View.OnClickListener, TeamFansLabelAddDialog.Builder.SetFansTagListener {
 
 
    private EditText et_memoName;
    private ImageView iv_clear;
    private int position;
    private TextView tv_invite_wx, tv_invite_click;
 
    private LinearLayout ll_labels, ll_boss, ll_level;
    private ImageView iv_label_add;
    private TextView tv_taoabo, tv_phone, tv_phone_copy, tv_join_time, tv_login_time, tv_level, tv_fans, tv_order, tv_boss;
 
    private String weiXin;
    private int weiXinState;
    private String workerId;
    private String inviteId;
 
    @Override
    public int getContentResource() {
        return R.layout.fragment_myteam_mark_info;
    }
 
    private void initView(View view) {
        ll_labels = view.findViewById(R.id.ll_labels);
        iv_label_add = view.findViewById(R.id.iv_label_add);
        tv_taoabo = view.findViewById(R.id.tv_taoabo);
        tv_phone = view.findViewById(R.id.tv_phone);
        tv_phone_copy = view.findViewById(R.id.tv_phone_copy);
        tv_join_time = view.findViewById(R.id.tv_join_time);
        tv_login_time = view.findViewById(R.id.tv_login_time);
        tv_level = view.findViewById(R.id.tv_level);
        tv_fans = view.findViewById(R.id.tv_fans);
        tv_order = view.findViewById(R.id.tv_order);
 
        et_memoName = view.findViewById(R.id.et_memoName);
        iv_clear = view.findViewById(R.id.iv_clear);
        tv_invite_wx = view.findViewById(R.id.tv_invite_wx);
        tv_invite_click = view.findViewById(R.id.tv_invite_click);
 
        ll_boss = view.findViewById(R.id.ll_boss);
        tv_boss = view.findViewById(R.id.tv_boss);
        ll_level = view.findViewById(R.id.ll_level);
 
 
        tv_phone_copy.setOnClickListener(this);
    }
 
    ShapeLoadingDialog pd = null;
 
    @Override
    public void onCreateView(View contentView, Bundle savedInstanceState) {
        Bundle bundle = getArguments();
        initView(contentView);
        pd = new ShapeLoadingDialog.Builder(getContext()).build();
        String nickName = bundle.getString("memoName");
        et_memoName.setText(nickName);
        et_memoName.setSelection(nickName.length());
 
        int state = bundle.getInt("state", 0);
        position = bundle.getInt("position", 0);
        weiXin = bundle.getString("weiXin");
        weiXinState = bundle.getInt("weiXinState", 1);
        workerId = bundle.getString("workerId");
        inviteId = bundle.getString("inviteId");
 
 
        iv_clear.setOnClickListener(this);
        tv_invite_click.setOnClickListener(this);
        getCountMyTeam();
        //动态改变shape
        GradientDrawable shape = new GradientDrawable();
        shape.setCornerRadius(ScreenUtils.dp2px(iv_clear.getContext(), 100));
        //设置颜色
        shape.setColor(Color.parseColor("#fff3f3f3"));
        //设置大小
        tv_invite_click.setBackground(shape);
        tv_phone_copy.setBackground(shape);
        getFansInfo(workerId);
    }
 
    /**
     * 队员-统计数量+上级
     */
    public void getCountMyTeam() {
 
        if (weiXin == null) {
            tv_invite_wx.setText("未添加微信号");
        } else
            tv_invite_wx.setText(weiXin);
 
        if (weiXinState == 1) {
            tv_invite_click.setText("提醒");
        } else if (weiXinState == 2) {// 状态: 1 提醒ta, 2已提醒 3复制(已绑定)
            tv_invite_click.setText("已提醒");
            tv_invite_click.setEnabled(false);
            tv_invite_click.setTextColor(Color.parseColor("#7f7f7f"));
        } else {
            tv_invite_click.setText("复制");
        }
    }
 
 
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_invite_click:
                if (tv_invite_click.getText().toString().equals("复制")) {
                    ClipboardUtil.copy(getContext(), tv_invite_wx.getText() + "");
                    Toast.makeText(getContext(), "复制成功", Toast.LENGTH_LONG).show();
                } else {
                    getRemindTeam();//发送提醒
                }
                break;
            case R.id.tv_phone_copy:
                ClipboardUtil.copy(getContext(), tv_phone.getText() + "");
                Toast.makeText(getContext(), "复制成功", Toast.LENGTH_LONG).show();
                break;
            case R.id.iv_clear:
                et_memoName.setText("");
                break;
        }
    }
 
    /**
     * 发送提醒
     */
    private void getRemindTeam() {
        ShoppingApi.getRemindTeam(getContext(), getUid(getContext()), workerId, new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optInt("code") == 0) {
                    if (jsonObject.optJSONObject("data").optInt("weiXinState") == 2) {
                        tv_invite_click.setText("已提醒");
                        tv_invite_click.setEnabled(false);
 
                        tv_invite_click.setTextColor(Color.parseColor("#7f7f7f"));
                        Toast.makeText(tv_invite_click.getContext(), jsonObject.optJSONObject("data").optString("weiXinTip"), Toast.LENGTH_SHORT).show();
                    }
                } else {
                    Toast.makeText(tv_invite_click.getContext(), jsonObject.optString("msg"), Toast.LENGTH_SHORT).show();
                }
            }
 
            @Override
            public void onFailure(int statusCode, Header[] headers, String jsonObject, Throwable e) {
 
            }
        });
    }
 
    /**
     * 保存备注名称
     */
    String memoName = "";
 
    private void saveMemoName() {
        Long uid = UserUtil.getUid(getContext());
        if (et_memoName.getText() != null && !StringUtils.isEmpty(et_memoName.getText().toString())) {
            memoName = et_memoName.getText().toString();
        }
        ShoppingApi.saveMemoName(getContext(), uid , inviteId, memoName, new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optInt("code") == 0) {
 
                } else {
                    Toast.makeText(getContext(), jsonObject.optString("msg"), Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
 
    @Override
    public void onDestroy() {
        saveMemoName();
        super.onDestroy();
    }
 
    private void setTags(List<String> tags) {
        ll_labels.removeAllViews();
        List<Label> labelList = new ArrayList<>();
        for (String tag : tags) {
            Label lable = new Label();
            lable.setColor("#22AC38");
            lable.setContent(tag);
            labelList.add(lable);
        }
        SetLabels.addLabel(getContext(), ll_labels, labelList, 12);
    }
 
    TeamFansLabelAddDialog dialog = null;
    TeamFansDetailVO vo;
 
    private void setData() {
 
        if (!StringUtils.isEmpty(vo.getBossNickName())) {
            tv_boss.setText(vo.getBossNickName());
            ll_boss.setVisibility(View.VISIBLE);
        } else {
            ll_boss.setVisibility(View.GONE);
        }
 
        if (!StringUtils.isEmpty(vo.getMemoName()))
            et_memoName.setText(vo.getMemoName());
        else
            et_memoName.setText(vo.getNickName());
        if (et_memoName.getText() != null)
            et_memoName.setSelection(et_memoName.getText().length());
        tv_fans.setText(vo.getFansNum());
        tv_join_time.setText(vo.getJoinTime());
 
        if (StringUtils.isEmpty(vo.getLevel()))
            ll_level.setVisibility(View.GONE);
        else {
            ll_level.setVisibility(View.VISIBLE);
            tv_level.setText(vo.getLevel());
        }
 
        tv_login_time.setText(vo.getLoginTime());
        tv_order.setText(vo.getOrderInfo());
        if (vo.isPhoneCopy()) {
            tv_phone_copy.setVisibility(View.VISIBLE);
        } else {
            tv_phone_copy.setVisibility(View.GONE);
        }
 
        if (StringUtil.isEmpty(vo.getPhone())) {
            tv_phone.setText("未绑定电话号码");
            tv_phone.setTextColor(Color.parseColor("#000000"));
            tv_phone_copy.setVisibility(View.GONE);
        } else {
            tv_phone.setText(vo.getPhone());
            tv_phone.setTextColor(Color.parseColor("#888888"));
        }
 
        if (StringUtil.isEmpty(vo.getWeixin())) {
            tv_invite_wx.setTextColor(Color.parseColor("#000000"));
            tv_invite_wx.setText("未添加微信号");
            tv_invite_click.setVisibility(View.GONE);
        } else {
            tv_invite_wx.setTextColor(Color.parseColor("#888888"));
            tv_invite_click.setVisibility(View.VISIBLE);
            tv_invite_click.setText("复制");
            tv_invite_wx.setText(vo.getWeixin());
        }
 
        if (vo.isTaobao()) {
            tv_taoabo.setTextColor(Color.parseColor("#888888"));
            tv_taoabo.setText("已授权");
        } else {
            tv_taoabo.setTextColor(Color.parseColor("#000000"));
            tv_taoabo.setText("未授权");
        }
 
        iv_label_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog = new TeamFansLabelAddDialog.Builder(getContext()).setTags(vo.getTags()).setFansTagListener(PlayerRemarkInfoFragment.this).create();
                dialog.show();
            }
        });
        setTags(vo.getTags());
    }
 
    private void getFansInfo(String workerId) {
        ShoppingApi.getFansInfo(getContext(), getUid(getContext()), workerId, new BasicTextHttpResponseHandler() {
            @Override
            public void onStart() {
                super.onStart();
                if (pd != null && !pd.isShowing())
                    pd.show();
            }
 
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                super.onSuccessPerfect(statusCode, headers, jsonObject);
                if (jsonObject.optInt("code") == 0) {
                    JSONObject data = jsonObject.optJSONObject("data");
                    vo = new Gson().fromJson(data.toString(), TeamFansDetailVO.class);
                    setData();
                } else {
                    Toast.makeText(getContext(), jsonObject.optString("msg"), Toast.LENGTH_SHORT).show();
                }
 
            }
 
            @Override
            public void onFinish() {
                super.onFinish();
                if (pd != null && pd.isShowing())
                    pd.dismiss();
            }
 
 
            @Override
            public void onFailure(int statusCode, Header[] headers, String jsonObject, Throwable e) {
                super.onFailure(statusCode, headers, jsonObject, e);
            }
        });
    }
 
 
    /**
     * 获取用户id
     *
     * @return
     */
    public Long getUid(Context mContext) {
        return UserUtil.getUid(ShoppingApplication.application);
    }
 
    @Override
    public void setTag(final List<String> tagList) {
        //保存标签
        ShoppingApi.saveTags(getContext(), getUid(getContext()), workerId, new Gson().toJson(tagList), new BasicTextHttpResponseHandler() {
            @Override
            public void onStart() {
                super.onStart();
                if (pd != null && !pd.isShowing())
                    pd.show();
            }
 
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                super.onSuccessPerfect(statusCode, headers, jsonObject);
                if (jsonObject.optInt("code") == 0) {
                    vo.setTags(tagList);
                    setTags(tagList);
                    dialog.dismiss();
//                    Toast.makeText(getContext(), "修改成功", Toast.LENGTH_SHORT).show();
                }
            }
 
            @Override
            public void onFailure(int statusCode, Header[] headers, String jsonObject, Throwable e) {
                super.onFailure(statusCode, headers, jsonObject, e);
                Toast.makeText(getContext(), "网络连接出错", Toast.LENGTH_SHORT).show();
            }
 
            @Override
            public void onFinish() {
                super.onFinish();
                if (pd != null && pd.isShowing())
                    pd.dismiss();
            }
        });
    }
 
    @Override
    public void close() {
        dialog.dismiss();
    }
}