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();
|
}
|
}
|