m层
public interface IModel {
void getNetModel(IView view);
}
public class NetModel implements IModel {
@Override
public void getNetModel( final IView view) {
Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl("http://c.m.163.com/nc/article/")
.build();
GetData getData = retrofit.create(GetData.class);
Call<Info> data = getData.getDdata();
data.enqueue(new Callback<Info>() {
@Override
public void onResponse(Call<Info> call, Response<Info> response) {
view.onResponse(call, response);
}
@Override
public void onFailure(Call<Info> call, Throwable t) {
view.onFailure(call, t);
}
});
}
public interface GetData{
@GET("list/T1379038288239/0-20.html")
@Headers("User-Agent:dlb")
Call<Info> getDdata();
}
}
V层
public interface IView<T> {
void onResponse(Call<T> call, Response<T> response);
void onFailure(Call<T> call,Throwable t);
}
P层
public interface IPersenter {
void getNetPersenter();
}
public class NetPersenter implements IPersenter, IView {
IView iView;
IModel iModel;
public NetPersenter(IView iView) {
this.iView = iView;
iModel=new NetModel();
}
@Override
public void getNetPersenter() {
iModel.getNetModel(this);
}
@Override
public void onResponse(Call call, Response response) {
iView.onResponse(call, response);
}
@Override
public void onFailure(Call call, Throwable t) {
iView.onFailure(call, t);
}
}