package com.example.zz201937.Model;
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;
public interface View {
void getshowView(String data);
void getzhucedata(String data);
}
package com.example.zz201937.Presenter;
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;
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.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ck.isChecked()){
myHomeAdapter.isCheck(true);
}else {
myHomeAdapter.isCheck(false);
}
}
});
myHomeAdapter.setOncheckClick(new MyHomeAdapter.OncheckClick() {
@Override
public void setBoolean(boolean check) {
ck.setChecked(check);
}
});
myHomeAdapter.setOnMoneyClick(new MyHomeAdapter.OnMoneyClick() {
@Override
public void setBoolean(int money) {
ck.setText(money+"");
}
});
}
});
}