Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_freeworld
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
android
android_freeworld
Commits
09ffc425
Commit
09ffc425
authored
Jul 13, 2021
by
mengcuiguang2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化response
parent
95295eb1
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
187 additions
and
265 deletions
+187
-265
build.gradle
app/build.gradle
+3
-7
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+2
-1
MainApi.kt
app/src/main/java/com/mints/street/api/MainApi.kt
+1
-1
BaseResponse.java
app/src/main/java/com/mints/street/bean/BaseResponse.java
+4
-3
UserBean.kt
app/src/main/java/com/mints/street/bean/UserBean.kt
+3
-4
LoginViewModel.kt
app/src/main/java/com/mints/street/login/LoginViewModel.kt
+1
-1
UserManager.kt
app/src/main/java/com/mints/street/manager/UserManager.kt
+20
-40
ApiModel.kt
app/src/main/java/com/mints/street/model/ApiModel.kt
+1
-1
HttpSubscribeImpl.kt
...n/java/com/mints/street/netwrok/base/HttpSubscribeImpl.kt
+1
-1
IHttpResponseListener.java
.../com/mints/street/netwrok/base/IHttpResponseListener.java
+2
-1
IHttpSubscribe.kt
...main/java/com/mints/street/netwrok/base/IHttpSubscribe.kt
+1
-1
GsonConverterFactory.java
...com/mints/street/netwrok/common/GsonConverterFactory.java
+1
-1
HttpErrorProcess.java
...ava/com/mints/street/netwrok/common/HttpErrorProcess.java
+2
-1
HttpManager.java
...ain/java/com/mints/street/netwrok/common/HttpManager.java
+1
-58
ApiDisposableObserver.java
.../java/me/goldze/mvvmhabit/http/ApiDisposableObserver.java
+122
-122
BaseArrayResponse.java
...main/java/me/goldze/mvvmhabit/http/BaseArrayResponse.java
+22
-22
No files found.
app/build.gradle
View file @
09ffc425
...
@@ -67,13 +67,9 @@ android {
...
@@ -67,13 +67,9 @@ android {
buildConfigField
"String"
,
"MainIp"
,
DEBUG_URL
buildConfigField
"String"
,
"MainIp"
,
DEBUG_URL
//混淆
//混淆
// minifyEnabled false
minifyEnabled
false
// zipAlignEnabled false
zipAlignEnabled
false
// shrinkResources false//打开
shrinkResources
false
//打开
minifyEnabled
true
zipAlignEnabled
true
shrinkResources
true
//打开
proguardFiles
getDefaultProguardFile
(
'proguard-android.txt'
),
'proguard-rules.pro'
proguardFiles
getDefaultProguardFile
(
'proguard-android.txt'
),
'proguard-rules.pro'
signingConfig
signingConfigs
.
debug
signingConfig
signingConfigs
.
debug
...
...
app/src/main/AndroidManifest.xml
View file @
09ffc425
...
@@ -59,9 +59,10 @@
...
@@ -59,9 +59,10 @@
<meta-data
<meta-data
android:name=
"Mob-AppSecret"
android:name=
"Mob-AppSecret"
android:value=
"${SHARE_SECRET}"
/>
android:value=
"${SHARE_SECRET}"
/>
<!--百度地图开放平台 -->
<meta-data
<meta-data
android:name=
"com.baidu.lbsapi.API_KEY"
android:name=
"com.baidu.lbsapi.API_KEY"
android:value=
"SD6luBGzUFSVEZ3n9Xjk3xTsvDFmuRCi"
/>
<!--百度地图开放平台 -->
android:value=
"SD6luBGzUFSVEZ3n9Xjk3xTsvDFmuRCi"
/>
<!--百度地图开放平台 service-->
<!--百度地图开放平台 service-->
<service
android:name=
"com.baidu.location.f"
<service
android:name=
"com.baidu.location.f"
android:enabled=
"true"
android:enabled=
"true"
...
...
app/src/main/java/com/mints/street/api/MainApi.kt
View file @
09ffc425
package
com.mints.street.api
package
com.mints.street.api
import
com.mints.street.bean.BaseResponse
import
com.mints.street.bean.UserBean
import
com.mints.street.bean.UserBean
import
com.mints.street.netwrok.common.HttpManager
import
com.mints.street.netwrok.common.HttpManager
import
io.reactivex.Observable
import
io.reactivex.Observable
import
me.goldze.mvvmhabit.http.BaseResponse
import
retrofit2.Response
import
retrofit2.Response
import
retrofit2.http.Body
import
retrofit2.http.Body
import
retrofit2.http.POST
import
retrofit2.http.POST
...
...
mvvmhabit/src/main/java/me/goldze/mvvmhabit/http
/BaseResponse.java
→
app/src/main/java/com/mints/street/bean
/BaseResponse.java
View file @
09ffc425
package
me
.
goldze
.
mvvmhabit
.
http
;
package
com
.
mints
.
street
.
bean
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.Nullable
;
import
com.google.gson.annotations.JsonAdapter
;
import
com.google.gson.annotations.SerializedName
;
import
com.google.gson.annotations.SerializedName
;
import
java.io.Serializable
;
/**
/**
* Created by goldze on 2017/5/10.
* Created by goldze on 2017/5/10.
* 该类仅供参考,实际业务返回的固定字段, 根据需求来定义,
* 该类仅供参考,实际业务返回的固定字段, 根据需求来定义,
*/
*/
public
class
BaseResponse
<
T
>
{
public
class
BaseResponse
<
T
>
implements
Serializable
{
private
int
status
;
private
int
status
;
private
String
message
;
private
String
message
;
...
...
app/src/main/java/com/mints/street/bean/UserBean.kt
View file @
09ffc425
...
@@ -12,13 +12,12 @@ class UserBean : Serializable {
...
@@ -12,13 +12,12 @@ class UserBean : Serializable {
val
consumer
:
ConsumerBean
?
=
null
val
consumer
:
ConsumerBean
?
=
null
inner
class
ConsumerBean
:
Serializable
{
inner
class
ConsumerBean
:
Serializable
{
val
head
:
String
=
""
val
openid
:
String
=
""
val
openid
:
String
=
""
val
nickname
:
String
=
""
val
nickname
:
String
=
""
val
mobile
:
String
=
""
val
mobile
:
String
=
""
val
real_name
:
String
=
""
val
idcode
:
String
=
""
val
idcode
:
String
=
""
val
pk_id
// 用户id
val
isForever
:
Boolean
=
false
:
Long
=
0
val
expireTime
:
Long
=
0
val
pk_id
:
Long
=
0
}
}
}
}
app/src/main/java/com/mints/street/login/LoginViewModel.kt
View file @
09ffc425
...
@@ -2,6 +2,7 @@ package com.mints.street.login
...
@@ -2,6 +2,7 @@ package com.mints.street.login
import
android.app.Application
import
android.app.Application
import
androidx.lifecycle.MutableLiveData
import
androidx.lifecycle.MutableLiveData
import
com.mints.street.bean.BaseResponse
import
com.mints.street.bean.UserBean
import
com.mints.street.bean.UserBean
import
com.mints.street.common.DeviceInfo
import
com.mints.street.common.DeviceInfo
import
com.mints.street.manager.UserManager
import
com.mints.street.manager.UserManager
...
@@ -9,7 +10,6 @@ import com.mints.street.model.ApiModel
...
@@ -9,7 +10,6 @@ import com.mints.street.model.ApiModel
import
com.mints.street.netwrok.base.HttpSubscribeImpl
import
com.mints.street.netwrok.base.HttpSubscribeImpl
import
com.mints.street.utils.DeviceUuidFactory
import
com.mints.street.utils.DeviceUuidFactory
import
me.goldze.mvvmhabit.base.BaseViewModel
import
me.goldze.mvvmhabit.base.BaseViewModel
import
me.goldze.mvvmhabit.http.BaseResponse
import
me.goldze.mvvmhabit.utils.KLog
import
me.goldze.mvvmhabit.utils.KLog
import
me.goldze.mvvmhabit.utils.ToastUtils
import
me.goldze.mvvmhabit.utils.ToastUtils
import
java.util.HashMap
import
java.util.HashMap
...
...
app/src/main/java/com/mints/street/manager/UserManager.kt
View file @
09ffc425
...
@@ -33,11 +33,6 @@ class UserManager {
...
@@ -33,11 +33,6 @@ class UserManager {
*/
*/
private
const
val
MOBILE
=
"mobile"
private
const
val
MOBILE
=
"mobile"
/**
* 姓名
*/
private
const
val
REAL_NAME
=
"realName"
/**
/**
* 微信名称
* 微信名称
*/
*/
...
@@ -53,6 +48,16 @@ class UserManager {
...
@@ -53,6 +48,16 @@ class UserManager {
*/
*/
private
const
val
WX_OPENID
=
"wx_openid"
private
const
val
WX_OPENID
=
"wx_openid"
/**
* 是否购买会员
*/
private
const
val
IS_FOREVER
=
"is_forever"
/**
* 会员是否永久
*/
private
const
val
EXPIRETIME
=
"expiretime"
val
INSTANCE
:
UserManager
by
lazy
(
mode
=
LazyThreadSafetyMode
.
SYNCHRONIZED
)
{
val
INSTANCE
:
UserManager
by
lazy
(
mode
=
LazyThreadSafetyMode
.
SYNCHRONIZED
)
{
UserManager
()
UserManager
()
}
}
...
@@ -83,11 +88,11 @@ class UserManager {
...
@@ -83,11 +88,11 @@ class UserManager {
MMKV
.
mmkvWithID
(
MOBILE
).
encode
(
MOBILE
,
mobile
)
MMKV
.
mmkvWithID
(
MOBILE
).
encode
(
MOBILE
,
mobile
)
}
}
MMKV
.
mmkvWithID
(
WX_NAME
).
encode
(
WX_NAME
,
user
.
nickname
.
toString
())
MMKV
.
mmkvWithID
(
WX_NAME
).
encode
(
WX_NAME
,
user
.
nickname
.
toString
())
MMKV
.
mmkvWithID
(
WX_HEADER
).
encode
(
WX_HEADER
,
user
.
head
)
MMKV
.
mmkvWithID
(
IS_FOREVER
).
encode
(
IS_FOREVER
,
user
.
isForever
)
MMKV
.
mmkvWithID
(
EXPIRETIME
).
encode
(
EXPIRETIME
,
user
.
expireTime
)
if
(!
TextUtils
.
isEmpty
(
openid
))
{
if
(!
TextUtils
.
isEmpty
(
openid
))
{
MMKV
.
mmkvWithID
(
WX_OPENID
).
encode
(
WX_OPENID
,
openid
)
MMKV
.
mmkvWithID
(
WX_OPENID
).
encode
(
WX_OPENID
,
openid
)
}
}
MMKV
.
mmkvWithID
(
REAL_NAME
).
encode
(
REAL_NAME
,
user
.
real_name
)
}
}
}
}
...
@@ -133,23 +138,6 @@ class UserManager {
...
@@ -133,23 +138,6 @@ class UserManager {
return
kv
.
decodeString
(
CODE_ID
,
""
)
return
kv
.
decodeString
(
CODE_ID
,
""
)
}
}
/**
* 获取真实姓名
*/
fun
getRealName
():
String
{
val
kv
=
MMKV
.
mmkvWithID
(
REAL_NAME
)
return
kv
.
decodeString
(
REAL_NAME
,
""
)
}
/**
* 设置真实姓名
*
* @param name
*/
fun
setRealName
(
name
:
String
?)
{
val
kv
=
MMKV
.
mmkvWithID
(
REAL_NAME
)
kv
.
encode
(
REAL_NAME
,
name
)
}
fun
getWxName
():
String
{
fun
getWxName
():
String
{
val
kv
=
MMKV
.
mmkvWithID
(
WX_NAME
)
val
kv
=
MMKV
.
mmkvWithID
(
WX_NAME
)
...
@@ -166,34 +154,26 @@ class UserManager {
...
@@ -166,34 +154,26 @@ class UserManager {
return
kv
.
decodeString
(
WX_OPENID
,
""
)
return
kv
.
decodeString
(
WX_OPENID
,
""
)
}
}
fun
setWxName
(
wxName
:
String
?)
{
fun
getIsforever
():
Boolean
{
val
kv
=
MMKV
.
mmkvWithID
(
WX_NAME
)
val
kv
=
MMKV
.
mmkvWithID
(
IS_FOREVER
)
kv
.
encode
(
WX_NAME
,
wxNam
e
)
return
kv
.
decodeBool
(
IS_FOREVER
,
fals
e
)
}
}
fun
setWxHeader
(
wxHeader
:
String
?)
{
fun
getExpiretime
():
Long
{
val
kv
=
MMKV
.
mmkvWithID
(
WX_HEADER
)
val
kv
=
MMKV
.
mmkvWithID
(
EXPIRETIME
)
kv
.
encode
(
WX_HEADER
,
wxHeader
)
return
kv
.
decodeLong
(
EXPIRETIME
,
0
)
}
}
/**
* mobile
*
* @param mobile
*/
fun
setMobile
(
mobile
:
String
?)
{
val
kv
=
MMKV
.
mmkvWithID
(
MOBILE
)
kv
.
encode
(
MOBILE
,
mobile
)
}
fun
userLogout
()
{
fun
userLogout
()
{
MMKV
.
mmkvWithID
(
USER_ID
).
remove
(
USER_ID
)
MMKV
.
mmkvWithID
(
USER_ID
).
remove
(
USER_ID
)
MMKV
.
mmkvWithID
(
CODE_ID
).
remove
(
CODE_ID
)
MMKV
.
mmkvWithID
(
CODE_ID
).
remove
(
CODE_ID
)
MMKV
.
mmkvWithID
(
TOKEN_ID
).
remove
(
TOKEN_ID
)
MMKV
.
mmkvWithID
(
TOKEN_ID
).
remove
(
TOKEN_ID
)
MMKV
.
mmkvWithID
(
REAL_NAME
).
remove
(
REAL_NAME
)
MMKV
.
mmkvWithID
(
WX_OPENID
).
remove
(
WX_OPENID
)
MMKV
.
mmkvWithID
(
WX_OPENID
).
remove
(
WX_OPENID
)
MMKV
.
mmkvWithID
(
WX_NAME
).
remove
(
WX_NAME
)
MMKV
.
mmkvWithID
(
WX_NAME
).
remove
(
WX_NAME
)
MMKV
.
mmkvWithID
(
WX_HEADER
).
remove
(
WX_HEADER
)
MMKV
.
mmkvWithID
(
WX_HEADER
).
remove
(
WX_HEADER
)
MMKV
.
mmkvWithID
(
IS_FOREVER
).
remove
(
IS_FOREVER
)
MMKV
.
mmkvWithID
(
EXPIRETIME
).
remove
(
EXPIRETIME
)
}
}
}
}
\ No newline at end of file
app/src/main/java/com/mints/street/model/ApiModel.kt
View file @
09ffc425
package
com.mints.street.model
package
com.mints.street.model
import
com.mints.street.api.MainApi
import
com.mints.street.api.MainApi
import
com.mints.street.bean.BaseResponse
import
com.mints.street.bean.UserBean
import
com.mints.street.bean.UserBean
import
com.mints.street.netwrok.common.HttpManager
import
com.mints.street.netwrok.common.HttpManager
import
com.trello.rxlifecycle2.LifecycleProvider
import
com.trello.rxlifecycle2.LifecycleProvider
import
io.reactivex.Observable
import
io.reactivex.Observable
import
me.goldze.mvvmhabit.http.BaseResponse
import
retrofit2.Response
import
retrofit2.Response
/**
/**
...
...
app/src/main/java/com/mints/street/netwrok/base/HttpSubscribeImpl.kt
View file @
09ffc425
package
com.mints.street.netwrok.base
package
com.mints.street.netwrok.base
import
com.mints.street.bean.BaseResponse
import
me.goldze.mvvmhabit._enum.ViewStatus
import
me.goldze.mvvmhabit._enum.ViewStatus
import
me.goldze.mvvmhabit.base.BaseViewModel
import
me.goldze.mvvmhabit.base.BaseViewModel
import
me.goldze.mvvmhabit.http.BaseResponse
import
me.goldze.mvvmhabit.http.ExceptionHandle
import
me.goldze.mvvmhabit.http.ExceptionHandle
import
me.goldze.mvvmhabit.http.ResponseThrowable
import
me.goldze.mvvmhabit.http.ResponseThrowable
import
me.goldze.mvvmhabit.utils.ToastUtils
import
me.goldze.mvvmhabit.utils.ToastUtils
...
...
app/src/main/java/com/mints/street/netwrok/base/IHttpResponseListener.java
View file @
09ffc425
package
com
.
mints
.
street
.
netwrok
.
base
;
package
com
.
mints
.
street
.
netwrok
.
base
;
import
com.mints.street.bean.BaseResponse
;
import
io.reactivex.disposables.Disposable
;
import
io.reactivex.disposables.Disposable
;
import
me.goldze.mvvmhabit.http.BaseResponse
;
import
me.goldze.mvvmhabit.http.ResponseThrowable
;
import
me.goldze.mvvmhabit.http.ResponseThrowable
;
import
retrofit2.Response
;
import
retrofit2.Response
;
...
...
app/src/main/java/com/mints/street/netwrok/base/IHttpSubscribe.kt
View file @
09ffc425
package
com.mints.street.netwrok.base
package
com.mints.street.netwrok.base
import
com.mints.street.bean.BaseResponse
import
io.reactivex.Observer
import
io.reactivex.Observer
import
io.reactivex.disposables.Disposable
import
io.reactivex.disposables.Disposable
import
me.goldze.mvvmhabit.base.BaseViewModel
import
me.goldze.mvvmhabit.base.BaseViewModel
import
me.goldze.mvvmhabit.http.BaseResponse
import
retrofit2.Response
import
retrofit2.Response
/**
/**
...
...
app/src/main/java/com/mints/street/netwrok/common/GsonConverterFactory.java
View file @
09ffc425
package
com
.
mints
.
street
.
netwrok
.
common
;
package
com
.
mints
.
street
.
netwrok
.
common
;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
com.mints.street.bean.BaseResponse
;
import
com.mints.street.manager.UserManager
;
import
com.mints.street.manager.UserManager
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -12,7 +13,6 @@ import java.lang.reflect.Type;
...
@@ -12,7 +13,6 @@ import java.lang.reflect.Type;
import
java.nio.charset.Charset
;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
me.goldze.mvvmhabit.http.BaseResponse
;
import
okhttp3.MediaType
;
import
okhttp3.MediaType
;
import
okhttp3.RequestBody
;
import
okhttp3.RequestBody
;
import
okhttp3.ResponseBody
;
import
okhttp3.ResponseBody
;
...
...
app/src/main/java/com/mints/street/netwrok/common/HttpErrorProcess.java
View file @
09ffc425
package
com
.
mints
.
street
.
netwrok
.
common
;
package
com
.
mints
.
street
.
netwrok
.
common
;
import
com.mints.street.bean.BaseResponse
;
import
io.reactivex.Observable
;
import
io.reactivex.Observable
;
import
io.reactivex.ObservableSource
;
import
io.reactivex.ObservableSource
;
import
io.reactivex.ObservableTransformer
;
import
io.reactivex.ObservableTransformer
;
import
io.reactivex.functions.Function
;
import
io.reactivex.functions.Function
;
import
me.goldze.mvvmhabit.http.BaseResponse
;
import
retrofit2.Response
;
import
retrofit2.Response
;
/**
/**
...
...
app/src/main/java/com/mints/street/netwrok/common/HttpManager.java
View file @
09ffc425
...
@@ -3,10 +3,10 @@ package com.mints.street.netwrok.common;
...
@@ -3,10 +3,10 @@ package com.mints.street.netwrok.common;
import
android.annotation.SuppressLint
;
import
android.annotation.SuppressLint
;
import
com.fry.base.global.Constants
;
import
com.fry.base.global.Constants
;
import
com.mints.street.bean.BaseResponse
;
import
com.mints.street.netwrok.base.HttpConfiguation
;
import
com.mints.street.netwrok.base.HttpConfiguation
;
import
com.mints.street.netwrok.base.IHttpResponseListener
;
import
com.mints.street.netwrok.base.IHttpResponseListener
;
import
com.mints.street.netwrok.base.RetrofitClient
;
import
com.mints.street.netwrok.base.RetrofitClient
;
import
com.mints.street.utils.encry.AESUtils
;
import
com.trello.rxlifecycle2.LifecycleProvider
;
import
com.trello.rxlifecycle2.LifecycleProvider
;
import
io.reactivex.Observable
;
import
io.reactivex.Observable
;
...
@@ -17,7 +17,6 @@ import io.reactivex.functions.Action;
...
@@ -17,7 +17,6 @@ import io.reactivex.functions.Action;
import
io.reactivex.functions.Consumer
;
import
io.reactivex.functions.Consumer
;
import
io.reactivex.functions.Function
;
import
io.reactivex.functions.Function
;
import
io.reactivex.schedulers.Schedulers
;
import
io.reactivex.schedulers.Schedulers
;
import
me.goldze.mvvmhabit.http.BaseResponse
;
import
me.goldze.mvvmhabit.http.ResponseThrowable
;
import
me.goldze.mvvmhabit.http.ResponseThrowable
;
import
me.goldze.mvvmhabit.utils.RxUtils
;
import
me.goldze.mvvmhabit.utils.RxUtils
;
import
retrofit2.Response
;
import
retrofit2.Response
;
...
@@ -79,60 +78,4 @@ public class HttpManager {
...
@@ -79,60 +78,4 @@ public class HttpManager {
.
compose
(
RxUtils
.
exceptionTransformer
())
.
compose
(
RxUtils
.
exceptionTransformer
())
.
compose
(
HttpErrorProcess
.
businessExceptionTransformer
());
.
compose
(
HttpErrorProcess
.
businessExceptionTransformer
());
}
}
@SuppressLint
(
"CheckResult"
)
public
<
B
extends
BaseResponse
,
T
extends
Response
<
B
>>
void
execute
(
LifecycleProvider
life
,
final
Observable
<
T
>
observable
,
IHttpResponseListener
<
B
>
listener
)
{
Observable
<
T
>
newObservable
=
Observable
.
just
(
observable
)
.
observeOn
(
Schedulers
.
io
())
.
flatMap
((
Function
<
Observable
<
T
>,
ObservableSource
<
T
>>)
tObservable
->
{
// ServerTimeHelper.requestServerTime();
return
observable
;
})
.
observeOn
(
AndroidSchedulers
.
mainThread
());
if
(
life
!=
null
)
{
newObservable
=
newObservable
.
compose
(
RxUtils
.
bindToLifecycle
(
life
));
}
newObservable
.
compose
(
RxUtils
.
schedulersTransformer
())
.
compose
(
RxUtils
.
exceptionTransformer
())
.
compose
(
HttpErrorProcess
.
businessExceptionTransformer
())
.
doOnSubscribe
(
new
Consumer
<
Disposable
>()
{
@Override
public
void
accept
(
Disposable
disposable
)
throws
Exception
{
if
(
listener
!=
null
)
{
listener
.
onStart
(
disposable
);
}
}
})
.
doFinally
(
new
Action
()
{
@Override
public
void
run
()
throws
Exception
{
if
(
listener
!=
null
)
{
listener
.
onCompleted
();
}
}
})
.
subscribe
(
t
->
{
if
(
listener
!=
null
)
{
// listener.onCompleted();
if
(!
listener
.
onParseResponse
(
t
))
{
if
(
t
.
body
()
!=
null
&&
t
.
body
().
isOk
())
{
listener
.
onBusinessSuccess
(
t
.
body
());
}
else
{
listener
.
onBusinessFail
(
t
.
body
());
}
}
}
},
throwable
->
{
if
(
listener
!=
null
&&
throwable
instanceof
ResponseThrowable
)
{
listener
.
onFailed
((
ResponseThrowable
)
throwable
);
}
throwable
.
printStackTrace
();
},
()
->
{
});
}
}
}
mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/ApiDisposableObserver.java
View file @
09ffc425
package
me
.
goldze
.
mvvmhabit
.
http
;
//package me.goldze.mvvmhabit.http;
//
//
import
io.reactivex.observers.DisposableObserver
;
//import io.reactivex.observers.DisposableObserver;
import
me.goldze.mvvmhabit.base.AppManager
;
//import me.goldze.mvvmhabit.base.AppManager;
import
me.goldze.mvvmhabit.utils.KLog
;
//import me.goldze.mvvmhabit.utils.KLog;
import
me.goldze.mvvmhabit.utils.ToastUtils
;
//import me.goldze.mvvmhabit.utils.ToastUtils;
import
me.goldze.mvvmhabit.utils.Utils
;
//import me.goldze.mvvmhabit.utils.Utils;
//
/**
///**
* Created by goldze on 2017/5/10.
// * Created by goldze on 2017/5/10.
* 统一的Code封装处理。该类仅供参考,实际业务逻辑, 根据需求来定义,
// * 统一的Code封装处理。该类仅供参考,实际业务逻辑, 根据需求来定义,
*/
// */
//
public
abstract
class
ApiDisposableObserver
<
T
>
extends
DisposableObserver
<
T
>
{
//public abstract class ApiDisposableObserver<T> extends DisposableObserver<T> {
public
abstract
void
onResult
(
T
t
);
// public abstract void onResult(T t);
//
@Override
// @Override
public
void
onComplete
()
{
// public void onComplete() {
//
}
// }
//
@Override
// @Override
public
void
onError
(
Throwable
e
)
{
// public void onError(Throwable e) {
e
.
printStackTrace
();
// e.printStackTrace();
KLog
.
e
(
e
.
getMessage
());
// KLog.e(e.getMessage());
if
(
e
instanceof
ResponseThrowable
)
{
// if (e instanceof ResponseThrowable) {
ResponseThrowable
rError
=
(
ResponseThrowable
)
e
;
// ResponseThrowable rError = (ResponseThrowable) e;
ToastUtils
.
showShort
(
rError
.
getMessage
());
// ToastUtils.showShort(rError.getMessage());
return
;
// return;
}
// }
//其他全部甩锅网络异常
// //其他全部甩锅网络异常
ToastUtils
.
showShort
(
"网络异常"
);
// ToastUtils.showShort("网络异常");
}
// }
//
@Override
// @Override
public
void
onStart
()
{
// public void onStart() {
super
.
onStart
();
// super.onStart();
ToastUtils
.
showShort
(
"http is start"
);
// ToastUtils.showShort("http is start");
// if NetworkAvailable no ! must to call onCompleted
// // if NetworkAvailable no ! must to call onCompleted
if
(!
NetworkUtil
.
isNetworkAvailable
(
Utils
.
getContext
()))
{
// if (!NetworkUtil.isNetworkAvailable(Utils.getContext())) {
ToastUtils
.
showShort
(
"无网络,读取缓存数据"
);
// ToastUtils.showShort("无网络,读取缓存数据");
onComplete
();
// onComplete();
}
// }
}
// }
//
@Override
// @Override
public
void
onNext
(
Object
o
)
{
// public void onNext(Object o) {
BaseResponse
baseResponse
=
(
BaseResponse
)
o
;
// BaseResponse baseResponse = (BaseResponse) o;
switch
(
baseResponse
.
getstatus
())
{
// switch (baseResponse.getstatus()) {
case
CodeRule
.
CODE_200
:
// case CodeRule.CODE_200:
//请求成功, 正确的操作方式
// //请求成功, 正确的操作方式
onResult
((
T
)
baseResponse
.
getResult
());
// onResult((T) baseResponse.getResult());
break
;
// break;
case
CodeRule
.
CODE_220
:
// case CodeRule.CODE_220:
// 请求成功, 正确的操作方式, 并消息提示
// // 请求成功, 正确的操作方式, 并消息提示
onResult
((
T
)
baseResponse
.
getResult
());
// onResult((T) baseResponse.getResult());
break
;
// break;
case
CodeRule
.
CODE_300
:
// case CodeRule.CODE_300:
//请求失败,不打印Message
// //请求失败,不打印Message
KLog
.
e
(
"请求失败"
);
// KLog.e("请求失败");
ToastUtils
.
showShort
(
"错误代码:"
,
baseResponse
.
getstatus
());
// ToastUtils.showShort("错误代码:", baseResponse.getstatus());
break
;
// break;
case
CodeRule
.
CODE_330
:
// case CodeRule.CODE_330:
//请求失败,打印Message
// //请求失败,打印Message
ToastUtils
.
showShort
(
baseResponse
.
getMessage
());
// ToastUtils.showShort(baseResponse.getMessage());
break
;
// break;
case
CodeRule
.
CODE_500
:
// case CodeRule.CODE_500:
//服务器内部异常
// //服务器内部异常
ToastUtils
.
showShort
(
"错误代码:"
,
baseResponse
.
getstatus
());
// ToastUtils.showShort("错误代码:", baseResponse.getstatus());
break
;
// break;
case
CodeRule
.
CODE_503
:
// case CodeRule.CODE_503:
//参数为空
// //参数为空
KLog
.
e
(
"参数为空"
);
// KLog.e("参数为空");
break
;
// break;
case
CodeRule
.
CODE_502
:
// case CodeRule.CODE_502:
//没有数据
// //没有数据
KLog
.
e
(
"没有数据"
);
// KLog.e("没有数据");
break
;
// break;
case
CodeRule
.
CODE_510
:
// case CodeRule.CODE_510:
//无效的Token,提示跳入登录页
// //无效的Token,提示跳入登录页
ToastUtils
.
showShort
(
"token已过期,请重新登录"
);
// ToastUtils.showShort("token已过期,请重新登录");
//关闭所有页面
// //关闭所有页面
AppManager
.
getAppManager
().
finishAllActivity
();
// AppManager.getAppManager().finishAllActivity();
//跳入登录界面
// //跳入登录界面
//*****该类仅供参考,实际业务Code, 根据需求来定义,******//
// //*****该类仅供参考,实际业务Code, 根据需求来定义,******//
break
;
// break;
case
CodeRule
.
CODE_530
:
// case CodeRule.CODE_530:
ToastUtils
.
showShort
(
"请先登录"
);
// ToastUtils.showShort("请先登录");
break
;
// break;
case
CodeRule
.
CODE_551
:
// case CodeRule.CODE_551:
ToastUtils
.
showShort
(
"错误代码:"
,
baseResponse
.
getstatus
());
// ToastUtils.showShort("错误代码:", baseResponse.getstatus());
break
;
// break;
default
:
// default:
ToastUtils
.
showShort
(
"错误代码:"
,
baseResponse
.
getstatus
());
// ToastUtils.showShort("错误代码:", baseResponse.getstatus());
break
;
// break;
}
// }
}
// }
//
public
static
final
class
CodeRule
{
// public static final class CodeRule {
//请求成功, 正确的操作方式
// //请求成功, 正确的操作方式
static
final
int
CODE_200
=
200
;
// static final int CODE_200 = 200;
//请求成功, 消息提示
// //请求成功, 消息提示
static
final
int
CODE_220
=
220
;
// static final int CODE_220 = 220;
//请求失败,不打印Message
// //请求失败,不打印Message
static
final
int
CODE_300
=
300
;
// static final int CODE_300 = 300;
//请求失败,打印Message
// //请求失败,打印Message
static
final
int
CODE_330
=
330
;
// static final int CODE_330 = 330;
//服务器内部异常
// //服务器内部异常
static
final
int
CODE_500
=
500
;
// static final int CODE_500 = 500;
//参数为空
// //参数为空
static
final
int
CODE_503
=
503
;
// static final int CODE_503 = 503;
//没有数据
// //没有数据
static
final
int
CODE_502
=
502
;
// static final int CODE_502 = 502;
//无效的Token
// //无效的Token
static
final
int
CODE_510
=
510
;
// static final int CODE_510 = 510;
//未登录
// //未登录
static
final
int
CODE_530
=
530
;
// static final int CODE_530 = 530;
//请求的操作异常终止:未知的页面类型
// //请求的操作异常终止:未知的页面类型
static
final
int
CODE_551
=
551
;
// static final int CODE_551 = 551;
}
// }
}
//}
\ No newline at end of file
\ No newline at end of file
mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/BaseArrayResponse.java
View file @
09ffc425
package
me
.
goldze
.
mvvmhabit
.
http
;
//
package me.goldze.mvvmhabit.http;
//
import
java.util.List
;
//
import java.util.List;
//
/**
/
//
**
* Created by goldze on 2017/5/10.
//
* Created by goldze on 2017/5/10.
* 该类仅供参考,实际业务返回的固定字段, 根据需求来定义,
//
* 该类仅供参考,实际业务返回的固定字段, 根据需求来定义,
*/
//
*/
public
class
BaseArrayResponse
<
T
>
extends
BaseResponse
<
List
<
T
>>{
//
public class BaseArrayResponse<T> extends BaseResponse<List<T>>{
//
//
@Override
//
@Override
public
List
<
T
>
getResult
()
{
//
public List<T> getResult() {
return
result
;
//
return result;
}
//
}
//
@Override
//
@Override
public
void
setResult
(
List
<
T
>
result
)
{
//
public void setResult(List<T> result) {
this
.
result
=
result
;
//
this.result = result;
}
//
}
//
}
//
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment