├── .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 |
13 |
14 |
15 |
16 |
17 |
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 |
55 |
56 | 1.8
57 |
58 |
59 |
60 |
61 |
62 |
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 |
5 |
6 |
7 |
8 |
9 |
10 |
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 |
24 |
25 |
35 |
36 |
46 |
47 |
48 |
52 |
53 |
63 |
64 |
74 |
75 |
76 |
77 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_recyclerview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_layout2.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_glide_image.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 积源
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/whh/initmvp/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.whh.initmvp;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/arouter/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/arouter/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | javaCompileOptions {
14 | annotationProcessorOptions {
15 | arguments = [moduleName: project.getName()]
16 |
17 | }
18 | }
19 | }
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | }
27 |
28 | dependencies {
29 | testCompile 'junit:junit:4.12'
30 |
31 | //baselib
32 | compile project(':baselib')
33 |
34 | //arouter
35 | compile 'com.alibaba:arouter-api:1.3.1'
36 | annotationProcessor 'com.alibaba:arouter-compiler:1.1.4'
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/arouter/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:\private\StudioSDK/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 |
--------------------------------------------------------------------------------
/arouter/src/androidTest/java/com/whh/irisking/arouter/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.whh.irisking.arouter;
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 | }
--------------------------------------------------------------------------------
/arouter/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/arouter/src/main/java/com/whh/irisking/arouter/ARouterResultActivity.java:
--------------------------------------------------------------------------------
1 | package com.whh.irisking.arouter;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.widget.TextView;
6 |
7 | import com.alibaba.android.arouter.facade.annotation.Autowired;
8 | import com.alibaba.android.arouter.facade.annotation.Route;
9 |
10 | @Route(path = "/arouter/ARouterResultActivity")
11 | public class ARouterResultActivity extends Activity {
12 |
13 | @Autowired()
14 | String key;
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_arouter);
20 |
21 | TextView receiveMsg = (TextView) findViewById(R.id.receiveMsg);
22 | receiveMsg.setText(key);
23 |
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/arouter/src/main/res/layout/activity_arouter.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/arouter/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/arouter/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/arouter/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/arouter/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/arouter/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/arouter/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/arouter/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/arouter/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/arouter/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/arouter/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/arouter/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/arouter/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/arouter/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/arouter/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/arouter/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/arouter/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/arouter/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/arouter/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/arouter/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/arouter/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/arouter/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/arouter/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ARouter
3 |
4 |
--------------------------------------------------------------------------------
/arouter/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/arouter/src/test/java/com/whh/irisking/arouter/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.whh.irisking.arouter;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/baselib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/baselib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 |
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(include: ['*.jar'], dir: 'libs')
24 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
25 | testCompile 'junit:junit:4.12'
26 | compile 'com.android.support:appcompat-v7:25.+'
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/baselib/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 |
--------------------------------------------------------------------------------
/baselib/src/androidTest/java/com/whh/baselib/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.whh.baselib;
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 | }
--------------------------------------------------------------------------------
/baselib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/baselib/src/main/java/com/whh/baselib/activity/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.whh.baselib.activity;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Activity;
5 | import android.content.Context;
6 | import android.content.pm.ActivityInfo;
7 | import android.content.pm.PackageManager;
8 | import android.os.Build;
9 | import android.os.Bundle;
10 | import android.os.Environment;
11 | import android.support.v4.app.ActivityCompat;
12 | import android.support.v4.app.FragmentActivity;
13 | import android.text.TextUtils;
14 | import android.util.Log;
15 | import android.view.LayoutInflater;
16 | import android.view.View;
17 | import android.view.Window;
18 | import android.widget.FrameLayout;
19 | import android.widget.ImageButton;
20 | import android.widget.ImageView;
21 | import android.widget.RelativeLayout;
22 | import android.widget.TextView;
23 |
24 | import com.whh.baselib.R;
25 | import com.whh.baselib.utils.FileUtil;
26 | import com.whh.baselib.utils.SystemUtils;
27 |
28 | import java.io.FileOutputStream;
29 | import java.io.IOException;
30 | import java.io.OutputStream;
31 |
32 | /**
33 | * Created by wuhuihui on 2019/5/17.
34 | */
35 |
36 | public class BaseActivity extends FragmentActivity implements View.OnClickListener {
37 |
38 | protected Activity activity;
39 | protected Context context;
40 | protected String TAG;
41 | protected FrameLayout content_layout;
42 |
43 | public static String DEFAULT_COVERAGE_FILE_PATH = Environment.getExternalStorageDirectory()+"/";
44 |
45 | @Override
46 | protected void onCreate(Bundle savedInstanceState) {
47 | super.onCreate(savedInstanceState);
48 | requestWindowFeature(Window.FEATURE_NO_TITLE);
49 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
50 |
51 | initActivity();
52 |
53 | }
54 |
55 | /**
56 | * 初始化Activity
57 | */
58 | private void initActivity() {
59 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//设置竖屏
60 | setContentView(R.layout.activity_base_layout);
61 |
62 | context = this;
63 | activity = this;
64 | TAG = getLocalClassName(); //初始化常量
65 |
66 | Log.i(TAG, TAG + " is onCreated!");
67 |
68 | requestPermission(
69 | new String[]{
70 | "android.permission.WRITE_EXTERNAL_STORAGE",
71 | "android.permission.READ_EXTERNAL_STORAGE",
72 | }
73 | );
74 |
75 | }
76 |
77 | private final int PERMISSION_REQUEST_CODE = 2000;
78 | @SuppressLint("WrongConstant")
79 | private void requestPermission(String[] permissions) {
80 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
81 | int resultCode = 0;
82 | for (String str : permissions) {
83 | resultCode = checkSelfPermission(str);
84 | if (resultCode != 0) {
85 | if (resultCode == PackageManager.PERMISSION_DENIED) {
86 | requestPermissions(permissions, PERMISSION_REQUEST_CODE);
87 | break;
88 | }
89 | }
90 | }
91 | }
92 | Log.i("wuhuihui", "BaseActivity.java BaseActivity requestPermission :");
93 | }
94 |
95 | @Override
96 | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
97 | if (requestCode == PERMISSION_REQUEST_CODE) {
98 | if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
99 | // 权限通过
100 | } else {
101 | // 权限拒绝
102 | if (!ActivityCompat.shouldShowRequestPermissionRationale(this, permissions[0])) {
103 | // 禁止后不再询问了!
104 | } else {
105 | // 用户此次选择了禁止权限
106 | }
107 | }
108 | return;
109 | }
110 | Log.i("wuhuihui", "BaseActivity.java BaseActivity onRequestPermissionsResult :");
111 | super.onRequestPermissionsResult(requestCode, permissions, grantResults);
112 | FileUtil.createFile(DEFAULT_COVERAGE_FILE_PATH, "initMVp_coverage.ec");
113 | }
114 |
115 | /**
116 | * 设置中间内容布局
117 | *
118 | * @param title
119 | */
120 | protected void setTitle(String title) {
121 |
122 | ImageButton return_btn = (ImageButton) findViewById(R.id.return_btn);
123 | if (isOtherActivity()) {
124 | return_btn.setOnClickListener(new View.OnClickListener() {
125 | @Override
126 | public void onClick(View v) {
127 | finish();
128 | }
129 | });
130 | } else {
131 | return_btn.setVisibility(View.GONE);
132 | }
133 |
134 | if (!TextUtils.isEmpty(title)) {
135 | //设置当前界面的title
136 | TextView titleView = (TextView) findViewById(R.id.title);
137 | titleView.setText(title);
138 | } else {
139 | RelativeLayout top_layout = (RelativeLayout) findViewById(R.id.top_layout);
140 | top_layout.setVisibility(View.GONE);
141 | }
142 | }
143 |
144 | /**
145 | * 设置中间内容布局
146 | *
147 | * @param layoutID
148 | * @param title
149 | */
150 | protected void setContentView(String title, int layoutID) {
151 |
152 | setTitle(title);
153 |
154 | //加载中间布局
155 | content_layout = (FrameLayout) findViewById(R.id.content_layout);
156 | content_layout.removeAllViews();
157 | View view = LayoutInflater.from(this).inflate(layoutID, null);
158 | content_layout.addView(view);
159 |
160 | }
161 |
162 | /**
163 | * 设置界面右上角按钮的点击事件
164 | *
165 | * @param text
166 | * @param listener
167 | */
168 | protected void setRightBtnListener(CharSequence text, View.OnClickListener listener) {
169 | if (!TextUtils.isEmpty(text)) {
170 | TextView right_btn = (TextView) findViewById(R.id.right_btn);
171 | right_btn.setVisibility(View.VISIBLE);
172 | right_btn.setText(text);
173 | right_btn.setOnClickListener(listener);
174 | findViewById(R.id.right_imgbtn).setVisibility(View.GONE);
175 | }
176 | }
177 |
178 | /**
179 | * 设置界面右上角图片按钮的点击事件
180 | *
181 | * @param resId
182 | * @param listener
183 | */
184 | protected void setRightImgBtnListener(int resId, View.OnClickListener listener) {
185 | ImageView right_imgbtn = (ImageView) findViewById(R.id.right_imgbtn);
186 | right_imgbtn.setVisibility(View.VISIBLE);
187 | right_imgbtn.setImageResource(resId);
188 | right_imgbtn.setOnClickListener(listener);
189 |
190 | findViewById(R.id.right_btn).setVisibility(View.GONE);
191 | }
192 |
193 | @Override
194 | public void onClick(View v) {
195 | if (SystemUtils.isFastDoubleClick()) {
196 | return;
197 | }
198 | }
199 |
200 | /**
201 | * 判断当前activity是不是非MainActivity
202 | *
203 | * @return
204 | */
205 | private boolean isOtherActivity() {
206 | return !TAG.contains("Http");
207 | }
208 |
209 |
210 | @Override
211 | protected void onResume() {
212 | super.onResume();
213 | Log.i(TAG, "lifecycle---" + TAG + " onResume");
214 | }
215 |
216 | @Override
217 | protected void onDestroy() {
218 | super.onDestroy();
219 | generateCoverageFile();
220 | Log.i(TAG, "lifecycle---" + TAG + " onDestroy");
221 |
222 | }
223 |
224 | /**
225 | * 生成executionData
226 | */
227 | public void generateCoverageFile() {
228 |
229 | OutputStream out = null;
230 |
231 | try {
232 | out = new FileOutputStream(DEFAULT_COVERAGE_FILE_PATH + "/initmvp_coverage.ec", false);
233 | Object agent = Class.forName("org.jacoco.agent.rt.RT").getMethod("getAgent").invoke(null);
234 | // 这里之下就统计不到了
235 | out.write((byte[]) agent.getClass().getMethod("getExecutionData", boolean.class).invoke(agent, false));
236 |
237 | Log.i("wuhuihui", "BaseActivity.java BaseActivity generateCoverageFile write success");
238 | } catch (Exception e) {
239 | Log.i("wuhuihui", "BaseActivity.java BaseActivity generateCoverageFile Exception:" + e.toString());
240 |
241 | } finally {
242 | if (out != null) {
243 | try {
244 | out.close();
245 | } catch (IOException e) {
246 | e.printStackTrace();
247 | }
248 | }
249 | }
250 | }
251 |
252 | }
253 |
--------------------------------------------------------------------------------
/baselib/src/main/java/com/whh/baselib/utils/DelayTask.java:
--------------------------------------------------------------------------------
1 | package com.whh.baselib.utils;
2 |
3 | /**
4 | * Created by wuhuihui on 2017/5/22.
5 | */
6 |
7 | import android.os.AsyncTask;
8 |
9 | /**
10 | * 延时操作
11 | */
12 | public class DelayTask extends AsyncTask {
13 |
14 | private long time;//延时时间
15 | private ICallBack callBack;//操作回调
16 |
17 | public DelayTask(long time, ICallBack callBack) {
18 | this.time = time;
19 | this.callBack = callBack;
20 | }
21 |
22 | @Override
23 | protected Void doInBackground(Void... params) {
24 | try {
25 | Thread.sleep(time);
26 | } catch (InterruptedException e) {
27 | e.printStackTrace();
28 | }
29 | return null;
30 | }
31 |
32 | @Override
33 | protected void onPostExecute(Void result) {
34 | callBack.deal();
35 | }
36 |
37 | public interface ICallBack {
38 | void deal();
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/baselib/src/main/java/com/whh/baselib/utils/DialogListener.java:
--------------------------------------------------------------------------------
1 | package com.whh.baselib.utils;
2 |
3 | /**
4 | * 自定义DialogListener
5 | * Created by wuhuihui on 2018/5/18.
6 | */
7 | public abstract class DialogListener {
8 | public abstract void onClick();
9 | }
10 |
--------------------------------------------------------------------------------
/baselib/src/main/java/com/whh/baselib/utils/DialogUtils.java:
--------------------------------------------------------------------------------
1 | package com.whh.baselib.utils;
2 |
3 | import android.app.Activity;
4 | import android.app.AlertDialog;
5 | import android.view.Display;
6 | import android.view.Gravity;
7 | import android.view.View;
8 | import android.view.Window;
9 | import android.view.WindowManager;
10 | import android.widget.Button;
11 | import android.widget.LinearLayout;
12 | import android.widget.TextView;
13 | import com.whh.baselib.R;
14 |
15 | /**
16 | * 自定义美观的AlertDialog
17 | */
18 | public class DialogUtils {
19 |
20 | private static TextView msg;
21 | private static LinearLayout noLayout;
22 | private static Button ok, no;
23 |
24 | /**
25 | * 初始化dialog
26 | * 界面弹框只弹一个,多个弹框时仅显示第一个
27 | *
28 | * @param activity
29 | * @return
30 | */
31 | public static AlertDialog initDialog(Activity activity) {
32 | AlertDialog.Builder builder = new AlertDialog.Builder(activity);
33 | AlertDialog dialog = builder.show();
34 | dialog.setCancelable(true);
35 | dialog.setContentView(R.layout.dialog_message);
36 |
37 | WindowManager manager = activity.getWindowManager();
38 | Window window = dialog.getWindow();
39 | Display display = manager.getDefaultDisplay();
40 | int width = display.getWidth();
41 | window.setLayout(width / 5 * 4, WindowManager.LayoutParams.WRAP_CONTENT);//设置宽度为屏幕的5/4,高度自适应
42 |
43 | msg = (TextView) dialog.findViewById(R.id.msg);
44 | noLayout = (LinearLayout) dialog.findViewById(R.id.noLayout);
45 | ok = (Button) dialog.findViewById(R.id.ok);
46 | no = (Button) dialog.findViewById(R.id.no);
47 |
48 | return dialog;
49 | }
50 |
51 | /**
52 | * 用于显示必要的提示说明,没有实际点击操作(点击后关闭)
53 | *
54 | * @param activity
55 | * @param message
56 | * @return
57 | */
58 | public static AlertDialog showMsgDialog(Activity activity, String message) {
59 | final AlertDialog dialog = initDialog(activity);
60 | msg.setText(message);
61 | if (message.length() > 12) msg.setGravity(Gravity.LEFT);
62 | ok.setOnClickListener(new View.OnClickListener() {
63 | @Override
64 | public void onClick(View v) {
65 | dialog.dismiss();
66 | }
67 | });
68 | return dialog;
69 | }
70 |
71 | /**
72 | * 用于显示必要的提示说明,单选操作(确定按钮)
73 | *
74 | * @param activity
75 | * @param message 提示说明
76 | * @param comfireListener 确定按钮
77 | * @return
78 | */
79 | public static AlertDialog showMsgDialog(Activity activity, String message, final DialogListener comfireListener) {
80 | final AlertDialog dialog = initDialog(activity);
81 | msg.setText(message);
82 | if (message.length() > 12) msg.setGravity(Gravity.LEFT);
83 | if (comfireListener != null) {
84 | noLayout.setVisibility(View.VISIBLE);
85 | ok.setBackgroundResource(R.drawable.dialog_right_btn_bkg);
86 | ok.setOnClickListener(new View.OnClickListener() {
87 | @Override
88 | public void onClick(View v) {
89 | dialog.dismiss();
90 | if (comfireListener != null) {
91 | comfireListener.onClick();
92 | }
93 | }
94 | });
95 | no.setOnClickListener(new View.OnClickListener() {
96 | @Override
97 | public void onClick(View v) {
98 | dialog.dismiss();
99 | }
100 | });
101 | }
102 | return dialog;
103 | }
104 |
105 | /**
106 | * 用于显示必要的提示说明,单选操作(确定按钮)
107 | *
108 | * @param activity
109 | * @param message 提示说明
110 | * @param isCancel 是否可以点击取消键
111 | * @param comfireListener 确定按钮
112 | * @return
113 | */
114 | public static AlertDialog showMsgDialog(Activity activity, String message, boolean isCancel, final DialogListener comfireListener) {
115 | final AlertDialog dialog = initDialog(activity);
116 | dialog.setCancelable(isCancel);
117 | msg.setText(message);
118 | if (message.length() > 12) msg.setGravity(Gravity.LEFT);
119 | if (comfireListener != null) {
120 | noLayout.setVisibility(View.VISIBLE);
121 | ok.setBackgroundResource(R.drawable.dialog_right_btn_bkg);
122 | ok.setOnClickListener(new View.OnClickListener() {
123 | @Override
124 | public void onClick(View v) {
125 | dialog.dismiss();
126 | if (comfireListener != null) {
127 | comfireListener.onClick();
128 | }
129 | }
130 | });
131 | no.setOnClickListener(new View.OnClickListener() {
132 | @Override
133 | public void onClick(View v) {
134 | dialog.dismiss();
135 | }
136 | });
137 | }
138 | return dialog;
139 | }
140 |
141 | /**
142 | * 用于显示必要的提示说明,单选操作(确定按钮,确定按钮的名称)
143 | *
144 | * @param activity
145 | * @param okTitle 确定按钮的名称
146 | * @param message 提示说明
147 | * @param comfireListener 确定按钮
148 | * @return
149 | */
150 | public static AlertDialog showMsgDialog(Activity activity, String message, String okTitle, final DialogListener comfireListener) {
151 | final AlertDialog dialog = initDialog(activity);
152 | msg.setText(message);
153 | if (message.length() > 12) msg.setGravity(Gravity.LEFT);
154 | if (comfireListener != null) {
155 | noLayout.setVisibility(View.VISIBLE);
156 | ok.setBackgroundResource(R.drawable.dialog_right_btn_bkg);
157 | ok.setText(okTitle);
158 | ok.setOnClickListener(new View.OnClickListener() {
159 | @Override
160 | public void onClick(View v) {
161 | dialog.dismiss();
162 | if (comfireListener != null) {
163 | comfireListener.onClick();
164 | }
165 | }
166 | });
167 | no.setOnClickListener(new View.OnClickListener() {
168 | @Override
169 | public void onClick(View v) {
170 | dialog.dismiss();
171 | }
172 | });
173 | }
174 | return dialog;
175 | }
176 |
177 | /**
178 | * 用于显示必要的提示说明,双选操作(确定按钮,确定按钮的名称;取消按钮,取消按钮的名称)
179 | *
180 | * @param activity
181 | * @param okTitle 确定按钮的名称
182 | * @param noTitle 取消按钮的名称
183 | * @param message 提示说明
184 | * @param comfireListener 确定按钮
185 | * @param cancelListener 取消按钮
186 | * @return
187 | */
188 | public static AlertDialog showMsgDialog(Activity activity, String message,
189 | String okTitle, final DialogListener comfireListener,
190 | String noTitle, final DialogListener cancelListener) {
191 | final AlertDialog dialog = initDialog(activity);
192 | msg.setText(message);
193 | if (message.length() > 12) msg.setGravity(Gravity.LEFT);
194 | if (comfireListener != null) {
195 | noLayout.setVisibility(View.VISIBLE);
196 | ok.setBackgroundResource(R.drawable.dialog_right_btn_bkg);
197 | ok.setText(okTitle);
198 | ok.setOnClickListener(new View.OnClickListener() {
199 | @Override
200 | public void onClick(View v) {
201 | dialog.dismiss();
202 | if (comfireListener != null) {
203 | comfireListener.onClick();
204 | }
205 | }
206 | });
207 |
208 | no.setText(noTitle);
209 | no.setOnClickListener(new View.OnClickListener() {
210 | @Override
211 | public void onClick(View v) {
212 | dialog.dismiss();
213 | if (cancelListener != null) {
214 | cancelListener.onClick();
215 | }
216 | }
217 | });
218 | }
219 | return dialog;
220 | }
221 |
222 | /**
223 | * 用于显示必要的提示说明,双选操作(确定按钮,确定按钮的名称;取消按钮,取消按钮的名称)
224 | *
225 | * @param activity
226 | * @param okTitle 确定按钮的名称
227 | * @param noTitle 取消按钮的名称
228 | * @param message 提示说明
229 | * @param isCancel 是否可以点击取消键
230 | * @param comfireListener 确定按钮
231 | * @param cancelListener 取消按钮
232 | * @return
233 | */
234 | public static AlertDialog showMsgDialog(Activity activity, String message, boolean isCancel,
235 | String okTitle, final DialogListener comfireListener,
236 | String noTitle, final DialogListener cancelListener) {
237 | final AlertDialog dialog = initDialog(activity);
238 | dialog.setCancelable(isCancel);
239 | msg.setText(message);
240 | if (message.length() > 12) msg.setGravity(Gravity.LEFT);
241 | if (comfireListener != null) {
242 | noLayout.setVisibility(View.VISIBLE);
243 | ok.setBackgroundResource(R.drawable.dialog_right_btn_bkg);
244 | ok.setText(okTitle);
245 | ok.setOnClickListener(new View.OnClickListener() {
246 | @Override
247 | public void onClick(View v) {
248 | dialog.dismiss();
249 | if (comfireListener != null) {
250 | comfireListener.onClick();
251 | }
252 | }
253 | });
254 |
255 | no.setText(noTitle);
256 | no.setOnClickListener(new View.OnClickListener() {
257 | @Override
258 | public void onClick(View v) {
259 | dialog.dismiss();
260 | if (cancelListener != null) {
261 | cancelListener.onClick();
262 | }
263 | }
264 | });
265 | }
266 | return dialog;
267 | }
268 |
269 | }
270 |
--------------------------------------------------------------------------------
/baselib/src/main/java/com/whh/baselib/utils/FileUtil.java:
--------------------------------------------------------------------------------
1 | package com.whh.baselib.utils;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 |
6 | public class FileUtil {
7 | public static void createFile(String path) {
8 | createFile(path, null);
9 | }
10 |
11 | public static void createFile(String path, String fileName) {
12 | File file = null;
13 | if (path == null) {
14 | new Exception("path no null");
15 | }
16 | if (fileName == null) {
17 | file = new File(path);
18 | } else {
19 | file = new File(path, fileName);
20 | }
21 | if (!file.exists()) {
22 | try {
23 | file.createNewFile();
24 | } catch (IOException e) {
25 | e.printStackTrace();
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/baselib/src/main/java/com/whh/baselib/utils/LogUtils.java:
--------------------------------------------------------------------------------
1 | package com.whh.baselib.utils;
2 |
3 | import android.util.Log;
4 |
5 | /**
6 | * 调试日志的统一输出
7 | * Created by wuhuihui on 2017/3/24.
8 | */
9 | public class LogUtils {
10 |
11 | // 是否输出日志的开关+
12 | public static final boolean DEBUG = true;
13 |
14 | public static void i(String TAG, String msg) {
15 | if (DEBUG) {
16 | Log.i(TAG, msg != null ? msg : "null");
17 | }
18 | }
19 |
20 | public static void i(String TAG, String msg, Throwable e) {
21 | if (DEBUG) {
22 | Log.i(TAG, msg, e);
23 | }
24 | }
25 |
26 | public static void e(String TAG, String msg) {
27 | if (DEBUG) {
28 | Log.e(TAG, msg);
29 | }
30 | }
31 |
32 | public static void e(String TAG, String msg, Throwable e) {
33 | if (DEBUG) {
34 | Log.e(TAG, msg, e);
35 | }
36 | }
37 |
38 | public static void d(String TAG, String msg) {
39 | if (DEBUG) {
40 | Log.d(TAG, msg);
41 | }
42 | }
43 |
44 | public static void d(String TAG, String msg, Throwable e) {
45 | if (DEBUG) {
46 | Log.d(TAG, msg, e);
47 | }
48 | }
49 |
50 | public static void v(String TAG, String msg) {
51 | if (DEBUG) {
52 | Log.v(TAG, msg);
53 | }
54 | }
55 |
56 | public static void v(String TAG, String msg, Throwable e) {
57 | if (DEBUG) {
58 | Log.v(TAG, msg, e);
59 | }
60 | }
61 |
62 | public static void w(String TAG, String msg) {
63 | if (DEBUG) {
64 | Log.w(TAG, msg);
65 | }
66 | }
67 |
68 | public static void w(String TAG, String msg, Throwable e) {
69 | if (DEBUG) {
70 | Log.w(TAG, msg, e);
71 | }
72 | }
73 |
74 | public static void println() {
75 | if (DEBUG) {
76 | System.out.println();
77 | }
78 | }
79 |
80 | public static void println(Object msg) {
81 | if (DEBUG) {
82 | System.out.println(msg);
83 | }
84 | }
85 |
86 | public static void print(Object msg) {
87 | if (DEBUG) {
88 | System.out.print(msg);
89 | }
90 | }
91 |
92 | public static void printStackTrace(Throwable e) {
93 | if (DEBUG) {
94 | e.printStackTrace();
95 | }
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/baselib/src/main/java/com/whh/baselib/utils/SystemUtils.java:
--------------------------------------------------------------------------------
1 | package com.whh.baselib.utils;
2 |
3 | import android.app.Activity;
4 | import android.app.ActivityManager;
5 | import android.content.ComponentName;
6 | import android.content.Context;
7 | import android.content.pm.PackageInfo;
8 | import android.content.pm.PackageManager;
9 | import android.net.ConnectivityManager;
10 | import android.net.NetworkInfo;
11 | import android.view.WindowManager;
12 | import android.view.inputmethod.InputMethodManager;
13 |
14 | /**
15 | * Created by wuhuihui on 2017/3/24.
16 | */
17 | public class SystemUtils {
18 |
19 | private static String TAG = "SystemUtils";
20 |
21 | //隐藏键盘
22 | public static void hideInput(Activity activity) {
23 | ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE))
24 | .hideSoftInputFromWindow(
25 | activity.getCurrentFocus().getWindowToken(),
26 | InputMethodManager.HIDE_NOT_ALWAYS);
27 | }
28 |
29 | /**
30 | * 获取版本号
31 | *
32 | * @return 当前应用的版本号
33 | */
34 | public static String getVersion(Context context) {
35 | PackageManager manager = context.getPackageManager();
36 | PackageInfo info = null;
37 | try {
38 | info = manager.getPackageInfo(context.getPackageName(), 0);
39 | } catch (Exception e) {
40 | LogUtils.e(TAG + "-getVersion", e.toString());
41 | e.printStackTrace();
42 | }
43 | return info.versionName;
44 | }
45 |
46 | /**
47 | * 获取当前运行的activity名字
48 | *
49 | * @param activity
50 | * @return
51 | */
52 | public static String getRunningActivityName(Activity activity) {
53 | ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
54 | ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
55 | return cn.getClassName();
56 | }
57 |
58 |
59 |
60 | /**
61 | * 判断网络是否为WIFI
62 | *
63 | * @param context
64 | * @return
65 | */
66 | public static boolean getIsWIFI(Context context) {
67 |
68 | boolean isWIFI = false;
69 | ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
70 | NetworkInfo networkInfo = manager.getActiveNetworkInfo();
71 |
72 | if (networkInfo != null && networkInfo.isConnected()) {
73 | String type = networkInfo.getTypeName();
74 |
75 | if (type.equalsIgnoreCase("WIFI")) {
76 | isWIFI = true;
77 | } else {
78 | isWIFI = false;
79 | }
80 | } else {
81 | isWIFI = false;
82 | }
83 |
84 | return isWIFI;
85 | }
86 |
87 |
88 | /**
89 | * 避免按钮短时间点击多次
90 | */
91 | private static long lastClickTime;
92 |
93 | public static boolean isFastDoubleClick() {
94 | long time = System.currentTimeMillis();
95 | long timeD = time - lastClickTime;
96 | if (0 < timeD && timeD < 1000) {
97 | return true;
98 | }
99 | lastClickTime = time;
100 | return false;
101 | }
102 |
103 | /**
104 | * 获取屏幕宽度
105 | *
106 | * @param activity
107 | * @return
108 | */
109 | public static int getWidth(Activity activity) {
110 | WindowManager wm = activity.getWindowManager();
111 | return wm.getDefaultDisplay().getWidth();
112 | }
113 |
114 | /**
115 | * 获取屏幕高度
116 | *
117 | * @param activity
118 | * @return
119 | */
120 | public static int getHeight(Activity activity) {
121 | WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
122 | return wm.getDefaultDisplay().getHeight();
123 | }
124 |
125 | /**
126 | * 判断网络是否连接
127 | */
128 | public static boolean isNetworkAvailable(Context context) {
129 | ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
130 | if (connectivity == null) {
131 | return false;
132 | } else {
133 | NetworkInfo[] info = connectivity.getAllNetworkInfo();
134 | if (info != null) {
135 | for (int i = 0; i < info.length; i++) {
136 | if (info[i].getState() == NetworkInfo.State.CONNECTED) {
137 | return true;
138 | }
139 | }
140 | }
141 | }
142 | return false;
143 | }
144 |
145 | }
146 |
--------------------------------------------------------------------------------
/baselib/src/main/java/com/whh/baselib/utils/ToosUtils.java:
--------------------------------------------------------------------------------
1 | package com.whh.baselib.utils;
2 |
3 | import android.content.Context;
4 | import android.content.res.AssetManager;
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapFactory;
7 |
8 | import java.io.IOException;
9 | import java.io.InputStream;
10 | import java.lang.reflect.ParameterizedType;
11 |
12 | /**
13 | * Created by wuhuihui on 2019/6/12.
14 | */
15 |
16 | public class ToosUtils {
17 |
18 |
19 | public class BaseDao {
20 |
21 | private Class clazz;
22 |
23 | // 使用反射技术得到T的真实类型
24 | public Class getRealType() {
25 | // 获取当前new的对象的泛型的父类类型
26 | ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
27 | // 获取第一个类型参数的真实类型
28 | this.clazz = (Class) pt.getActualTypeArguments()[0];
29 | return clazz;
30 | }
31 |
32 | }
33 |
34 | class ClassB extends BaseDao {
35 |
36 | public void main(String[] args) {
37 | ClassB classB = new ClassB();
38 | Class realType = classB.getRealType();
39 | System.out.println(realType.getName());
40 | }
41 | }
42 |
43 |
44 | /**
45 | * 从assets中读取图片
46 | */
47 | private Bitmap getImageFromAssetsFile(Context context, String fileName) {
48 | Bitmap image = null;
49 | AssetManager am = context.getResources().getAssets();
50 | try {
51 | InputStream is = am.open(fileName);
52 | image = BitmapFactory.decodeStream(is);
53 | is.close();
54 | } catch (IOException e) {
55 | e.printStackTrace();
56 | }
57 |
58 | return image;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/baselib/src/main/res/drawable/dialog_btn_bkg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/baselib/src/main/res/drawable/dialog_right_btn_bkg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/baselib/src/main/res/drawable/icon_action_bar_more.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/baselib/src/main/res/drawable/icon_action_bar_more.png
--------------------------------------------------------------------------------
/baselib/src/main/res/drawable/picerror.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/baselib/src/main/res/drawable/picerror.png
--------------------------------------------------------------------------------
/baselib/src/main/res/drawable/picloading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/baselib/src/main/res/drawable/picloading.png
--------------------------------------------------------------------------------
/baselib/src/main/res/drawable/return_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/baselib/src/main/res/drawable/return_icon.png
--------------------------------------------------------------------------------
/baselib/src/main/res/drawable/shape_bottom_btn_bkg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
11 |
12 |
13 |
17 |
18 |
--------------------------------------------------------------------------------
/baselib/src/main/res/drawable/shape_btn_bkg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
13 |
14 |
15 |
19 |
20 |
--------------------------------------------------------------------------------
/baselib/src/main/res/drawable/shape_white.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
13 |
14 |
18 |
19 |
--------------------------------------------------------------------------------
/baselib/src/main/res/layout/activity_base_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
26 |
27 |
37 |
38 |
50 |
51 |
63 |
64 |
65 |
66 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/baselib/src/main/res/layout/dialog_message.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
21 |
22 |
28 |
29 |
30 |
40 |
41 |
46 |
47 |
54 |
55 |
60 |
61 |
65 |
66 |
76 |
77 |
78 |
82 |
83 |
84 |
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/baselib/src/main/res/mipmap-mdpi/app_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/baselib/src/main/res/mipmap-mdpi/app_logo.png
--------------------------------------------------------------------------------
/baselib/src/main/res/mipmap-xhdpi/app_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/baselib/src/main/res/mipmap-xhdpi/app_logo.png
--------------------------------------------------------------------------------
/baselib/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3300cc
4 | #F5F5F5
5 | @android:color/darker_gray
6 | @android:color/transparent
7 | @android:color/white
8 | @android:color/holo_red_light
9 | @android:color/black
10 | #000093
11 |
12 | #333333
13 | #d0d0d0
14 | #4F4F4F
15 | #8E8E8E
16 |
17 | #7D7DFF
18 |
19 | #3F51B5
20 | #303F9F
21 | #FF4081
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/baselib/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 22sp
4 | 18sp
5 | 15sp
6 | 12sp
7 | 10sp
8 |
9 |
10 |
--------------------------------------------------------------------------------
/baselib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BaseLib
3 |
4 |
--------------------------------------------------------------------------------
/baselib/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/baselib/src/test/java/com/whh/baselib/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.whh.baselib;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.2'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | maven { url "https://jitpack.io" }
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
--------------------------------------------------------------------------------
/eventbus3/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/eventbus3/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 |
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(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 |
26 | //EventBus
27 | compile 'org.greenrobot:eventbus:3.1.1'
28 |
29 | //baselib
30 | compile project(':baselib')
31 | }
32 |
--------------------------------------------------------------------------------
/eventbus3/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 |
--------------------------------------------------------------------------------
/eventbus3/src/androidTest/java/com/whh/eventbus3/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.whh.eventbus3;
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 | }
--------------------------------------------------------------------------------
/eventbus3/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/eventbus3/src/main/java/com/whh/eventbus3/activity/EventBus2Activity.java:
--------------------------------------------------------------------------------
1 | package com.whh.eventbus3.activity;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 | import android.widget.Button;
6 | import android.widget.TextView;
7 |
8 | import com.whh.baselib.activity.BaseActivity;
9 | import com.whh.eventbus3.R;
10 | import com.whh.eventbus3.model.EventMessage;
11 |
12 | import org.greenrobot.eventbus.EventBus;
13 | import org.greenrobot.eventbus.Subscribe;
14 | import org.greenrobot.eventbus.ThreadMode;
15 |
16 |
17 | /**
18 | * Created by wuhuihui on 2019/5/18.
19 | * 发送普通事件给EventBusActivity
20 | * 接收EventBusActivity发来的粘性事件
21 | */
22 | public class EventBus2Activity extends BaseActivity {
23 |
24 | private TextView showData1, showData2;
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView("粘性事件", R.layout.activity_eventbus);
30 |
31 | if (!EventBus.getDefault().isRegistered(this))
32 | EventBus.getDefault().register(this); //注册事件,不可重复注册事件
33 |
34 | showData1 = (TextView) findViewById(R.id.showData1);
35 | showData1.setText("2222EventBus2Activity");
36 | showData2 = (TextView) findViewById(R.id.showData2);
37 | Button send = (Button) findViewById(R.id.send);
38 | send.setText("2222发送消息");
39 | send.setOnClickListener(new View.OnClickListener() {
40 | @Override
41 | public void onClick(View v) {
42 | EventBus.getDefault().post(new EventMessage(1, "2222eventBus上线啦~~"));
43 | finish();
44 | }
45 | });
46 |
47 | }
48 |
49 | @Subscribe(threadMode = ThreadMode.ASYNC, sticky = true)
50 | public void getEventMessage(EventMessage eMsg) {
51 | if (eMsg.getType() == 2) showData2.setText(eMsg.getMessage());
52 | }
53 |
54 | @Override
55 | protected void onDestroy() {
56 | super.onDestroy();
57 | if (EventBus.getDefault().isRegistered(this))
58 | EventBus.getDefault().unregister(this); //注销事件
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/eventbus3/src/main/java/com/whh/eventbus3/model/EventMessage.java:
--------------------------------------------------------------------------------
1 | package com.whh.eventbus3.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 |
--------------------------------------------------------------------------------
/eventbus3/src/main/res/layout/activity_eventbus.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
19 |
20 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/eventbus3/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/eventbus3/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | EventBus3
3 |
4 |
--------------------------------------------------------------------------------
/eventbus3/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/eventbus3/src/test/java/com/whh/eventbus3/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.whh.eventbus3;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhuihui2016/InitMVP/4447630b280038e86f9eea3841651f1eb7b641cb/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu May 16 11:36:01 CST 2019
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-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':eventbus3', ':baselib', ':arouter'
2 |
--------------------------------------------------------------------------------
/weather.json:
--------------------------------------------------------------------------------
1 | {
2 | "time": "2019-05-17 16:52:09",
3 | "cityInfo": {
4 | "city": "北京市",
5 | "cityId": "101010100",
6 | "parent": "北京",
7 | "updateTime": "15:59"
8 | },
9 | "date": "20190517",
10 | "message": "Success !",
11 | "status": 200,
12 | "data": {
13 | "shidu": "45%",
14 | "pm25": 95,
15 | "pm10": 0,
16 | "quality": "轻度污染",
17 | "wendu": "28",
18 | "ganmao": "儿童、老年人及心脏、呼吸系统疾病患者人群应减少长时间或高强度户外锻炼",
19 | "yesterday": {
20 | "date": "16",
21 | "sunrise": "05:00",
22 | "high": "高温 32.0℃",
23 | "low": "低温 19.0℃",
24 | "sunset": "19:22",
25 | "aqi": 114,
26 | "ymd": "2019-05-16",
27 | "week": "星期四",
28 | "fx": "西南风",
29 | "fl": "3-4级",
30 | "type": "晴",
31 | "notice": "愿你拥有比阳光明媚的心情"
32 | },
33 | "forecast": [
34 | {
35 | "date": "17",
36 | "sunrise": "04:59",
37 | "high": "高温 31.0℃",
38 | "low": "低温 20.0℃",
39 | "sunset": "19:23",
40 | "aqi": 161,
41 | "ymd": "2019-05-17",
42 | "week": "星期五",
43 | "fx": "东南风",
44 | "fl": "3-4级",
45 | "type": "多云",
46 | "notice": "阴晴之间,谨防紫外线侵扰"
47 | },
48 | {
49 | "date": "18",
50 | "sunrise": "04:58",
51 | "high": "高温 29.0℃",
52 | "low": "低温 18.0℃",
53 | "sunset": "19:24",
54 | "aqi": 82,
55 | "ymd": "2019-05-18",
56 | "week": "星期六",
57 | "fx": "东南风",
58 | "fl": "3-4级",
59 | "type": "阴",
60 | "notice": "不要被阴云遮挡住好心情"
61 | },
62 | {
63 | "date": "19",
64 | "sunrise": "04:58",
65 | "high": "高温 28.0℃",
66 | "low": "低温 13.0℃",
67 | "sunset": "19:25",
68 | "aqi": 71,
69 | "ymd": "2019-05-19",
70 | "week": "星期日",
71 | "fx": "西北风",
72 | "fl": "4-5级",
73 | "type": "小雨",
74 | "notice": "雨虽小,注意保暖别感冒"
75 | },
76 | {
77 | "date": "20",
78 | "sunrise": "04:57",
79 | "high": "高温 25.0℃",
80 | "low": "低温 15.0℃",
81 | "sunset": "19:26",
82 | "aqi": 46,
83 | "ymd": "2019-05-20",
84 | "week": "星期一",
85 | "fx": "西北风",
86 | "fl": "4-5级",
87 | "type": "晴",
88 | "notice": "愿你拥有比阳光明媚的心情"
89 | },
90 | {
91 | "date": "21",
92 | "sunrise": "04:56",
93 | "high": "高温 30.0℃",
94 | "low": "低温 16.0℃",
95 | "sunset": "19:27",
96 | "aqi": 34,
97 | "ymd": "2019-05-21",
98 | "week": "星期二",
99 | "fx": "西北风",
100 | "fl": "4-5级",
101 | "type": "晴",
102 | "notice": "愿你拥有比阳光明媚的心情"
103 | },
104 | {
105 | "date": "22",
106 | "sunrise": "04:55",
107 | "high": "高温 32.0℃",
108 | "low": "低温 16.0℃",
109 | "sunset": "19:28",
110 | "aqi": 50,
111 | "ymd": "2019-05-22",
112 | "week": "星期三",
113 | "fx": "西南风",
114 | "fl": "<3级",
115 | "type": "晴",
116 | "notice": "愿你拥有比阳光明媚的心情"
117 | },
118 | {
119 | "date": "23",
120 | "sunrise": "04:54",
121 | "high": "高温 34.0℃",
122 | "low": "低温 17.0℃",
123 | "sunset": "19:28",
124 | "ymd": "2019-05-23",
125 | "week": "星期四",
126 | "fx": "东南风",
127 | "fl": "<3级",
128 | "type": "晴",
129 | "notice": "愿你拥有比阳光明媚的心情"
130 | },
131 | {
132 | "date": "24",
133 | "sunrise": "04:54",
134 | "high": "高温 36.0℃",
135 | "low": "低温 17.0℃",
136 | "sunset": "19:29",
137 | "ymd": "2019-05-24",
138 | "week": "星期五",
139 | "fx": "西南风",
140 | "fl": "<3级",
141 | "type": "多云",
142 | "notice": "阴晴之间,谨防紫外线侵扰"
143 | },
144 | {
145 | "date": "25",
146 | "sunrise": "04:53",
147 | "high": "高温 35.0℃",
148 | "low": "低温 19.0℃",
149 | "sunset": "19:30",
150 | "ymd": "2019-05-25",
151 | "week": "星期六",
152 | "fx": "南风",
153 | "fl": "<3级",
154 | "type": "阴",
155 | "notice": "不要被阴云遮挡住好心情"
156 | },
157 | {
158 | "date": "26",
159 | "sunrise": "04:52",
160 | "high": "高温 33.0℃",
161 | "low": "低温 17.0℃",
162 | "sunset": "19:31",
163 | "ymd": "2019-05-26",
164 | "week": "星期日",
165 | "fx": "北风",
166 | "fl": "<3级",
167 | "type": "多云",
168 | "notice": "阴晴之间,谨防紫外线侵扰"
169 | },
170 | {
171 | "date": "27",
172 | "sunrise": "04:52",
173 | "high": "高温 32.0℃",
174 | "low": "低温 17.0℃",
175 | "sunset": "19:32",
176 | "ymd": "2019-05-27",
177 | "week": "星期一",
178 | "fx": "南风",
179 | "fl": "<3级",
180 | "type": "多云",
181 | "notice": "阴晴之间,谨防紫外线侵扰"
182 | },
183 | {
184 | "date": "28",
185 | "sunrise": "04:51",
186 | "high": "高温 34.0℃",
187 | "low": "低温 18.0℃",
188 | "sunset": "19:33",
189 | "ymd": "2019-05-28",
190 | "week": "星期二",
191 | "fx": "南风",
192 | "fl": "<3级",
193 | "type": "多云",
194 | "notice": "阴晴之间,谨防紫外线侵扰"
195 | },
196 | {
197 | "date": "29",
198 | "sunrise": "04:50",
199 | "high": "高温 38.0℃",
200 | "low": "低温 21.0℃",
201 | "sunset": "19:33",
202 | "ymd": "2019-05-29",
203 | "week": "星期三",
204 | "fx": "西南风",
205 | "fl": "<3级",
206 | "type": "多云",
207 | "notice": "阴晴之间,谨防紫外线侵扰"
208 | },
209 | {
210 | "date": "30",
211 | "sunrise": "04:50",
212 | "high": "高温 38.0℃",
213 | "low": "低温 22.0℃",
214 | "sunset": "19:34",
215 | "ymd": "2019-05-30",
216 | "week": "星期四",
217 | "fx": "南风",
218 | "fl": "<3级",
219 | "type": "多云",
220 | "notice": "阴晴之间,谨防紫外线侵扰"
221 | },
222 | {
223 | "date": "31",
224 | "sunrise": "04:49",
225 | "high": "高温 35.0℃",
226 | "low": "低温 20.0℃",
227 | "sunset": "19:35",
228 | "ymd": "2019-05-31",
229 | "week": "星期五",
230 | "fx": "东风",
231 | "fl": "<3级",
232 | "type": "小雨",
233 | "notice": "雨虽小,注意保暖别感冒"
234 | }
235 | ]
236 | }
237 | }
--------------------------------------------------------------------------------