Mvp抽取

package com.example.zz201937.Model;

/**
 * @Auther: luck
 * @Date: 2019/3/7 08:58:07
 * @Description:
 */
public interface Model_2 {
    void getshow(String url, Callback callback);
    void zhucedata(String url,String phone,String pwd,Callback callback);
    interface Callback{
        void onsuess(String data);
        void Loseer();
    }

}

public class Model implements Model_2{
    @Override
    public void getshow(String url, final Callback callback) {
        OkHttpUtils.getInstance().doget(url, new okhttp3.Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                callback.onsuess(response.body().string());
            }
        });
    }

    @Override
    public void zhucedata(String url, String phone, String pwd, final Callback callback) {
        OkHttpUtils.getInstance().dopost(url, phone, pwd, new okhttp3.Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
            callback.onsuess(response.body().string());
            }
        });

    }
}
package com.example.zz201937.View;

/**
 * @Auther: luck
 * @Date: 2019/3/7 09:01:02
 * @Description:
 */
public interface View {

    void getshowView(String data);
    void getzhucedata(String data);

}
package com.example.zz201937.Presenter;

/**
 * @Auther: luck
 * @Date: 2019/3/7 09:01:43
 * @Description:
 */
public interface Presenter_2 {

  //需要传值时在这写参数
    void getpresenterdata(String name);
    void getzhucepresenterdata(String phone,String pwd);
}

package com.example.zz201937.Presenter;

import com.example.zz201937.Api;
import com.example.zz201937.Model.Model;
import com.example.zz201937.Model.Model_2;
import com.example.zz201937.View.View;

/**
 * @Auther: luck
 * @Date: 2019/3/7 09:01:34
 * @Description:
 */
public class Presenter implements Presenter_2{
    private Model model;
    private View view;

    public Presenter(View view) {
        model=new Model();
        this.view = view;
    }


    @Override
    public void getpresenterdata(String name) {
        model.getshow(Api.SAPi, new Model_2.Callback() {
            @Override
            public void onsuess(String data) {
                view.getshowView(data);
            }

            @Override
            public void Loseer() {

            }
        });
    }

    @Override
    public void getzhucepresenterdata(String phone, String pwd) {
        model.zhucedata(Api.SAPi, phone, pwd, new Model_2.Callback() {
            @Override
            public void onsuess(String data) {
                view.getzhucedata(data);
            }

            @Override
            public void Loseer() {

            }
        });
    }
}
   @Override
    public void getHomeView(final String data) {


        getActivity().runOnUiThread(new Runnable() {

            private MyHomeAdapter myHomeAdapter;

            @Override
            public void run() {
                Gson gson = new Gson();
                HomeBean homeBean = gson.fromJson(data, HomeBean.class);
                HomeBean.ResultBean result = homeBean.getResult();
                commodityList = result.getRxxp().getCommodityList();
                myHomeAdapter = new MyHomeAdapter(getContext(), commodityList);


                xrecyclerview.setLayoutManager(new LinearLayoutManager(getActivity(), OrientationHelper.VERTICAL, false));
                myHomeAdapter.notifyDataSetChanged();
                xrecyclerview.setAdapter(myHomeAdapter);
               /* ck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                      myHomeAdapter.Chekca(isChecked);
                    }
                });*/
                //
                //选中之后传来值
                ck.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (ck.isChecked()){
                            myHomeAdapter.isCheck(true);
                        }else {
                            myHomeAdapter.isCheck(false);
                        }
                    }
                });
                //这是选中接口回调从Adapter里传来
                myHomeAdapter.setOncheckClick(new MyHomeAdapter.OncheckClick() {
                    @Override
                    public void setBoolean(boolean check) {
                        ck.setChecked(check);
                    }
                });


                //这是钱的接口回调从Adapter里传来
                myHomeAdapter.setOnMoneyClick(new MyHomeAdapter.OnMoneyClick() {
                    @Override
                    public void setBoolean(int money) {
                        ck.setText(money+"");
                    }
                });
            }
        });


    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值