Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_street
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_street
Commits
a6fac0d4
Commit
a6fac0d4
authored
Jul 15, 2021
by
mengcuiguang2
Browse files
Options
Browse Files
Download
Plain Diff
解决冲突
parents
bd1e5224
99259dea
Changes
29
Hide whitespace changes
Inline
Side-by-side
Showing
29 changed files
with
378 additions
and
426 deletions
+378
-426
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+4
-1
MainApi.kt
app/src/main/java/com/mints/street/api/MainApi.kt
+1
-3
AppRequest.kt
app/src/main/java/com/mints/street/bean/AppRequest.kt
+1
-1
AwardBean.kt
app/src/main/java/com/mints/street/bean/AwardBean.kt
+0
-20
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
Constant.kt
app/src/main/java/com/mints/street/common/Constant.kt
+4
-0
LoginViewModel.kt
app/src/main/java/com/mints/street/login/LoginViewModel.kt
+31
-38
HomeFragment.kt
app/src/main/java/com/mints/street/main/home/HomeFragment.kt
+4
-0
MyFragment.kt
app/src/main/java/com/mints/street/main/my/MyFragment.kt
+1
-1
PermissionsActivity.kt
...main/java/com/mints/street/main/my/PermissionsActivity.kt
+65
-5
UserManager.kt
app/src/main/java/com/mints/street/manager/UserManager.kt
+24
-42
ApiModel.kt
app/src/main/java/com/mints/street/model/ApiModel.kt
+1
-2
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
RetrofitClient.java
...in/java/com/mints/street/netwrok/base/RetrofitClient.java
+1
-50
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
OkHttpInterceptor.kt
...java/com/mints/street/netwrok/common/OkHttpInterceptor.kt
+1
-1
SplashActivity.kt
app/src/main/java/com/mints/street/splash/SplashActivity.kt
+10
-2
shape_bt_agree.xml
app/src/main/res/drawable/shape_bt_agree.xml
+1
-1
shape_bt_disagree.xml
app/src/main/res/drawable/shape_bt_disagree.xml
+1
-1
activity_permissions.xml
app/src/main/res/layout/activity_permissions.xml
+67
-42
gradle.properties
gradle.properties
+2
-1
build.gradle
mvvmhabit/build.gradle
+0
-1
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/src/main/AndroidManifest.xml
View file @
a6fac0d4
...
...
@@ -12,6 +12,8 @@
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<!-- 调用相机,用于实现扫描二维码,预览个性化地图编辑器生成的个性化地图样式(开发者实际开发中地图SDK不需要该权限) -->
<uses-permission
android:name=
"android.permission.CAMERA"
/>
<!-- 获取手机状态信息 -->
<uses-permission
android:name=
"android.permission.READ_PHONE_STATE"
/>
<!-- android10以后 后台运行位置 -->
<uses-permission
android:name=
"android.permission.ACCESS_BACKGROUND_LOCATION"
/>
<application
android:name=
".AppApplication"
...
...
@@ -50,9 +52,10 @@
<meta-data
android:name=
"Mob-AppSecret"
android:value=
"${SHARE_SECRET}"
/>
<!--百度地图开放平台 -->
<meta-data
android:name=
"com.baidu.lbsapi.API_KEY"
android:value=
"SD6luBGzUFSVEZ3n9Xjk3xTsvDFmuRCi"
/>
<!-- 百度地图开放平台 -->
android:value=
"SD6luBGzUFSVEZ3n9Xjk3xTsvDFmuRCi"
/>
<!-- 百度地图开放平台 service -->
<service
android:name=
"com.baidu.location.f"
...
...
app/src/main/java/com/mints/street/api/MainApi.kt
View file @
a6fac0d4
package
com.mints.street.api
import
com.google.gson.JsonObject
import
com.mints.street.bean.AwardBean
import
com.mints.street.bean.BaseResponse
import
com.mints.street.bean.UserBean
import
com.mints.street.bean.VipBean
import
com.mints.street.netwrok.common.HttpManager
import
io.reactivex.Observable
import
me.goldze.mvvmhabit.http.BaseResponse
import
retrofit2.Response
import
retrofit2.http.Body
import
retrofit2.http.POST
...
...
library_base/src/main/java/com/fry/base
/bean/AppRequest.kt
→
app/src/main/java/com/mints/street
/bean/AppRequest.kt
View file @
a6fac0d4
package
com.
fry.base
.bean
package
com.
mints.street
.bean
import
android.annotation.SuppressLint
import
android.os.Parcelable
...
...
app/src/main/java/com/mints/street/bean/AwardBean.kt
deleted
100644 → 0
View file @
bd1e5224
package
com.mints.street.bean
import
android.annotation.SuppressLint
import
android.os.Parcelable
import
kotlinx.android.parcel.Parcelize
/**
*
* @author jyx
* @date 2021/4/7
* @des
*/
@SuppressLint
(
"ParcelCreator"
)
@Parcelize
data class
AwardBean
(
var
highCoin
:
Int
=
0
,
var
showHigh
:
Boolean
=
false
,
var
coin
:
Int
=
0
,
var
riskinfoRate
:
Boolean
=
false
)
:
Parcelable
\ No newline at end of file
mvvmhabit/src/main/java/me/goldze/mvvmhabit/http
/BaseResponse.java
→
app/src/main/java/com/mints/street/bean
/BaseResponse.java
View file @
a6fac0d4
package
me
.
goldze
.
mvvmhabit
.
http
;
package
com
.
mints
.
street
.
bean
;
import
androidx.annotation.Nullable
;
import
com.google.gson.annotations.JsonAdapter
;
import
com.google.gson.annotations.SerializedName
;
import
java.io.Serializable
;
/**
* Created by goldze on 2017/5/10.
* 该类仅供参考,实际业务返回的固定字段, 根据需求来定义,
*/
public
class
BaseResponse
<
T
>
{
public
class
BaseResponse
<
T
>
implements
Serializable
{
private
int
status
;
private
String
message
;
...
...
app/src/main/java/com/mints/street/bean/UserBean.kt
View file @
a6fac0d4
...
...
@@ -12,13 +12,12 @@ class UserBean : Serializable {
val
consumer
:
ConsumerBean
?
=
null
inner
class
ConsumerBean
:
Serializable
{
val
head
:
String
=
""
val
openid
:
String
=
""
val
nickname
:
String
=
""
val
mobile
:
String
=
""
val
real_name
:
String
=
""
val
idcode
:
String
=
""
val
pk_id
// 用户id
:
Long
=
0
val
isForever
:
Boolean
=
false
val
expireTime
:
Long
=
0
val
pk_id
:
Long
=
0
}
}
app/src/main/java/com/mints/street/common/Constant.kt
View file @
a6fac0d4
...
...
@@ -12,4 +12,8 @@ object Constant {
*/
const
val
MINTS_PKG_NAME
=
"com.mints.street"
/**
* 第一次打开权限页面
*/
const
val
FIRST_OPEN_PERMISSIONS
=
"first_open_permissions"
}
app/src/main/java/com/mints/street/login/LoginViewModel.kt
View file @
a6fac0d4
...
...
@@ -2,19 +2,14 @@ package com.mints.street.login
import
android.app.Application
import
androidx.lifecycle.MutableLiveData
import
android.text.TextUtils
import
androidx.lifecycle.viewModelScope
import
com.mints.street.bean.AwardBean
import
com.mints.street.bean.BaseResponse
import
com.mints.street.bean.UserBean
import
com.mints.street.common.DeviceInfo
import
com.mints.street.manager.UserManager
import
com.mints.street.model.ApiModel
import
com.mints.street.netwrok.base.HttpSubscribeImpl
import
com.mints.street.utils.DeviceUuidFactory
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
me.goldze.mvvmhabit.base.BaseViewModel
import
me.goldze.mvvmhabit.http.BaseResponse
import
me.goldze.mvvmhabit.utils.KLog
import
me.goldze.mvvmhabit.utils.ToastUtils
import
java.util.HashMap
...
...
@@ -55,6 +50,7 @@ class LoginViewModel(application: Application) : BaseViewModel(application) {
}
fun
login
(
mobile
:
String
,
smsCode
:
String
)
{
// showDialog()
val
vo
=
HashMap
<
String
,
Any
>()
vo
[
"mobile"
]
=
mobile
vo
[
"smsCode"
]
=
smsCode
...
...
@@ -64,12 +60,16 @@ class LoginViewModel(application: Application) : BaseViewModel(application) {
object
:
HttpSubscribeImpl
<
BaseResponse
<
UserBean
>>(
this
@LoginViewModel
,
true
)
{
override
fun
onBusinessSuccess
(
response
:
BaseResponse
<
UserBean
>)
{
data
.
value
=
response
.
message
KLog
.
e
(
"login"
,
response
.
result
.
toString
())
// ToastUtils.showShort("登录信息="+response.result.ConsumerBean().idcode)
//展示业务逻辑
UserManager
.
INSTANCE
.
saveUserInfo
(
response
.
result
)
// dismissDialog()
this
@LoginViewModel
.
saveTerminalInfo
()
UserManager
.
INSTANCE
.
saveUserInfo
(
response
.
result
)
KLog
.
e
(
"login"
,
response
.
result
.
toString
())
ToastUtils
.
showShort
(
"登录信息="
+
response
.
result
.
consumer
?.
idcode
)
data
.
value
=
response
.
message
}
override
fun
onError
(
e
:
Throwable
)
{
...
...
@@ -84,35 +84,28 @@ class LoginViewModel(application: Application) : BaseViewModel(application) {
* 提交设备信息
*/
fun
saveTerminalInfo
()
{
viewModelScope
.
launch
(
Dispatchers
.
IO
)
{
val
appInfoMap
=
deviceInfo
.
getAppInfoMap
()
launch
(
Dispatchers
.
Main
)
{
val
vo
=
hashMapOf
<
String
,
Any
>()
val
macAddress
:
String
=
deviceInfo
.
getMacAddress
()
val
mac
=
macAddress
.
replace
(
":"
,
""
)
vo
[
"mac"
]
=
mac
vo
[
"mac1"
]
=
macAddress
vo
[
"androidid"
]
=
deviceInfo
.
getAndroidId
(
null
)
vo
[
"imei"
]
=
deviceInfo
.
iMEI
val
vo
=
hashMapOf
<
String
,
Any
>()
val
macAddress
:
String
=
deviceInfo
.
getMacAddress
()
val
mac
=
macAddress
.
replace
(
":"
,
""
)
vo
[
"mac"
]
=
mac
vo
[
"mac1"
]
=
macAddress
vo
[
"androidid"
]
=
deviceInfo
.
getAndroidId
(
null
)
vo
[
"imei"
]
=
deviceInfo
.
iMEI
// if (!TextUtils.isEmpty(App.OAID)) {
// vo["oaid"] = App.OAID
// }
vo
[
"os"
]
=
"android"
vo
[
"model"
]
=
deviceInfo
.
newModel
vo
[
"uuid"
]
=
DeviceUuidFactory
().
deviceUuid
vo
[
"osversion"
]
=
deviceInfo
.
oSVersion
vo
[
"appversion"
]
=
deviceInfo
.
versionName
vo
[
"appPkgList"
]
=
appInfoMap
ApiModel
.
saveTerminalInfo
(
lifecycleProvider
,
vo
).
safeSubscribe
(
object
:
HttpSubscribeImpl
<
BaseResponse
<
Any
>>(
this
@LoginViewModel
,
true
)
{
override
fun
onBusinessSuccess
(
response
:
BaseResponse
<
Any
>)
{
KLog
.
e
(
"saveTerminalInfo"
,
response
.
result
.
toString
())
}
})
}
}
vo
[
"os"
]
=
"android"
vo
[
"model"
]
=
deviceInfo
.
newModel
vo
[
"uuid"
]
=
DeviceUuidFactory
().
deviceUuid
vo
[
"osversion"
]
=
deviceInfo
.
oSVersion
vo
[
"appversion"
]
=
deviceInfo
.
versionName
ApiModel
.
saveTerminalInfo
(
lifecycleProvider
,
vo
).
safeSubscribe
(
object
:
HttpSubscribeImpl
<
BaseResponse
<
Any
>>(
this
@LoginViewModel
,
true
)
{
override
fun
onBusinessSuccess
(
response
:
BaseResponse
<
Any
>)
{
KLog
.
e
(
"saveTerminalInfo"
,
response
.
result
.
toString
())
}
})
}
}
\ No newline at end of file
app/src/main/java/com/mints/street/main/home/HomeFragment.kt
View file @
a6fac0d4
...
...
@@ -134,6 +134,10 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(), SensorE
binding
.
imageOut
.
setOnClickListener
{
mBaiduMap
?.
setMapStatus
(
MapStatusUpdateFactory
.
zoomOut
())
}
//历史影像
binding
.
imageMapHistory
.
setOnClickListener
{
startActivity
(
HistoricalimageActivity
::
class
.
java
)
}
mRecommendStopSearch
=
RecommendStopSearch
.
newInstance
()
mRecommendStopSearch
?.
setOnGetRecommendStopResultListener
{
result
->
if
(
result
!=
null
)
{
...
...
app/src/main/java/com/mints/street/main/my/MyFragment.kt
View file @
a6fac0d4
...
...
@@ -93,7 +93,7 @@ class MyFragment : BaseFragment<FragmentMyBinding, MyViewModel>(), View.OnClickL
when
(
v
?.
id
)
{
R
.
id
.
aboutus
->
{
startActivity
(
AboutusActivity
::
class
.
java
)
// startActivity(
Historicalimage
Activity::class.java)
// startActivity(
Permissions
Activity::class.java)
}
R
.
id
.
moresettings
->
{
startActivity
(
MoresettingsActivity
::
class
.
java
)
...
...
app/src/main/java/com/mints/street/main/my/PermissionsActivity.kt
View file @
a6fac0d4
package
com.mints.street.main.my
import
android.Manifest
import
android.os.Build
import
android.os.Bundle
import
android.view.View
import
com.fry.base.base.BaseActivity
import
com.github.iielse.switchbutton.SwitchView
import
com.mints.street.BR
import
com.mints.street.R
import
com.mints.street.
databinding.ActivityMoresettingsBinding
import
com.mints.street.
common.Constant
import
com.mints.street.databinding.ActivityPermissionsBinding
import
com.mints.street.main.MainActivity
import
com.tbruyelle.rxpermissions2.RxPermissions
import
com.tencent.mmkv.MMKV
import
kotlinx.android.synthetic.main.activity_permissions.*
import
me.goldze.mvvmhabit.utils.ToastUtils
/**
* 描述:权限授权
* 作者:孟崔广
* 时间:2021/7/14 15:51
*/
class
PermissionsActivity
:
BaseActivity
<
ActivityPermissionsBinding
,
PermissionsViewModel
>(),
View
.
OnClickListener
{
class
PermissionsActivity
:
BaseActivity
<
ActivityPermissionsBinding
,
PermissionsViewModel
>()
{
override
fun
initVariableId
()
=
BR
.
viewModel
override
fun
initContentView
(
savedInstanceState
:
Bundle
?)=
R
.
layout
.
activity_permissions
override
fun
initData
()
{
super
.
initData
()
initView
()
initListener
()
}
private
fun
initListener
()
{
btnPermissionsDont
.
setOnClickListener
(
this
)
btnPermissionsNext
.
setOnClickListener
(
this
)
}
private
fun
initView
()
{
sv_positioning
.
setOnStateChangedListener
(
object
:
SwitchView
.
OnStateChangedListener
{
svPosition
.
setOnStateChangedListener
(
object
:
SwitchView
.
OnStateChangedListener
{
override
fun
toggleToOn
(
view
:
SwitchView
?)
{
svPosition
?.
isOpened
=
true
}
override
fun
toggleToOff
(
view
:
SwitchView
?)
{
svPosition
?.
isOpened
=
false
}
})
svStrong
.
setOnStateChangedListener
(
object
:
SwitchView
.
OnStateChangedListener
{
override
fun
toggleToOn
(
view
:
SwitchView
?)
{
svStrong
?.
isOpened
=
true
}
override
fun
toggleToOff
(
view
:
SwitchView
?)
{
svStrong
?.
isOpened
=
false
}
})
svReadmsg
.
setOnStateChangedListener
(
object
:
SwitchView
.
OnStateChangedListener
{
override
fun
toggleToOn
(
view
:
SwitchView
?)
{
sv
_positionin
g
?.
isOpened
=
true
sv
Readms
g
?.
isOpened
=
true
}
override
fun
toggleToOff
(
view
:
SwitchView
?)
{
sv
_positionin
g
?.
isOpened
=
false
sv
Readms
g
?.
isOpened
=
false
}
})
}
override
fun
onClick
(
v
:
View
?)
{
when
(
v
?.
id
){
R
.
id
.
btnPermissionsDont
->
ToastUtils
.
showLong
(
"请您同意授权,否则将无法使用APP功能"
)
R
.
id
.
btnPermissionsNext
->{
val
rxPermissions
=
RxPermissions
(
this
)
rxPermissions
.
request
(
if
(
svPosition
.
isOpened
&&
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
Q
)
Manifest
.
permission
.
ACCESS_BACKGROUND_LOCATION
else
""
,
if
(
svPosition
.
isOpened
)
Manifest
.
permission
.
ACCESS_FINE_LOCATION
else
""
,
if
(
svStrong
.
isOpened
)
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
else
""
,
if
(
svReadmsg
.
isOpened
)
Manifest
.
permission
.
READ_PHONE_STATE
else
""
)
.
subscribe
{
startActivityThenKill
(
MainActivity
::
class
.
java
)
}
MMKV
.
mmkvWithID
(
Constant
.
FIRST_OPEN_PERMISSIONS
).
encode
(
Constant
.
FIRST_OPEN_PERMISSIONS
,
true
)
}
}
}
}
\ No newline at end of file
app/src/main/java/com/mints/street/manager/UserManager.kt
View file @
a6fac0d4
...
...
@@ -33,11 +33,6 @@ class UserManager {
*/
private
const
val
MOBILE
=
"mobile"
/**
* 姓名
*/
private
const
val
REAL_NAME
=
"realName"
/**
* 微信名称
*/
...
...
@@ -53,6 +48,16 @@ class UserManager {
*/
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
)
{
UserManager
()
}
...
...
@@ -78,16 +83,18 @@ class UserManager {
val
mobile
:
String
?
=
user
.
mobile
val
openid
:
String
?
=
user
.
openid
MMKV
.
mmkvWithID
(
USER_ID
).
encode
(
USER_ID
,
user
.
pk_id
.
toString
())
MMKV
.
mmkvWithID
(
CODE_ID
).
encode
(
CODE_ID
,
user
.
idcode
.
toString
()
)
MMKV
.
mmkvWithID
(
CODE_ID
).
encode
(
CODE_ID
,
user
.
idcode
)
if
(!
TextUtils
.
isEmpty
(
mobile
))
{
MMKV
.
mmkvWithID
(
MOBILE
).
encode
(
MOBILE
,
mobile
)
}
MMKV
.
mmkvWithID
(
WX_NAME
).
encode
(
WX_NAME
,
user
.
nickname
.
toString
())
MMKV
.
mmkvWithID
(
WX_HEADER
).
encode
(
WX_HEADER
,
user
.
head
)
if
(!
TextUtils
.
isEmpty
(
user
.
nickname
))
{
MMKV
.
mmkvWithID
(
WX_NAME
).
encode
(
WX_NAME
,
user
.
nickname
)
}
MMKV
.
mmkvWithID
(
IS_FOREVER
).
encode
(
IS_FOREVER
,
user
.
isForever
)
MMKV
.
mmkvWithID
(
EXPIRETIME
).
encode
(
EXPIRETIME
,
user
.
expireTime
)
if
(!
TextUtils
.
isEmpty
(
openid
))
{
MMKV
.
mmkvWithID
(
WX_OPENID
).
encode
(
WX_OPENID
,
openid
)
}
MMKV
.
mmkvWithID
(
REAL_NAME
).
encode
(
REAL_NAME
,
user
.
real_name
)
}
}
...
...
@@ -133,23 +140,6 @@ class UserManager {
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
{
val
kv
=
MMKV
.
mmkvWithID
(
WX_NAME
)
...
...
@@ -166,34 +156,26 @@ class UserManager {
return
kv
.
decodeString
(
WX_OPENID
,
""
)
}
fun
setWxName
(
wxName
:
String
?)
{
val
kv
=
MMKV
.
mmkvWithID
(
WX_NAME
)
kv
.
encode
(
WX_NAME
,
wxNam
e
)
fun
getIsforever
():
Boolean
{
val
kv
=
MMKV
.
mmkvWithID
(
IS_FOREVER
)
return
kv
.
decodeBool
(
IS_FOREVER
,
fals
e
)
}
fun
setWxHeader
(
wxHeader
:
String
?)
{
val
kv
=
MMKV
.
mmkvWithID
(
WX_HEADER
)
kv
.
encode
(
WX_HEADER
,
wxHeader
)
fun
getExpiretime
():
Long
{
val
kv
=
MMKV
.
mmkvWithID
(
EXPIRETIME
)
return
kv
.
decodeLong
(
EXPIRETIME
,
0
)
}
/**
* mobile
*
* @param mobile
*/
fun
setMobile
(
mobile
:
String
?)
{
val
kv
=
MMKV
.
mmkvWithID
(
MOBILE
)
kv
.
encode
(
MOBILE
,
mobile
)
}
fun
userLogout
()
{
MMKV
.
mmkvWithID
(
USER_ID
).
remove
(
USER_ID
)
MMKV
.
mmkvWithID
(
CODE_ID
).
remove
(
CODE_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_NAME
).
remove
(
WX_NAME
)
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 @
a6fac0d4
package
com.mints.street.model
import
com.mints.street.api.MainApi
import
com.mints.street.bean.
AwardBean
import
com.mints.street.bean.
BaseResponse
import
com.mints.street.bean.UserBean
import
com.mints.street.netwrok.common.HttpManager
import
com.trello.rxlifecycle2.LifecycleProvider
import
io.reactivex.Observable
import
me.goldze.mvvmhabit.http.BaseResponse
import
retrofit2.Response
/**
...
...
app/src/main/java/com/mints/street/netwrok/base/HttpSubscribeImpl.kt
View file @
a6fac0d4
package
com.mints.street.netwrok.base
import
com.mints.street.bean.BaseResponse
import
me.goldze.mvvmhabit._enum.ViewStatus
import
me.goldze.mvvmhabit.base.BaseViewModel
import
me.goldze.mvvmhabit.http.BaseResponse
import
me.goldze.mvvmhabit.http.ExceptionHandle
import
me.goldze.mvvmhabit.http.ResponseThrowable
import
me.goldze.mvvmhabit.utils.ToastUtils
...
...
app/src/main/java/com/mints/street/netwrok/base/IHttpResponseListener.java
View file @
a6fac0d4
package
com
.
mints
.
street
.
netwrok
.
base
;
import
com.mints.street.bean.BaseResponse
;
import
io.reactivex.disposables.Disposable
;
import
me.goldze.mvvmhabit.http.BaseResponse
;
import
me.goldze.mvvmhabit.http.ResponseThrowable
;
import
retrofit2.Response
;
...
...
app/src/main/java/com/mints/street/netwrok/base/IHttpSubscribe.kt
View file @
a6fac0d4
package
com.mints.street.netwrok.base
import
com.mints.street.bean.BaseResponse
import
io.reactivex.Observer
import
io.reactivex.disposables.Disposable
import
me.goldze.mvvmhabit.base.BaseViewModel
import
me.goldze.mvvmhabit.http.BaseResponse
import
retrofit2.Response
/**
...
...
app/src/main/java/com/mints/street/netwrok/base/RetrofitClient.java
View file @
a6fac0d4
...
...
@@ -31,7 +31,7 @@ import retrofit2.Retrofit;
import
retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
;
/**
* Created by
jeme on 2019/1/31
* Created by
mcg
*/
public
class
RetrofitClient
{
...
...
@@ -50,38 +50,10 @@ public class RetrofitClient {
OkHttpClient
.
Builder
clientBuilder
=
new
OkHttpClient
.
Builder
()
.
cookieJar
(
new
CookieJarImpl
(
new
PersistentCookieStore
(
mContext
)))
// .cache(cache)
// .addInterceptor()
// .addInterceptor(new CacheInterceptor(mContext))
// .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)
.
connectTimeout
(
mHttpConfig
.
getTimeOut
(),
TimeUnit
.
SECONDS
)
.
writeTimeout
(
mHttpConfig
.
getTimeOut
(),
TimeUnit
.
SECONDS
)
.
readTimeout
(
mHttpConfig
.
getTimeOut
(),
TimeUnit
.
SECONDS
)
.
connectionPool
(
new
ConnectionPool
(
8
,
15
,
TimeUnit
.
SECONDS
));
// 这里你可以根据自己的机型设置同时连接的个数和时间,我这里8个,和每个保持时间为10s
// if (configuation.getInterceptors() != null) {
// for (Interceptor interceptor : configuation.getInterceptors()) {
// clientBuilder.addInterceptor(interceptor);
// }
// }
// if(BuildConfig.IS_DEV) {
// clientBuilder.addInterceptor(new LoggingInterceptor
// .Builder()
// //是否开启日志打印
// .loggable(BuildConfig.DEBUG)
// //打印的等级
// .setLevel(Level.BASIC)
// // 打印类型
// .log(Platform.INFO)
// // request的Tag
// .request("Request")
// // Response的Tag
// .response("Request")
//// .addHeader("log-header", "I am the log request header.") // 添加打印头, 注意 key 和 value 都不能是中文
// .build()
// );
// }
if
(
BuildConfig
.
DEBUG
)
{
HttpLoggingInterceptor
logging
=
new
HttpLoggingInterceptor
(
message
->
{
...
...
@@ -122,25 +94,4 @@ public class RetrofitClient {
}
return
mRetrofit
.
create
(
service
);
}
/**
* /**
* execute your customer API
* For example:
* MyApiService service =
* RetrofitClient.getInstance(MainActivity.this).create(MyApiService.class);
* <p>
* RetrofitClient.getInstance(MainActivity.this)
* .execute(service.lgon("name", "password"), subscriber)
* * @param subscriber
*/
public
static
<
T
>
T
execute
(
Observable
<
T
>
observable
,
Observer
<
T
>
subscriber
)
{
observable
.
subscribeOn
(
Schedulers
.
io
())
.
unsubscribeOn
(
Schedulers
.
io
())
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
subscriber
);
return
null
;
}
}
app/src/main/java/com/mints/street/netwrok/common/GsonConverterFactory.java
View file @
a6fac0d4
package
com
.
mints
.
street
.
netwrok
.
common
;
import
com.google.gson.Gson
;
import
com.mints.street.bean.BaseResponse
;
import
com.mints.street.manager.UserManager
;
import
java.io.IOException
;
...
...
@@ -12,7 +13,6 @@ import java.lang.reflect.Type;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
me.goldze.mvvmhabit.http.BaseResponse
;
import
okhttp3.MediaType
;
import
okhttp3.RequestBody
;
import
okhttp3.ResponseBody
;
...
...
app/src/main/java/com/mints/street/netwrok/common/HttpErrorProcess.java
View file @
a6fac0d4
package
com
.
mints
.
street
.
netwrok
.
common
;
import
com.mints.street.bean.BaseResponse
;
import
io.reactivex.Observable
;
import
io.reactivex.ObservableSource
;
import
io.reactivex.ObservableTransformer
;
import
io.reactivex.functions.Function
;
import
me.goldze.mvvmhabit.http.BaseResponse
;
import
retrofit2.Response
;
/**
...
...
app/src/main/java/com/mints/street/netwrok/common/HttpManager.java
View file @
a6fac0d4
...
...
@@ -3,10 +3,10 @@ package com.mints.street.netwrok.common;
import
android.annotation.SuppressLint
;
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.IHttpResponseListener
;
import
com.mints.street.netwrok.base.RetrofitClient
;
import
com.mints.street.utils.encry.AESUtils
;
import
com.trello.rxlifecycle2.LifecycleProvider
;
import
io.reactivex.Observable
;
...
...
@@ -17,7 +17,6 @@ import io.reactivex.functions.Action;
import
io.reactivex.functions.Consumer
;
import
io.reactivex.functions.Function
;
import
io.reactivex.schedulers.Schedulers
;
import
me.goldze.mvvmhabit.http.BaseResponse
;
import
me.goldze.mvvmhabit.http.ResponseThrowable
;
import
me.goldze.mvvmhabit.utils.RxUtils
;
import
retrofit2.Response
;
...
...
@@ -79,60 +78,4 @@ public class HttpManager {
.
compose
(
RxUtils
.
exceptionTransformer
())
.
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
();
},
()
->
{
});
}
}
app/src/main/java/com/mints/street/netwrok/common/OkHttpInterceptor.kt
View file @
a6fac0d4
...
...
@@ -3,10 +3,10 @@ package com.mints.street.netwrok.common
import
android.text.TextUtils
import
android.util.Log
import
com.bytedance.hume.readapk.HumeSDK
import
com.fry.base.bean.AppRequest
import
com.google.gson.Gson
import
com.mints.street.AppApplication
import
com.mints.street.BuildConfig
import
com.mints.street.bean.AppRequest
import
com.mints.street.manager.UserManager
import
com.mints.street.utils.CommonUtils
import
com.mints.street.utils.encry.AESUtils
...
...
app/src/main/java/com/mints/street/splash/SplashActivity.kt
View file @
a6fac0d4
...
...
@@ -12,10 +12,14 @@ import com.bytedance.msdk.api.splash.TTSplashAdLoadCallback
import
com.fry.base.base.BaseActivity
import
com.mints.street.BR
import
com.mints.street.R
import
com.mints.street.common.Constant
import
com.mints.street.common.DeviceInfo
import
com.mints.street.databinding.ActivitySplashBinding
import
com.mints.street.main.MainActivity
import
com.mints.street.main.my.PermissionsActivity
import
com.mints.street.manager.CsjGroMoreManager
import
com.mints.street.manager.UserManager
import
com.tencent.mmkv.MMKV
/**
* 描述:gromore开屏页
...
...
@@ -163,7 +167,11 @@ class SplashActivity:BaseActivity<ActivitySplashBinding,SplashViewModel>() {
* 跳转到主页面
*/
private
fun
goToMainActivity
()
{
// startActivityThenKill(MainActivity::class.java)
startActivityThenKill
(
GuideActivity
::
class
.
java
)
if
(
MMKV
.
mmkvWithID
(
Constant
.
FIRST_OPEN_PERMISSIONS
).
decodeBool
(
Constant
.
FIRST_OPEN_PERMISSIONS
,
false
)){
// 非新用户
startActivityThenKill
(
MainActivity
::
class
.
java
)
}
else
{
startActivityThenKill
(
PermissionsActivity
::
class
.
java
)
}
}
}
\ No newline at end of file
app/src/main/res/drawable/shape_bt_agree.xml
View file @
a6fac0d4
...
...
@@ -2,6 +2,6 @@
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:shape=
"rectangle"
>
<solid
android:color=
"#2196F3"
/>
<corners
android:radius=
"
21
dp"
/>
<corners
android:radius=
"
30
dp"
/>
</shape>
\ No newline at end of file
app/src/main/res/drawable/shape_bt_disagree.xml
View file @
a6fac0d4
...
...
@@ -7,6 +7,6 @@
android:color=
"#74000000"
/>
<solid
android:color=
"#ffffffff"
/>
<corners
android:radius=
"
21
dp"
/>
<corners
android:radius=
"
30
dp"
/>
</shape>
\ No newline at end of file
app/src/main/res/layout/activity_permissions.xml
View file @
a6fac0d4
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<data>
<variable
...
...
@@ -9,7 +10,8 @@
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"716dp"
android:layout_height=
"match_parent"
android:background=
"@color/white"
android:orientation=
"vertical"
>
<TextView
...
...
@@ -17,7 +19,8 @@
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:layout_marginTop=
"25dp"
android:text=
"世界街景3D地图"
android:text=
"3D高清街景"
android:textStyle=
"bold"
android:textColor=
"@color/black"
android:textSize=
"25dp"
/>
...
...
@@ -26,20 +29,20 @@
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:layout_marginTop=
"10dp"
android:layout_marginBottom=
"
10
pt"
android:text=
"为了提供
一
下服务"
android:layout_marginBottom=
"
4
pt"
android:text=
"为了提供
以
下服务"
android:textColor=
"#CD000000"
/>
<RelativeLayout
android:layout_width=
"match_parent"
android:layout_height=
"1
1
0dp"
android:layout_height=
"1
0
0dp"
android:layout_margin=
"10dp"
android:background=
"@drawable/shape_gold_blue"
>
<ImageView
android:id=
"@+id/iv1"
android:layout_width=
"
8
0dp"
android:layout_height=
"
8
0dp"
android:layout_width=
"
7
0dp"
android:layout_height=
"
7
0dp"
android:layout_centerVertical=
"true"
android:layout_marginLeft=
"10dp"
android:src=
"@mipmap/ic_my"
/>
...
...
@@ -49,25 +52,30 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignTop=
"@+id/iv1"
android:layout_marginStart=
"
2
0dp"
android:layout_marginStart=
"
1
0dp"
android:layout_toRightOf=
"@id/iv1"
android:text=
"提供精准定位及导航服务"
android:layout_marginTop=
"10dp"
android:textStyle=
"bold"
android:textColor=
"@color/black"
android:textSize=
"1
2
sp"
/>
android:textSize=
"1
4
sp"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignBottom=
"@+id/iv1"
android:layout_marginStart=
"
2
0dp"
android:layout_marginStart=
"
1
0dp"
android:layout_toRightOf=
"@+id/iv1"
android:text=
"基于您当前位置...."
android:textSize=
"12sp"
android:text=
"基于您当前位置、为您提供完整的周边信息"
android:layout_marginBottom=
"10dp"
android:textColor=
"#A9000000"
/>
<com.github.iielse.switchbutton.SwitchView
android:id=
"@+id/sv
_positioning
"
android:id=
"@+id/sv
Position
"
android:layout_width=
"wrap_content"
android:layout_height=
"20dp"
app:isOpened=
"true"
android:layout_alignParentEnd=
"true"
android:layout_centerHorizontal=
"true"
android:layout_centerVertical=
"true"
...
...
@@ -76,14 +84,14 @@
<RelativeLayout
android:layout_width=
"match_parent"
android:layout_height=
"1
1
0dp"
android:layout_height=
"1
0
0dp"
android:layout_margin=
"10dp"
android:background=
"@drawable/shape_gold_blue"
>
<ImageView
android:id=
"@+id/iv2"
android:layout_width=
"
8
0dp"
android:layout_height=
"
8
0dp"
android:layout_width=
"
7
0dp"
android:layout_height=
"
7
0dp"
android:layout_centerVertical=
"true"
android:layout_marginLeft=
"10dp"
android:src=
"@mipmap/ic_my"
/>
...
...
@@ -93,25 +101,31 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignTop=
"@+id/iv2"
android:layout_marginStart=
"
2
0dp"
android:layout_marginStart=
"
1
0dp"
android:layout_toRightOf=
"@id/iv2"
android:text=
"提供精准定位及导航服务"
android:text=
"存储地图等相关数据"
android:layout_marginTop=
"10dp"
android:textStyle=
"bold"
android:textColor=
"@color/black"
android:textSize=
"1
2sp"
/>
android:textSize=
"1
4sp"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignBottom=
"@+id/iv2"
android:layout_marginStart=
"
2
0dp"
android:layout_marginStart=
"
1
0dp"
android:layout_toRightOf=
"@+id/iv2"
android:text=
"基于您当前位置...."
android:textSize=
"12sp"
android:text=
"用于读写地图、常用地址等相关数据"
android:layout_marginBottom=
"10dp"
android:textColor=
"#A9000000"
/>
<com.github.iielse.switchbutton.SwitchView
android:id=
"@+id/svStrong"
android:layout_width=
"wrap_content"
android:layout_height=
"20dp"
android:layout_alignParentEnd=
"true"
app:isOpened=
"true"
android:layout_centerHorizontal=
"true"
android:layout_centerVertical=
"true"
android:layout_marginRight=
"10dp"
/>
...
...
@@ -119,14 +133,14 @@
<RelativeLayout
android:layout_width=
"match_parent"
android:layout_height=
"1
1
0dp"
android:layout_height=
"1
0
0dp"
android:layout_margin=
"10dp"
android:background=
"@drawable/shape_gold_blue"
>
<ImageView
android:id=
"@+id/iv3"
android:layout_width=
"
8
0dp"
android:layout_height=
"
8
0dp"
android:layout_width=
"
7
0dp"
android:layout_height=
"
7
0dp"
android:layout_centerVertical=
"true"
android:layout_marginLeft=
"10dp"
android:src=
"@mipmap/ic_my"
/>
...
...
@@ -136,38 +150,52 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignTop=
"@+id/iv3"
android:layout_marginStart=
"
2
0dp"
android:layout_marginStart=
"
1
0dp"
android:layout_toRightOf=
"@id/iv3"
android:text=
"提供精准定位及导航服务"
android:text=
"问题诊断及修复"
android:layout_marginTop=
"10dp"
android:textStyle=
"bold"
android:textColor=
"@color/black"
android:textSize=
"1
2sp"
/>
android:textSize=
"1
4sp"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignBottom=
"@+id/iv3"
android:layout_marginStart=
"
2
0dp"
android:layout_marginStart=
"
1
0dp"
android:layout_toRightOf=
"@+id/iv3"
android:text=
"基于您当前位置...."
android:textSize=
"12sp"
android:text=
"用于读取信息、快速确诊问题"
android:layout_marginBottom=
"10dp"
android:textColor=
"#A9000000"
/>
<com.github.iielse.switchbutton.SwitchView
android:id=
"@+id/svReadmsg"
android:layout_width=
"wrap_content"
android:layout_height=
"20dp"
app:isOpened=
"true"
android:layout_alignParentEnd=
"true"
android:layout_centerHorizontal=
"true"
android:layout_centerVertical=
"true"
android:layout_marginRight=
"10dp"
/>
</RelativeLayout>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"您的个人信息将受到严格的保密,3D高清街景不会将您的个人信息泄露给他人。您也可以在系统设置中关闭授权,但可能影响部分功能使用。"
android:layout_margin=
"10dp"
android:textColor=
"#CD000000"
/>
<LinearLayout
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:layout_marginTop=
"
2
0pt"
android:layout_marginTop=
"
1
0pt"
android:orientation=
"horizontal"
>
<Button
android:id=
"@+id/btnPermissionsDont"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginRight=
"10dp"
...
...
@@ -178,6 +206,7 @@
android:textColor=
"#43000000"
/>
<Button
android:id=
"@+id/btnPermissionsNext"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"10dp"
...
...
@@ -188,37 +217,33 @@
android:textColor=
"@color/white"
/>
</LinearLayout>
<View
android:layout_width=
"match_parent"
android:layout_height=
"0dp"
android:layout_weight=
"1"
/>
<LinearLayout
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_horizontal"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_marginBottom=
"20dp"
android:gravity=
"bottom|center_horizontal"
android:orientation=
"horizontal"
>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"
match_par
ent"
android:layout_height=
"
wrap_cont
ent"
android:text=
"链接网络后可查看并同意完整的"
android:textColor=
"@color/black"
android:textSize=
"
8
sp"
/>
android:textSize=
"
12
sp"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"《隐私协议》"
android:textColor=
"@color/black"
android:textSize=
"
8
sp"
/>
android:textSize=
"
12
sp"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"《用户协议》"
android:textColor=
"@color/black"
android:textSize=
"
8
sp"
/>
android:textSize=
"
12
sp"
/>
</LinearLayout>
</LinearLayout>
...
...
gradle.properties
View file @
a6fac0d4
...
...
@@ -21,7 +21,8 @@ android.enableJetifier=true
isBuildModule
=
false
DEBUG_URL
=
"http://test.mints-id.com/map-api/"
RELEASE_URL
=
"https://api.mints-id.com/gc-api/"
#RELEASE_URL="https://api.mints-id.com/map-api/"
RELEASE_URL
=
"http://test.mints-id.com/map-api/"
RELEASE_KEY_PASSWORD
=
mints.street
RELEASE_KEY_ALIAS
=
mints_street
...
...
mvvmhabit/build.gradle
View file @
a6fac0d4
...
...
@@ -70,7 +70,6 @@ dependencies {
//Google LiveData和ViewModel组件
api
rootProject
.
ext
.
dependencies
[
"lifecycle-extensions"
]
kapt
rootProject
.
ext
.
dependencies
[
"lifecycle-compiler"
]
api
"androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
//api "com.jeme:gif:1.0.5@aar"
//使用aar库引用
...
...
mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/ApiDisposableObserver.java
View file @
a6fac0d4
package
me
.
goldze
.
mvvmhabit
.
http
;
import
io.reactivex.observers.DisposableObserver
;
import
me.goldze.mvvmhabit.base.AppManager
;
import
me.goldze.mvvmhabit.utils.KLog
;
import
me.goldze.mvvmhabit.utils.ToastUtils
;
import
me.goldze.mvvmhabit.utils.Utils
;
/**
* Created by goldze on 2017/5/10.
* 统一的Code封装处理。该类仅供参考,实际业务逻辑, 根据需求来定义,
*/
public
abstract
class
ApiDisposableObserver
<
T
>
extends
DisposableObserver
<
T
>
{
public
abstract
void
onResult
(
T
t
);
@Override
public
void
onComplete
()
{
}
@Override
public
void
onError
(
Throwable
e
)
{
e
.
printStackTrace
();
KLog
.
e
(
e
.
getMessage
());
if
(
e
instanceof
ResponseThrowable
)
{
ResponseThrowable
rError
=
(
ResponseThrowable
)
e
;
ToastUtils
.
showShort
(
rError
.
getMessage
());
return
;
}
//其他全部甩锅网络异常
ToastUtils
.
showShort
(
"网络异常"
);
}
@Override
public
void
onStart
()
{
super
.
onStart
();
ToastUtils
.
showShort
(
"http is start"
);
// if NetworkAvailable no ! must to call onCompleted
if
(!
NetworkUtil
.
isNetworkAvailable
(
Utils
.
getContext
()))
{
ToastUtils
.
showShort
(
"无网络,读取缓存数据"
);
onComplete
();
}
}
@Override
public
void
onNext
(
Object
o
)
{
BaseResponse
baseResponse
=
(
BaseResponse
)
o
;
switch
(
baseResponse
.
getstatus
())
{
case
CodeRule
.
CODE_200
:
//请求成功, 正确的操作方式
onResult
((
T
)
baseResponse
.
getResult
());
break
;
case
CodeRule
.
CODE_220
:
// 请求成功, 正确的操作方式, 并消息提示
onResult
((
T
)
baseResponse
.
getResult
());
break
;
case
CodeRule
.
CODE_300
:
//请求失败,不打印Message
KLog
.
e
(
"请求失败"
);
ToastUtils
.
showShort
(
"错误代码:"
,
baseResponse
.
getstatus
());
break
;
case
CodeRule
.
CODE_330
:
//请求失败,打印Message
ToastUtils
.
showShort
(
baseResponse
.
getMessage
());
break
;
case
CodeRule
.
CODE_500
:
//服务器内部异常
ToastUtils
.
showShort
(
"错误代码:"
,
baseResponse
.
getstatus
());
break
;
case
CodeRule
.
CODE_503
:
//参数为空
KLog
.
e
(
"参数为空"
);
break
;
case
CodeRule
.
CODE_502
:
//没有数据
KLog
.
e
(
"没有数据"
);
break
;
case
CodeRule
.
CODE_510
:
//无效的Token,提示跳入登录页
ToastUtils
.
showShort
(
"token已过期,请重新登录"
);
//关闭所有页面
AppManager
.
getAppManager
().
finishAllActivity
();
//跳入登录界面
//*****该类仅供参考,实际业务Code, 根据需求来定义,******//
break
;
case
CodeRule
.
CODE_530
:
ToastUtils
.
showShort
(
"请先登录"
);
break
;
case
CodeRule
.
CODE_551
:
ToastUtils
.
showShort
(
"错误代码:"
,
baseResponse
.
getstatus
());
break
;
default
:
ToastUtils
.
showShort
(
"错误代码:"
,
baseResponse
.
getstatus
());
break
;
}
}
public
static
final
class
CodeRule
{
//请求成功, 正确的操作方式
static
final
int
CODE_200
=
200
;
//请求成功, 消息提示
static
final
int
CODE_220
=
220
;
//请求失败,不打印Message
static
final
int
CODE_300
=
300
;
//请求失败,打印Message
static
final
int
CODE_330
=
330
;
//服务器内部异常
static
final
int
CODE_500
=
500
;
//参数为空
static
final
int
CODE_503
=
503
;
//没有数据
static
final
int
CODE_502
=
502
;
//无效的Token
static
final
int
CODE_510
=
510
;
//未登录
static
final
int
CODE_530
=
530
;
//请求的操作异常终止:未知的页面类型
static
final
int
CODE_551
=
551
;
}
}
\ No newline at end of file
//package me.goldze.mvvmhabit.http;
//
//
//import io.reactivex.observers.DisposableObserver;
//import me.goldze.mvvmhabit.base.AppManager;
//import me.goldze.mvvmhabit.utils.KLog;
//import me.goldze.mvvmhabit.utils.ToastUtils;
//import me.goldze.mvvmhabit.utils.Utils;
//
///**
// * Created by goldze on 2017/5/10.
// * 统一的Code封装处理。该类仅供参考,实际业务逻辑, 根据需求来定义,
// */
//
//public abstract class ApiDisposableObserver<T> extends DisposableObserver<T> {
// public abstract void onResult(T t);
//
// @Override
// public void onComplete() {
//
// }
//
// @Override
// public void onError(Throwable e) {
// e.printStackTrace();
// KLog.e(e.getMessage());
// if (e instanceof ResponseThrowable) {
// ResponseThrowable rError = (ResponseThrowable) e;
// ToastUtils.showShort(rError.getMessage());
// return;
// }
// //其他全部甩锅网络异常
// ToastUtils.showShort("网络异常");
// }
//
// @Override
// public void onStart() {
// super.onStart();
// ToastUtils.showShort("http is start");
// // if NetworkAvailable no ! must to call onCompleted
// if (!NetworkUtil.isNetworkAvailable(Utils.getContext())) {
// ToastUtils.showShort("无网络,读取缓存数据");
// onComplete();
// }
// }
//
// @Override
// public void onNext(Object o) {
// BaseResponse baseResponse = (BaseResponse) o;
// switch (baseResponse.getstatus()) {
// case CodeRule.CODE_200:
// //请求成功, 正确的操作方式
// onResult((T) baseResponse.getResult());
// break;
// case CodeRule.CODE_220:
// // 请求成功, 正确的操作方式, 并消息提示
// onResult((T) baseResponse.getResult());
// break;
// case CodeRule.CODE_300:
// //请求失败,不打印Message
// KLog.e("请求失败");
// ToastUtils.showShort("错误代码:", baseResponse.getstatus());
// break;
// case CodeRule.CODE_330:
// //请求失败,打印Message
// ToastUtils.showShort(baseResponse.getMessage());
// break;
// case CodeRule.CODE_500:
// //服务器内部异常
// ToastUtils.showShort("错误代码:", baseResponse.getstatus());
// break;
// case CodeRule.CODE_503:
// //参数为空
// KLog.e("参数为空");
// break;
// case CodeRule.CODE_502:
// //没有数据
// KLog.e("没有数据");
// break;
// case CodeRule.CODE_510:
// //无效的Token,提示跳入登录页
// ToastUtils.showShort("token已过期,请重新登录");
// //关闭所有页面
// AppManager.getAppManager().finishAllActivity();
// //跳入登录界面
// //*****该类仅供参考,实际业务Code, 根据需求来定义,******//
// break;
// case CodeRule.CODE_530:
// ToastUtils.showShort("请先登录");
// break;
// case CodeRule.CODE_551:
// ToastUtils.showShort("错误代码:", baseResponse.getstatus());
// break;
// default:
// ToastUtils.showShort("错误代码:", baseResponse.getstatus());
// break;
// }
// }
//
// public static final class CodeRule {
// //请求成功, 正确的操作方式
// static final int CODE_200 = 200;
// //请求成功, 消息提示
// static final int CODE_220 = 220;
// //请求失败,不打印Message
// static final int CODE_300 = 300;
// //请求失败,打印Message
// static final int CODE_330 = 330;
// //服务器内部异常
// static final int CODE_500 = 500;
// //参数为空
// static final int CODE_503 = 503;
// //没有数据
// static final int CODE_502 = 502;
// //无效的Token
// static final int CODE_510 = 510;
// //未登录
// static final int CODE_530 = 530;
// //请求的操作异常终止:未知的页面类型
// static final int CODE_551 = 551;
// }
//}
\ No newline at end of file
mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/BaseArrayResponse.java
View file @
a6fac0d4
package
me
.
goldze
.
mvvmhabit
.
http
;
import
java.util.List
;
/**
* Created by goldze on 2017/5/10.
* 该类仅供参考,实际业务返回的固定字段, 根据需求来定义,
*/
public
class
BaseArrayResponse
<
T
>
extends
BaseResponse
<
List
<
T
>>{
@Override
public
List
<
T
>
getResult
()
{
return
result
;
}
@Override
public
void
setResult
(
List
<
T
>
result
)
{
this
.
result
=
result
;
}
}
//
package me.goldze.mvvmhabit.http;
//
//
import java.util.List;
//
/
//
**
//
* Created by goldze on 2017/5/10.
//
* 该类仅供参考,实际业务返回的固定字段, 根据需求来定义,
//
*/
//
public class BaseArrayResponse<T> extends BaseResponse<List<T>>{
//
//
//
@Override
//
public List<T> getResult() {
//
return result;
//
}
//
//
@Override
//
public void setResult(List<T> 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