MVP parsing and mvp mode parsing practices
A set of MVP frameworks that can be directly copied and used
Through the MVP design model learning, I also have a preliminary understanding of MVP. Taking logging on to the Login module as an example, the MVP is encapsulated as follows:
Package com. example. administrator. frameapp. api;/*** interface for storing URLs * Created by Zyh on 2016/11/17. */public interface ApiUrl {String IP = "http: // 192.168.8.4/tp3/"; String BASEURL = IP + "api. php/Home /";}
package com.example.administrator.frameapp.api;import io.reactivex.Flowable;import retrofit2.http.Field;import retrofit2.http.FormUrlEncoded;import retrofit2.http.POST;/** * Created by Zyh on 2016/11/17. */public interface ApiService { @FormUrlEncoded @POST("login/login") Flowable<ApiResult> login(@Field("name") String name, @Field("password") String password);}
package com.example.administrator.frameapp.api;/** * Created by Zyh on 2016/11/17. */public class ApiResult<T> { private int code; private String Msg; private T data; public int getCode() { return code; } @Override public String toString() { return "ApiResult{" + "code=" + code + ", Msg='" + Msg + '\'' + ", data=" + data + '}'; } public void setCode(int code) { this.code = code; } public String getMsg() { return Msg; } public void setMsg(String msg) { Msg = msg; } public T getData() { return data; } public void setData(T data) { this.data = data; }}
Package com. example. administrator. frameapp. api; import com. jakewharton. using fit2.adapter. rxjava2.RxJava2CallAdapterFactory; import okhttp3.OkHttpClient; import okhttp3.logging. httpLoggingInterceptor; import using fit2.20.fit; import using fit2.converter. gson. gsonConverterFactory;/*** Created by Zyh on 2016/11/17. */public class Api {private paifit m0000fit; public ApiService mApiservice; private Api () {HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor (); interceptor. setLevel (HttpLoggingInterceptor. level. BODY); // The request content and response content both exist in the system BODY OkHttpClient mOkHttpClient = new OkHttpClient. builder (). addInterceptor (interceptor ). build (); m1_fit = new 1_fit. builder (). client (mOkHttpClient ). addCallAdapterFactory (RxJava2CallAdapterFactory. create ()). addConverterFactory (GsonConverterFactory. create ()). baseUrl (ApiUrl. BASEURL ). build (); mApiservice = m1_fit. create (ApiService. class);} // Singleton mode of the static internal class: the internal class determines when to load it, private static class SingleHolder {private static final Api INSTANCE = new Api ();} public static Api getInstance () {return SingleHolder. INSTANCE ;}}
Package com. example. administrator. frameapp. ui. base;/*** create base class for unified management * BasePresent is an abstract class * Associate model and view * Created by Zyh on. */public abstract class BasePresent <M, V> {public M mModel; public V mView; public void setVM (V v, M m) {// this method maps the types in the Chinese method of LoginPresenter to specific types. this. mModel = m; this. mView = v ;}}
package com.example.administrator.frameapp.ui.base;/** * Created by Zyh on 2016/11/17. */public interface BaseView {}
package com.example.administrator.frameapp.ui.base;/** * Created by Zyh on 2016/11/17. */public interface BaseModel {}