package com.tejia.lijin.app.ui.mine;
|
|
import android.content.Intent;
|
import android.graphics.Color;
|
import android.os.Bundle;
|
import android.text.Spannable;
|
import android.text.SpannableString;
|
import android.text.Spanned;
|
import android.text.style.RelativeSizeSpan;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.ViewGroup;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.wpc.library.util.common.DimenUtils;
|
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.ui.BaseActivity;
|
import com.tejia.lijin.app.ui.invite.ShareBrowserActivity;
|
import com.tejia.lijin.app.util.TopStatusSettings;
|
import com.tejia.lijin.app.util.user.UserUtil;
|
|
import org.apache.http.Header;
|
import org.json.JSONObject;
|
|
import java.io.IOException;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import okhttp3.Call;
|
|
/**
|
* Created by weikou2015 on 2018/1/18.
|
* 资金
|
*/
|
|
public class UserOrderRewardStatisticActivity extends BaseActivity implements View.OnClickListener {
|
TextView tv_left, tv_middle;
|
private String TYPE = "money";
|
private TextView tv_notice_content;
|
private LinearLayout ll_notice;
|
private ImageView iv_close, iv_top_bar_right1;
|
private LinearLayout ll_money_data;
|
|
private LinearLayout ll_list;
|
|
private TextView tv_money_1, tv_name_1, tv_money_2, tv_name_2, tv_money_3, tv_name_3, tv_money_total, tv_name_total;
|
private View view_cutline_2;
|
private LinearLayout ll_3, ll_total;
|
private String helpLink = null;
|
|
int type;
|
|
@Override
|
protected void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
setContentView(R.layout.activity_user_order_reward_statistic);
|
TopStatusSettings.setStatusViewAndDeepColor(this);
|
tv_left = findViewById(R.id.tv_top_bar_left);
|
tv_middle = findViewById(R.id.tv_top_bar_middle);
|
iv_top_bar_right1 = findViewById(R.id.iv_top_bar_right1);
|
iv_top_bar_right1.setVisibility(View.VISIBLE);
|
|
ll_list = findViewById(R.id.ll_list);
|
tv_money_1 = findViewById(R.id.tv_money_1);
|
tv_name_1 = findViewById(R.id.tv_name_1);
|
tv_money_2 = findViewById(R.id.tv_money_2);
|
tv_name_2 = findViewById(R.id.tv_name_2);
|
tv_money_3 = findViewById(R.id.tv_money_3);
|
tv_name_3 = findViewById(R.id.tv_name_3);
|
|
tv_money_total = findViewById(R.id.tv_money_total);
|
tv_name_total = findViewById(R.id.tv_name_total);
|
|
view_cutline_2 = findViewById(R.id.view_cutline_2);
|
ll_3 = findViewById(R.id.ll_3);
|
ll_total = findViewById(R.id.ll_total);
|
ll_money_data = findViewById(R.id.ll_money_data);
|
|
type = Integer.parseInt(getIntent().getStringExtra("type"));
|
if (type == 1) {
|
tv_middle.setText("自购返利");
|
} else if (type == 2) {
|
tv_middle.setText("分享奖金");
|
} else if (type == 3) {
|
tv_middle.setText("团队收益");
|
}
|
|
iv_top_bar_right1.setOnClickListener(this);
|
tv_left.setOnClickListener(this);
|
init();
|
getUserMoney();
|
}
|
|
private void init() {
|
if (type == 3) {
|
ll_total.setVisibility(View.VISIBLE);
|
ll_3.setVisibility(View.VISIBLE);
|
view_cutline_2.setVisibility(View.VISIBLE);
|
tv_name_1.setText("累计团队奖金(元)");
|
tv_name_2.setText("累计团队补贴(元)");
|
tv_name_3.setText("累计团队分红(元)");
|
ViewGroup.LayoutParams params = ll_money_data.getLayoutParams();
|
params.height = DimenUtils.dip2px(getApplicationContext(), 60);
|
ll_money_data.setLayoutParams(params);
|
} else {
|
ll_total.setVisibility(View.GONE);
|
ll_3.setVisibility(View.GONE);
|
view_cutline_2.setVisibility(View.GONE);
|
tv_name_1.setText("累计已到账(元)");
|
tv_name_2.setText("累计未到账(元)");
|
ViewGroup.LayoutParams params = ll_money_data.getLayoutParams();
|
params.height = DimenUtils.dip2px(this, 96);
|
ll_money_data.setLayoutParams(params);
|
}
|
}
|
|
|
@Override
|
protected void onResume() {
|
super.onResume();
|
}
|
|
/**
|
* 用户资金统计
|
*/
|
private void getUserMoney() {
|
ShoppingApi.getCurrentBonus(getApplicationContext(), UserUtil.getUid(getApplicationContext()), type + "", new BasicTextHttpResponseHandler() {
|
@Override
|
public void onStart() {
|
super.onStart();
|
}
|
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
super.onSuccessPerfect(statusCode, headers, jsonObject);
|
if (jsonObject.optInt("code") == 0) {
|
parseData(jsonObject.optJSONObject("data"));
|
} else {
|
Toast.makeText(UserOrderRewardStatisticActivity.this, jsonObject.optString("msg"), Toast.LENGTH_SHORT).show();
|
}
|
}
|
|
@Override
|
public void onFinish() {
|
super.onFinish();
|
}
|
|
@Override
|
public void onFailure(Call call, IOException e) {
|
super.onFailure(call, e);
|
tv_left.post(new Runnable() {
|
@Override
|
public void run() {
|
Toast.makeText(UserOrderRewardStatisticActivity.this, "网络连接出错", Toast.LENGTH_SHORT).show();
|
}
|
});
|
}
|
});
|
}
|
|
|
@Override
|
public void onClick(View view) {
|
switch (view.getId()) {
|
case R.id.tv_top_bar_left:
|
finish();
|
break;
|
case R.id.iv_top_bar_right1:
|
if (StringUtils.isEmpty(helpLink))
|
return;
|
startActivity(new Intent(this, ShareBrowserActivity.class).putExtra("url", helpLink));
|
break;
|
}
|
}
|
|
private void parseData(JSONObject data) {
|
helpLink = data.optString("link");
|
if (type == 3) {
|
setMoney(tv_money_total, data.optString("total"), 1.333f);
|
setMoney(tv_money_1, data.optString("totalBonus"), 1.333f);
|
setMoney(tv_money_2, data.optString("totalubsidy"), 1.333f);
|
setMoney(tv_money_3, data.optString("totalDividend"), 1.333f);
|
|
List<DateMoneyVO> voList = new ArrayList<>();
|
JSONObject bonus = data.optJSONObject("bonus");//团队奖金
|
DateMoneyVO vo = new DateMoneyVO(new DateMoney(new MoneyInfo("今日预估", bonus.optString("today")), new MoneyInfo("昨日预估", bonus.optString("yesterday")), new MoneyInfo("本月预估", bonus.optString("thisMonth")), new MoneyInfo("上月已到账", bonus.optString("lastMonth"))), "团队奖金(元)", R.drawable.shape_user_order_reward_statistic_blue_bottom, Color.parseColor("#DEF2FF"), R.drawable.shape_user_order_reward_statistic_blue);
|
voList.add(vo);
|
|
bonus = data.optJSONObject("subsidy");//补贴
|
vo = new DateMoneyVO(new DateMoney(new MoneyInfo("今日预估", bonus.optString("today")), new MoneyInfo("昨日预估", bonus.optString("yesterday")), new MoneyInfo("本月预估", bonus.optString("thisMonth")), new MoneyInfo("上月已到账", bonus.optString("lastMonth"))), "团队补贴(元)", R.drawable.shape_user_order_reward_statistic_yellow_bottom, Color.parseColor("#FFF5E0"), R.drawable.shape_user_order_reward_statistic_yellow);
|
voList.add(vo);
|
|
bonus = data.optJSONObject("dividend");//分红
|
vo = new DateMoneyVO(new DateMoney(null, null, new MoneyInfo("本月预估", bonus.optString("thisMonth")), new MoneyInfo("上月已到账", bonus.optString("lastMonth"))), "团队分红(元)", R.drawable.shape_user_order_reward_statistic_red_bottom, Color.parseColor("#FFF1F7"), R.drawable.shape_user_order_reward_statistic_red);
|
voList.add(vo);
|
|
setData(voList);
|
} else {
|
setMoney(tv_money_1, data.optString("total"), 1.333f);
|
setMoney(tv_money_2, data.optString("totalNot"), 1.333f);
|
List<DateMoneyVO> voList = new ArrayList<>();
|
JSONObject bonus = data.optJSONObject("bonus");//已到账
|
DateMoneyVO vo = new DateMoneyVO(new DateMoney(new MoneyInfo("今日", bonus.optString("today")), new MoneyInfo("昨日", bonus.optString("yesterday")), new MoneyInfo("本月", bonus.optString("thisMonth")), new MoneyInfo("上月", bonus.optString("lastMonth"))), "已到账(元)", R.drawable.shape_user_order_reward_statistic_red_bottom, Color.parseColor("#FFF1F7"), R.drawable.shape_user_order_reward_statistic_red);
|
voList.add(vo);
|
bonus = data.optJSONObject("bonusNot");//未到账
|
vo = new DateMoneyVO(new DateMoney(new MoneyInfo("今日", bonus.optString("today")), new MoneyInfo("昨日", bonus.optString("yesterday")), new MoneyInfo("本月", bonus.optString("thisMonth")), new MoneyInfo("上月", bonus.optString("lastMonth"))), "已到账(元)", R.drawable.shape_user_order_reward_statistic_yellow_bottom, Color.parseColor("#FFF5E0"), R.drawable.shape_user_order_reward_statistic_yellow);
|
voList.add(vo);
|
setData(voList);
|
}
|
}
|
|
private void setMoney(TextView tv, String money, float rate) {
|
int start = 0;
|
int end = money.length() - 1;
|
if (money.indexOf(".") > -1) {
|
end = money.indexOf(".");
|
}
|
Spannable span = new SpannableString(money);
|
span.setSpan(new RelativeSizeSpan(rate), start, end,
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
tv.setText(span);
|
}
|
|
private void setData(List<DateMoneyVO> voList) {
|
LayoutInflater inflater = LayoutInflater.from(this);
|
for (DateMoneyVO vo : voList) {
|
View view = inflater.inflate(R.layout.item_user_order_reward_statistic, null);
|
LinearLayout ll_content = view.findViewById(R.id.ll_content);
|
LinearLayout ll_money = view.findViewById(R.id.ll_money);
|
TextView tv_name = view.findViewById(R.id.tv_name);
|
tv_name.setText(vo.getName());
|
ll_content.setBackgroundResource(vo.getBackground());
|
setItemData(ll_money, vo);
|
ll_list.addView(view);
|
}
|
}
|
|
private void setItemData(LinearLayout container, DateMoneyVO vo) {
|
LayoutInflater inflater = LayoutInflater.from(this);
|
|
List<MoneyInfo> moneyList = new ArrayList<>();
|
if (vo.getDateMoney().getToday() != null)
|
moneyList.add(vo.getDateMoney().getToday());
|
if (vo.getDateMoney().getYesterday() != null)
|
moneyList.add(vo.getDateMoney().getYesterday());
|
if (vo.getDateMoney().getThisMonth() != null)
|
moneyList.add(vo.getDateMoney().getThisMonth());
|
if (vo.getDateMoney().getLastMonth() != null)
|
moneyList.add(vo.getDateMoney().getLastMonth());
|
|
|
for (int i = 0; i < moneyList.size(); i++) {
|
View view = inflater.inflate(R.layout.item_user_order_reward_statistic_content, null);
|
FrameLayout fl_content = view.findViewById(R.id.fl_content);
|
TextView tv_date = view.findViewById(R.id.tv_date);
|
TextView tv_money = view.findViewById(R.id.tv_money);
|
setMoney(tv_money, moneyList.get(i).getMoney(), 1.25f);
|
tv_date.setText(moneyList.get(i).getName());
|
|
if (i == moneyList.size() - 1) {
|
fl_content.setBackgroundResource(vo.getItemBackground());
|
} else if (i % 2 == 0) {
|
fl_content.setBackgroundColor(Color.WHITE);
|
} else {
|
fl_content.setBackgroundColor(vo.getEvenBackground());
|
}
|
container.addView(view);
|
}
|
}
|
|
|
@Override
|
protected void onPause() {
|
super.onPause();
|
}
|
|
@Override
|
protected void onDestroy() {
|
super.onDestroy();
|
}
|
|
|
class MoneyInfo {
|
public String getName() {
|
return name;
|
}
|
|
public void setName(String name) {
|
this.name = name;
|
}
|
|
public String getMoney() {
|
return money;
|
}
|
|
public void setMoney(String money) {
|
this.money = money;
|
}
|
|
public MoneyInfo(String name, String money) {
|
this.name = name;
|
this.money = money;
|
}
|
|
private String money;
|
private String name;
|
}
|
|
class DateMoney {
|
private MoneyInfo lastMonth;
|
private MoneyInfo thisMonth;
|
private MoneyInfo today;
|
|
public DateMoney(MoneyInfo today, MoneyInfo yesterday, MoneyInfo thisMonth, MoneyInfo lastMonth) {
|
this.lastMonth = lastMonth;
|
this.thisMonth = thisMonth;
|
this.today = today;
|
this.yesterday = yesterday;
|
}
|
|
private MoneyInfo yesterday;
|
|
public MoneyInfo getLastMonth() {
|
return lastMonth;
|
}
|
|
public void setLastMonth(MoneyInfo lastMonth) {
|
this.lastMonth = lastMonth;
|
}
|
|
public MoneyInfo getThisMonth() {
|
return thisMonth;
|
}
|
|
public void setThisMonth(MoneyInfo thisMonth) {
|
this.thisMonth = thisMonth;
|
}
|
|
public MoneyInfo getToday() {
|
return today;
|
}
|
|
public void setToday(MoneyInfo today) {
|
this.today = today;
|
}
|
|
public MoneyInfo getYesterday() {
|
return yesterday;
|
}
|
|
public void setYesterday(MoneyInfo yesterday) {
|
this.yesterday = yesterday;
|
}
|
|
|
}
|
|
|
class DateMoneyVO {
|
private DateMoney dateMoney;
|
private String name;
|
private int itemBackground;
|
private int evenBackground;
|
|
public DateMoneyVO(DateMoney dateMoney, String name, int itemBackground, int evenBackground, int background) {
|
this.dateMoney = dateMoney;
|
this.name = name;
|
this.itemBackground = itemBackground;
|
this.evenBackground = evenBackground;
|
this.background = background;
|
}
|
|
private int background;
|
|
public int getBackground() {
|
return background;
|
}
|
|
public void setBackground(int background) {
|
this.background = background;
|
}
|
|
|
public int getEvenBackground() {
|
return evenBackground;
|
}
|
|
public void setEvenBackground(int evenBackground) {
|
this.evenBackground = evenBackground;
|
}
|
|
|
public int getItemBackground() {
|
return itemBackground;
|
}
|
|
public void setItemBackground(int itemBackground) {
|
this.itemBackground = itemBackground;
|
}
|
|
|
public DateMoney getDateMoney() {
|
return dateMoney;
|
}
|
|
public void setDateMoney(DateMoney dateMoney) {
|
this.dateMoney = dateMoney;
|
}
|
|
public String getName() {
|
return name;
|
}
|
|
public void setName(String name) {
|
this.name = name;
|
}
|
|
|
}
|
}
|