订单

//model
public class Model2 implements ModelPort2{
    PresenterPort1 po;

    public Model2(PresenterPort1 po) {
        this.po = po;
    }

    @Override
    public void update(String url) {
        NetWorkOkHttp.doGet(url, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                            if(response.isSuccessful()) {
                                String s = response.body().string();
                                if (s != "" && s != null) {
                                    Gson gson = new Gson();
                                    MyDeteAdd myDeteAdd = gson.fromJson(s, MyDeteAdd.class);
                                    po.update(myDeteAdd);
                                }
                            }
            }
        });
    }
}


//model接口
public interface ModelPort2 {
    public void update(String url);
}
//presenter
public class Presenter1 implements PresenterPort1 {
    Main2 ma;
    ModelPort2 mo;
    public Presenter1(Main2 ma) {
        this.ma = ma;
        mo=new Model2(this);
    }
    public void getadd(String url){
        mo.update(url);
    }

    @Override
    public void update(MyDeteAdd myDeteGouWu) {
        ma.gou(myDeteGouWu);
    }
}


//接口
public interface PresenterPort1 {
    public void update(MyDeteAdd myDeteGouWu);
}


//接口
public interface Main2 {
    public void gou(MyDeteAdd myDeteGouWu);
}






//布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
        <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <TextView
        android:id="@+id/dingtite"
        android:layout_width="wrap_content"
        android:layout_weight="1"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/zhifu"
        android:layout_width="70dp"
        android:layout_height="wrap_content" />

</LinearLayout>


    <TextView
        android:id="@+id/dingpric"
        android:layout_width="wrap_content"
        android:gravity="center_vertical"
        android:layout_height="50dp"
        android:textColor="#FF00"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:id="@+id/dingtime"
            android:layout_width="wrap_content"
            android:layout_weight="1"
            android:layout_height="40dp" />

        <Button
            android:id="@+id/quxiao"
            android:layout_width="70dp"
            android:layout_height="40dp"
            android:text="取消订单"/>

    </LinearLayout>
</LinearLayout>
//适配器

public class DingDanRecy extends BaseAdapter implements Main2 {
    Context context;
    List<MySelectDingDan.DataBean> data;
    private final Presenter1 pr;

    public DingDanRecy(Context context, List<MySelectDingDan.DataBean> data) {
        this.context = context;
        this.data=data;
        pr = new Presenter1(this);

    }


    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        final Hodels holder;
        if(view==null){
            holder=new Hodels();
            view=View.inflate(context,R.layout.dingdanrecy,null);
           holder.bu = (Button) view.findViewById(R.id.quxiao);
            holder.dingtime = (TextView) view.findViewById(R.id.dingtime);
            holder.dingtite = (TextView) view.findViewById(R.id.dingtite);
            holder.zhifu = (TextView) view.findViewById(R.id.zhifu);
            holder.dingpric = (TextView)view.findViewById(R.id.dingpric);
            view.setTag(holder);
        }else{
            holder=(Hodels)view.getTag();
        }
        holder.dingtime.setText(data.get(i).getCreatetime());
        holder.dingpric.setText(data.get(i).getPrice()+"");
        holder.dingtite.setText(data.get(i).getTitle());
        int status = data.get(i).getStatus();
        if(status==0){
            holder.zhifu.setText("待支付");
        }else if(status==1){
            holder.zhifu.setText("已支付");
            holder.bu.setText("查看订单");
        }else{
            holder.zhifu.setText("已取消");
            holder.bu.setText("查看订单");
        }
        holder.bu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog.Builder bu=new AlertDialog.Builder(context);
                bu.setTitle("确认"+holder.bu.getText());
                bu.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int j) {if(data.get(i).getStatus()==0) {
                        pr.getadd("https://www.zhaoapi.cn/product/updateOrder?uid=3907&status=1&orderId=" + data.get(i).getOrderid());
                        notifyDataSetChanged();
                    }else if(data.get(i).getStatus()==1){
                        pr.getadd("https://www.zhaoapi.cn/product/updateOrder?uid=3907&status=2&orderId=" + data.get(i).getOrderid());
                        notifyDataSetChanged();
                    }else{
                        notifyDataSetChanged();
                    }


                    }
                });
                bu.setNeutralButton("取消",null);
                bu.show();
                notifyDataSetChanged();
            }
        });
        return view;
    }

    @Override
    public void gou(MyDeteAdd myDeteGouWu) {

    }

    class  Hodels{
    public  TextView dingtite;
    public TextView zhifu;
    public  TextView dingpric;
    public  TextView dingtime;
    public  Button bu;
}


}
 
 
//Viewpager适配器
 
/**
 * Created by dell on 2017/12/20.
 */

public class ListPagerBase extends FragmentPagerAdapter {
    List<String> li;
    List<Fragment> frs;


    public ListPagerBase(FragmentManager fm,List<Fragment> frs, List<String> li) {
        super(fm);
        this.li=li;
        this.frs=frs;
    }
    @Override
    public Fragment getItem(int position) {
        return frs.get(position);
    }

    @Override
    public int getCount() {
        return frs.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return li.get(position);
    }
}

 
/**定单界面
 * Created by dell on 2017/12/19.
 */

public class FragmentDingDan extends Fragment{

    private View view;
    private RecyclerView re;
    private Presenter pr;
    private TabLayout tab;
    private ViewPager pv;
    private List<String> li;
    private List<Fragment> frs;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragmentdingdan, container, false);
         tab= (TabLayout) view.findViewById(R.id.tab);
        pv = (ViewPager) view.findViewById(R.id.pv);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        li = new ArrayList<>();
        frs = new ArrayList<>();

        li.add("全部");
        li.add("待支付");
        li.add("已支付");
        li.add("已取消");
        for(int i = 0; i< li.size(); i++){
            tab.addTab(tab.newTab().setText( li.get(i)));
        }
        FragmentDZF de=new FragmentDZF();
        FragmentQB qx=new FragmentQB();
        FragmentWZF w=new FragmentWZF();
        FragmentYZH y=new FragmentYZH();

        frs.add(qx);
        frs.add(de);
        frs.add(w);
        frs.add(y);
        FragmentManager childFragmentManager = getChildFragmentManager();
        ListPagerBase pa=new ListPagerBase(childFragmentManager, frs, li);
        pv.setAdapter(pa);
        tab.setupWithViewPager(pv);
        tab.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                String s = tab.getText().toString();
                Toast.makeText(getActivity(),"---"+s,Toast.LENGTH_SHORT).show();
                for (int i = 0; i< li.size(); i++){
                    if(s.equals(li.get(i))){
                        pv.setCurrentItem(i);
                    }
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });


    }
}

 
 
 
 
/**
 * Created by dell on 2017/12/20.
 */

public class FragmentQB extends Fragment implements Main1 {

    private View view;
    private Presenter pr;
//自定义ListView控件使用PullToRefreshScrollView需计算listView的高度

    private ListView1 re;
    List<MySelectDingDan.DataBean> data=new ArrayList<>();
    private DingDanRecy din;
    private PullToRefreshScrollView pu;
    int pid=1;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragmentqb, container, false);
        re = (ListView1) view.findViewById(R.id.qdinglv);
       pu = (PullToRefreshScrollView) view.findViewById(R.id.pull);
        pr = new Presenter(this);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        pr.getselectdingdan("https://www.zhaoapi.cn/product/getOrders?uid=3907");
      pu.setMode(PullToRefreshBase.Mode.BOTH);
//设置刷新
        ILoadingLayout loadingLayoutProxy = pu.getLoadingLayoutProxy(true, false);
        loadingLayoutProxy.setPullLabel("下拉刷新");
        loadingLayoutProxy.setRefreshingLabel("正在拉");
        loadingLayoutProxy.setReleaseLabel("放开刷新");
        ILoadingLayout load = pu.getLoadingLayoutProxy(false, true);
        load.setPullLabel("上拉刷新");
        load.setRefreshingLabel("正在加载");
        load.setReleaseLabel("放开刷新");

    }

    @Override
    public void gou(MyDeteGouWu myDeteGouWu) {

    }

    @Override
    public void add(MyDeteAdd myDeteAdd) {

    }

    @Override
    public void dingDan(MyDingDan myDeteAdd) {

    }

    @Override
    public void selectDingDan(final MySelectDingDan mySelectDingDan) {
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                data.addAll( mySelectDingDan.getData());
              Toast.makeText(getActivity(),""+data.get(5).getTitle(),Toast.LENGTH_LONG).show();
                if(din==null){
                    din= new DingDanRecy(getActivity(),data);
                     re.setAdapter(din);
                }else{
                    din.notifyDataSetChanged();
                }

               pu.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
                    @Override
                    public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                        data.clear();
                        pr.getselectdingdan("https://www.zhaoapi.cn/product/getOrders?uid=3907&page=1");
                        pu.onRefreshComplete();
                    }
                    @Override
                    public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                        pid++;
                        pr.getselectdingdan("https://www.zhaoapi.cn/product/getOrders?uid=3907&page="+pid);
                        pu.onRefreshComplete();
                    }
                });

            }
        });
    }
}

 
 
 
//自定义适配器
public class ListView1 extends ListView {

    public ListView1(Context context) {
        super(context);
    }

    public ListView1(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ListView1(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//计算ListView的高度
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
                MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }
}

 
 
 
//布局文件
 <com.handmark.pulltorefresh.library.PullToRefreshScrollView
     xmlns:ptr="http://schemas.android.com/apk/res-auto"
     android:id="@+id/pull"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     ptr:ptrAnimationStyle="flip"
     ptr:ptrDrawable="@drawable/default_ptr_flip"
     ptr:ptrHeaderBackground="#383838"
     ptr:ptrHeaderTextColor="#FFFFFF">
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent">
         <com.example.dell.wanghao2011.View.ListView1
             android:id="@+id/qdinglv"
             android:layout_width="match_parent"
             android:layout_height="wrap_content">

         </com.example.dell.wanghao2011.View.ListView1>

     </LinearLayout>

</com.handmark.pulltorefresh.library.PullToRefreshScrollView>


                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值