package com.yeshi.ec.rebate.myapplication.ui.mine;
|
|
import android.content.Context;
|
import android.content.Intent;
|
import android.content.SharedPreferences;
|
import android.graphics.drawable.AnimationDrawable;
|
import android.os.Bundle;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.RecyclerView;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.TextView;
|
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.google.gson.reflect.TypeToken;
|
import com.wpc.library.content.ConnectivityChangeHelper;
|
import com.wpc.library.dialog.dateselect.CustomDatePicker;
|
import com.wpc.library.dialog.dateselect.DateFormatUtils;
|
import com.wpc.library.util.common.StringUtils;
|
import com.yeshi.ec.rebate.myapplication.BasicTextHttpResponseHandler;
|
import com.yeshi.ec.rebate.myapplication.R;
|
import com.yeshi.ec.rebate.myapplication.ShoppingApi;
|
import com.yeshi.ec.rebate.myapplication.entity.Account;
|
import com.yeshi.ec.rebate.myapplication.entity.AccountMonth;
|
import com.yeshi.ec.rebate.myapplication.ui.BaseActivity;
|
import com.yeshi.ec.rebate.myapplication.ui.invite.ShareBrowserActivity;
|
import com.yeshi.ec.rebate.myapplication.util.TopStatusSettings;
|
|
import org.apache.http.Header;
|
import org.json.JSONObject;
|
|
import java.util.ArrayList;
|
import java.util.Calendar;
|
import java.util.List;
|
|
/**
|
* 推广红包明细
|
*/
|
public class PromotionDetailActivity extends BaseActivity implements View.OnClickListener {
|
private TextView tv_left, tv_middle, tv_no_data_hint,
|
tv_select_time, tv_all_income, tv_all_expenses;
|
private SwipeRefreshLayout srl_account_desc;
|
private RecyclerView rv_account_desc;
|
View bottom;
|
private ImageView iv_loading;
|
private TextView tv_loading;
|
private String TYPE = "accountDetail";
|
private TextView tv_notice_content;
|
private LinearLayout ll_notice;
|
private ImageView iv_close;
|
private LinearLayout srl_account_layout;
|
|
private ConnectivityChangeHelper mChangeHelper;
|
private LinearLayout ll_no_net, ll_no_data, ll_request_failture, ll_title;
|
List<Account> mList = new ArrayList<>();
|
private String index = "";
|
private String mYear = "";
|
private String mMonth = "";
|
private AccountDescAdapter34 adapter;
|
private float mSuspensionHeight = 0;
|
LinearLayoutManager linearLayoutManager;
|
int mCurrentPosition = 0;
|
int count = 0;
|
private CustomDatePicker mDatePicker;
|
private boolean isLoad = false;
|
|
@Override
|
protected void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
setContentView(R.layout.activity_promotiondetail);
|
TopStatusSettings.setStatusViewAndDeepColor(this);
|
initView();
|
addListener();
|
}
|
|
private void initView() {
|
tv_left = findViewById(R.id.tv_top_bar_left);
|
tv_middle = findViewById(R.id.tv_top_bar_middle);
|
ll_title = findViewById(R.id.ll_title);
|
tv_select_time = findViewById(R.id.tv_select_time);
|
tv_all_income = findViewById(R.id.tv_all_income);
|
tv_all_expenses = findViewById(R.id.tv_all_expenses);
|
srl_account_desc = findViewById(R.id.srl_account_desc);
|
rv_account_desc = findViewById(R.id.rv_account_desc);
|
srl_account_layout = findViewById(R.id.srl_account_layout);
|
linearLayoutManager = new LinearLayoutManager(this);
|
rv_account_desc.setLayoutManager(linearLayoutManager);
|
// DividerItemDecoration vDivider = new DividerItemDecoration();
|
// vDivider.setColor(getResources().getColor(R.color.register_gray));
|
// vDivider.setSize(1);
|
// rv_account_desc.addItemDecoration(vDivider);
|
adapter = new AccountDescAdapter34(this, mList);
|
rv_account_desc.setAdapter(adapter);
|
srl_account_desc.setColorSchemeColors(getResources().getColor(R.color.theme));
|
bottom = LayoutInflater.from(this).inflate(R.layout.item_recyclerview_bottom, null);
|
tv_loading = bottom.findViewById(R.id.tv_loading);
|
iv_loading = bottom.findViewById(R.id.iv_loading);
|
AnimationDrawable animationDrawable = (AnimationDrawable) getResources().getDrawable(
|
R.drawable.anim_list_loading);
|
iv_loading.setImageDrawable(animationDrawable);
|
animationDrawable.start();
|
// Glide.with(this).load(R.drawable.gif_loading).into(iv_loading);
|
bottom.setVisibility(View.GONE);
|
adapter.addFooterView(bottom);
|
|
tv_notice_content = findViewById(R.id.tv_notice_content);
|
ll_notice = findViewById(R.id.ll_notice);
|
iv_close = findViewById(R.id.iv_close);
|
getAppPageNotification();
|
|
ll_no_net = findViewById(R.id.ll_no_net);
|
ll_no_data = findViewById(R.id.ll_no_data);
|
ll_request_failture = findViewById(R.id.ll_request_failture);
|
tv_no_data_hint = findViewById(R.id.tv_no_data_hint);
|
tv_no_data_hint.setText("红包有大用处哦~");
|
tv_middle.setText("红包明细");
|
iv_no_data = findViewById(R.id.iv_no_data);
|
iv_no_data.setImageResource(R.drawable.ic_redpacket_desc_null);
|
}
|
|
private ImageView iv_no_data;
|
|
private void addListener() {
|
tv_left.setOnClickListener(this);
|
ll_title.setOnClickListener(this);
|
findViewById(R.id.tv_net_setting).setOnClickListener(this);
|
findViewById(R.id.tv_refresh).setOnClickListener(this);
|
mChangeHelper = new ConnectivityChangeHelper(this,
|
new ConnectivityChangeHelper.OnConnectivityChangeListener() {
|
|
@Override
|
public void onNetworkUnAvailable() {
|
if (mList.size()==0)
|
requestState(3);
|
}
|
|
@Override
|
public void onNetworkAvailable() {
|
requestState(0);
|
if (mList.size() == 0) {
|
getAccountDesc();
|
}
|
}
|
|
});
|
srl_account_desc.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
@Override
|
public void onRefresh() {
|
index = "";
|
mYear = "";
|
mMonth = "";
|
getAccountDesc();
|
}
|
});
|
rv_account_desc.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
@Override
|
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
super.onScrollStateChanged(recyclerView, newState);
|
mSuspensionHeight = ll_title.getHeight();
|
LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
|
int last = manager.findLastVisibleItemPosition();
|
int total = manager.getItemCount();
|
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
if (last == total - 1 && mList.size() < count && isLoad) {
|
index = mList.get(mList.size() - 1).getDetail().getId();
|
isLoad = false;
|
iv_loading.setVisibility(View.VISIBLE);
|
tv_loading.setText("正在加载更多是数据");
|
getAccountDesc();
|
}
|
}
|
}
|
|
@Override
|
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
super.onScrolled(recyclerView, dx, dy);
|
View view = linearLayoutManager.findViewByPosition(mCurrentPosition + 1);
|
|
//获取到的view顶部坐标小于悬浮条最底部的y轴坐标就是要重叠了
|
//datas.get(mCurrentPosition+1).isTo 表示下个item存在悬浮条
|
if (view != null && view.getTop() <= mSuspensionHeight && mList.size() > (mCurrentPosition + 1) && mList.get(mCurrentPosition + 1).getMonth() != null) {
|
ll_title.setY(-(mSuspensionHeight - view.getTop()));
|
float height = view.getTop();
|
// Log.e("mResult", "onScrolled: " + height);
|
|
} else {
|
ll_title.setY(0);
|
if (mList.size() - 1 <= mCurrentPosition) {
|
return;
|
}
|
if (dy >= 0) {
|
if (mList.get(mCurrentPosition).getMonth() != null) {
|
tv_select_time.setText(mList.get(mCurrentPosition).getMonth().getYear() + "年"
|
+ mList.get(mCurrentPosition).getMonth().getMonth() + "月");
|
tv_all_income.setText("总获得:¥" + mList.get(mCurrentPosition).getMonth().getIncome());
|
tv_all_expenses.setText("总使用:¥" + mList.get(mCurrentPosition).getMonth().getExpend());
|
}
|
} else {
|
if (mCurrentPosition >= 0 && mList.get(mCurrentPosition).getDetail() != null &&
|
mList.get(mCurrentPosition).getDetail().getAccountMonth() != null) {
|
// Log.e("mResult", mCurrentPosition + "");
|
tv_select_time.setText(mList.get(mCurrentPosition).getDetail().getAccountMonth().getYear() + "年"
|
+ mList.get(mCurrentPosition).getDetail().getAccountMonth().getMonth() + "月");
|
tv_all_income.setText("总获得:¥" + mList.get(mCurrentPosition).getDetail().getAccountMonth().getIncome());
|
tv_all_expenses.setText("总使用:¥" + mList.get(mCurrentPosition).getDetail().getAccountMonth().getExpend());
|
}
|
}
|
}
|
|
//mCurrentPosition 不是 当前显示最顶部的position
|
if (mCurrentPosition != linearLayoutManager.findFirstVisibleItemPosition()) {
|
mCurrentPosition = linearLayoutManager.findFirstVisibleItemPosition();
|
ll_title.setY(0);
|
}
|
}
|
});
|
}
|
|
/**
|
* 获取红包明细
|
*/
|
private void getAccountDesc() {
|
String uid = getSharedPreferences("user", MODE_PRIVATE).getString("uid", "");
|
ShoppingApi.getMoneyDetails(this, uid, index, mYear, mMonth, new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onStart() {
|
super.onStart();
|
if (!StringUtils.isEmpty(index)) {
|
bottom.setVisibility(View.VISIBLE);
|
} else {
|
bottom.setVisibility(View.GONE);
|
}
|
}
|
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optInt("code") == 0) {
|
Gson gson = new GsonBuilder().serializeNulls().create();
|
List<Account> list = gson.fromJson(jsonObject.optJSONObject("data").optJSONArray("data").toString(), new TypeToken<List<Account>>() {
|
}.getType());
|
boolean isSelectTime = false;
|
if (StringUtils.isEmpty(index)) {
|
mList.clear();
|
isSelectTime = true;
|
}
|
AccountMonth month = null;
|
for (int i = 0; i < list.size(); i++) {
|
if (list.get(i).getMonth() != null) {
|
month = list.get(i).getMonth();
|
}
|
if (list.get(i).getDetail() != null) {
|
list.get(i).getDetail().setAccountMonth(month);
|
}
|
}
|
mList.addAll(list);
|
//没有记录 显示无数据
|
if (mList.size() == 0) {
|
ll_no_data.setVisibility(View.VISIBLE);
|
srl_account_layout.setVisibility(View.GONE);
|
} else { // 有记录 显示记录
|
ll_no_data.setVisibility(View.GONE);
|
srl_account_layout.setVisibility(View.VISIBLE);
|
}
|
if (isSelectTime) {
|
rv_account_desc.setAdapter(adapter);
|
} else {
|
adapter.notifyDataSetChanged();
|
// adapter.notifyItemRangeChanged(mList.size() - 1, list.size());//倒序批量刷新列表
|
}
|
|
if (mList.size() == 1) {
|
tv_select_time.setText(mList.get(mCurrentPosition).getMonth().getYear() + "年"
|
+ mList.get(mCurrentPosition).getMonth().getMonth() + "月");
|
tv_all_income.setText("总获得:¥" + mList.get(mCurrentPosition).getMonth().getIncome());
|
tv_all_expenses.setText("总使用:¥" + mList.get(mCurrentPosition).getMonth().getExpend());
|
}
|
|
count = Integer.parseInt(jsonObject.optJSONObject("data").optString("count"));
|
if (mList.size() == count) {
|
bottom.setVisibility(View.VISIBLE);
|
iv_loading.setVisibility(View.GONE);
|
tv_loading.setText(getResources().getString(R.string.list_no_more));
|
} else {
|
bottom.setVisibility(View.GONE);
|
}
|
|
}
|
}
|
|
@Override
|
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
|
super.onFailure(statusCode, headers, responseString, throwable);
|
bottom.setVisibility(View.GONE);
|
}
|
|
@Override
|
public void onFinish() {
|
super.onFinish();
|
isLoad = true;
|
srl_account_desc.setRefreshing(false);
|
|
}
|
});
|
}
|
|
@Override
|
protected void onResume() {
|
super.onResume();
|
mChangeHelper.registerReceiver();
|
}
|
|
@Override
|
protected void onPause() {
|
super.onPause();
|
mChangeHelper.unregisterReceiver();
|
}
|
|
private void getAppPageNotification() {
|
ShoppingApi.getAppPageNotification(this, TYPE, new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optInt("code") == 0) {
|
boolean isClose = jsonObject.optJSONObject("data").optBoolean("canClose");
|
String content = jsonObject.optJSONObject("data").optString("content");
|
final String contentUrl = jsonObject.optJSONObject("data").optString("contentUrl");
|
final String md5 = jsonObject.optJSONObject("data").optString("md5");
|
|
tv_notice_content.setText(content);
|
final SharedPreferences sp = getSharedPreferences("notice", Context.MODE_PRIVATE);
|
if (!sp.getBoolean(md5, false)) {//false 展示,true不展示
|
ll_notice.setVisibility(View.VISIBLE);
|
} else {
|
ll_notice.setVisibility(View.GONE);
|
}
|
|
if (isClose) {
|
iv_close.setImageDrawable(getResources().getDrawable(R.drawable.ic_notice_close));
|
iv_close.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
ll_notice.setVisibility(View.GONE);
|
SharedPreferences.Editor editor = sp.edit();
|
editor.putBoolean(md5, true);
|
editor.commit();
|
}
|
});
|
} else {
|
iv_close.setImageDrawable(getResources().getDrawable(R.drawable.ic_notice_input));
|
}
|
ll_notice.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (StringUtils.isEmpty(contentUrl))
|
return;
|
Intent intent = new Intent(PromotionDetailActivity.this, ShareBrowserActivity.class);
|
intent.putExtra("url", contentUrl);
|
startActivity(intent);
|
}
|
});
|
} else {
|
|
}
|
}
|
});
|
}
|
|
@Override
|
public void onClick(View v) {
|
switch (v.getId()) {
|
case R.id.tv_top_bar_left:
|
finish();
|
break;
|
case R.id.ll_title:
|
// UserCustomEvent.userMoneyDetailMonthChoice(AccountDescActivity33.this);
|
long endTimestamp = System.currentTimeMillis();
|
int year = Calendar.getInstance().get(Calendar.YEAR);
|
int month = Calendar.getInstance().get(Calendar.MONTH) + 1;
|
long beginTimestamp = DateFormatUtils.str2Long((year - 4) + "年" + month + "月", false);
|
// 通过时间戳初始化日期,毫秒级别
|
mDatePicker = new CustomDatePicker(this, new CustomDatePicker.Callback() {
|
@Override
|
public void onTimeSelected(long timestamp) {
|
tv_select_time.setText(DateFormatUtils.long2Str(timestamp, false));
|
String cMonth = tv_select_time.getText().toString();
|
mYear = cMonth.substring(0, cMonth.indexOf("年"));
|
String temp = cMonth.substring(0, cMonth.indexOf("月"));
|
mMonth = temp.substring(temp.indexOf("年") + 1);
|
index = "";
|
mCurrentPosition = 0;
|
getAccountDesc();
|
}
|
}, beginTimestamp, endTimestamp, false);
|
// 不允许点击屏幕或物理返回键关闭
|
mDatePicker.setCancelable(true);
|
// 不显示时和分
|
mDatePicker.setCanShowPreciseTime(false);
|
// 不允许循环滚动
|
mDatePicker.setScrollLoop(false);
|
// 不允许滚动动画
|
mDatePicker.setCanShowAnim(false);
|
mDatePicker.show(tv_select_time.getText().toString());
|
break;
|
}
|
}
|
|
|
/**
|
* 请求状态 0 数据正常展示;1 返回数据为空;2 网络请求失败;3 没有连接网络
|
*
|
* @param state
|
*/
|
private void requestState(int state) {
|
srl_account_desc.setVisibility(state == 0 ? View.VISIBLE : View.GONE);
|
rv_account_desc.setVisibility(state == 0 ? View.VISIBLE : View.GONE);
|
ll_no_data.setVisibility(state == 1 ? View.VISIBLE : View.GONE);
|
ll_request_failture.setVisibility(state == 2 ? View.VISIBLE : View.GONE);
|
ll_no_net.setVisibility(state == 3 ? View.VISIBLE : View.GONE);
|
}
|
}
|