public class MyDingActivity extends AppCompatActivity {
private TabLayout tab;
private ViewPager vp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_ding);
findViewById();
final String[] title={"全部","待查付","已支付","已取消"};
for (int i=0;i<title.length;i++){
tab.addTab(tab.newTab().setText(title[i]));
}
vp.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
//2.重写这个方法getPageTitle,,,得到当前页面的标题
@Override
public CharSequence getPageTitle(int position) {
return title[position];
}
@Override
public Fragment getItem(int position) {
MyFragment myFragment = new MyFragment();
Bundle bundle=new Bundle();
bundle.putString("state",title[position]);
myFragment.setArguments(bundle);
return myFragment;
}
@Override
public int getCount() {
return title.length;
}
});
tab.setupWithViewPager(vp);
}
private void findViewById() {
vp = findViewById(R.id.vp);
tab = findViewById(R.id.tab);
}
}
public class MyFragment extends Fragment implements IChaDing, IUpdate {
private ChaDingPre chaDingPre;private View inflate;
private XRecyclerView xc;
private int page = 1;
private UpdatePre updatePre;
private String state;
private List<DingBean.DataBean> list = new ArrayList();
// List<DingBean.DataBean>
int a;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
inflate = View.inflate(getActivity(), R.layout.fragment_layout, null);
chaDingPre = new ChaDingPre(this);
updatePre = new UpdatePre(this);
state = getArguments().getString("state");
if ("全部".equals(state)){
a=3;
Log.i("state", state);
}else if ("待查付".equals(state)){
a=0;
}else if ("已支付".equals(state)){
a=1;
}else if ("已取消".equals(state)){
a=2;
}
return inflate;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
xc = inflate.findViewById(R.id.xc);
getDataFromet();
xc.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
xc.setPullRefreshEnabled(true);
xc.setLoadingMoreEnabled(true);
xc.setLoadingListener(new XRecyclerView.LoadingListener() {
@Override
public void onRefresh() {
getDataFromet();
}
@Override
public void onLoadMore() {
page++;
chaDingPre.setPath("https://www.zhaoapi.cn/product/getOrders?uid=2775&token=C1264FBBC844ADB47FFAC4333C20E8EE&page=" + page);
}
});
}
private void getDataFromet() {
chaDingPre.setPath("https://www.zhaoapi.cn/product/getOrders?uid=2775&token=C1264FBBC844ADB47FFAC4333C20E8EE&page=1");
}
@Override
public void success(DingBean dingBean) {
/* 订单状态:
0 待支付
1 已支付
2 已取消*/
List<DingBean.DataBean> data = dingBean.getData();
// Log.i("=======", a+"");
if (a==3){
list.clear();
list.addAll(data);
}else {
for (int i=0;i<data.size();i++){
if (data.get(i).getStatus()==a){
list.clear();
DingBean.DataBean dataBean= data.get(i);
list.add(dataBean);
}
}
}
XcAdapter adp = new XcAdapter(getActivity(), list);
xc.setAdapter(adp);
adp.setListner(new IQuxiao() {
@Override
public void getQuXiaoPosition(int Orderid) {
updatePre.setPath("https://www.zhaoapi.cn/product/updateOrder?uid=2775&status=2&orderId=" + Orderid + "&token=C1264FBBC844ADB47FFAC4333C20E8EE");
}
});
}
@Override
public void update(String msg) {
Log.i("++++", msg);
if ("订单状态修改成功".equals(msg)) {
chaDingPre.setPath("https://www.zhaoapi.cn/product/getOrders?uid=2775&token=C1264FBBC844ADB47FFAC4333C20E8EE&page=1");
}
}
}
public interface IChaDing {
void success(DingBean dingBean);
}
public interface IUpdate {
void update(String msg);
}