Skip to content

Commit 729bbd8

Browse files
committed
重构网络框架
1 parent 773fbec commit 729bbd8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3077
-52
lines changed

app/src/main/java/com/wzq/sample/app/App.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.jeremyliao.liveeventbus.LiveEventBus
55
import com.scwang.smartrefresh.layout.SmartRefreshLayout
66
import com.scwang.smartrefresh.layout.footer.ClassicsFooter
77
import com.scwang.smartrefresh.layout.header.ClassicsHeader
8+
import com.tencent.mmkv.MMKV
89
import com.wzq.mvvmsmart.base.BaseApplicationMVVM
910
import com.wzq.mvvmsmart.utils.KLog
1011
import com.wzq.sample.BuildConfig
@@ -18,6 +19,7 @@ class App : BaseApplicationMVVM() {
1819
KLog.init(BuildConfig.DEBUG)
1920
//初始化全局异常崩溃
2021
initCrash()
22+
MMKV.initialize(this)
2123
LiveEventBus
2224
.config()
2325
.supportBroadcast(this) // 配置支持跨进程、跨APP通信,传入Context,需要在application onCreate中配置
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
package com.wzq.sample.bean;
2+
3+
/**
4+
* <p>作者:wzq<p>
5+
* <p>创建时间:2019-11-13<p>
6+
* <p>文件描述:<p>
7+
*
8+
*/
9+
public class User {
10+
/**
11+
* userType
12+
* 0:学生
13+
* 1:家长
14+
* 2:教师
15+
* 3:代理商
16+
* 4:后台
17+
*/
18+
/**
19+
* nickname : 张三
20+
* userType : 0
21+
* headerUrl : https://stepover-example.oss-cn-beijing.aliyuncs.com/image/0.jpg
22+
* coverUrl : https://stepover-example.oss-cn-beijing.aliyuncs.com/image/cover.jpg
23+
* currentSkillName : 四年级
24+
* nextSkillName : 五年级
25+
* skillUpgradeProcess : 60
26+
* readTime : 10012
27+
* goldNum : 1123
28+
* runningDays : 10
29+
* surpassPercent : 70
30+
* unreadMailNum : 3
31+
* unreadMessageNum : 12
32+
* unreadReportNum : 1
33+
*/
34+
35+
private String nickname;
36+
private int userType;
37+
private String headerUrl;
38+
private String coverUrl;
39+
private String currentSkillName;
40+
private String nextSkillName;
41+
private int skillUpgradeProcess;
42+
private int readTime;
43+
private int goldNum;
44+
private int runningDays;
45+
private int surpassPercent;
46+
private int unreadMailNum;
47+
private int unreadReportNum;
48+
private int unreadMessageNum;
49+
private int voucherNumber;
50+
51+
public String getNickname() {
52+
return nickname;
53+
}
54+
55+
public void setNickname(String nickname) {
56+
this.nickname = nickname;
57+
}
58+
59+
public int getUserType() {
60+
return userType;
61+
}
62+
63+
public void setUserType(int userType) {
64+
this.userType = userType;
65+
}
66+
67+
public String getHeaderUrl() {
68+
return headerUrl;
69+
}
70+
71+
public void setHeaderUrl(String headerUrl) {
72+
this.headerUrl = headerUrl;
73+
}
74+
75+
public String getCoverUrl() {
76+
return coverUrl;
77+
}
78+
79+
public void setCoverUrl(String coverUrl) {
80+
this.coverUrl = coverUrl;
81+
}
82+
83+
public String getCurrentSkillName() {
84+
return currentSkillName;
85+
}
86+
87+
public void setCurrentSkillName(String currentSkillName) {
88+
this.currentSkillName = currentSkillName;
89+
}
90+
91+
public String getNextSkillName() {
92+
return nextSkillName;
93+
}
94+
95+
public void setNextSkillName(String nextSkillName) {
96+
this.nextSkillName = nextSkillName;
97+
}
98+
99+
public int getSkillUpgradeProcess() {
100+
return skillUpgradeProcess;
101+
}
102+
103+
public void setSkillUpgradeProcess(int skillUpgradeProcess) {
104+
this.skillUpgradeProcess = skillUpgradeProcess;
105+
// notifyPropertyChanged(com.reading.win.personal.BR.currentSkillName);
106+
}
107+
108+
public int getReadTime() {
109+
return readTime;
110+
}
111+
112+
public void setReadTime(int readTime) {
113+
this.readTime = readTime;
114+
}
115+
116+
public int getGoldNum() {
117+
return goldNum;
118+
}
119+
120+
public void setGoldNum(int goldNum) {
121+
this.goldNum = goldNum;
122+
}
123+
124+
public int getRunningDays() {
125+
return runningDays;
126+
}
127+
128+
public void setRunningDays(int runningDays) {
129+
this.runningDays = runningDays;
130+
}
131+
132+
public int getSurpassPercent() {
133+
return surpassPercent;
134+
}
135+
136+
public void setSurpassPercent(int surpassPercent) {
137+
this.surpassPercent = surpassPercent;
138+
}
139+
140+
public int getUnreadMailNum() {
141+
int formatNum = 0;
142+
if (unreadMailNum < 0) {
143+
formatNum = 0;
144+
} else {
145+
formatNum = unreadMailNum;
146+
}
147+
return formatNum;
148+
}
149+
150+
public void setUnreadMailNum(int unreadMailNum) {
151+
this.unreadMailNum = unreadMailNum;
152+
}
153+
154+
public int getUnreadMessageNum() {
155+
int formatNum ;
156+
if (unreadMessageNum < 0) {
157+
formatNum = 0;
158+
} else {
159+
formatNum = unreadMessageNum;
160+
}
161+
return formatNum;
162+
}
163+
164+
public void setUnreadMessageNum(int unreadMessageNum) {
165+
this.unreadMessageNum = unreadMessageNum;
166+
}
167+
168+
public int getUnreadReportNum() {
169+
int formatNum = 0;
170+
if (unreadReportNum < 0) {
171+
formatNum = 0;
172+
} else {
173+
formatNum = unreadReportNum;
174+
}
175+
// MLog.e("unreadReportNum:" + unreadReportNum);
176+
// MLog.e("formatNum:" + formatNum);
177+
return formatNum;
178+
}
179+
180+
public void setUnreadReportNum(int unreadReportNum) {
181+
this.unreadReportNum = unreadReportNum;
182+
}
183+
184+
@Override
185+
public String toString() {
186+
return "User{" +
187+
"nickname='" + nickname + '\'' +
188+
", userType=" + userType +
189+
", headerUrl='" + headerUrl + '\'' +
190+
", coverUrl='" + coverUrl + '\'' +
191+
", currentSkillName='" + currentSkillName + '\'' +
192+
", nextSkillName='" + nextSkillName + '\'' +
193+
", skillUpgradeProcess=" + skillUpgradeProcess +
194+
", readTime=" + readTime +
195+
", goldNum=" + goldNum +
196+
", runningDays=" + runningDays +
197+
", surpassPercent=" + surpassPercent +
198+
", unreadMailNum=" + unreadMailNum +
199+
", unreadMessageNum=" + unreadMessageNum +
200+
", unreadReportNum=" + unreadReportNum +
201+
'}';
202+
}
203+
204+
205+
public int getVoucherNumber() {
206+
return voucherNumber;
207+
}
208+
209+
public void setVoucherNumber(int voucherNumber) {
210+
this.voucherNumber = voucherNumber;
211+
}
212+
}

app/src/main/java/com/wzq/sample/data/source/http/service/DemoApiService.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import com.wzq.sample.bean.DemoBean
55
import io.reactivex.Observable
66
import retrofit2.http.*
77

8+
/**
9+
* created 王志强 2020.04.30
10+
*/
811
interface DemoApiService {
912
@GET("action/apiv2/banner")
1013
fun demoGet(@Query("catalog") pageNum: Int): Observable<BaseResponse<DemoBean>>
@@ -15,4 +18,5 @@ interface DemoApiService {
1518

1619
@get:GET("getJsonFile")
1720
val jsonFile: Observable<BaseResponse<Any>>
21+
1822
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.wzq.sample.http2.service
2+
3+
import com.wzq.sample.bean.User
4+
import com.wzq.sample.http2.model.BaseResponse
5+
import io.reactivex.Observable
6+
import okhttp3.RequestBody
7+
import retrofit2.http.Body
8+
import retrofit2.http.POST
9+
10+
interface DemoApiService {
11+
// 获取用户个人信息
12+
@POST("data/center/summary")
13+
fun getPersonalSummary(@Body requestBody: RequestBody?): Observable<BaseResponse<User>>
14+
15+
// 获取用户个人信息2
16+
@POST("center/summary")
17+
fun getPersonalSummary2(@Body requestBody: RequestBody?): Observable<BaseResponse<User>>
18+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.wzq.sample.data.source.http.service2;
2+
3+
import android.annotation.SuppressLint;
4+
import android.content.Context;
5+
6+
import com.wzq.sample.bean.User;
7+
import com.wzq.sample.http2.listener.OnServerResponseListener;
8+
import com.wzq.sample.http2.model.BaseResponse;
9+
import com.wzq.sample.http2.model.BaseVmRequst;
10+
import com.wzq.sample.http2.service.DemoApiService;
11+
12+
import io.reactivex.Observable;
13+
import okhttp3.MediaType;
14+
import okhttp3.RequestBody;
15+
16+
/**
17+
* author :王志强
18+
* date : 2019/11/12 11:10
19+
*/
20+
public class MRequest extends BaseVmRequst {
21+
private DemoApiService service;
22+
23+
public static MRequest getInstance() {
24+
return Holder.INSTANCE;
25+
}
26+
27+
private static class Holder {
28+
@SuppressLint("StaticFieldLeak")
29+
static MRequest INSTANCE = new MRequest();
30+
}
31+
32+
private MRequest() {
33+
super();
34+
this.service = retrofit.create(DemoApiService.class);
35+
}
36+
// 获取个人信息
37+
public void getPersonalSummary(Context context, int what, String jsonParams, OnServerResponseListener listener) {
38+
this.mContext = context;
39+
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), jsonParams);
40+
Observable<BaseResponse<User>> observable = service.getPersonalSummary(requestBody);
41+
doRequest(observable, what, listener);
42+
}
43+
44+
// 获取个人信息2
45+
public void getPersonalSummary2(Context context, int what, String jsonParams, OnServerResponseListener listener) {
46+
this.mContext = context;
47+
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), jsonParams);
48+
Observable<BaseResponse<User>> observable = service.getPersonalSummary2(requestBody);
49+
doRequest(observable, what, listener);
50+
}
51+
52+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.wzq.sample.http2;
2+
3+
/**
4+
* created 王志强 2020.04.30
5+
**/
6+
public class BaseConfig {
7+
public static final int GLIDE_MEMORYCACHE_MAXSIZE = 1024 * 1024 * 20; // 20mb
8+
public static int IL_ERROR_RES = -1;
9+
public static final long TIMESCREENON = 90000;
10+
public static final int OKHTTP_CONNECTTIMEOUT = 15;
11+
public static final int OKHTTP_READTIMEOUT = 15;
12+
}

0 commit comments

Comments
 (0)