├── .gitignore ├── .idea ├── caches │ ├── build_file_checksums.ser │ └── gradle_models.ser ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── VERSION.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── whh │ │ └── initmvp │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── whh │ │ │ └── initmvp │ │ │ ├── MyApp.java │ │ │ ├── activity │ │ │ ├── EventBusActivity.java │ │ │ ├── GlideActivity.java │ │ │ ├── HttpAppVersionActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── RecyclerViewActivity.java │ │ │ └── WeatherActivity.java │ │ │ ├── adapter │ │ │ ├── ListAdapter.java │ │ │ └── ListAdapter2.java │ │ │ ├── manager │ │ │ └── DataManager.java │ │ │ ├── model │ │ │ ├── AppVersion.java │ │ │ ├── EventMessage.java │ │ │ ├── GitUser.java │ │ │ └── Weather.java │ │ │ ├── presenter │ │ │ ├── AppVersionPresenter.java │ │ │ ├── GitUserPresenter.java │ │ │ ├── Presenter.java │ │ │ └── WeatherPresenter.java │ │ │ ├── receiver │ │ │ └── NetworkReceiver.java │ │ │ ├── retrofit │ │ │ ├── RetrofitHelper.java │ │ │ └── RetrofitService.java │ │ │ ├── utils │ │ │ ├── ContantUtils.java │ │ │ └── OkHttpUtils.java │ │ │ └── view │ │ │ ├── AppVersionView.java │ │ │ ├── GitUserView.java │ │ │ ├── View.java │ │ │ └── WeatherView.java │ └── res │ │ ├── layout │ │ ├── activity_glide.xml │ │ ├── activity_main.xml │ │ ├── activity_recyclerview.xml │ │ ├── item_layout.xml │ │ ├── item_layout2.xml │ │ └── layout_glide_image.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── whh │ └── initmvp │ └── ExampleUnitTest.java ├── arouter ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── whh │ │ └── irisking │ │ └── arouter │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── whh │ │ │ └── irisking │ │ │ └── arouter │ │ │ └── ARouterResultActivity.java │ └── res │ │ ├── layout │ │ └── activity_arouter.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── whh │ └── irisking │ └── arouter │ └── ExampleUnitTest.java ├── baselib ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── whh │ │ └── baselib │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── whh │ │ │ └── baselib │ │ │ ├── activity │ │ │ └── BaseActivity.java │ │ │ └── utils │ │ │ ├── DelayTask.java │ │ │ ├── DialogListener.java │ │ │ ├── DialogUtils.java │ │ │ ├── FileUtil.java │ │ │ ├── LogUtils.java │ │ │ ├── SystemUtils.java │ │ │ └── ToosUtils.java │ └── res │ │ ├── drawable │ │ ├── dialog_btn_bkg.xml │ │ ├── dialog_right_btn_bkg.xml │ │ ├── icon_action_bar_more.png │ │ ├── picerror.png │ │ ├── picloading.png │ │ ├── return_icon.png │ │ ├── shape_bottom_btn_bkg.xml │ │ ├── shape_btn_bkg.xml │ │ └── shape_white.xml │ │ ├── layout │ │ ├── activity_base_layout.xml │ │ └── dialog_message.xml │ │ ├── mipmap-mdpi │ │ └── app_logo.png │ │ ├── mipmap-xhdpi │ │ └── app_logo.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── whh │ └── baselib │ └── ExampleUnitTest.java ├── build.gradle ├── city.json ├── eventbus3 ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── whh │ │ └── eventbus3 │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── whh │ │ │ └── eventbus3 │ │ │ ├── activity │ │ │ └── EventBus2Activity.java │ │ │ └── model │ │ │ └── EventMessage.java │ └── res │ │ ├── layout │ │ └── activity_eventbus.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── whh │ └── eventbus3 │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── weather.json /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/caches/gradle_models.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/.idea/caches/gradle_models.ser -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 30 | 45 | 46 | 47 | 48 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | 1.8 57 | 58 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # InitMVP 2 | github:https://github.com/wuhuihui2016/InitMVP.git 3 | 4 | ==================================================================================================================================== 5 | 6 | 一、mvp+okhttp3+retrofit2+rxjava2 7 | 8 | 利用mvp+okhttp3+retrofit2+rxjava2搭建框架实现网络请求及刷新UI数据。 9 | 10 | MVP(Model-View-Presenter) :从经典的模式MVC演变而来,Presenter负责逻辑的处理,Model提供数据,View负责显示。 11 | MVP的优点:(1)降低耦合度;(2)模块职责划分明显;(3)利于测试驱动开发;(4)代码复用;(5)隐藏数据;(6)代码灵活性 12 | 13 | OkHttp3:Square公司的一款开源的网络请求库。 14 | Retrofit:Square公司开发的一款针对Android 网络请求的框架(底层默认是基于OkHttp 实现)。 15 | RxJava2:一个在 Java VM 上使用可观测的序列来组成异步的、基于事件的程序的库),RxJava使异步操作变得非常简单。 16 | 17 | HttpLoggingInterceptor:日志拦截器,okHttp记录拦截器,用于记录应用中的网络请求的信息。 18 | 19 | 三个网络请求例子: 20 | 由于三个请求API的base_url都不同,需要初始化不同的retrofit,初始化方法在调用时切换 21 | private RetrofitHelper(Context context) { 22 | this.context = context; 23 | // initRetrofit(); //版本信息 24 | // initWeatherRetrofit(); //天气信息 25 | initGitUserRetrofit(); //https gitUser信息 26 | } 27 | 建立不同Activity,在manifest.xml切换不同的activity为启动页 28 | 1.版本信息:post请求,retrofit初始化方法initRetrofit,activity为AppVersionActivity。目的:框架的初实现 29 | 2.天气信息:get请求,retrofit初始化方法initWeatherRetrofit,activity为WeatherActivity。目的:熟练框架的使用 30 | 3.gitUser信息:get请求,retrofit初始化方法initGitUserRetrofit,activity为GitUserActivity。目的:尝试https在框架的实现,实现方法并无差别。 31 | 32 | 框架实现整理文章:https://www.jianshu.com/p/3625061c98ad 33 | 34 | ==================================================================================================================================== 35 | 36 | 二、EventBus 37 | EventBus是一种用于Android的事件发布-订阅总线,由GreenRobot开发。 38 | Gihub地址 :https://github.com/greenrobot/EventBus。 39 | EventBus能够简化各组件间的通信,代码书写变得简单,能有效的分离事件发送方和接收方(也就是解耦的意思),能避免复杂和容易出错的依赖性和生命周期问题。 40 | EventBus可以代替Android传统的Intent,Handler,Broadcast或接口函数,在Fragment、Activity、Service线程之间传递数据,执行方法。 41 | 特点:代码简洁,是一种发布订阅设计模式(观察者设计模式)。 42 | 43 | EventBus整理文章:https://www.jianshu.com/p/5ad5ea7180a2 44 | 45 | ==================================================================================================================================== 46 | 47 | 三、Glide 48 | 图片加载框架。Glide和Picasso 有90%相似度,而Glide在Picasso基础上进行的二次开发,可以其优势显而易见。UniversalImageLoader已停止服务。 49 | 使用Glide在大多数情况下我们不需要指定图片大小,因为Glide会自动根据ImageView的大小来决定图片的大小,以此保证图片不会占用过多的内存从而引发OOM。 50 | Glide可以加载GIF图片,Picasso是不支持这个功能的。使用Glide加载GIF图不需要编写额外代码,Glide内部会自动判断图片格式。同时可以加载本地视频。 51 | 52 | ==================================================================================================================================== 53 | 54 | 四、RecyclerView简单/复杂item加载 55 | 1.简单加载:ListAdapter extents BaseQuickAdapter 56 | 构造方法、convert() 57 | 2.复杂加载:ListAdapter2 extents RecyclerView.Adapter 58 | onCreateViewHolder()、onBindViewHolder()、getItemCount()、getItemViewType() 59 | 60 | ==================================================================================================================================== 61 | 62 | 五、IntentService的使用 (2019/6/10) 63 | NetworkReceiver 64 | IntentService会创建独立的worker线程来处理所有的Intent请求; 65 | 会创建独立的worker线程来处理onHandleIntent()方法实现的代码,无需处理多线程的问题; 66 | 所有请求处理完成后,IntentService会自动停止,无需调用stopSelf()方法停止Service; 67 | 为Service的onBind()提供默认实现,返回null; 68 | 为Service的onStartCommand提供默认实现,将请求Intent添加到队列中 69 | 70 | ==================================================================================================================================== 71 | 72 | 六、module模块化(2019/6/13) 73 | 1.baselib BaseActivity, 公共工具类,自定义dialog; 74 | 2.eventbus3 测试跨module发送接收事件 75 | 76 | ==================================================================================================================================== 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /VERSION.md: -------------------------------------------------------------------------------- 1 | # InitMVP version 2 | V1.0 3 | (190517)mvp+okhttp3+retrofit2+rxjava2 框架搭建初实现 4 | (190517)练习代码,增加天气API请求 5 | (190518)增加日志拦截器HttpLoggingInterceptor 6 | (190518)尝试HTTPS网络请求,与HTTP并无区别,okHttp已封装HTTPS方法 7 | (190518)PersistentCookieJar持久化Cookie、RxJava2CallAdapterFactory实现异步、增加依赖库Glide、EventBus 8 | (190519)EventBus事件的发送接收及粘性事件 9 | (190519)Glide加载图片;启动页优化;项目风格统一;BaseActivity优化 10 | 11 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'jacoco' //加载代码覆盖库jacoco 3 | 4 | jacoco { 5 | toolVersion = "0.7.9" //代码覆盖库jacoco版本号 6 | } 7 | 8 | android { 9 | compileSdkVersion 25 10 | buildToolsVersion "25.0.3" 11 | defaultConfig { 12 | applicationId "com.whh.initmvp" 13 | minSdkVersion 15 14 | targetSdkVersion 25 15 | versionCode 1 16 | versionName "1.0" 17 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 18 | } 19 | buildTypes { 20 | release { 21 | testCoverageEnabled = true //实现代码覆盖率 22 | minifyEnabled false //获取代码覆盖率需要设为false 23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 24 | } 25 | debug { 26 | testCoverageEnabled = true //实现代码覆盖率 27 | minifyEnabled false //获取代码覆盖率需要设为false 28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 29 | } 30 | } 31 | } 32 | 33 | dependencies { 34 | compile fileTree(include: ['*.jar'], dir: 'libs') 35 | testCompile 'junit:junit:4.12' 36 | 37 | //网络请求 okhttp3 38 | compile 'com.squareup.okhttp3:okhttp:3.9.1' 39 | //日志的拦截器 40 | compile 'com.squareup.okhttp3:logging-interceptor:3.9.1' 41 | compile 'com.squareup.okhttp3:mockwebserver:3.9.1' 42 | //Facebook强大的监测工具 43 | compile 'com.facebook.stetho:stetho-okhttp3:1.3.1' 44 | //Retrofit2库 45 | compile 'com.squareup.retrofit2:retrofit:2.3.0' 46 | compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0' 47 | //gson解析 48 | compile 'com.squareup.retrofit2:converter-gson:2.3.0' 49 | compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0' 50 | //rxjava2库 51 | compile 'io.reactivex.rxjava2:rxjava:2.0.1' 52 | compile 'io.reactivex.rxjava2:rxandroid:2.0.1' 53 | //Cookie持久化管理 54 | compile 'com.github.franmontiel:PersistentCookieJar:v1.0.1' 55 | 56 | //Glide 57 | compile 'com.github.bumptech.glide:glide:3.7.0' 58 | 59 | //recyclerview 60 | compile 'com.android.support:recyclerview-v7:25.+' 61 | compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' 62 | 63 | //eventbus3 64 | compile project(':eventbus3') 65 | 66 | // //arouter 67 | // annotationProcessor 'com.alibaba:arouter-compiler:1.1.4' 68 | 69 | //代码覆盖率jacoco 70 | // compile 'org.jacoco:org.jacoco.core:0.7.9' 71 | 72 | 73 | } 74 | 75 | //代码覆盖率相关配置 start 76 | def coverageSourceDirs = [ 77 | '../app/src/main/java' 78 | ] 79 | 80 | task jacocoTestReport(type: JacocoReport) { 81 | group = "Reporting" 82 | description = "Generate Jacoco coverage reports after running tests." 83 | 84 | reports { 85 | xml.enabled = true 86 | html.enabled = true 87 | } 88 | 89 | //build\intermediates\javac\debug\compileDebugJavaWithJavac\classes\com\irisking\gacloud\api 90 | classDirectories = fileTree( 91 | //检测覆盖率的class所在目录(以项目class所在目录为准) 92 | dir: './build/intermediates/classes/debug', //gradle2.3 class所在目录 93 | //gradle3.2 class所在目录 dir: './build/intermediates/javac/debug/compileDebugJavaWithJavac/classes', 94 | //排除以上目录中不检测的文件列表 95 | excludes: ['**/R*.class', 96 | '**/*$InjectAdapter.class', 97 | '**/*$ModuleAdapter.class', 98 | '**/*$ViewInjector*.class' 99 | ] 100 | ) 101 | 102 | sourceDirectories = files(coverageSourceDirs) //设置需要检测覆盖率的目录 103 | executionData = files("$buildDir/outputs/code-coverage/connected/initmvp_coverage.ec") //存储APP运行时产生报告的目录 104 | 105 | // doFirst { 106 | // new File("$buildDir/intermediates/classes/").eachFileRecurse { file -> 107 | // if (file.name.contains('$$')) { 108 | // file.renameTo(file.path.replace('$$', '$')) 109 | // } 110 | // } 111 | // } 112 | } 113 | //代码覆盖率相关配置 end -------------------------------------------------------------------------------- /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 D:\installSoftCache\Android\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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/whh/initmvp/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp; 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/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 57 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/MyApp.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | 6 | import com.facebook.stetho.Stetho; 7 | import com.whh.initmvp.utils.ContantUtils; 8 | import com.whh.initmvp.utils.OkHttpUtils; 9 | 10 | import okhttp3.OkHttpClient; 11 | 12 | /** 13 | * Created by Administrator on 2019/5/16. 14 | */ 15 | 16 | public class MyApp extends Application { 17 | 18 | private static Context context; 19 | 20 | public static OkHttpClient okHtpClient; 21 | 22 | private boolean isDebugARouter = true; //ARouter调试开关 23 | 24 | @Override 25 | public void onCreate() { 26 | super.onCreate(); 27 | context = this; 28 | 29 | ContantUtils.setCompositeDisposable(); //获取网络请求订阅器 30 | 31 | //获取okHtpClient,使用log拦截器 32 | okHtpClient = OkHttpUtils.getInstance().getOkHttpClient(); 33 | 34 | //初始化FaceBook调试器,可在Chrome调试网络请求,查看SharePreferences,数据库等 35 | Stetho.initializeWithDefaults(this); 36 | 37 | //初始化ARouter 38 | // if(isDebugARouter) { 39 | // ARouter.openLog(); //开启日志 40 | // ARouter.openDebug(); //开启调试模式 41 | // } 42 | // ARouter.init(this); 43 | 44 | } 45 | 46 | public static Context getInstance() { 47 | return context; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/activity/EventBusActivity.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.activity; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import android.widget.Button; 7 | import android.widget.TextView; 8 | 9 | import com.whh.baselib.activity.BaseActivity; 10 | import com.whh.eventbus3.activity.EventBus2Activity; 11 | import com.whh.initmvp.R; 12 | import com.whh.initmvp.model.EventMessage; 13 | 14 | import org.greenrobot.eventbus.EventBus; 15 | import org.greenrobot.eventbus.Subscribe; 16 | import org.greenrobot.eventbus.ThreadMode; 17 | 18 | /** 19 | * Created by wuhuihui on 2019/5/18. 20 | * 发送粘性事件给EventBus2Activity 21 | * 接收EventBus2Activity发来的普通事件 22 | */ 23 | public class EventBusActivity extends BaseActivity { 24 | 25 | private TextView showData1, showData2; 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView("发送事件", R.layout.activity_eventbus); 31 | 32 | if (!EventBus.getDefault().isRegistered(this)) 33 | EventBus.getDefault().register(this); //注册事件,不可重复注册事件 34 | 35 | showData1 = (TextView) findViewById(R.id.showData1); 36 | showData1.setText("1111EventBusActivity"); 37 | showData2 = (TextView) findViewById(R.id.showData2); 38 | 39 | Button send = (Button) findViewById(R.id.send); 40 | send.setText("1111跳转页面"); 41 | send.setOnClickListener(new View.OnClickListener() { 42 | @Override 43 | public void onClick(View v) { 44 | EventBus.getDefault().postSticky(new EventMessage(2, "11111发来粘性事件~")); //发送粘性事件 45 | startActivity(new Intent(activity, EventBus2Activity.class)); 46 | } 47 | }); 48 | } 49 | 50 | @Subscribe(threadMode = ThreadMode.MAIN) 51 | public void getEventMessage(EventMessage eMsg) { 52 | if (eMsg.getType() == 1) showData2.setText(eMsg.getMessage()); 53 | } 54 | 55 | 56 | @Override 57 | protected void onDestroy() { 58 | super.onDestroy(); 59 | if (EventBus.getDefault().isRegistered(this)) 60 | EventBus.getDefault().unregister(this); //注销事件 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/activity/GlideActivity.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.activity; 2 | 3 | import android.os.Bundle; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.widget.ImageView; 7 | import android.widget.LinearLayout; 8 | 9 | import com.bumptech.glide.Glide; 10 | import com.bumptech.glide.Priority; 11 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 12 | import com.whh.baselib.activity.BaseActivity; 13 | import com.whh.initmvp.R; 14 | 15 | /** 16 | * Created by wuhuihui on 2019/5/17. 17 | * Glide图片加载 18 | * 参考文章:https://www.jianshu.com/p/7ce7b02988a4 19 | * https://www.jianshu.com/p/791ee473a89b 20 | * 可以显示gif图,也能显示视频,但只是本地视频 21 | */ 22 | 23 | public class GlideActivity extends BaseActivity { 24 | 25 | private LinearLayout images_layout; 26 | private ImageView imageView; 27 | 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView("Glide加载图片", R.layout.activity_glide); 33 | 34 | images_layout = (LinearLayout) findViewById(R.id.images_layout); 35 | for (int i = 0; i < 5; i++) { 36 | loadImage(); 37 | } 38 | 39 | } 40 | 41 | private void loadImage() { 42 | View glide_image = LayoutInflater.from(activity).inflate(R.layout.layout_glide_image, null); 43 | imageView = (ImageView) glide_image.findViewById(R.id.imageView); 44 | String url = "http://cn.bing.com/az/hprichbg/rb/TOAD_ZH-CN7336795473_1920x1080.jpg"; 45 | Glide.with(context) 46 | .load(url) 47 | .placeholder(R.drawable.picloading) //加载过程中显示的图片 48 | .error(R.drawable.picerror) //加载失败后显示的图片 49 | .thumbnail(0.5f) //设置缩略图:加载原图的0.5倍 50 | .override(400, 240) //裁剪图片的大小,单位px 51 | .skipMemoryCache(true) //支持内存缓存(默认打开) 52 | 53 | .diskCacheStrategy(DiskCacheStrategy.ALL) 54 | /* DiskCacheStrategy.NONE 什么都不缓存 55 | DiskCacheStrategy.SOURCE 只缓存全尺寸图 56 | DiskCacheStrategy.RESULT 只缓存最终的加载图 57 | DiskCacheStrategy.ALL 缓存所有版本图(默认行为)*/ 58 | .priority(Priority.HIGH) //设置优先级 59 | 60 | .into(imageView); 61 | images_layout.addView(glide_image); 62 | } 63 | 64 | 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/activity/HttpAppVersionActivity.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.activity; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import android.widget.TextView; 7 | import android.widget.Toast; 8 | 9 | import com.whh.baselib.activity.BaseActivity; 10 | import com.whh.baselib.utils.SystemUtils; 11 | import com.whh.initmvp.R; 12 | import com.whh.initmvp.model.AppVersion; 13 | import com.whh.initmvp.presenter.AppVersionPresenter; 14 | import com.whh.initmvp.view.AppVersionView; 15 | 16 | import java.util.List; 17 | 18 | /** 19 | * Created by wuhuihui on 2019/5/16. 20 | * 加载版本信息 21 | */ 22 | 23 | public class HttpAppVersionActivity extends BaseActivity { 24 | 25 | private TextView showData; 26 | 27 | private AppVersionPresenter appVersionPresenter = new AppVersionPresenter(this); 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView("加载版本信息", R.layout.activity_main); 33 | 34 | showAppVersion(); //显示版本信息 35 | 36 | initEventBus(); //EventBus事件 37 | 38 | initGlide(); //Glide 39 | 40 | } 41 | 42 | /** 43 | * 显示版本信息 44 | */ 45 | private void showAppVersion() { 46 | findViewById(R.id.loadData).setOnClickListener(new View.OnClickListener() { 47 | @Override 48 | public void onClick(View v) { 49 | if(SystemUtils.isNetworkAvailable(activity)) { 50 | showData = (TextView) findViewById(R.id.showData); 51 | 52 | appVersionPresenter.onCreate(); //启动Presenter,订阅View 53 | appVersionPresenter.getAppVersion("6.0", "android"); //开始请求数据 54 | //刷新UI,显示数据 55 | appVersionPresenter.attachView(new AppVersionView() { 56 | @Override 57 | public void onSuccess(AppVersion appVersion) { 58 | showData.setText(appVersion.getLatestVersion() 59 | + "\n" + appVersion.getSize() 60 | + "\n" + appVersion.getUrl() 61 | + "\n\n新版本更新内容:\n" 62 | ); 63 | 64 | List list = appVersion.getFunctions(); 65 | for (int i = 0; i < list.size(); i++) { 66 | showData.append(list.get(i) + "\n"); 67 | } 68 | } 69 | 70 | @Override 71 | public void onError(String error) { 72 | showData.setText(error); 73 | } 74 | }); 75 | } else Toast.makeText(getApplicationContext(), "当前网络不可用", Toast.LENGTH_SHORT).show(); 76 | } 77 | }); 78 | } 79 | 80 | /** 81 | * EventBus 82 | */ 83 | private void initEventBus() { 84 | findViewById(R.id.eventBus).setOnClickListener(new View.OnClickListener() { 85 | @Override 86 | public void onClick(View v) { 87 | startActivity(new Intent(activity, EventBusActivity.class)); 88 | } 89 | }); 90 | } 91 | 92 | /** 93 | * Glide 94 | */ 95 | private void initGlide() { 96 | findViewById(R.id.glide).setOnClickListener(new View.OnClickListener() { 97 | @Override 98 | public void onClick(View v) { 99 | startActivity(new Intent(activity, GlideActivity.class)); 100 | } 101 | }); 102 | } 103 | 104 | @Override 105 | protected void onDestroy() { 106 | super.onDestroy(); 107 | appVersionPresenter.onDestory(); //取消view的引用,避免内存泄漏 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.activity; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.text.method.LinkMovementMethod; 6 | import android.view.View; 7 | import android.widget.TextView; 8 | import android.widget.Toast; 9 | 10 | import com.whh.baselib.activity.BaseActivity; 11 | import com.whh.baselib.utils.SystemUtils; 12 | import com.whh.initmvp.R; 13 | import com.whh.initmvp.model.GitUser; 14 | import com.whh.initmvp.presenter.GitUserPresenter; 15 | import com.whh.initmvp.utils.ContantUtils; 16 | import com.whh.initmvp.view.GitUserView; 17 | 18 | import io.reactivex.disposables.CompositeDisposable; 19 | 20 | import static com.whh.initmvp.R.id.initRecyclerView; 21 | 22 | /** 23 | * Created by wuhuihui on 2019/5/16. 24 | * https加载githubUser信息 25 | */ 26 | public class MainActivity extends BaseActivity { 27 | 28 | private TextView showData; 29 | 30 | private GitUserPresenter gitUserPresenter = new GitUserPresenter(this); 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView("https请求加载", R.layout.activity_main); 36 | 37 | showGitUser(); //显示gitUser 38 | 39 | initEventBus(); //EventBus事件 40 | 41 | initGlide(); //Glide 42 | 43 | initRecyclerView(); //initRecyclerView 44 | 45 | // initARouter(); //初始化ARouter 46 | 47 | } 48 | 49 | /** 50 | * 显示gitUser 51 | */ 52 | private void showGitUser() { 53 | findViewById(R.id.loadData).setOnClickListener(new View.OnClickListener() { 54 | @Override 55 | public void onClick(View v) { 56 | if (SystemUtils.isNetworkAvailable(activity)) { 57 | showData = (TextView) findViewById(R.id.showData); 58 | // showData.setMovementMethod(ScrollingMovementMethod.getInstance()); //设置可滑动 59 | showData.setMovementMethod(LinkMovementMethod.getInstance()); //设置链接 60 | 61 | gitUserPresenter.onCreate(); //启动Presenter,订阅View 62 | gitUserPresenter.getGitUser(); //开始请求数据 63 | //刷新UI,显示数据 64 | gitUserPresenter.attachView(new GitUserView() { 65 | @Override 66 | public void onSuccess(GitUser gitUser) { 67 | showData.setText(gitUser.toString()); 68 | } 69 | 70 | @Override 71 | public void onError(String error) { 72 | showData.setText(error); 73 | } 74 | }); 75 | } else 76 | Toast.makeText(getApplicationContext(), "当前网络不可用", Toast.LENGTH_SHORT).show(); 77 | } 78 | }); 79 | } 80 | 81 | /** 82 | * EventBus 83 | */ 84 | private void initEventBus() { 85 | findViewById(R.id.eventBus).setOnClickListener(new View.OnClickListener() { 86 | @Override 87 | public void onClick(View v) { 88 | startActivity(new Intent(activity, EventBusActivity.class)); 89 | } 90 | }); 91 | } 92 | 93 | /** 94 | * Glide 95 | */ 96 | private void initGlide() { 97 | findViewById(R.id.glide).setOnClickListener(new View.OnClickListener() { 98 | @Override 99 | public void onClick(View v) { 100 | startActivity(new Intent(activity, GlideActivity.class)); 101 | } 102 | }); 103 | } 104 | 105 | /** 106 | * RecyclerView 107 | */ 108 | private void initRecyclerView() { 109 | findViewById(initRecyclerView).setOnClickListener(new View.OnClickListener() { 110 | @Override 111 | public void onClick(View v) { 112 | startActivity(new Intent(activity, RecyclerViewActivity.class)); 113 | } 114 | }); 115 | } 116 | 117 | /** 118 | * ARouter 119 | */ 120 | // private void initARouter() { 121 | // ARouter.getInstance().inject(this); //注入到当前页面 122 | // 123 | // findViewById(R.id.arouter).setOnClickListener(new View.OnClickListener() { 124 | // @Override 125 | // public void onClick(View v) { 126 | // ARouter.getInstance().build("/arouter/ARouterResultActivity").withString("key", "ARouter20190708 14:46").navigation(); 127 | // } 128 | // }); 129 | // } 130 | 131 | 132 | @Override 133 | protected void onDestroy() { 134 | super.onDestroy(); 135 | gitUserPresenter.onDestory(); //取消view的引用,避免内存泄漏 136 | 137 | //清除所有订阅 138 | CompositeDisposable compositeDisposable = ContantUtils.compositeDisposable; 139 | if (compositeDisposable != null) { 140 | compositeDisposable.clear(); 141 | } 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/activity/RecyclerViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.widget.DividerItemDecoration; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | 8 | import com.whh.baselib.activity.BaseActivity; 9 | import com.whh.initmvp.R; 10 | import com.whh.initmvp.adapter.ListAdapter; 11 | import com.whh.initmvp.adapter.ListAdapter2; 12 | import com.whh.initmvp.model.EventMessage; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | /** 18 | * Created by wuhuihui on 2019/6/10. 19 | */ 20 | 21 | public class RecyclerViewActivity extends BaseActivity { 22 | 23 | private RecyclerView recyclerView; 24 | private ListAdapter adapter; 25 | private ListAdapter2 adapter2; 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView("RecyclerView", R.layout.activity_recyclerview); 31 | 32 | recyclerView = (RecyclerView) findViewById(R.id.recyclerView); 33 | recyclerView.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)); 34 | recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL)); 35 | 36 | // //简单加载 37 | // if (adapter == null) { 38 | // adapter = new ListAdapter(R.layout.item_layout, null); 39 | // recyclerView.setAdapter(adapter); 40 | // } else adapter.notifyDataSetChanged(); 41 | // adapter.setNewData(initData()); 42 | 43 | //复杂加载数据(多个不同item) 44 | if (adapter2 == null) { 45 | adapter2 = new ListAdapter2(activity); 46 | recyclerView.setAdapter(adapter2); 47 | } else adapter2.notifyDataSetChanged(); 48 | adapter2.addList(initData()); 49 | } 50 | 51 | /** 52 | * 初始化数据 53 | * @return 54 | */ 55 | private List initData() { 56 | List eventMessages = new ArrayList<>(); 57 | eventMessages.add(new EventMessage(0, "000")); 58 | eventMessages.add(new EventMessage(1, "111")); 59 | eventMessages.add(new EventMessage(2, "222")); 60 | eventMessages.add(new EventMessage(3, "333")); 61 | eventMessages.add(new EventMessage(4, "444")); 62 | return eventMessages; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/activity/WeatherActivity.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.activity; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import android.widget.TextView; 7 | import android.widget.Toast; 8 | 9 | import com.whh.baselib.activity.BaseActivity; 10 | import com.whh.baselib.utils.SystemUtils; 11 | import com.whh.initmvp.R; 12 | import com.whh.initmvp.model.Weather; 13 | import com.whh.initmvp.presenter.WeatherPresenter; 14 | import com.whh.initmvp.view.WeatherView; 15 | 16 | /** 17 | * Created by wuhuihui on 2019/5/16. 18 | * 加载天气信息 因为免费地多次测试,导致IP被封,天气接口访问失败 19 | */ 20 | 21 | public class WeatherActivity extends BaseActivity { 22 | 23 | private TextView showData; 24 | 25 | private WeatherPresenter weatherPresenter = new WeatherPresenter(this); 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView("加载天气信息", R.layout.activity_main); 31 | 32 | showWeather(); //显示天气信息 33 | 34 | initEventBus(); //EventBus事件 35 | 36 | initGlide(); //Glide 37 | } 38 | 39 | 40 | /** 41 | * 显示天气信息 42 | */ 43 | private void showWeather() { 44 | findViewById(R.id.loadData).setOnClickListener(new View.OnClickListener() { 45 | @Override 46 | public void onClick(View v) { 47 | if (SystemUtils.isNetworkAvailable(activity)) { 48 | 49 | showData = (TextView) findViewById(R.id.showData); 50 | 51 | weatherPresenter.onCreate(); //启动Presenter,订阅View 52 | weatherPresenter.getWeather(); //开始请求数据 53 | //刷新UI,显示数据 54 | weatherPresenter.attachView(new WeatherView() { 55 | @Override 56 | public void onSuccess(Weather weather) { 57 | showData.setText("getTime:\n" + weather.getTime() 58 | + "\n\n\ngetCityInfo:\n" + weather.getCityInfo() 59 | + "\n\n\ngetData:\n" + weather.getData() 60 | ); 61 | 62 | } 63 | 64 | @Override 65 | public void onError(String error) { 66 | showData.setText(error); 67 | } 68 | }); 69 | } else 70 | Toast.makeText(getApplicationContext(), "当前网络不可用", Toast.LENGTH_SHORT).show(); 71 | } 72 | }); 73 | } 74 | 75 | /** 76 | * EventBus 77 | */ 78 | private void initEventBus() { 79 | findViewById(R.id.eventBus).setOnClickListener(new View.OnClickListener() { 80 | @Override 81 | public void onClick(View v) { 82 | startActivity(new Intent(activity, EventBusActivity.class)); 83 | } 84 | }); 85 | } 86 | 87 | /** 88 | * Glide 89 | */ 90 | private void initGlide() { 91 | findViewById(R.id.glide).setOnClickListener(new View.OnClickListener() { 92 | @Override 93 | public void onClick(View v) { 94 | startActivity(new Intent(activity, GlideActivity.class)); 95 | } 96 | }); 97 | } 98 | 99 | 100 | @Override 101 | protected void onDestroy() { 102 | super.onDestroy(); 103 | weatherPresenter.onDestory(); //取消view的引用,避免内存泄漏 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/adapter/ListAdapter.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.adapter; 2 | 3 | import android.support.annotation.LayoutRes; 4 | import android.support.annotation.Nullable; 5 | 6 | import com.chad.library.adapter.base.BaseQuickAdapter; 7 | import com.chad.library.adapter.base.BaseViewHolder; 8 | import com.whh.initmvp.R; 9 | import com.whh.initmvp.model.EventMessage; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Created by wuhuihui on 2019/6/10. 15 | */ 16 | 17 | public class ListAdapter extends BaseQuickAdapter{ 18 | 19 | 20 | public ListAdapter(@LayoutRes int layoutResId, @Nullable List data) { 21 | super(layoutResId, data); 22 | } 23 | 24 | @Override 25 | protected void convert(BaseViewHolder helper, EventMessage item) { 26 | helper.setText(R.id.msg, item.getMessage()); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/adapter/ListAdapter2.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.util.Log; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.TextView; 10 | 11 | import com.whh.initmvp.R; 12 | import com.whh.initmvp.model.EventMessage; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | /** 18 | * Created by wuhuihui on 2019/6/10. 19 | */ 20 | 21 | public class ListAdapter2 extends RecyclerView.Adapter { 22 | 23 | public static enum ITEM_TYPE { 24 | ITEM_TYPE_ONE, 25 | ITEM_TYPE_TWO 26 | } 27 | 28 | private Context context; 29 | private LayoutInflater layoutInflater; 30 | private List eventMessages = new ArrayList<>(); 31 | 32 | public ListAdapter2(Context context) { 33 | this.context = context; 34 | layoutInflater = LayoutInflater.from(context); 35 | } 36 | 37 | public void addList(List list) { 38 | eventMessages.addAll(list); 39 | } 40 | 41 | @Override 42 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 43 | 44 | if (viewType == ITEM_TYPE.ITEM_TYPE_ONE.ordinal()) { 45 | return new OneHolder(layoutInflater.inflate(R.layout.item_layout, parent, false)); 46 | } else { 47 | return new TwoHolder(layoutInflater.inflate(R.layout.item_layout2, parent, false)); 48 | } 49 | 50 | } 51 | 52 | @Override 53 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 54 | 55 | EventMessage eventMessage = eventMessages.get(position); 56 | if (holder instanceof OneHolder) { 57 | ((OneHolder) holder).msg.setText(eventMessage.getMessage()); 58 | } else if (holder instanceof TwoHolder) { 59 | ((TwoHolder) holder).type.setText(eventMessage.getType() + ""); 60 | ((TwoHolder) holder).msg.setText(eventMessage.getMessage()); 61 | } 62 | } 63 | 64 | @Override 65 | public int getItemCount() { 66 | return eventMessages == null ? 0 : eventMessages.size(); 67 | } 68 | 69 | @Override 70 | public int getItemViewType(int position) { 71 | return position % 2 == 0 ? ITEM_TYPE.ITEM_TYPE_ONE.ordinal() : ITEM_TYPE.ITEM_TYPE_TWO.ordinal(); 72 | } 73 | 74 | public static class OneHolder extends RecyclerView.ViewHolder { 75 | public TextView msg; 76 | 77 | OneHolder(View view) { 78 | super(view); 79 | 80 | msg = (TextView) view.findViewById(R.id.msg); 81 | view.setOnClickListener(new View.OnClickListener() { 82 | @Override 83 | public void onClick(View v) { 84 | Log.d("OneHolder", "onClick--> position = " + getPosition()); 85 | } 86 | }); 87 | } 88 | } 89 | 90 | public static class TwoHolder extends RecyclerView.ViewHolder { 91 | public TextView type; 92 | public TextView msg; 93 | 94 | 95 | TwoHolder(View view) { 96 | super(view); 97 | 98 | type = (TextView) view.findViewById(R.id.type); 99 | msg = (TextView) view.findViewById(R.id.msg); 100 | view.setOnClickListener(new View.OnClickListener() { 101 | @Override 102 | public void onClick(View v) { 103 | Log.d("TwoHolder", "onClick--> position = " + getPosition()); 104 | } 105 | }); 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/manager/DataManager.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.manager; 2 | 3 | import android.content.Context; 4 | 5 | import com.whh.initmvp.model.AppVersion; 6 | import com.whh.initmvp.model.GitUser; 7 | import com.whh.initmvp.model.Weather; 8 | import com.whh.initmvp.retrofit.RetrofitHelper; 9 | import com.whh.initmvp.retrofit.RetrofitService; 10 | 11 | import io.reactivex.Observable; 12 | 13 | /** 14 | * Created by wuhuihui on 2019/5/17. 15 | * DataManager:数据处理管理器,用于处理多个API Observable 16 | */ 17 | 18 | public class DataManager { 19 | 20 | private RetrofitService retrofitService; 21 | 22 | public DataManager(Context context) { 23 | this.retrofitService = RetrofitHelper.getInstance(context).getServer(); 24 | } 25 | 26 | /** 27 | * 获取AppVersion 28 | * @param currentVersion 29 | * @param type 30 | * @return 31 | */ 32 | public Observable getAppVersion(String currentVersion, String type) { 33 | return retrofitService.getAppVersion(currentVersion, type); 34 | } 35 | 36 | 37 | /** 38 | * 获取Weather 39 | * @return 40 | */ 41 | public Observable getWeather() { 42 | return retrofitService.getWeather(); 43 | } 44 | 45 | /** 46 | * 获取Weather 47 | * @return 48 | */ 49 | public Observable getGitUser() { 50 | return retrofitService.getGitUser(); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/model/AppVersion.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.model; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by wuhuihuhi on 2019/5/16. 7 | * AppVersion 满足Gson解析的数据结构 8 | */ 9 | 10 | public class AppVersion { 11 | 12 | /** 13 | * http://ios.mobile.che-by.com/appversion-getAppVersion?currentVersion=6.0.2&type=android 14 | * 15 | * { 16 | "size": "14MB", 17 | "functions": ["1.上线新活动\n2.部分页面优化更新\n3.修复已知BUG"], 18 | "latestVersion": "6.0.4", 19 | "must": -1, 20 | "url": "http://download.fengyangtech.com/apk/ChebyMall.apk" 21 | } 22 | */ 23 | 24 | private String size; 25 | private List functions; 26 | private String latestVersion; 27 | private int must; 28 | private String url; 29 | 30 | public AppVersion(String size, List functions, 31 | String latestVersion, int must, String url) { 32 | this.size = size; 33 | this.functions = functions; 34 | this.latestVersion = latestVersion; 35 | this.must = must; 36 | this.url = url; 37 | } 38 | 39 | public String getSize() { 40 | return size; 41 | } 42 | 43 | public void setSize(String size) { 44 | this.size = size; 45 | } 46 | 47 | public List getFunctions() { 48 | return functions; 49 | } 50 | 51 | public void setFunctions(List functions) { 52 | this.functions = functions; 53 | } 54 | 55 | public String getLatestVersion() { 56 | return latestVersion; 57 | } 58 | 59 | public void setLatestVersion(String latestVersion) { 60 | this.latestVersion = latestVersion; 61 | } 62 | 63 | public int getMust() { 64 | return must; 65 | } 66 | 67 | public void setMust(int must) { 68 | this.must = must; 69 | } 70 | 71 | public String getUrl() { 72 | return url; 73 | } 74 | 75 | public void setUrl(String url) { 76 | this.url = url; 77 | } 78 | 79 | @Override 80 | public String toString() { 81 | return "AppVersion{" + 82 | "size='" + size + '\'' + 83 | ", functions=" + functions + 84 | ", latestVersion='" + latestVersion + '\'' + 85 | ", must=" + must + 86 | ", url='" + url + '\'' + 87 | '}'; 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/model/EventMessage.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.model; 2 | 3 | /** 4 | * Created by wuhuihui on 2019/5/18. 5 | */ 6 | 7 | public class EventMessage { 8 | private int type; //为了区别消息的类型,相当于handler里的what 9 | private String message; 10 | 11 | public EventMessage(int type, String message) { 12 | this.type = type; 13 | this.message = message; 14 | } 15 | 16 | public int getType() { 17 | return type; 18 | } 19 | 20 | public void setType(int type) { 21 | this.type = type; 22 | } 23 | 24 | public String getMessage() { 25 | return message; 26 | } 27 | 28 | public void setMessage(String message) { 29 | this.message = message; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "EventMessage{" + 35 | "type=" + type + 36 | ", message='" + message + '\'' + 37 | '}'; 38 | } 39 | } 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/model/GitUser.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.model; 2 | 3 | /** 4 | * Created by wuhuihui on 2019/5/18. 5 | */ 6 | 7 | public class GitUser { 8 | /** 9 | * "login": "basil2style", 10 | * "id": 1285344, 11 | * "node_id": "MDQ6VXNlcjEyODUzNDQ=", 12 | * "avatar_url": "https://avatars1.githubusercontent.com/u/1285344?v=4", 13 | * "gravatar_id": "", 14 | * "url": "https://api.github.com/users/basil2style", 15 | * "html_url": "https://github.com/basil2style", 16 | * "followers_url": "https://api.github.com/users/basil2style/followers", 17 | * "following_url": "https://api.github.com/users/basil2style/following{/other_user}", 18 | * "gists_url": "https://api.github.com/users/basil2style/gists{/gist_id}", 19 | * "starred_url": "https://api.github.com/users/basil2style/starred{/owner}{/repo}", 20 | * "subscriptions_url": "https://api.github.com/users/basil2style/subscriptions", 21 | * "organizations_url": "https://api.github.com/users/basil2style/orgs", 22 | * "repos_url": "https://api.github.com/users/basil2style/repos", 23 | * "events_url": "https://api.github.com/users/basil2style/events{/privacy}", 24 | * "received_events_url": "https://api.github.com/users/basil2style/received_events", 25 | * "type": "User", 26 | * "site_admin": false, 27 | * "name": "Basil Alias", 28 | * "company": "https://www.ribitt.io/", 29 | * "blog": "https://www.linkedin.com/in/basilalias92/", 30 | * "location": "Toronto, Canada", 31 | * "email": null, 32 | * "hireable": true, 33 | * "bio": "Developer | Marketer | Reader | Cinephile | Entrepreneur", 34 | * "public_repos": 92, 35 | * "public_gists": 11, 36 | * "followers": 81, 37 | * "following": 94, 38 | * "created_at": "2011-12-26T00:17:22Z", 39 | * "updated_at": "2019-05-15T19:54:46Z" 40 | */ 41 | private String login; 42 | private double id; 43 | private String node_id; 44 | private String avatar_url; 45 | private String gravatar_id; 46 | private String url; 47 | private String html_url; 48 | private String followers_url; 49 | private String following_url; 50 | private String gists_url; 51 | private String starred_url; 52 | private String subscriptions_url; 53 | private String organizations_url; 54 | private String repos_url; 55 | private String events_url; 56 | private String received_events_url; 57 | private String type; 58 | private boolean site_admin; 59 | private String name; 60 | private String company; 61 | private String blog; 62 | private String location; 63 | private String email; 64 | private String hireable; 65 | private String bio; 66 | private String public_repos; 67 | private String public_gists; 68 | private String followers; 69 | private String following; 70 | private String created_at; 71 | private String updated_at; 72 | 73 | public GitUser(String login, double id, String node_id, String avatar_url, 74 | String gravatar_id, String url, String html_url, String followers_url, 75 | String following_url, String gists_url, String starred_url, 76 | String subscriptions_url, String organizations_url, String repos_url, 77 | String events_url, String received_events_url, String type, boolean site_admin, 78 | String name, String company, String blog, String location, String email, 79 | String hireable, String bio, String public_repos, String public_gists, String followers, 80 | String following, String created_at, String updated_at) { 81 | this.login = login; 82 | this.id = id; 83 | this.node_id = node_id; 84 | this.avatar_url = avatar_url; 85 | this.gravatar_id = gravatar_id; 86 | this.url = url; 87 | this.html_url = html_url; 88 | this.followers_url = followers_url; 89 | this.following_url = following_url; 90 | this.gists_url = gists_url; 91 | this.starred_url = starred_url; 92 | this.subscriptions_url = subscriptions_url; 93 | this.organizations_url = organizations_url; 94 | this.repos_url = repos_url; 95 | this.events_url = events_url; 96 | this.received_events_url = received_events_url; 97 | this.type = type; 98 | this.site_admin = site_admin; 99 | this.name = name; 100 | this.company = company; 101 | this.blog = blog; 102 | this.location = location; 103 | this.email = email; 104 | this.hireable = hireable; 105 | this.bio = bio; 106 | this.public_repos = public_repos; 107 | this.public_gists = public_gists; 108 | this.followers = followers; 109 | this.following = following; 110 | this.created_at = created_at; 111 | this.updated_at = updated_at; 112 | } 113 | 114 | public String getLogin() { 115 | return login; 116 | } 117 | 118 | public void setLogin(String login) { 119 | this.login = login; 120 | } 121 | 122 | public double getId() { 123 | return id; 124 | } 125 | 126 | public void setId(double id) { 127 | this.id = id; 128 | } 129 | 130 | public String getNode_id() { 131 | return node_id; 132 | } 133 | 134 | public void setNode_id(String node_id) { 135 | this.node_id = node_id; 136 | } 137 | 138 | public String getAvatar_url() { 139 | return avatar_url; 140 | } 141 | 142 | public void setAvatar_url(String avatar_url) { 143 | this.avatar_url = avatar_url; 144 | } 145 | 146 | public String getGravatar_id() { 147 | return gravatar_id; 148 | } 149 | 150 | public void setGravatar_id(String gravatar_id) { 151 | this.gravatar_id = gravatar_id; 152 | } 153 | 154 | public String getUrl() { 155 | return url; 156 | } 157 | 158 | public void setUrl(String url) { 159 | this.url = url; 160 | } 161 | 162 | public String getHtml_url() { 163 | return html_url; 164 | } 165 | 166 | public void setHtml_url(String html_url) { 167 | this.html_url = html_url; 168 | } 169 | 170 | public String getFollowers_url() { 171 | return followers_url; 172 | } 173 | 174 | public void setFollowers_url(String followers_url) { 175 | this.followers_url = followers_url; 176 | } 177 | 178 | public String getFollowing_url() { 179 | return following_url; 180 | } 181 | 182 | public void setFollowing_url(String following_url) { 183 | this.following_url = following_url; 184 | } 185 | 186 | public String getGists_url() { 187 | return gists_url; 188 | } 189 | 190 | public void setGists_url(String gists_url) { 191 | this.gists_url = gists_url; 192 | } 193 | 194 | public String getStarred_url() { 195 | return starred_url; 196 | } 197 | 198 | public void setStarred_url(String starred_url) { 199 | this.starred_url = starred_url; 200 | } 201 | 202 | public String getSubscriptions_url() { 203 | return subscriptions_url; 204 | } 205 | 206 | public void setSubscriptions_url(String subscriptions_url) { 207 | this.subscriptions_url = subscriptions_url; 208 | } 209 | 210 | public String getOrganizations_url() { 211 | return organizations_url; 212 | } 213 | 214 | public void setOrganizations_url(String organizations_url) { 215 | this.organizations_url = organizations_url; 216 | } 217 | 218 | public String getRepos_url() { 219 | return repos_url; 220 | } 221 | 222 | public void setRepos_url(String repos_url) { 223 | this.repos_url = repos_url; 224 | } 225 | 226 | public String getEvents_url() { 227 | return events_url; 228 | } 229 | 230 | public void setEvents_url(String events_url) { 231 | this.events_url = events_url; 232 | } 233 | 234 | public String getReceived_events_url() { 235 | return received_events_url; 236 | } 237 | 238 | public void setReceived_events_url(String received_events_url) { 239 | this.received_events_url = received_events_url; 240 | } 241 | 242 | public String getType() { 243 | return type; 244 | } 245 | 246 | public void setType(String type) { 247 | this.type = type; 248 | } 249 | 250 | public boolean isSite_admin() { 251 | return site_admin; 252 | } 253 | 254 | public void setSite_admin(boolean site_admin) { 255 | this.site_admin = site_admin; 256 | } 257 | 258 | public String getName() { 259 | return name; 260 | } 261 | 262 | public void setName(String name) { 263 | this.name = name; 264 | } 265 | 266 | public String getCompany() { 267 | return company; 268 | } 269 | 270 | public void setCompany(String company) { 271 | this.company = company; 272 | } 273 | 274 | public String getBlog() { 275 | return blog; 276 | } 277 | 278 | public void setBlog(String blog) { 279 | this.blog = blog; 280 | } 281 | 282 | public String getLocation() { 283 | return location; 284 | } 285 | 286 | public void setLocation(String location) { 287 | this.location = location; 288 | } 289 | 290 | public String getEmail() { 291 | return email; 292 | } 293 | 294 | public void setEmail(String email) { 295 | this.email = email; 296 | } 297 | 298 | public String getHireable() { 299 | return hireable; 300 | } 301 | 302 | public void setHireable(String hireable) { 303 | this.hireable = hireable; 304 | } 305 | 306 | public String getBio() { 307 | return bio; 308 | } 309 | 310 | public void setBio(String bio) { 311 | this.bio = bio; 312 | } 313 | 314 | public String getPublic_repos() { 315 | return public_repos; 316 | } 317 | 318 | public void setPublic_repos(String public_repos) { 319 | this.public_repos = public_repos; 320 | } 321 | 322 | public String getPublic_gists() { 323 | return public_gists; 324 | } 325 | 326 | public void setPublic_gists(String public_gists) { 327 | this.public_gists = public_gists; 328 | } 329 | 330 | public String getFollowers() { 331 | return followers; 332 | } 333 | 334 | public void setFollowers(String followers) { 335 | this.followers = followers; 336 | } 337 | 338 | public String getFollowing() { 339 | return following; 340 | } 341 | 342 | public void setFollowing(String following) { 343 | this.following = following; 344 | } 345 | 346 | public String getCreated_at() { 347 | return created_at; 348 | } 349 | 350 | public void setCreated_at(String created_at) { 351 | this.created_at = created_at; 352 | } 353 | 354 | public String getUpdated_at() { 355 | return updated_at; 356 | } 357 | 358 | public void setUpdated_at(String updated_at) { 359 | this.updated_at = updated_at; 360 | } 361 | 362 | @Override 363 | public String toString() { 364 | return "GitUser{" + 365 | "login='" + login + '\'' + 366 | ", id=" + id + 367 | ", node_id='" + node_id + '\'' + 368 | ", avatar_url='" + avatar_url + '\'' + 369 | ", gravatar_id='" + gravatar_id + '\'' + 370 | ", url='" + url + '\'' + 371 | ", html_url='" + html_url + '\'' + 372 | ", followers_url='" + followers_url + '\'' + 373 | ", following_url='" + following_url + '\'' + 374 | ", gists_url='" + gists_url + '\'' + 375 | ", starred_url='" + starred_url + '\'' + 376 | ", subscriptions_url='" + subscriptions_url + '\'' + 377 | ", organizations_url='" + organizations_url + '\'' + 378 | ", repos_url='" + repos_url + '\'' + 379 | ", events_url='" + events_url + '\'' + 380 | ", received_events_url='" + received_events_url + '\'' + 381 | ", type='" + type + '\'' + 382 | ", site_admin=" + site_admin + 383 | ", name='" + name + '\'' + 384 | ", company='" + company + '\'' + 385 | ", blog='" + blog + '\'' + 386 | ", location='" + location + '\'' + 387 | ", email='" + email + '\'' + 388 | ", hireable='" + hireable + '\'' + 389 | ", bio='" + bio + '\'' + 390 | ", public_repos='" + public_repos + '\'' + 391 | ", public_gists='" + public_gists + '\'' + 392 | ", followers='" + followers + '\'' + 393 | ", following='" + following + '\'' + 394 | ", created_at='" + created_at + '\'' + 395 | ", updated_at='" + updated_at + '\'' + 396 | '}'; 397 | } 398 | } 399 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/model/Weather.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.model; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by wuhuihui on 2019/5/17. 7 | */ 8 | 9 | public class Weather { 10 | 11 | private String time; 12 | private CityInfo cityInfo; 13 | private String date; 14 | private String message; 15 | private int status; 16 | private Data data; 17 | 18 | public Weather(String time, CityInfo cityInfo, String date, String message, int status, Data data) { 19 | this.time = time; 20 | this.cityInfo = cityInfo; 21 | this.date = date; 22 | this.message = message; 23 | this.status = status; 24 | this.data = data; 25 | } 26 | 27 | public String getTime() { 28 | return time; 29 | } 30 | 31 | public void setTime(String time) { 32 | this.time = time; 33 | } 34 | 35 | public CityInfo getCityInfo() { 36 | return cityInfo; 37 | } 38 | 39 | public void setCityInfo(CityInfo cityInfo) { 40 | this.cityInfo = cityInfo; 41 | } 42 | 43 | public String getDate() { 44 | return date; 45 | } 46 | 47 | public void setDate(String date) { 48 | this.date = date; 49 | } 50 | 51 | public String getMessage() { 52 | return message; 53 | } 54 | 55 | public void setMessage(String message) { 56 | this.message = message; 57 | } 58 | 59 | public int getStatus() { 60 | return status; 61 | } 62 | 63 | public void setStatus(int status) { 64 | this.status = status; 65 | } 66 | 67 | public Data getData() { 68 | return data; 69 | } 70 | 71 | public void setData(Data data) { 72 | this.data = data; 73 | } 74 | 75 | class CityInfo { 76 | private String city; 77 | private String cityId; 78 | private String parent; 79 | private String updateTime; 80 | 81 | public CityInfo(String city, String cityId, String parent, String updateTime) { 82 | this.city = city; 83 | this.cityId = cityId; 84 | this.parent = parent; 85 | this.updateTime = updateTime; 86 | } 87 | 88 | public String getCity() { 89 | return city; 90 | } 91 | 92 | public void setCity(String city) { 93 | this.city = city; 94 | } 95 | 96 | public String getCityId() { 97 | return cityId; 98 | } 99 | 100 | public void setCityId(String cityId) { 101 | this.cityId = cityId; 102 | } 103 | 104 | public String getParent() { 105 | return parent; 106 | } 107 | 108 | public void setParent(String parent) { 109 | this.parent = parent; 110 | } 111 | 112 | public String getUpdateTime() { 113 | return updateTime; 114 | } 115 | 116 | public void setUpdateTime(String updateTime) { 117 | this.updateTime = updateTime; 118 | } 119 | 120 | @Override 121 | public String toString() { 122 | return "CityInfo{" + 123 | "city='" + city + '\'' + 124 | ", cityId='" + cityId + '\'' + 125 | ", parent='" + parent + '\'' + 126 | ", updateTime='" + updateTime + '\'' + 127 | '}'; 128 | } 129 | } 130 | 131 | class Data { 132 | private String shidu; 133 | private int pm25; 134 | private int pm10; 135 | private String quality; 136 | private String wendu; 137 | private String ganmao; 138 | private Yesterday yesterday; 139 | private List forecast; 140 | 141 | /** 142 | * { 143 | * "date": "16", 144 | * "sunrise": "05:00", 145 | * "high": "高温 32.0℃", 146 | * "low": "低温 19.0℃", 147 | * "sunset": "19:22", 148 | * "aqi": 114, 149 | * "ymd": "2019-05-16", 150 | * "week": "星期四", 151 | * "fx": "西南风", 152 | * "fl": "3-4级", 153 | * "type": "晴", 154 | * "notice": "愿你拥有比阳光明媚的心情" 155 | * } 156 | */ 157 | class DayWeather { 158 | private String date; 159 | private String sunrise; 160 | private String high; 161 | private String low; 162 | private String sunset; 163 | private int aqi; 164 | private String ymd; 165 | private String week; 166 | private String fx; 167 | private String fl; 168 | private String type; 169 | private String notice; 170 | 171 | public DayWeather(String date, String sunrise, String high, String low, String sunset, int aqi, String ymd, String week, String fx, String fl, String type, String notice) { 172 | this.date = date; 173 | this.sunrise = sunrise; 174 | this.high = high; 175 | this.low = low; 176 | this.sunset = sunset; 177 | this.aqi = aqi; 178 | this.ymd = ymd; 179 | this.week = week; 180 | this.fx = fx; 181 | this.fl = fl; 182 | this.type = type; 183 | this.notice = notice; 184 | } 185 | 186 | public String getDate() { 187 | return date; 188 | } 189 | 190 | public void setDate(String date) { 191 | this.date = date; 192 | } 193 | 194 | public String getSunrise() { 195 | return sunrise; 196 | } 197 | 198 | public void setSunrise(String sunrise) { 199 | this.sunrise = sunrise; 200 | } 201 | 202 | public String getHigh() { 203 | return high; 204 | } 205 | 206 | public void setHigh(String high) { 207 | this.high = high; 208 | } 209 | 210 | public String getLow() { 211 | return low; 212 | } 213 | 214 | public void setLow(String low) { 215 | this.low = low; 216 | } 217 | 218 | public String getSunset() { 219 | return sunset; 220 | } 221 | 222 | public void setSunset(String sunset) { 223 | this.sunset = sunset; 224 | } 225 | 226 | public int getAqi() { 227 | return aqi; 228 | } 229 | 230 | public void setAqi(int aqi) { 231 | this.aqi = aqi; 232 | } 233 | 234 | public String getYmd() { 235 | return ymd; 236 | } 237 | 238 | public void setYmd(String ymd) { 239 | this.ymd = ymd; 240 | } 241 | 242 | public String getWeek() { 243 | return week; 244 | } 245 | 246 | public void setWeek(String week) { 247 | this.week = week; 248 | } 249 | 250 | public String getFx() { 251 | return fx; 252 | } 253 | 254 | public void setFx(String fx) { 255 | this.fx = fx; 256 | } 257 | 258 | public String getFl() { 259 | return fl; 260 | } 261 | 262 | public void setFl(String fl) { 263 | this.fl = fl; 264 | } 265 | 266 | public String getType() { 267 | return type; 268 | } 269 | 270 | public void setType(String type) { 271 | this.type = type; 272 | } 273 | 274 | public String getNotice() { 275 | return notice; 276 | } 277 | 278 | public void setNotice(String notice) { 279 | this.notice = notice; 280 | } 281 | 282 | @Override 283 | public String toString() { 284 | return "\n" + "DayWeather{" + 285 | "date='" + date + '\'' + 286 | ", sunrise='" + sunrise + '\'' + 287 | ", high='" + high + '\'' + 288 | ", low='" + low + '\'' + 289 | ", sunset='" + sunset + '\'' + 290 | ", aqi=" + aqi + 291 | ", ymd='" + ymd + '\'' + 292 | ", week='" + week + '\'' + 293 | ", fx='" + fx + '\'' + 294 | ", fl='" + fl + '\'' + 295 | ", type='" + type + '\'' + 296 | ", notice='" + notice + '\'' + 297 | '}'; 298 | } 299 | } 300 | 301 | class Yesterday extends DayWeather { 302 | 303 | public Yesterday(String date, String sunrise, String high, String low, String sunset, int aqi, String ymd, String week, String fx, String fl, String type, String notice) { 304 | super(date, sunrise, high, low, sunset, aqi, ymd, week, fx, fl, type, notice); 305 | } 306 | 307 | } 308 | 309 | public Data(String shidu, int pm25, int pm10, String quality, String wendu, 310 | String ganmao, Yesterday yesterday, List forecast) { 311 | this.shidu = shidu; 312 | this.pm25 = pm25; 313 | this.pm10 = pm10; 314 | this.quality = quality; 315 | this.wendu = wendu; 316 | this.ganmao = ganmao; 317 | this.yesterday = yesterday; 318 | this.forecast = forecast; 319 | } 320 | 321 | public String getShidu() { 322 | return shidu; 323 | } 324 | 325 | public void setShidu(String shidu) { 326 | this.shidu = shidu; 327 | } 328 | 329 | public int getPm25() { 330 | return pm25; 331 | } 332 | 333 | public void setPm25(int pm25) { 334 | this.pm25 = pm25; 335 | } 336 | 337 | public int getPm10() { 338 | return pm10; 339 | } 340 | 341 | public void setPm10(int pm10) { 342 | this.pm10 = pm10; 343 | } 344 | 345 | public String getQuality() { 346 | return quality; 347 | } 348 | 349 | public void setQuality(String quality) { 350 | this.quality = quality; 351 | } 352 | 353 | public String getWendu() { 354 | return wendu; 355 | } 356 | 357 | public void setWendu(String wendu) { 358 | this.wendu = wendu; 359 | } 360 | 361 | public String getGanmao() { 362 | return ganmao; 363 | } 364 | 365 | public void setGanmao(String ganmao) { 366 | this.ganmao = ganmao; 367 | } 368 | 369 | public Yesterday getYesterday() { 370 | return yesterday; 371 | } 372 | 373 | public void setYesterday(Yesterday yesterday) { 374 | this.yesterday = yesterday; 375 | } 376 | 377 | public List getForecast() { 378 | return forecast; 379 | } 380 | 381 | public void setForecast(List forecast) { 382 | this.forecast = forecast; 383 | } 384 | 385 | @Override 386 | public String toString() { 387 | return "Data{" + 388 | "shidu='" + shidu + '\'' + 389 | ", pm25=" + pm25 + 390 | ", pm10=" + pm10 + 391 | ", quality='" + quality + '\'' + 392 | ", wendu='" + wendu + '\'' + 393 | ", ganmao='" + ganmao + '\'' + 394 | ",\n\n dayWeather=" + yesterday + 395 | ",\n\n dayWeathers=" + forecast + 396 | '}'; 397 | } 398 | } 399 | 400 | 401 | @Override 402 | public String toString() { 403 | return "Weather{" + 404 | "time='" + time + '\'' + 405 | ", cityInfo=" + cityInfo + 406 | ", date='" + date + '\'' + 407 | ", message='" + message + '\'' + 408 | ", status=" + status + 409 | ", data=" + data + 410 | '}'; 411 | } 412 | } 413 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/presenter/AppVersionPresenter.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.presenter; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.util.Log; 6 | 7 | import com.whh.initmvp.utils.ContantUtils; 8 | import com.whh.initmvp.model.AppVersion; 9 | import com.whh.initmvp.manager.DataManager; 10 | import com.whh.initmvp.view.AppVersionView; 11 | import com.whh.initmvp.view.View; 12 | 13 | import io.reactivex.Observable; 14 | import io.reactivex.Observer; 15 | import io.reactivex.android.schedulers.AndroidSchedulers; 16 | import io.reactivex.disposables.CompositeDisposable; 17 | import io.reactivex.disposables.Disposable; 18 | import io.reactivex.schedulers.Schedulers; 19 | 20 | /** 21 | * Created by wuhuihui on 2019/5/17. 22 | * AppVersionPresenter 处理AppVersion返回的数据,与View交互 23 | */ 24 | 25 | public class AppVersionPresenter implements Presenter { 26 | 27 | private final static String TAG = "AppVersionPresenter"; 28 | 29 | private Context context; 30 | private DataManager manager; 31 | private CompositeDisposable compositeDisposable; 32 | private AppVersionView appVersionView; 33 | private AppVersion appVersion; 34 | 35 | public AppVersionPresenter(Context context) { 36 | this.context = context; 37 | } 38 | 39 | 40 | @Override 41 | public void onCreate() { 42 | manager = new DataManager(context); //参数0标识为当前是请求版本信息数据 43 | compositeDisposable = ContantUtils.compositeDisposable; 44 | //RxJava1: mCompositeSubscription = new CompositeSubscription(); 45 | } 46 | 47 | @Override 48 | public void onStart() { 49 | } 50 | 51 | @Override 52 | public void onDestory() { 53 | if (compositeDisposable != null && !compositeDisposable.isDisposed()) { 54 | compositeDisposable.dispose(); //解除订阅 55 | 56 | //RxJava1:CompositeSubscription.unsubscribe(); 57 | } 58 | } 59 | 60 | @Override 61 | public void pause() { 62 | 63 | } 64 | 65 | @Override 66 | public void attachView(View view) { 67 | appVersionView = (AppVersionView) view; 68 | } 69 | 70 | @Override 71 | public void attachIncomingIntent(Intent intent) { 72 | 73 | } 74 | 75 | public void getAppVersion(String currentVersion, String type) { 76 | Observable observable = manager.getAppVersion(currentVersion, type); 77 | observable.subscribeOn(Schedulers.io()) //在IO线程进行网络请求 78 | .observeOn(AndroidSchedulers.mainThread()) //回到主线程去处理请求结果 79 | .subscribe(new Observer() { 80 | @Override 81 | public void onSubscribe(Disposable d) { 82 | compositeDisposable.add(d); 83 | } 84 | 85 | @Override 86 | public void onNext(AppVersion value) { 87 | appVersion = value; 88 | } 89 | 90 | @Override 91 | public void onError(Throwable e) { 92 | e.printStackTrace(); 93 | Log.i(TAG, "onError:" + e.toString()); 94 | appVersionView.onError("请求失败:\n" + e.toString()); 95 | } 96 | 97 | @Override 98 | public void onComplete() { 99 | Log.i(TAG, "onComplete!"); 100 | if (appVersionView != null) { 101 | appVersionView.onSuccess(appVersion); 102 | Log.i(TAG, "appVersion:" + appVersion.toString()); 103 | } 104 | } 105 | }); 106 | } 107 | 108 | /** 109 | * subscribeOn() 指定的是上游发送事件的线程, observeOn() 指定的是下游接收事件的线程. 110 | 多次指定上游的线程只有第一次指定的有效, 也就是说多次调用subscribeOn() 只有第一次的有效, 其余的会被忽略. 111 | 多次指定下游的线程是可以的, 也就是说每调用一次observeOn() , 下游的线程就会切换一次. 112 | 113 | 作者:Season_zlc 114 | 链接:https://www.jianshu.com/p/8818b98c44e2 115 | 来源:简书 116 | 简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。 117 | */ 118 | 119 | } 120 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/presenter/GitUserPresenter.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.presenter; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.util.Log; 6 | 7 | import com.whh.initmvp.utils.ContantUtils; 8 | import com.whh.initmvp.manager.DataManager; 9 | import com.whh.initmvp.model.GitUser; 10 | import com.whh.initmvp.view.GitUserView; 11 | import com.whh.initmvp.view.View; 12 | 13 | import io.reactivex.Observable; 14 | import io.reactivex.Observer; 15 | import io.reactivex.android.schedulers.AndroidSchedulers; 16 | import io.reactivex.disposables.CompositeDisposable; 17 | import io.reactivex.disposables.Disposable; 18 | import io.reactivex.schedulers.Schedulers; 19 | 20 | /** 21 | * Created by wuhuihui on 2019/5/18. 22 | * GitUserPresenter 处理GitUser返回的数据,与View交互 23 | */ 24 | 25 | public class GitUserPresenter implements Presenter { 26 | 27 | private final static String TAG = "GitUserPresenter"; 28 | 29 | private Context context; 30 | private DataManager manager; 31 | private CompositeDisposable compositeDisposable; 32 | private GitUserView gitUserView; 33 | private GitUser gitUser; 34 | 35 | public GitUserPresenter(Context context) { 36 | this.context = context; 37 | } 38 | 39 | 40 | @Override 41 | public void onCreate() { 42 | manager = new DataManager(context); 43 | compositeDisposable = ContantUtils.compositeDisposable; 44 | //RxJava1: mCompositeSubscription = new CompositeSubscription(); 45 | } 46 | 47 | @Override 48 | public void onStart() { 49 | } 50 | 51 | @Override 52 | public void onDestory() { 53 | if (compositeDisposable != null && !compositeDisposable.isDisposed()) { 54 | compositeDisposable.dispose(); //解除订阅 55 | //RxJava1:CompositeSubscription.unsubscribe(); 56 | } 57 | } 58 | 59 | @Override 60 | public void pause() { 61 | 62 | } 63 | 64 | @Override 65 | public void attachView(View view) { 66 | gitUserView = (GitUserView) view; 67 | } 68 | 69 | @Override 70 | public void attachIncomingIntent(Intent intent) { 71 | 72 | } 73 | 74 | public void getGitUser() { 75 | Observable observable = manager.getGitUser(); 76 | observable.subscribeOn(Schedulers.io()) 77 | .observeOn(AndroidSchedulers.mainThread()) 78 | .subscribe(new Observer() { 79 | @Override 80 | public void onSubscribe(Disposable d) { 81 | compositeDisposable.add(d); 82 | } 83 | 84 | @Override 85 | public void onNext(GitUser value) { 86 | gitUser = value; 87 | } 88 | 89 | @Override 90 | public void onError(Throwable e) { 91 | e.printStackTrace(); 92 | Log.i(TAG, "onError:" + e.toString()); 93 | gitUserView.onError("请求失败:\n" + e.toString()); 94 | } 95 | 96 | @Override 97 | public void onComplete() { 98 | Log.i(TAG, "onComplete!"); 99 | if (gitUserView != null) { 100 | gitUserView.onSuccess(gitUser); 101 | Log.i(TAG, "gitUser:" + gitUser.toString()); 102 | } 103 | } 104 | }); 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/presenter/Presenter.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.presenter; 2 | 3 | import android.content.Intent; 4 | 5 | import com.whh.initmvp.view.View; 6 | 7 | /** 8 | * Created by wuhuihui on 2019/5/17. 9 | * Presenter:基类方法用于Activity或Fragment在onDestory解绑View 10 | * 所有presenter的基类,子类实现其方法, 11 | */ 12 | 13 | public interface Presenter { 14 | 15 | void onCreate(); 16 | 17 | void onStart(); 18 | 19 | void onDestory(); 20 | 21 | void pause(); 22 | 23 | void attachView(View view); 24 | 25 | void attachIncomingIntent(Intent intent); 26 | } 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/presenter/WeatherPresenter.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.presenter; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.util.Log; 6 | 7 | import com.whh.initmvp.utils.ContantUtils; 8 | import com.whh.initmvp.manager.DataManager; 9 | import com.whh.initmvp.model.Weather; 10 | import com.whh.initmvp.view.View; 11 | import com.whh.initmvp.view.WeatherView; 12 | 13 | import io.reactivex.Observable; 14 | import io.reactivex.Observer; 15 | import io.reactivex.android.schedulers.AndroidSchedulers; 16 | import io.reactivex.disposables.CompositeDisposable; 17 | import io.reactivex.disposables.Disposable; 18 | import io.reactivex.schedulers.Schedulers; 19 | 20 | /** 21 | * Created by wuhuihui on 2019/5/17. 22 | * WeatherPresenter 处理Weather返回的数据,与View交互 23 | */ 24 | 25 | public class WeatherPresenter implements Presenter { 26 | 27 | private final static String TAG = "WeatherPresenter"; 28 | 29 | private Context context; 30 | private DataManager manager; 31 | private CompositeDisposable compositeDisposable; 32 | private WeatherView weatherView; 33 | private Weather weather; 34 | 35 | public WeatherPresenter(Context context) { 36 | this.context = context; 37 | } 38 | 39 | 40 | @Override 41 | public void onCreate() { 42 | manager = new DataManager(context); //参数1标识为当前是请求天气信息数据 43 | compositeDisposable = ContantUtils.compositeDisposable; 44 | //RxJava1: mCompositeSubscription = new CompositeSubscription(); 45 | } 46 | 47 | @Override 48 | public void onStart() { 49 | } 50 | 51 | @Override 52 | public void onDestory() { 53 | if (compositeDisposable != null && !compositeDisposable.isDisposed()) { 54 | compositeDisposable.dispose(); //解除订阅 55 | //RxJava1:CompositeSubscription.unsubscribe(); 56 | } 57 | } 58 | 59 | @Override 60 | public void pause() { 61 | 62 | } 63 | 64 | @Override 65 | public void attachView(View view) { 66 | weatherView = (WeatherView) view; 67 | } 68 | 69 | @Override 70 | public void attachIncomingIntent(Intent intent) { 71 | 72 | } 73 | 74 | public void getWeather() { 75 | Observable observable = manager.getWeather(); 76 | observable.subscribeOn(Schedulers.io()) 77 | .observeOn(AndroidSchedulers.mainThread()) 78 | .subscribe(new Observer() { 79 | @Override 80 | public void onSubscribe(Disposable d) { 81 | compositeDisposable.add(d); 82 | } 83 | 84 | @Override 85 | public void onNext(Weather value) { 86 | weather = value; 87 | } 88 | 89 | @Override 90 | public void onError(Throwable e) { 91 | e.printStackTrace(); 92 | Log.i(TAG, "onError:" + e.toString()); 93 | weatherView.onError("请求失败:\n" + e.toString()); 94 | } 95 | 96 | @Override 97 | public void onComplete() { 98 | Log.i(TAG, "onComplete!"); 99 | if (weatherView != null) { 100 | weatherView.onSuccess(weather); 101 | Log.i(TAG, "weather:" + weather.toString()); 102 | } 103 | } 104 | }); 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/receiver/NetworkReceiver.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.receiver; 2 | 3 | import android.app.IntentService; 4 | import android.content.BroadcastReceiver; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.support.annotation.Nullable; 8 | 9 | import com.whh.baselib.utils.SystemUtils; 10 | 11 | /** 12 | * IntentService的使用 13 | * Created by wuhuihui on 2019/6/10. 14 | */ 15 | public class NetworkReceiver extends BroadcastReceiver { 16 | 17 | private static final String TAG = NetworkReceiver.class.getSimpleName(); 18 | 19 | @Override 20 | public void onReceive(Context context, Intent intent) { 21 | if (SystemUtils.isNetworkAvailable(context)) { 22 | // upload data by start intentservice 23 | Intent serviceIntent = new Intent(context, NetworkService.class); 24 | context.startService(serviceIntent); 25 | } 26 | 27 | } 28 | 29 | public static class NetworkService extends IntentService { 30 | 31 | public NetworkService() { 32 | super("NetworkService"); 33 | } 34 | 35 | @Override 36 | protected void onHandleIntent(@Nullable Intent intent) { 37 | //执行耗时操作 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/retrofit/RetrofitHelper.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.retrofit; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | 6 | import com.google.gson.GsonBuilder; 7 | import com.whh.initmvp.MyApp; 8 | import com.whh.initmvp.utils.ContantUtils; 9 | 10 | import retrofit2.Retrofit; 11 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; 12 | import retrofit2.converter.gson.GsonConverterFactory; 13 | 14 | /** 15 | * Created by wuhuihui on 2019/5/17. 16 | * RetrofitHelper:初始化Retrofit,设置请求API的baseUrl、gson解析方式 17 | */ 18 | 19 | public class RetrofitHelper { 20 | private final String TAG = "RetrofitHelper"; 21 | private Context context; 22 | 23 | private static RetrofitHelper instance = null; 24 | private Retrofit retrofit = null; 25 | 26 | private RetrofitHelper(Context context) { 27 | this.context = context; 28 | // initRetrofit(); 29 | // initWeatherRetrofit(); 30 | initGitUserRetrofit(); 31 | } 32 | 33 | public static RetrofitHelper getInstance(Context context) { 34 | if (instance == null) instance = new RetrofitHelper(context); 35 | return instance; 36 | } 37 | 38 | private void initRetrofit() { 39 | Log.i(TAG, ContantUtils.APPVERSION_BASE_URL); 40 | retrofit = new Retrofit.Builder() 41 | .baseUrl(ContantUtils.APPVERSION_BASE_URL) 42 | .addConverterFactory(GsonConverterFactory.create( 43 | new GsonBuilder().create())) 44 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) //实现异步 45 | .client(MyApp.okHtpClient) 46 | .build(); 47 | } 48 | 49 | /** 50 | * 访问天气的网络请求 51 | */ 52 | private void initWeatherRetrofit() { 53 | Log.i(TAG, ContantUtils.WEATHER_BASE_URL); 54 | retrofit = new Retrofit.Builder() 55 | .baseUrl(ContantUtils.WEATHER_BASE_URL) 56 | .addConverterFactory(GsonConverterFactory.create( 57 | new GsonBuilder().create())) 58 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) 59 | .client(MyApp.okHtpClient) 60 | .build(); 61 | } 62 | 63 | /** 64 | * GitUser https请求 65 | */ 66 | private void initGitUserRetrofit() { 67 | Log.i(TAG, ContantUtils.GITHUBSER_BASE_URL); 68 | retrofit = new Retrofit.Builder() 69 | .baseUrl(ContantUtils.GITHUBSER_BASE_URL) 70 | .addConverterFactory(GsonConverterFactory.create( 71 | new GsonBuilder().create())) 72 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) 73 | .client(MyApp.okHtpClient) 74 | .build(); 75 | } 76 | 77 | public RetrofitService getServer() { 78 | return retrofit.create(RetrofitService.class); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/retrofit/RetrofitService.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.retrofit; 2 | 3 | 4 | import com.whh.initmvp.model.AppVersion; 5 | import com.whh.initmvp.model.GitUser; 6 | import com.whh.initmvp.model.Weather; 7 | 8 | import io.reactivex.Observable; 9 | import retrofit2.http.Field; 10 | import retrofit2.http.FormUrlEncoded; 11 | import retrofit2.http.GET; 12 | import retrofit2.http.POST; 13 | 14 | /** 15 | * Created by wuhuihui on 2019/5/17. 16 | * RetrofitService:管理Retrofit的各种数据请求(post、get),包含请求api、请求参数 17 | */ 18 | 19 | public interface RetrofitService { 20 | 21 | //get请求 22 | // @GET("appversion-getAppVersion") 23 | // Observable getAppVersion(@Query("currentVersion") String currentVersion, 24 | // @Query("type") String type); 25 | 26 | //post请求 27 | @FormUrlEncoded 28 | @POST("appversion-getAppVersion") 29 | Observable getAppVersion(@Field("currentVersion") String currentVersion, 30 | @Field("type") String type); 31 | //get请求 32 | @GET("api/weather/city/101010100") 33 | Observable getWeather(); 34 | 35 | //get请求 36 | @GET("basil2style") 37 | Observable getGitUser(); 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/utils/ContantUtils.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.utils; 2 | 3 | import io.reactivex.disposables.CompositeDisposable; 4 | 5 | /** 6 | * Created by wuhuihui on 2019/5/17. 7 | */ 8 | 9 | public class ContantUtils { 10 | 11 | public static String APPVERSION_BASE_URL = "http://ios.mobile.che-by.com/"; 12 | public static String WEATHER_BASE_URL = "http://t.weather.sojson.com/"; 13 | public static String GITHUBSER_BASE_URL = "https://api.github.com/users/"; 14 | 15 | public static CompositeDisposable compositeDisposable; 16 | 17 | /** 18 | * 新建订阅容器,供APP全局使用 19 | */ 20 | public static void setCompositeDisposable() { 21 | compositeDisposable = new CompositeDisposable(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/utils/OkHttpUtils.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.utils; 2 | 3 | import android.util.Log; 4 | 5 | import com.facebook.stetho.okhttp3.StethoInterceptor; 6 | import com.franmontiel.persistentcookiejar.PersistentCookieJar; 7 | import com.franmontiel.persistentcookiejar.cache.SetCookieCache; 8 | import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor; 9 | import com.whh.initmvp.MyApp; 10 | 11 | import java.util.concurrent.TimeUnit; 12 | 13 | import okhttp3.OkHttpClient; 14 | import okhttp3.logging.HttpLoggingInterceptor; 15 | 16 | /** 17 | * Created by wuhuihui on 2019/5/18. 18 | * OkHttpUtils 日志拦截器 19 | */ 20 | 21 | public class OkHttpUtils { 22 | 23 | private static final String TAG = "OkHttpUtils"; 24 | public static final long DEFAULT_READ_TIMEOUT_MILLIS = 15 * 1000; 25 | public static final long DEFAULT_WRITE_TIMEOUT_MILLIS = 20 * 1000; 26 | public static final long DEFAULT_CONNECT_TIMEOUT_MILLIS = 20 * 1000; 27 | private static final long HTTP_RESPONSE_DISK_CACHE_MAX_SIZE = 10 * 1024 * 1024; 28 | 29 | private static volatile OkHttpUtils instance; 30 | private OkHttpClient okHttpClient; 31 | 32 | /** 33 | * 获取log拦截器,单例模式,仅获取一次,共APP全局使用 34 | */ 35 | private OkHttpUtils() { 36 | // 设置HttpLoggingInterceptor 37 | HttpLoggingInterceptor interceptor = 38 | new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() { 39 | @Override 40 | public void log(String message) { 41 | try { 42 | Log.i(TAG, message); 43 | } catch (Exception e) { 44 | e.printStackTrace(); 45 | Log.e(TAG, message); 46 | } 47 | } 48 | }); 49 | 50 | 51 | //包含header、body数据 52 | interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); 53 | // setlevel用来设置日志打印的级别,共包括了四个级别:NONE,BASIC,HEADER,BODY 54 | // BASEIC:请求/响应行 55 | // HEADER:请求/响应行 + 头 56 | // BODY:请求/响应行 + 头 + 体 57 | 58 | // 初始化OkHttpClient 59 | okHttpClient = new OkHttpClient.Builder() 60 | .readTimeout(DEFAULT_READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS) 61 | .writeTimeout(DEFAULT_WRITE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS) 62 | .connectTimeout(DEFAULT_CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS) 63 | //FaceBook 网络调试器,可在Chrome调试网络请求,查看SharePreferences,数据库等 64 | .addNetworkInterceptor(new StethoInterceptor()) 65 | .addInterceptor(interceptor) 66 | //持久化Cookie,OKHttp管理Cookie 67 | //用户登录时保存的cookie,在下次需要用到该用户的cookie放在请求头里 68 | .cookieJar(new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(MyApp.getInstance()))) 69 | .build(); 70 | } 71 | 72 | public static OkHttpUtils getInstance() { 73 | if (instance == null) { 74 | synchronized (OkHttpUtils.class) { 75 | if (instance == null) { 76 | instance = new OkHttpUtils(); 77 | } 78 | } 79 | } 80 | return instance; 81 | } 82 | 83 | /** 84 | * 获取OkHttpClient 85 | * 86 | * @return 87 | */ 88 | public OkHttpClient getOkHttpClient() { 89 | return okHttpClient; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/view/AppVersionView.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.view; 2 | 3 | import com.whh.initmvp.model.AppVersion; 4 | 5 | /** 6 | * Created by wuhuihui on 2019/5/17. 7 | */ 8 | 9 | public interface AppVersionView extends View{ 10 | 11 | void onSuccess(AppVersion appVersion); 12 | 13 | void onError(String error); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/view/GitUserView.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.view; 2 | 3 | import com.whh.initmvp.model.GitUser; 4 | 5 | /** 6 | * Created by wuhuihui on 2019/5/17. 7 | */ 8 | 9 | public interface GitUserView extends View{ 10 | 11 | void onSuccess(GitUser gitUser); 12 | 13 | void onError(String error); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/view/View.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.view; 2 | 3 | /** 4 | * Created by wuhuihui on 2019/5/17. 5 | */ 6 | 7 | public interface View { 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/whh/initmvp/view/WeatherView.java: -------------------------------------------------------------------------------- 1 | package com.whh.initmvp.view; 2 | 3 | import com.whh.initmvp.model.Weather; 4 | 5 | /** 6 | * Created by wuhuihui on 2019/5/17. 7 | */ 8 | 9 | public interface WeatherView extends View{ 10 | 11 | void onSuccess(Weather weather); 12 | 13 | void onError(String error); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_glide.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 |