package com.tejia.lijin.app.ui.BrandRebate;
|
|
import android.content.DialogInterface;
|
import android.content.SharedPreferences;
|
import android.graphics.Color;
|
import android.graphics.drawable.AnimationDrawable;
|
import android.os.Build;
|
import android.os.Bundle;
|
import androidx.appcompat.widget.LinearLayoutCompat;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.RecyclerView;
|
import android.view.LayoutInflater;
|
import android.view.MotionEvent;
|
import android.view.View;
|
import android.view.Window;
|
import android.view.WindowManager;
|
import android.widget.CheckBox;
|
import android.widget.CompoundButton;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.RelativeLayout;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.app.hubert.guide.util.ScreenUtils;
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.google.gson.reflect.TypeToken;
|
import com.tejia.lijin.app.ShoppingApplication;
|
import com.tejia.lijin.app.util.user.UserUtil;
|
import com.wpc.library.okhttp.OkHttpUtils;
|
import com.wpc.library.util.NetUtils;
|
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.dialog.OrderAppealHistoryDeleteHintDialog;
|
|
import org.apache.http.Header;
|
import org.json.JSONObject;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 店铺足迹
|
*/
|
public class BrandFootprintInfoActivity extends BaseActivity implements View.OnClickListener {
|
private TextView tv_middle, tv_top_bar_left;
|
private LinearLayout ll_no_net, ll_request_failture;
|
private TextView tv_top_bar_right;
|
private RecyclerView brandfootprintinfo_rv;
|
private BrandFootprintInfoAdapter adapter;//淘宝商品适配
|
private List<History> mlist = new ArrayList<>();
|
private LinearLayoutCompat brandfootprintinfo_buttom;
|
protected CheckBox brandfootprintinfo_cb;//全选
|
private TextView brandfootprintinfo_delete;//删除
|
private LinearLayout brandfootprintinfo_go_scan;//无数据
|
View bottom;
|
LinearLayout ff_loading;
|
TextView tv_loading;
|
ImageView iv_loading;
|
private int page = 1;
|
private boolean isLoad = true;
|
private int count = 1;
|
private boolean cb_touch = false;
|
|
private String tag1 = "brand/getHistory";
|
private String tag2 = "brand/deleteHistory";
|
|
@Override
|
protected void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
setContentView(R.layout.activity_brandfootprintinfo);
|
inint();//初始化控件
|
OnClickListener();//註冊单击事件
|
tv_middle.setText("店铺足迹");
|
tv_top_bar_right.setText("编辑");
|
|
brandfootprintinfo_rv.setLayoutManager(new LinearLayoutManager(this));
|
brandfootprintinfo_rv.setBackgroundColor(getResources().getColor(R.color.white));
|
|
adapter = new BrandFootprintInfoAdapter(this, mlist, null, false);
|
adapter.isHorizontal = true;
|
adapter.isFirst = true;
|
brandfootprintinfo_rv.setAdapter(adapter);
|
bottom = LayoutInflater.from(this).inflate(R.layout.item_recyclerview_bottom2, null);
|
tv_loading = bottom.findViewById(R.id.tv_loading2);
|
iv_loading = bottom.findViewById(R.id.iv_loading2);
|
bottom.findViewById(R.id.ff_loading2).setBackgroundColor(Color.parseColor("#ffffffff"));
|
AnimationDrawable animationDrawable = (AnimationDrawable) getResources().getDrawable(R.drawable.anim_list_loading);
|
iv_loading.setImageDrawable(animationDrawable);
|
animationDrawable.start();
|
bottom.setVisibility(View.GONE);
|
adapter.addFooterView(bottom);
|
|
brandfootprintinfo_rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
@Override
|
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
super.onScrollStateChanged(recyclerView, newState);
|
LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
|
int first = manager.findFirstVisibleItemPosition();
|
int last = manager.findLastVisibleItemPosition();
|
int total = manager.getItemCount();
|
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
if (last == total - 1 && mlist.size() < count && isLoad) {
|
page++;
|
isLoad = false;
|
tv_loading.setText(getResources().getString(R.string.loading_more_text));
|
iv_loading.setVisibility(View.VISIBLE);
|
getHistory();
|
}
|
}
|
}
|
});
|
brandfootprintinfo_cb.setOnTouchListener(new View.OnTouchListener() {
|
@Override
|
public boolean onTouch(View v, MotionEvent event) {
|
cb_touch = true;
|
return false;
|
}
|
});
|
//全选
|
brandfootprintinfo_cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
@Override
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
if (isChecked) {
|
adapter.setMdisplay(true);
|
} else {
|
if (cb_touch)
|
adapter.setMdisplay(false);
|
}
|
cb_touch = false;
|
}
|
});
|
}
|
|
@Override
|
protected void onResume() {
|
super.onResume();
|
getHistory();
|
}
|
|
private void getHistory() {
|
SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
|
ShoppingApi.getHistory(this, page + "", UserUtil.getUid(ShoppingApplication.application), "2", new BasicTextHttpResponseHandler() {
|
@Override
|
public void onStart() {
|
super.onStart();
|
if (page > 1) {
|
bottom.setVisibility(View.VISIBLE);
|
} else {
|
bottom.setVisibility(View.GONE);
|
}
|
}
|
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optString("code").equalsIgnoreCase("0")) {
|
Gson gson = new GsonBuilder().serializeNulls().create();
|
List<History> list = gson.fromJson(jsonObject.optJSONObject("data").optJSONArray("list").toString(),
|
new TypeToken<List<History>>() {
|
}.getType());
|
count = Integer.parseInt(jsonObject.optJSONObject("data").optString("count"));
|
if (page == 1 && mlist.size() > 0)//防止 删除刷新后数据重复
|
mlist.clear();
|
if (count == 0) {
|
brandfootprintinfo_rv.setVisibility(View.GONE);
|
brandfootprintinfo_buttom.setVisibility(View.GONE);
|
tv_top_bar_right.setVisibility(View.GONE);
|
brandfootprintinfo_go_scan.setVisibility(View.VISIBLE);
|
} else {
|
mlist.addAll(list);
|
}
|
|
if (mlist.size() >= count && mlist.size() > 5) {
|
bottom.setVisibility(View.VISIBLE);
|
iv_loading.setVisibility(View.GONE);
|
tv_loading.setText(getResources().getString(R.string.list_no_more));
|
} else {
|
bottom.setVisibility(View.GONE);
|
}
|
adapter.notifyDataSetChanged();
|
isLoad = true;
|
}
|
}
|
|
@Override
|
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
|
super.onFailure(statusCode, headers, responseString, throwable);
|
bottom.setVisibility(View.GONE);
|
if (mlist.size() == 0) {
|
if (NetUtils.getNetworkState(BrandFootprintInfoActivity.this).equalsIgnoreCase(NetUtils.NETWORK_NONE)) {
|
requestState(3);
|
} else {
|
requestState(2);
|
}
|
} else {
|
if (NetUtils.getNetworkState(BrandFootprintInfoActivity.this).equalsIgnoreCase(NetUtils.NETWORK_NONE)) {
|
// SingleToast.showToast(MyFootmarkActivity.this, "网络未连接,请检测网络设置");
|
Toast.makeText(BrandFootprintInfoActivity.this, "网络未连接,请检测网络设置", Toast.LENGTH_SHORT).show();
|
} else {
|
// SingleToast.showToast(MyFootmarkActivity.this, "网络连接异常,请检测网络设置");
|
Toast.makeText(BrandFootprintInfoActivity.this, "网络连接异常,请检测网络设置", Toast.LENGTH_SHORT).show();
|
}
|
}
|
}
|
|
@Override
|
public void onFinish() {
|
super.onFinish();
|
isLoad = true;
|
}
|
});
|
}
|
|
private void requestState(int state) {
|
tv_top_bar_right.setVisibility(state == 0 ? View.VISIBLE : View.INVISIBLE);
|
brandfootprintinfo_go_scan.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);
|
}
|
|
/**
|
* 初始化控件
|
*/
|
private void inint() {
|
tv_middle = findViewById(R.id.tv_top_bar_middle);
|
tv_top_bar_left = findViewById(R.id.tv_top_bar_left);
|
tv_top_bar_right = findViewById(R.id.tv_top_bar_right);
|
brandfootprintinfo_rv = findViewById(R.id.brandfootprintinfo_rv);
|
brandfootprintinfo_delete = findViewById(R.id.brandfootprintinfo_delete);
|
brandfootprintinfo_cb = findViewById(R.id.brandfootprintinfo_cb);
|
brandfootprintinfo_buttom = findViewById(R.id.brandfootprintinfo_buttom);
|
brandfootprintinfo_go_scan = findViewById(R.id.brandfootprintinfo_go_scan);
|
ll_request_failture = findViewById(R.id.ll_request_failture);
|
ll_no_net = findViewById(R.id.ll_no_net);
|
tv_top_bar_right.setVisibility(View.VISIBLE);
|
|
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) tv_top_bar_right.getLayoutParams();
|
lp.leftMargin = ScreenUtils.dp2px(this, 15);
|
tv_top_bar_right.setLayoutParams(lp);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
Window window = getWindow();
|
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
window.setStatusBarColor(Color.TRANSPARENT);
|
int result = 0;
|
int resourceId = getResources().getIdentifier("status_bar_height",
|
"dimen", "android");
|
if (resourceId > 0) {
|
result = getResources().getDimensionPixelSize(resourceId);
|
}
|
//设置状态栏文字颜色及图标为深色
|
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
|
result);
|
findViewById(R.id.v_status_bar).setLayoutParams(params);
|
} else {
|
findViewById(R.id.v_status_bar).setVisibility(View.GONE);
|
}
|
}
|
|
/**
|
* 註冊单击事件
|
*/
|
private void OnClickListener() {
|
tv_top_bar_left.setOnClickListener(this);
|
tv_top_bar_right.setOnClickListener(this);
|
brandfootprintinfo_delete.setOnClickListener(this);
|
}
|
|
@Override
|
public void onClick(View v) {
|
switch (v.getId()) {
|
//j返回
|
case R.id.tv_top_bar_left:
|
finish();
|
break;
|
//编辑or完成
|
case R.id.tv_top_bar_right:
|
if (tv_top_bar_right.getText().toString().equals("完成")) {//完成 状态
|
tv_top_bar_right.setText("编辑");
|
adapter.setSelectedMode(false);//设置 全选取消
|
adapter.setMdisplay(false);
|
brandfootprintinfo_buttom.setVisibility(View.GONE);
|
} else {//编辑状态
|
tv_top_bar_right.setText("完成");
|
adapter.setSelectedMode(true);//设置全选
|
brandfootprintinfo_buttom.setVisibility(View.VISIBLE);
|
if (brandfootprintinfo_cb.isChecked()) {
|
brandfootprintinfo_cb.setChecked(false);
|
}
|
adapter.setMdisplay(false);
|
}
|
|
break;
|
|
case R.id.brandfootprintinfo_delete://删除
|
Map<String, String> map = adapter.getMaps();
|
if (map.size() > 0) {
|
String sid = "";
|
for (String key : map.keySet()) {
|
String value = map.get(key);
|
System.out.println(key + " " + value);
|
if (sid.equals("")) {
|
sid = value;
|
} else {
|
sid += "," + value;
|
}
|
}
|
|
OrderAppealHistoryDeleteHintDialog.Builder builder = new OrderAppealHistoryDeleteHintDialog.Builder(this);
|
final String finalSid = sid;
|
builder.setMessage("确定要删除足迹吗?").setNegativeButton("不了", new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
dialog.dismiss();
|
}
|
}).setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
dialog.dismiss();
|
deleteHistory(finalSid);
|
if (brandfootprintinfo_cb.isChecked()) {
|
brandfootprintinfo_cb.setChecked(false);
|
} else {
|
adapter.setMdisplay(false);
|
}
|
}
|
}).create().show();
|
|
} else {
|
Toast.makeText(this, "请选择删除项", Toast.LENGTH_LONG).show();
|
}
|
break;
|
|
default:
|
break;
|
}
|
}
|
|
/**
|
* .删除选中店铺
|
*
|
* @param sid
|
*/
|
private void deleteHistory(String sid) {
|
SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
|
ShoppingApi.deleteHistory(this, sid, UserUtil.getUid(ShoppingApplication.application), new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optInt("code") == 0) {
|
page = 1;
|
getHistory();
|
}
|
|
}
|
});
|
}
|
|
@Override
|
protected void onDestroy() {
|
super.onDestroy();
|
brandfootprintinfo_rv = null;
|
adapter = null;//淘宝商品适配
|
mlist = null;
|
brandfootprintinfo_buttom = null;
|
brandfootprintinfo_cb = null;//全选
|
brandfootprintinfo_delete = null;//删除
|
brandfootprintinfo_go_scan = null;//无数据
|
bottom = null;
|
ff_loading = null;
|
tv_loading = null;
|
iv_loading = null;
|
page = 0;
|
isLoad = false;
|
count = 0;
|
OkHttpUtils.getInstance().cancelTag(tag1);
|
OkHttpUtils.getInstance().cancelTag(tag2);
|
}
|
}
|