├── .idea ├── .name ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── vcs.xml ├── modules.xml ├── runConfigurations.xml ├── compiler.xml ├── gradle.xml └── misc.xml ├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ ├── drawable │ │ │ │ └── iconfont_shouqi.xml │ │ │ └── layout │ │ │ │ └── activity_main.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── lpf │ │ │ │ └── mvptest │ │ │ │ ├── base │ │ │ │ ├── BaseBean.java │ │ │ │ ├── BaseModel.java │ │ │ │ ├── MyApplication.java │ │ │ │ ├── IBasePresenter.java │ │ │ │ ├── IBaseView.java │ │ │ │ └── BasePresenterImpl.java │ │ │ │ ├── view │ │ │ │ ├── PhoneNumInfoView.java │ │ │ │ └── ui │ │ │ │ │ └── MainActivity.java │ │ │ │ ├── utils │ │ │ │ ├── AppContextUtil.java │ │ │ │ └── NetUtil.java │ │ │ │ ├── service │ │ │ │ └── PhoneNunInfoService.java │ │ │ │ ├── presenter │ │ │ │ └── PhonePresenterImpl.java │ │ │ │ ├── model │ │ │ │ ├── PhoneModelImpl.java │ │ │ │ └── PhoneNumInfo.java │ │ │ │ └── helper │ │ │ │ └── RetrofitManager.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── lpf │ │ │ └── mvptest │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── lpf │ │ └── mvptest │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── gradlew └── README.md /.idea/.name: -------------------------------------------------------------------------------- 1 | MVPTest -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | MVPTest 3 | 4 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/183619962/MVPTest/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/183619962/MVPTest/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/183619962/MVPTest/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/183619962/MVPTest/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/183619962/MVPTest/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/183619962/MVPTest/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Feb 19 21:36:54 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/lpf/mvptest/base/BaseBean.java: -------------------------------------------------------------------------------- 1 | package com.lpf.mvptest.base; 2 | 3 | /** 4 | * 接口的公共协议头 5 | */ 6 | public class BaseBean { 7 | 8 | public String success; 9 | 10 | public String getSuccess() { 11 | return success; 12 | } 13 | 14 | public void setSuccess(String success) { 15 | this.success = success; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/lpf/mvptest/base/BaseModel.java: -------------------------------------------------------------------------------- 1 | package com.lpf.mvptest.base; 2 | 3 | 4 | import com.lpf.mvptest.helper.RetrofitManager; 5 | 6 | /** 7 | * 业务对象的基类 8 | */ 9 | public class BaseModel { 10 | //retrofit请求数据的管理类 11 | public RetrofitManager retrofitManager; 12 | 13 | public BaseModel() { 14 | retrofitManager = RetrofitManager.builder(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/test/java/com/lpf/mvptest/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.lpf.mvptest; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/com/lpf/mvptest/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.lpf.mvptest; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/java/com/lpf/mvptest/view/PhoneNumInfoView.java: -------------------------------------------------------------------------------- 1 | package com.lpf.mvptest.view; 2 | 3 | import com.lpf.mvptest.base.IBaseView; 4 | import com.lpf.mvptest.model.PhoneNumInfo; 5 | 6 | /** 7 | * 号码归属地查询的View 8 | * 如果没有什么特殊的动作,可以不用定义这个view,在activity里面直接实现IBaseView接口即可 9 | * 10 | */ 11 | public interface PhoneNumInfoView extends IBaseView { 12 | //这里这么写的目的是为了明确view的作用,如果这里的view有更多的操作,可以在这里定义更多的接口 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/lpf/mvptest/utils/AppContextUtil.java: -------------------------------------------------------------------------------- 1 | package com.lpf.mvptest.utils; 2 | 3 | import android.content.Context; 4 | 5 | public class AppContextUtil { 6 | private static Context sContext; 7 | 8 | private AppContextUtil() { 9 | 10 | } 11 | 12 | public static void init(Context context) { 13 | sContext = context; 14 | } 15 | 16 | public static Context getInstance() { 17 | if (sContext == null) { 18 | throw new NullPointerException("the context is null,please init AppContextUtil in Application first."); 19 | } 20 | return sContext; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/lpf/mvptest/base/MyApplication.java: -------------------------------------------------------------------------------- 1 | package com.lpf.mvptest.base; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | 6 | import com.lpf.mvptest.utils.AppContextUtil; 7 | 8 | /** 9 | * Created by laucherish on 16/3/17. 10 | */ 11 | public class MyApplication extends Application { 12 | 13 | private static Context mApplicationContext; 14 | 15 | @Override 16 | public void onCreate() { 17 | super.onCreate(); 18 | AppContextUtil.init(this); 19 | mApplicationContext = this; 20 | } 21 | 22 | // 获取ApplicationContext 23 | public static Context getContext() { 24 | return mApplicationContext; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\bf\sdk_20160316\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/lpf/mvptest/base/IBasePresenter.java: -------------------------------------------------------------------------------- 1 | package com.lpf.mvptest.base; 2 | 3 | /** 4 | * 控制器的基础回调接口 5 | * Presenter用于接受model获取(加载)数据后的回调 6 | * Created by Administrator on 2016/3/23. 7 | */ 8 | public interface IBasePresenter { 9 | /** 10 | * 开始请求之前 11 | */ 12 | void beforeRequest(int requestTag); 13 | 14 | /** 15 | * 请求失败 16 | * 17 | * @param e 失败的原因 18 | */ 19 | void requestError(Throwable e, int requestTag); 20 | 21 | /** 22 | * 请求结束 23 | */ 24 | void requestComplete(int requestTag); 25 | 26 | /** 27 | * 请求成功 28 | * 29 | * @param callBack 根据业务返回相应的数据 30 | */ 31 | void retuestSuccess(T callBack, int requestTag); 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/iconfont_shouqi.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 23 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 20 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | ## Project-wide Gradle settings. 2 | # 3 | # For more details on how to configure your build environment visit 4 | # http://www.gradle.org/docs/current/userguide/build_environment.html 5 | # 6 | # Specifies the JVM arguments used for the daemon process. 7 | # The setting is particularly useful for tweaking memory settings. 8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 10 | # 11 | # When configured, Gradle will run in incubating parallel mode. 12 | # This option should only be used with decoupled projects. More details, visit 13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 14 | # org.gradle.parallel=true 15 | #Sun Apr 03 23:17:02 CST 2016 16 | systemProp.http.proxyHost=sdk.gdgshanghai.com 17 | systemProp.http.proxyPort=8000 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/lpf/mvptest/base/IBaseView.java: -------------------------------------------------------------------------------- 1 | package com.lpf.mvptest.base; 2 | 3 | /** 4 | * 视图(View层)基础回调接口 5 | */ 6 | public interface IBaseView { 7 | /** 8 | * 通过toast提示用户 9 | * 10 | * @param msg 提示的信息 11 | * @param requestTag 请求标识 12 | */ 13 | void toast(String msg, int requestTag); 14 | 15 | /** 16 | * 显示进度 17 | * 18 | * @param requestTag 请求标识 19 | */ 20 | void showProgress(int requestTag); 21 | 22 | /** 23 | * 隐藏进度 24 | * 25 | * @param requestTag 请求标识 26 | */ 27 | void hideProgress(int requestTag); 28 | 29 | /** 30 | * 基础的请求的返回 31 | * 32 | * @param data 33 | * @param requestTag 请求标识 34 | */ 35 | void loadDataSuccess(T data, int requestTag); 36 | 37 | /** 38 | * 基础请求的错误 39 | * 40 | * @param e 41 | * @param requestTag 请求标识 42 | */ 43 | void loadDataError(Throwable e, int requestTag); 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/com/lpf/mvptest/service/PhoneNunInfoService.java: -------------------------------------------------------------------------------- 1 | package com.lpf.mvptest.service; 2 | 3 | import com.lpf.mvptest.helper.RetrofitManager; 4 | import com.lpf.mvptest.model.PhoneNumInfo; 5 | 6 | import retrofit2.http.GET; 7 | import retrofit2.http.Headers; 8 | import retrofit2.http.POST; 9 | import retrofit2.http.Path; 10 | import retrofit2.http.Query; 11 | import rx.Observable; 12 | 13 | /** 14 | * 归属地请求的服务 15 | */ 16 | public interface PhoneNunInfoService { 17 | //http://api.k780.com:88/?app=phone.get&phone={phoneNum}&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json 18 | @Headers(RetrofitManager.CACHE_CONTROL_AGE + RetrofitManager.CACHE_STALE_LONG) 19 | @GET("/") 20 | Observable getBeforeNews(@Query("app") String app 21 | , @Query("phone") String phone 22 | , @Query("appkey") String appkey 23 | , @Query("sign") String sign 24 | , @Query("format") String format); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/lpf/mvptest/presenter/PhonePresenterImpl.java: -------------------------------------------------------------------------------- 1 | package com.lpf.mvptest.presenter; 2 | 3 | import android.content.Context; 4 | 5 | import com.lpf.mvptest.base.BasePresenterImpl; 6 | import com.lpf.mvptest.model.PhoneModelImpl; 7 | import com.lpf.mvptest.model.PhoneNumInfo; 8 | import com.lpf.mvptest.view.PhoneNumInfoView; 9 | 10 | 11 | /** 12 | * Presenter的实现,协调model去加载数据,获取model加载完成时候的回调,控制界面加载框的显示与隐藏 13 | */ 14 | public class PhonePresenterImpl extends BasePresenterImpl { 15 | private PhoneModelImpl phoneModel; 16 | private Context mContext; 17 | 18 | 19 | public PhonePresenterImpl(PhoneNumInfoView phoneNumInfoView, Context context) { 20 | super(phoneNumInfoView); 21 | this.mContext = context; 22 | phoneModel = new PhoneModelImpl(mContext); 23 | } 24 | 25 | /** 26 | * 获取归属地信息 27 | * 28 | * @param phoneNum 电话号码 29 | * @param requestTag 请求标识 30 | */ 31 | public void getPhoneNumInfo(String phoneNum, int requestTag) { 32 | phoneModel.loadPhoneNumInfo(phoneNum, this, requestTag); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/lpf/mvptest/base/BasePresenterImpl.java: -------------------------------------------------------------------------------- 1 | package com.lpf.mvptest.base; 2 | 3 | /** 4 | * 代理对象的基础实现 5 | * 6 | * @param 视图接口对象(view) 具体业务各自继承自IBaseView 7 | * @param 业务请求返回的具体对象 8 | */ 9 | public class BasePresenterImpl implements IBasePresenter { 10 | public IBaseView iView; 11 | 12 | /** 13 | * 构造方法 14 | * 15 | * @param view 具体业务的接口对象 16 | */ 17 | public BasePresenterImpl(T view) { 18 | this.iView = view; 19 | } 20 | 21 | @Override 22 | public void beforeRequest(int requestTag) { 23 | //显示LOading 24 | iView.showProgress(requestTag); 25 | } 26 | 27 | @Override 28 | public void requestError(Throwable e, int requestTag) { 29 | //通知UI具体的错误信息 30 | iView.loadDataError(e,requestTag); 31 | } 32 | 33 | @Override 34 | public void requestComplete(int requestTag) { 35 | //隐藏Loading 36 | iView.hideProgress(requestTag); 37 | } 38 | 39 | @Override 40 | public void retuestSuccess(V callBack, int requestTag) { 41 | //将获取的数据回调给UI(activity或者fragment) 42 | iView.loadDataSuccess(callBack, requestTag); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.lpf.mvptest" 9 | minSdkVersion 10 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.2.1' 26 | // retrofit2 + okhttp3 27 | compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4' 28 | compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4' 29 | compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4' 30 | compile 'com.squareup.okhttp3:okhttp:3.2.0' 31 | compile 'com.squareup.okhttp3:logging-interceptor:3.2.0' 32 | // rxjava 33 | compile 'io.reactivex:rxandroid:1.1.0' 34 | compile 'io.reactivex:rxjava:1.1.0' 35 | // stetho 36 | compile 'com.facebook.stetho:stetho:1.3.1' 37 | compile 'com.facebook.stetho:stetho-okhttp3:1.3.1' 38 | 39 | compile 'com.jakewharton:butterknife:7.0.1' 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 16 | 17 | 21 | 22 | 27 | 28 | 29 | 30 |