Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
HBHAndroid
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
1
Merge Requests
1
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
杨秀秀
HBHAndroid
Commits
61142e3b
Commit
61142e3b
authored
Feb 05, 2024
by
小费同学阿
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
强制更新优化主页版本检测
parent
c3cf7fd2
Changes
11
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
540 additions
and
115 deletions
+540
-115
HomeFragment.java
...rc/main/java/com/xx/merchanthbh/ui/home/HomeFragment.java
+1
-1
MineViewModel.java
...c/main/java/com/xx/merchanthbh/ui/mine/MineViewModel.java
+38
-40
HomeRequest.java
...java/com/xx/hbhbcompany/data/http/requst/HomeRequest.java
+28
-11
WorkRequest.kt
...n/java/com/xx/hbhbcompany/data/http/requst/WorkRequest.kt
+12
-1
HomeFragment.java
...rc/main/java/com/xx/hbhbcompany/ui/home/HomeFragment.java
+32
-0
HomeViewModel.java
...c/main/java/com/xx/hbhbcompany/ui/home/HomeViewModel.java
+181
-21
LoginActivity.kt
...rc/main/java/com/xx/hbhbcompany/ui/login/LoginActivity.kt
+3
-3
MineFragment.java
...rc/main/java/com/xx/hbhbcompany/ui/mine/MineFragment.java
+26
-2
MineViewModel.java
...c/main/java/com/xx/hbhbcompany/ui/mine/MineViewModel.java
+30
-35
WorkFragment.java
...rc/main/java/com/xx/hbhbcompany/ui/work/WorkFragment.java
+30
-1
WorkViewModel.java
...c/main/java/com/xx/hbhbcompany/ui/work/WorkViewModel.java
+159
-0
No files found.
app/src/main/java/com/xx/merchanthbh/ui/home/HomeFragment.java
View file @
61142e3b
...
@@ -62,7 +62,7 @@ public class HomeFragment extends BaseFragment<FragmentHomeBinding, HomeViewMode
...
@@ -62,7 +62,7 @@ public class HomeFragment extends BaseFragment<FragmentHomeBinding, HomeViewMode
/*检查版本*/
/*检查版本*/
viewModel
.
checkVersion
(
binding
.
getRoot
().
getRootView
());
viewModel
.
checkVersion
(
binding
.
getRoot
().
getRootView
());
// 安装新版本
// 安装新版本
viewModel
.
openInstall
.
observe
(
this
,
new
Observer
<
String
>()
{
viewModel
.
openInstall
.
observe
(
this
,
new
Observer
<
String
>()
{
@Override
@Override
public
void
onChanged
(
String
s
)
{
public
void
onChanged
(
String
s
)
{
...
...
app/src/main/java/com/xx/merchanthbh/ui/mine/MineViewModel.java
View file @
61142e3b
...
@@ -68,22 +68,23 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -68,22 +68,23 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
public
ObservableField
<
String
>
versionName
=
new
ObservableField
<>(
""
);
public
ObservableField
<
String
>
versionName
=
new
ObservableField
<>(
""
);
public
MutableLiveData
<
String
>
openInstall
=
new
MutableLiveData
<>(
""
);
public
MutableLiveData
<
String
>
openInstall
=
new
MutableLiveData
<>(
""
);
public
MineViewModel
(
@NonNull
Application
application
)
{
public
MineViewModel
(
@NonNull
Application
application
)
{
super
(
application
);
super
(
application
);
model
=
new
MineRequest
();
model
=
new
MineRequest
();
}
}
private
void
setValueToNickName
()
{
private
void
setValueToNickName
()
{
nickName
.
set
(
LocalData
.
getUser
().
getNickName
());
nickName
.
set
(
LocalData
.
getUser
().
getNickName
());
createTime
.
set
(
"创建日期:"
+
CommUtilsKt
.
getTimeForm
(
LocalData
.
getUser
().
getCreateTime
()));
createTime
.
set
(
"创建日期:"
+
CommUtilsKt
.
getTimeForm
(
LocalData
.
getUser
().
getCreateTime
()));
roleName
.
set
(
LocalData
.
getUser
().
getUserId
()
==
LocalData
.
getMerchant
().
getUserId
()?
"店长"
:
"店员"
);
roleName
.
set
(
LocalData
.
getUser
().
getUserId
()
==
LocalData
.
getMerchant
().
getUserId
()
?
"店长"
:
"店员"
);
avatarImageUrl
.
setValue
(
LocalData
.
getUser
().
getAvatar
());
avatarImageUrl
.
setValue
(
LocalData
.
getUser
().
getAvatar
());
}
}
//跳转注销账号界面
//跳转注销账号界面
public
BindingCommand
goLogOffUser
=
new
BindingCommand
(
new
BindingAction
()
{
public
BindingCommand
goLogOffUser
=
new
BindingCommand
(
new
BindingAction
()
{
@Override
@Override
...
@@ -98,9 +99,11 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -98,9 +99,11 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
public
LiveData
<
String
>
getAvatarImageUrl
()
{
public
LiveData
<
String
>
getAvatarImageUrl
()
{
return
avatarImageUrl
;
return
avatarImageUrl
;
}
}
public
void
refreshNickName
()
{
public
void
refreshNickName
()
{
setValueToNickName
();
setValueToNickName
();
}
}
//跳转修改密码界面
//跳转修改密码界面
public
BindingCommand
goChangePwd
=
new
BindingCommand
(
new
BindingAction
()
{
public
BindingCommand
goChangePwd
=
new
BindingCommand
(
new
BindingAction
()
{
@Override
@Override
...
@@ -138,13 +141,12 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -138,13 +141,12 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
}
}
});
});
public
void
goUserinfo
(
View
view
)
public
void
goUserinfo
(
View
view
)
{
{
startActivity
(
UserInfoActivity
.
class
);
startActivity
(
UserInfoActivity
.
class
);
}
}
public
void
clearCookie
(
View
view
)
{
public
void
clearCookie
(
View
view
)
{
PersistentCookieStore
p
=
new
PersistentCookieStore
(
view
.
getContext
());
PersistentCookieStore
p
=
new
PersistentCookieStore
(
view
.
getContext
());
p
.
removeAllCookie
();
p
.
removeAllCookie
();
ToastUtils
.
showShort
(
"清除缓存成功"
);
ToastUtils
.
showShort
(
"清除缓存成功"
);
}
}
...
@@ -152,10 +154,10 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -152,10 +154,10 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
/**
/**
* 获取最新APK版本号
* 获取最新APK版本号
*
* @param view
* @param view
*/
*/
public
void
checkVersion
(
View
view
)
public
void
checkVersion
(
View
view
)
{
{
model
.
checkVersion
().
compose
(
RxUtils
.
schedulersTransformer
())
//线程调度
model
.
checkVersion
().
compose
(
RxUtils
.
schedulersTransformer
())
//线程调度
...
@@ -168,14 +170,12 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -168,14 +170,12 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
@Override
@Override
public
void
onSuccess
(
VersionBean
resultBean
)
{
public
void
onSuccess
(
VersionBean
resultBean
)
{
if
(
CommUtilsKt
.
checkVersionUpdata
(
CommUtilsKt
.
getVersion
(
view
.
getContext
()),
resultBean
.
getAppVersion
()))
if
(
CommUtilsKt
.
checkVersionUpdata
(
CommUtilsKt
.
getVersion
(
view
.
getContext
()),
resultBean
.
getAppVersion
()))
{
{
//不强制
//不强制
if
(
resultBean
.
getPushFlag
().
equals
(
"0"
))
if
(
resultBean
.
getPushFlag
().
equals
(
"0"
))
{
{
showCommTextDialog
(
new
RefuseDialogBean
(
"是否前往更新"
,
"确定"
,
"取消"
,
"更新提示"
),
new
CommTextDialog
.
onAcceptCallBack
()
{
showCommTextDialog
(
new
RefuseDialogBean
(
"是否前往更新"
,
"确定"
,
"取消"
,
"更新提示"
),
new
CommTextDialog
.
onAcceptCallBack
()
{
@Override
@Override
public
void
refuseBack
()
{
public
void
refuseBack
()
{
...
@@ -208,11 +208,11 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -208,11 +208,11 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
}
}
});
});
}
else
{
}
else
{
showCommTextDialog
(
new
RefuseDialogBean
(
"请前往更新"
,
"确定"
,
null
),
new
CommTextDialog
.
onAcceptCallBack
()
{
showCommTextDialog
(
new
RefuseDialogBean
(
"请前往更新"
,
"确定"
,
null
),
new
CommTextDialog
.
onAcceptCallBack
()
{
@Override
@Override
public
void
refuseBack
()
{
public
void
refuseBack
()
{
finish
();
}
}
@Override
@Override
...
@@ -243,7 +243,7 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -243,7 +243,7 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
});
});
}
}
}
else
{
}
else
{
ToastUtils
.
showShort
(
"版本已是最新!"
);
ToastUtils
.
showShort
(
"版本已是最新!"
);
}
}
...
@@ -260,17 +260,17 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -260,17 +260,17 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
/**
/**
* 下载APK
* 下载APK
*
* @param context
* @param context
* @param url 下载地址
* @param url
下载地址
* @param name 文件名字
* @param name
文件名字
*/
*/
public
void
updataApk
(
Context
context
,
String
url
,
String
name
)
public
void
updataApk
(
Context
context
,
String
url
,
String
name
)
{
{
showDialog
();
showDialog
();
model
.
downFile
(
url
,
name
).
subscribe
(
new
Observer
<
ResponseBody
>()
{
model
.
downFile
(
url
,
name
).
subscribe
(
new
Observer
<
ResponseBody
>()
{
@Override
@Override
public
void
onSubscribe
(
@io
.
reactivex
.
rxjava3
.
annotations
.
NonNull
Disposable
d
)
{
public
void
onSubscribe
(
@io
.
reactivex
.
rxjava3
.
annotations
.
NonNull
Disposable
d
)
{
Log
.
e
(
"下载"
,
"onSubscribe"
);
Log
.
e
(
"下载"
,
"onSubscribe"
);
}
}
@Override
@Override
...
@@ -286,10 +286,10 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -286,10 +286,10 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
@Override
@Override
public
void
onComplete
()
{
public
void
onComplete
()
{
Log
.
e
(
"下载"
,
"onComplete"
);
Log
.
e
(
"下载"
,
"onComplete"
);
dismissDialog
();
dismissDialog
();
ToastUtils
.
showShort
(
"下载成功"
);
ToastUtils
.
showShort
(
"下载成功"
);
installApk
(
context
,
name
);
installApk
(
context
,
name
);
}
}
});
});
}
}
...
@@ -309,11 +309,9 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -309,11 +309,9 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
context
.
startActivity
(
intent
);
context
.
startActivity
(
intent
);
}
}
public
void
goProtocol
(
View
view
)
public
void
goProtocol
(
View
view
)
{
{
if
(
StaticData
.
Protocols
.
size
()
>=
3
)
{
if
(
StaticData
.
Protocols
.
size
()>=
3
)
Bundle
bundle
=
new
Bundle
();
{
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
"title"
,
"隐私条款"
);
bundle
.
putString
(
"title"
,
"隐私条款"
);
bundle
.
putString
(
"URL"
,
RetrofitClient
.
baseH5Url
+
StaticData
.
Protocols
.
get
(
2
));
bundle
.
putString
(
"URL"
,
RetrofitClient
.
baseH5Url
+
StaticData
.
Protocols
.
get
(
2
));
startActivity
(
CommWabActivity
.
class
,
bundle
);
startActivity
(
CommWabActivity
.
class
,
bundle
);
...
...
hbhbcompany/src/main/java/com/xx/hbhbcompany/data/http/requst/HomeRequest.java
View file @
61142e3b
...
@@ -8,6 +8,8 @@ import com.xx.hbhbcompany.data.http.respons.ConsultationInformationBean;
...
@@ -8,6 +8,8 @@ import com.xx.hbhbcompany.data.http.respons.ConsultationInformationBean;
import
com.xx.hbhbcompany.data.http.respons.ConsultationTitleBean
;
import
com.xx.hbhbcompany.data.http.respons.ConsultationTitleBean
;
import
com.xx.hbhbcompany.data.http.respons.JobInformationBean
;
import
com.xx.hbhbcompany.data.http.respons.JobInformationBean
;
import
com.xx.hbhbcompany.data.http.respons.MessageBean
;
import
com.xx.hbhbcompany.data.http.respons.MessageBean
;
import
com.xx.xxviewlibrary.model.VersionBean
;
import
com.xx.xxviewlibrary.model.VersionBody
;
import
java.util.List
;
import
java.util.List
;
...
@@ -18,9 +20,20 @@ import me.goldze.mvvmhabit.http.BaseResponse;
...
@@ -18,9 +20,20 @@ import me.goldze.mvvmhabit.http.BaseResponse;
import
okhttp3.RequestBody
;
import
okhttp3.RequestBody
;
public
class
HomeRequest
extends
BaseRespons
{
public
class
HomeRequest
extends
BaseRespons
{
/** * 获取消息列表 */
/**
public
Observable
<
BasePageResponse
<
MessageBean
>>
getMessageList
(
String
flag
,
Integer
page
)
{
* 获取消息列表
return
getApiService
().
getMessageList
(
flag
,
page
);
*/
public
Observable
<
BasePageResponse
<
MessageBean
>>
getMessageList
(
String
flag
,
Integer
page
)
{
return
getApiService
().
getMessageList
(
flag
,
page
);
}
/**
* 强制更新
*/
public
Observable
<
BaseResponse
<
VersionBean
>>
checkVersion
()
{
return
getApiService
().
getLineVersion
(
new
ApiParams
<
VersionBody
>().
setParams
(
new
VersionBody
(
"1"
,
"2"
)
));
}
}
/**
/**
...
@@ -31,20 +44,20 @@ public class HomeRequest extends BaseRespons {
...
@@ -31,20 +44,20 @@ public class HomeRequest extends BaseRespons {
ApiParams
<
HomeRequestBody
>
apiParams
=
new
ApiParams
<
HomeRequestBody
>();
ApiParams
<
HomeRequestBody
>
apiParams
=
new
ApiParams
<
HomeRequestBody
>();
HomeRequestBody
requestBody
=
new
HomeRequestBody
(
"2"
);
HomeRequestBody
requestBody
=
new
HomeRequestBody
(
"2"
);
RequestBody
body
=
apiParams
.
setParams
(
requestBody
);
RequestBody
body
=
apiParams
.
setParams
(
requestBody
);
return
getApiService
().
getActivityList
(
body
,
page
);
return
getApiService
().
getActivityList
(
body
,
page
);
}
}
/**
/**
* 招聘列表
* 招聘列表
*/
*/
public
Observable
<
BasePageResponse
<
JobInformationBean
>>
getJobInformationList
(
String
recruitment
)
public
Observable
<
BasePageResponse
<
JobInformationBean
>>
getJobInformationList
(
String
recruitment
)
{
{
ApiParams
<
JobRequestBody
>
apiParams
=
new
ApiParams
<
JobRequestBody
>();
ApiParams
<
JobRequestBody
>
apiParams
=
new
ApiParams
<
JobRequestBody
>();
JobRequestBody
requestBody
=
new
JobRequestBody
(
recruitment
);
JobRequestBody
requestBody
=
new
JobRequestBody
(
recruitment
);
RequestBody
body
=
apiParams
.
setParams
(
requestBody
);
RequestBody
body
=
apiParams
.
setParams
(
requestBody
);
return
getApiService
().
getJobInformationList
(
body
,
1
);
return
getApiService
().
getJobInformationList
(
body
,
1
);
}
}
/**
/**
* 资讯列表
* 资讯列表
*/
*/
...
@@ -62,8 +75,8 @@ public class HomeRequest extends BaseRespons {
...
@@ -62,8 +75,8 @@ public class HomeRequest extends BaseRespons {
*/
*/
public
Observable
<
BaseResponse
<
List
<
AdvertisingBean
>>>
getAdList
()
{
public
Observable
<
BaseResponse
<
List
<
AdvertisingBean
>>>
getAdList
()
{
ApiParams
<
AdvertisingRequestBody
>
apiParams
=
new
ApiParams
<
AdvertisingRequestBody
>();
ApiParams
<
AdvertisingRequestBody
>
apiParams
=
new
ApiParams
<
AdvertisingRequestBody
>();
AdvertisingRequestBody
requestBody
=
new
AdvertisingRequestBody
(
"1"
,
"3"
);
AdvertisingRequestBody
requestBody
=
new
AdvertisingRequestBody
(
"1"
,
"3"
);
RequestBody
body
=
apiParams
.
setParams
(
requestBody
);
RequestBody
body
=
apiParams
.
setParams
(
requestBody
);
return
getApiService
().
getADList
(
body
);
return
getApiService
().
getADList
(
body
);
}
}
...
@@ -84,10 +97,12 @@ public class HomeRequest extends BaseRespons {
...
@@ -84,10 +97,12 @@ public class HomeRequest extends BaseRespons {
*/
*/
public
class
ConsultationRequestBody
{
public
class
ConsultationRequestBody
{
public
String
appSide
;
public
String
appSide
;
public
ConsultationRequestBody
(
String
appSide
)
{
public
ConsultationRequestBody
(
String
appSide
)
{
this
.
appSide
=
appSide
;
this
.
appSide
=
appSide
;
}
}
}
}
/**
/**
* 不需要传参
* 不需要传参
*/
*/
...
@@ -100,6 +115,7 @@ public class HomeRequest extends BaseRespons {
...
@@ -100,6 +115,7 @@ public class HomeRequest extends BaseRespons {
this
.
recruitmentType
=
recruitmentType
;
this
.
recruitmentType
=
recruitmentType
;
}
}
}
}
/**
/**
* 获取广告列表
* 获取广告列表
* affiliatedCompany string 所属公司 1- 河西 2-滨海
* affiliatedCompany string 所属公司 1- 河西 2-滨海
...
@@ -109,7 +125,7 @@ public class HomeRequest extends BaseRespons {
...
@@ -109,7 +125,7 @@ public class HomeRequest extends BaseRespons {
public
String
affiliatedCompany
;
public
String
affiliatedCompany
;
public
String
rotographDisplay
;
public
String
rotographDisplay
;
public
AdvertisingRequestBody
(
String
affiliatedCompany
,
String
rotographDisplay
)
{
public
AdvertisingRequestBody
(
String
affiliatedCompany
,
String
rotographDisplay
)
{
this
.
affiliatedCompany
=
affiliatedCompany
;
this
.
affiliatedCompany
=
affiliatedCompany
;
this
.
rotographDisplay
=
rotographDisplay
;
this
.
rotographDisplay
=
rotographDisplay
;
}
}
...
@@ -118,6 +134,7 @@ public class HomeRequest extends BaseRespons {
...
@@ -118,6 +134,7 @@ public class HomeRequest extends BaseRespons {
/**
/**
* 添加浏览数
* 添加浏览数
*
* @param id 咨询id
* @param id 咨询id
* @return
* @return
*/
*/
...
@@ -125,6 +142,6 @@ public class HomeRequest extends BaseRespons {
...
@@ -125,6 +142,6 @@ public class HomeRequest extends BaseRespons {
ApiParams
<
PointOrderDetailRequest
.
ConfirmReceiptRequestBody
>
apiParams
=
new
ApiParams
<
PointOrderDetailRequest
.
ConfirmReceiptRequestBody
>();
ApiParams
<
PointOrderDetailRequest
.
ConfirmReceiptRequestBody
>
apiParams
=
new
ApiParams
<
PointOrderDetailRequest
.
ConfirmReceiptRequestBody
>();
return
getApiService
().
addLook
(
apiParams
.
setParams
(
new
PointOrderDetailRequest
.
ConfirmReceiptRequestBody
(
id
,
null
)));
return
getApiService
().
addLook
(
apiParams
.
setParams
(
new
PointOrderDetailRequest
.
ConfirmReceiptRequestBody
(
id
,
null
)));
}
}
}
}
hbhbcompany/src/main/java/com/xx/hbhbcompany/data/http/requst/WorkRequest.kt
View file @
61142e3b
...
@@ -6,6 +6,8 @@ import com.xx.hbhbcompany.data.http.respons.UserBean
...
@@ -6,6 +6,8 @@ import com.xx.hbhbcompany.data.http.respons.UserBean
import
com.xx.hbhbcompany.data.http.respons.WorkBean
import
com.xx.hbhbcompany.data.http.respons.WorkBean
import
com.xx.hbhbcompany.data.local.LocalData
import
com.xx.hbhbcompany.data.local.LocalData
import
com.xx.hbhbcompany.data.staticdata.StaticData
import
com.xx.hbhbcompany.data.staticdata.StaticData
import
com.xx.xxviewlibrary.model.VersionBean
import
com.xx.xxviewlibrary.model.VersionBody
import
io.reactivex.rxjava3.core.Observable
import
io.reactivex.rxjava3.core.Observable
import
me.goldze.mvvmhabit.http.ApiParams
import
me.goldze.mvvmhabit.http.ApiParams
import
me.goldze.mvvmhabit.http.BasePageResponse
import
me.goldze.mvvmhabit.http.BasePageResponse
...
@@ -14,7 +16,16 @@ import me.goldze.mvvmhabit.http.BaseResponse
...
@@ -14,7 +16,16 @@ import me.goldze.mvvmhabit.http.BaseResponse
class
WorkRequest
:
BaseRespons
()
{
class
WorkRequest
:
BaseRespons
()
{
var
user
:
UserBean
=
LocalData
.
getUser
();
var
user
:
UserBean
=
LocalData
.
getUser
();
/**
* 强制更新
*/
fun
checkVersion
():
Observable
<
BaseResponse
<
VersionBean
>>
{
return
apiService
.
getLineVersion
(
ApiParams
<
VersionBody
>().
setParams
(
VersionBody
(
"1"
,
"2"
)
)
)
}
fun
getMerchantAuditList
(
fun
getMerchantAuditList
(
static
:
String
,
static
:
String
,
pageNum
:
Int
pageNum
:
Int
...
...
hbhbcompany/src/main/java/com/xx/hbhbcompany/ui/home/HomeFragment.java
View file @
61142e3b
...
@@ -6,7 +6,11 @@ import static me.goldze.mvvmhabit.utils.Utils.Interceptor_TOKEN;
...
@@ -6,7 +6,11 @@ import static me.goldze.mvvmhabit.utils.Utils.Interceptor_TOKEN;
import
android.Manifest
;
import
android.Manifest
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.os.Environment
;
import
android.provider.Settings
;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
...
@@ -48,6 +52,34 @@ import me.tatarka.bindingcollectionadapter2.BR;
...
@@ -48,6 +52,34 @@ import me.tatarka.bindingcollectionadapter2.BR;
public
class
HomeFragment
extends
BaseFragment
<
FragmentHomeBinding
,
HomeViewModel
>
{
public
class
HomeFragment
extends
BaseFragment
<
FragmentHomeBinding
,
HomeViewModel
>
{
@Override
public
void
onResume
()
{
super
.
onResume
();
// 检查版本
viewModel
.
rxPermissions
=
new
RxPermissions
(
this
);
/*检查版本*/
viewModel
.
checkVersion
(
binding
.
getRoot
().
getRootView
());
// 安装新版本
viewModel
.
openInstall
.
observe
(
this
,
new
Observer
<
String
>()
{
@Override
public
void
onChanged
(
String
s
)
{
if
(
"1"
.
equals
(
s
))
{
Uri
packageURI
=
Uri
.
parse
(
"package:"
+
getContext
().
getPackageName
());
Intent
intent
=
new
Intent
(
Settings
.
ACTION_MANAGE_UNKNOWN_APP_SOURCES
,
packageURI
);
startActivityForResult
(
intent
,
1002
);
}
}
});
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
R
)
{
if
(!
Environment
.
isExternalStorageManager
())
{
Intent
intent
=
new
Intent
(
Settings
.
ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
);
intent
.
setData
(
Uri
.
parse
(
"package:"
+
getContext
().
getPackageName
()));
startActivityForResult
(
intent
,
1024
);
}
}
}
// 重写初始方法调用参数
// 重写初始方法调用参数
@Override
@Override
public
void
initData
()
{
public
void
initData
()
{
...
...
hbhbcompany/src/main/java/com/xx/hbhbcompany/ui/home/HomeViewModel.java
View file @
61142e3b
This diff is collapsed.
Click to expand it.
hbhbcompany/src/main/java/com/xx/hbhbcompany/ui/login/LoginActivity.kt
View file @
61142e3b
...
@@ -56,13 +56,13 @@ class LoginActivity() : BaseActivity<ActivityLoginBinding, LoginViewModel>() {
...
@@ -56,13 +56,13 @@ class LoginActivity() : BaseActivity<ActivityLoginBinding, LoginViewModel>() {
// 使用SharedPreferences检查是否是第一次打开应用
// 使用SharedPreferences检查是否是第一次打开应用
val
preferences
=
getPreferences
(
Context
.
MODE_PRIVATE
)
val
preferences
=
getPreferences
(
Context
.
MODE_PRIVATE
)
val
isAgreeFlag
=
preferences
.
getBoolean
(
"is_agree_flag"
,
true
)
val
isAgreeFlag
=
preferences
.
getBoolean
(
"is_agree_flag"
,
true
)
if
(
isAgreeFlag
)
{
/*
if (isAgreeFlag) {
// 如果是第一次打开应用,执行相应的操作
// 如果是第一次打开应用,执行相应的操作
// ToastUtils.showShort("第一次登录")
// ToastUtils.showShort("第一次登录")
viewModel.agreeContent.observe(this) { agreeContent: String? ->
viewModel.agreeContent.observe(this) { agreeContent: String? ->
if (agreeContent != null) {
if (agreeContent != null) {
agreementContext = agreeContent
agreementContext = agreeContent
/*在这里加上隐私协议弹窗*/
*//*在这里加上隐私协议弹窗*//*
showCommTextAgreeDialog(
showCommTextAgreeDialog(
RefuseDialogBean(agreementContext, "同意", "不同意", "隐私条款"),
RefuseDialogBean(agreementContext, "同意", "不同意", "隐私条款"),
object : CommTextDialog.onAcceptCallBack, CommTextAgreeDialog.onAcceptCallBack {
object : CommTextDialog.onAcceptCallBack, CommTextAgreeDialog.onAcceptCallBack {
...
@@ -86,7 +86,7 @@ class LoginActivity() : BaseActivity<ActivityLoginBinding, LoginViewModel>() {
...
@@ -86,7 +86,7 @@ class LoginActivity() : BaseActivity<ActivityLoginBinding, LoginViewModel>() {
}
}
}else{
}else{
viewModel.checkVersion(binding.root.rootView)
viewModel.checkVersion(binding.root.rootView)
}
}
*/
/*强制更新标识位变更--重置用户登录*/
/*强制更新标识位变更--重置用户登录*/
StaticData
.
updateLogin
=
1
StaticData
.
updateLogin
=
1
// 安装新版本
// 安装新版本
...
...
hbhbcompany/src/main/java/com/xx/hbhbcompany/ui/mine/MineFragment.java
View file @
61142e3b
...
@@ -4,7 +4,9 @@ import static com.xx.hbhbcompany.utils.RetrofitClient.baseImgUrl;
...
@@ -4,7 +4,9 @@ import static com.xx.hbhbcompany.utils.RetrofitClient.baseImgUrl;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.os.Environment
;
import
android.provider.Settings
;
import
android.provider.Settings
;
import
android.util.Log
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
...
@@ -30,6 +32,7 @@ import me.goldze.mvvmhabit.base.BaseFragment;
...
@@ -30,6 +32,7 @@ import me.goldze.mvvmhabit.base.BaseFragment;
import
me.goldze.mvvmhabit.utils.StringUtils
;
import
me.goldze.mvvmhabit.utils.StringUtils
;
public
class
MineFragment
extends
BaseFragment
<
FragmentMineBinding
,
MineViewModel
>
{
public
class
MineFragment
extends
BaseFragment
<
FragmentMineBinding
,
MineViewModel
>
{
@Override
@Override
public
int
viewModelType
()
{
public
int
viewModelType
()
{
return
0
;
return
0
;
...
@@ -100,7 +103,28 @@ public class MineFragment extends BaseFragment<FragmentMineBinding, MineViewMode
...
@@ -100,7 +103,28 @@ public class MineFragment extends BaseFragment<FragmentMineBinding, MineViewMode
@Override
@Override
public
void
onResume
()
{
public
void
onResume
()
{
super
.
onResume
();
super
.
onResume
();
viewModel
.
refreshNickName
();
// 检查版本
viewModel
.
rxPermissions
=
new
RxPermissions
(
this
);
/*检查版本*/
viewModel
.
checkVersion
(
binding
.
getRoot
().
getRootView
());
// 安装新版本
viewModel
.
openInstall
.
observe
(
this
,
new
Observer
<
String
>()
{
@Override
public
void
onChanged
(
String
s
)
{
if
(
"1"
.
equals
(
s
))
{
Uri
packageURI
=
Uri
.
parse
(
"package:"
+
getContext
().
getPackageName
());
Intent
intent
=
new
Intent
(
Settings
.
ACTION_MANAGE_UNKNOWN_APP_SOURCES
,
packageURI
);
startActivityForResult
(
intent
,
1002
);
}
}
}
});
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
R
)
{
if
(!
Environment
.
isExternalStorageManager
())
{
Intent
intent
=
new
Intent
(
Settings
.
ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
);
intent
.
setData
(
Uri
.
parse
(
"package:"
+
getContext
().
getPackageName
()));
startActivityForResult
(
intent
,
1024
);
}
}
}
}
}
hbhbcompany/src/main/java/com/xx/hbhbcompany/ui/mine/MineViewModel.java
View file @
61142e3b
...
@@ -51,7 +51,7 @@ import okhttp3.ResponseBody;
...
@@ -51,7 +51,7 @@ import okhttp3.ResponseBody;
public
class
MineViewModel
extends
BaseViewModel
<
MineRequest
>
{
public
class
MineViewModel
extends
BaseViewModel
<
MineRequest
>
{
RxPermissions
rxPermissions
;
RxPermissions
rxPermissions
;
public
MutableLiveData
<
String
>
openInstall
=
new
MutableLiveData
<>(
""
);
//头像的绑定
//头像的绑定
private
MutableLiveData
<
String
>
avatarImageUrl
=
new
MutableLiveData
<>();
private
MutableLiveData
<
String
>
avatarImageUrl
=
new
MutableLiveData
<>();
//昵称的绑定
//昵称的绑定
...
@@ -61,14 +61,14 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -61,14 +61,14 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
//职位的绑定
//职位的绑定
public
ObservableField
<
String
>
roleName
=
new
ObservableField
<>(
""
);
public
ObservableField
<
String
>
roleName
=
new
ObservableField
<>(
""
);
public
MutableLiveData
<
String
>
openInstall
=
new
MutableLiveData
<>(
""
);
//版本号
//版本号
public
ObservableField
<
String
>
versionName
=
new
ObservableField
<>(
""
);
public
ObservableField
<
String
>
versionName
=
new
ObservableField
<>(
""
);
public
MineViewModel
(
@NonNull
Application
application
)
{
public
MineViewModel
(
@NonNull
Application
application
)
{
super
(
application
);
super
(
application
);
}
}
public
MineViewModel
(
@NonNull
Application
application
,
MineRequest
model
)
{
public
MineViewModel
(
@NonNull
Application
application
,
MineRequest
model
)
{
super
(
application
,
model
);
super
(
application
,
model
);
}
}
...
@@ -83,6 +83,7 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -83,6 +83,7 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
public
void
refreshNickName
()
{
public
void
refreshNickName
()
{
setValueToNickName
();
setValueToNickName
();
}
}
/*头像回显*/
/*头像回显*/
public
LiveData
<
String
>
getAvatarImageUrl
()
{
public
LiveData
<
String
>
getAvatarImageUrl
()
{
return
avatarImageUrl
;
return
avatarImageUrl
;
...
@@ -124,8 +125,7 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -124,8 +125,7 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
});
});
public
void
exitLogin
(
View
view
)
public
void
exitLogin
(
View
view
)
{
{
showCommTextDialog
(
new
RefuseDialogBean
(
"是否确定退出?"
,
"确定"
,
"取消"
),
new
CommTextDialog
.
onAcceptCallBack
()
{
showCommTextDialog
(
new
RefuseDialogBean
(
"是否确定退出?"
,
"确定"
,
"取消"
),
new
CommTextDialog
.
onAcceptCallBack
()
{
@Override
@Override
...
@@ -142,9 +142,8 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -142,9 +142,8 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
}
}
public
void
clearCookie
(
View
view
)
public
void
clearCookie
(
View
view
)
{
{
PersistentCookieStore
p
=
new
PersistentCookieStore
(
view
.
getContext
());
PersistentCookieStore
p
=
new
PersistentCookieStore
(
view
.
getContext
());
p
.
removeAllCookie
();
p
.
removeAllCookie
();
ToastUtils
.
showShort
(
"清除缓存成功"
);
ToastUtils
.
showShort
(
"清除缓存成功"
);
}
}
...
@@ -152,10 +151,10 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -152,10 +151,10 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
/**
/**
* 获取最新APK版本号
* 获取最新APK版本号
*
* @param view
* @param view
*/
*/
public
void
checkVersion
(
View
view
)
public
void
checkVersion
(
View
view
)
{
{
model
.
checkVersion
().
compose
(
RxUtils
.
schedulersTransformer
())
//线程调度
model
.
checkVersion
().
compose
(
RxUtils
.
schedulersTransformer
())
//线程调度
.
doOnSubscribe
(
MineViewModel
.
this
)
.
doOnSubscribe
(
MineViewModel
.
this
)
.
doOnSubscribe
(
new
Consumer
<
Disposable
>()
{
.
doOnSubscribe
(
new
Consumer
<
Disposable
>()
{
...
@@ -166,12 +165,10 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -166,12 +165,10 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
@Override
@Override
public
void
onSuccess
(
VersionBean
resultBean
)
{
public
void
onSuccess
(
VersionBean
resultBean
)
{
if
(
CommUtilsKt
.
checkVersionUpdata
(
CommUtilsKt
.
getVersion
(
view
.
getContext
()),
resultBean
.
getAppVersion
()))
if
(
CommUtilsKt
.
checkVersionUpdata
(
CommUtilsKt
.
getVersion
(
view
.
getContext
()),
resultBean
.
getAppVersion
()))
{
{
//不强制
//不强制
if
(
resultBean
.
getPushFlag
().
equals
(
"0"
))
if
(
resultBean
.
getPushFlag
().
equals
(
"0"
))
{
{
showCommTextDialog
(
new
RefuseDialogBean
(
"是否前往更新"
,
"确定"
,
"取消"
,
"更新提示"
),
new
CommTextDialog
.
onAcceptCallBack
()
{
showCommTextDialog
(
new
RefuseDialogBean
(
"是否前往更新"
,
"确定"
,
"取消"
,
"更新提示"
),
new
CommTextDialog
.
onAcceptCallBack
()
{
@Override
@Override
public
void
refuseBack
()
{
public
void
refuseBack
()
{
...
@@ -205,11 +202,11 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -205,11 +202,11 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
}
}
});
});
}
else
{
}
else
{
showCommTextDialog
(
new
RefuseDialogBean
(
"请前往更新"
,
"确定"
,
null
),
new
CommTextDialog
.
onAcceptCallBack
()
{
showCommTextDialog
(
new
RefuseDialogBean
(
"请前往更新"
,
"确定"
,
null
),
new
CommTextDialog
.
onAcceptCallBack
()
{
@Override
@Override
public
void
refuseBack
()
{
public
void
refuseBack
()
{
finish
();
}
}
@Override
@Override
...
@@ -231,7 +228,7 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -231,7 +228,7 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
});
});
}
}
}
else
{
}
else
{
ToastUtils
.
showShort
(
"版本已是最新!"
);
ToastUtils
.
showShort
(
"版本已是最新!"
);
}
}
}
}
...
@@ -246,17 +243,17 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -246,17 +243,17 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
/**
/**
* 下载APK
* 下载APK
*
* @param context
* @param context
* @param url 下载地址
* @param url
下载地址
* @param name 文件名字
* @param name
文件名字
*/
*/
public
void
updataApk
(
Context
context
,
String
url
,
String
name
)
public
void
updataApk
(
Context
context
,
String
url
,
String
name
)
{
{
showDialog
();
showDialog
();
model
.
downFile
(
url
,
name
).
subscribe
(
new
Observer
<
ResponseBody
>()
{
model
.
downFile
(
url
,
name
).
subscribe
(
new
Observer
<
ResponseBody
>()
{
@Override
@Override
public
void
onSubscribe
(
@io
.
reactivex
.
rxjava3
.
annotations
.
NonNull
Disposable
d
)
{
public
void
onSubscribe
(
@io
.
reactivex
.
rxjava3
.
annotations
.
NonNull
Disposable
d
)
{
Log
.
e
(
"下载"
,
"onSubscribe"
);
Log
.
e
(
"下载"
,
"onSubscribe"
);
}
}
@Override
@Override
...
@@ -272,18 +269,18 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -272,18 +269,18 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
@Override
@Override
public
void
onComplete
()
{
public
void
onComplete
()
{
Log
.
e
(
"下载"
,
"onComplete"
);
Log
.
e
(
"下载"
,
"onComplete"
);
dismissDialog
();
dismissDialog
();
ToastUtils
.
showShort
(
"下载成功"
);
ToastUtils
.
showShort
(
"下载成功"
);
installApk
(
context
,
name
);
installApk
(
context
,
name
);
}
}
});
});
}
}
//跳转安装APP
//跳转安装APP
private
void
installApk
(
Context
context
,
String
path
)
{
private
void
installApk
(
Context
context
,
String
path
)
{
Intent
intent
=
new
Intent
(
Intent
.
ACTION_VIEW
);
Intent
intent
=
new
Intent
(
Intent
.
ACTION_VIEW
);
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
File
file
=
new
File
(
Uri
.
parse
(
path
).
getPath
());
File
file
=
new
File
(
Uri
.
parse
(
path
).
getPath
());
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
N
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
N
)
{
intent
.
setFlags
(
Intent
.
FLAG_GRANT_READ_URI_PERMISSION
);
intent
.
setFlags
(
Intent
.
FLAG_GRANT_READ_URI_PERMISSION
);
...
@@ -292,16 +289,14 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
...
@@ -292,16 +289,14 @@ public class MineViewModel extends BaseViewModel<MineRequest> {
}
else
{
}
else
{
intent
.
setDataAndType
(
Uri
.
fromFile
(
file
),
"application/vnd.android.package-archive"
);
intent
.
setDataAndType
(
Uri
.
fromFile
(
file
),
"application/vnd.android.package-archive"
);
}
}
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
// Adding the flag here
context
.
startActivity
(
intent
);
context
.
startActivity
(
intent
);
}
}
public
void
goProtocol
(
View
view
)
public
void
goProtocol
(
View
view
)
{
{
if
(
StaticData
.
Protocols
.
size
()
>=
3
)
{
if
(
StaticData
.
Protocols
.
size
()>=
3
)
Bundle
bundle
=
new
Bundle
();
{
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
"title"
,
"隐私条款"
);
bundle
.
putString
(
"title"
,
"隐私条款"
);
bundle
.
putString
(
"URL"
,
RetrofitClient
.
baseH5Url
+
StaticData
.
Protocols
.
get
(
2
));
bundle
.
putString
(
"URL"
,
RetrofitClient
.
baseH5Url
+
StaticData
.
Protocols
.
get
(
2
));
startActivity
(
CommWabActivity
.
class
,
bundle
);
startActivity
(
CommWabActivity
.
class
,
bundle
);
...
...
hbhbcompany/src/main/java/com/xx/hbhbcompany/ui/work/WorkFragment.java
View file @
61142e3b
package
com
.
xx
.
hbhbcompany
.
ui
.
work
;
package
com
.
xx
.
hbhbcompany
.
ui
.
work
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.os.Environment
;
import
android.provider.Settings
;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.Nullable
;
import
androidx.lifecycle.Observer
;
import
androidx.lifecycle.Observer
;
import
com.tbruyelle.rxpermissions3.RxPermissions
;
import
com.xx.hbhbcompany.BR
;
import
com.xx.hbhbcompany.BR
;
import
com.xx.hbhbcompany.R
;
import
com.xx.hbhbcompany.R
;
import
com.xx.hbhbcompany.activity.adapter.WorkIconsAdapter
;
import
com.xx.hbhbcompany.activity.adapter.WorkIconsAdapter
;
...
@@ -97,7 +103,30 @@ public class WorkFragment extends BaseFragment<FragmentWorkBinding, WorkViewMode
...
@@ -97,7 +103,30 @@ public class WorkFragment extends BaseFragment<FragmentWorkBinding, WorkViewMode
@Override
@Override
public
void
onResume
()
{
public
void
onResume
()
{
super
.
onResume
();
super
.
onResume
();
/*调取工作台三个统计数接口*/
// 调取工作台三个统计数接口
viewModel
.
getWorkNumber
();
viewModel
.
getWorkNumber
();
// 检查版本
viewModel
.
rxPermissions
=
new
RxPermissions
(
this
);
// 检查版本
viewModel
.
checkVersion
(
binding
.
getRoot
().
getRootView
());
// 安装新版本
viewModel
.
openInstall
.
observe
(
this
,
new
Observer
<
String
>()
{
@Override
public
void
onChanged
(
String
s
)
{
if
(
"1"
.
equals
(
s
))
{
Uri
packageURI
=
Uri
.
parse
(
"package:"
+
getContext
().
getPackageName
());
Intent
intent
=
new
Intent
(
Settings
.
ACTION_MANAGE_UNKNOWN_APP_SOURCES
,
packageURI
);
startActivityForResult
(
intent
,
1002
);
}
}
});
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
R
)
{
if
(!
Environment
.
isExternalStorageManager
())
{
Intent
intent
=
new
Intent
(
Settings
.
ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
);
intent
.
setData
(
Uri
.
parse
(
"package:"
+
getContext
().
getPackageName
()));
startActivityForResult
(
intent
,
1024
);
}
}
}
}
}
}
hbhbcompany/src/main/java/com/xx/hbhbcompany/ui/work/WorkViewModel.java
View file @
61142e3b
package
com
.
xx
.
hbhbcompany
.
ui
.
work
;
package
com
.
xx
.
hbhbcompany
.
ui
.
work
;
import
android.Manifest
;
import
android.app.Application
;
import
android.app.Application
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.view.View
;
import
android.view.View
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.NonNull
;
import
androidx.core.content.FileProvider
;
import
androidx.databinding.ObservableField
;
import
androidx.databinding.ObservableField
;
import
androidx.lifecycle.MutableLiveData
;
import
androidx.lifecycle.MutableLiveData
;
import
com.tbruyelle.rxpermissions3.RxPermissions
;
import
com.xx.hbhbcompany.R
;
import
com.xx.hbhbcompany.R
;
import
com.xx.hbhbcompany.activity.adapter.WorkIconsAdapter
;
import
com.xx.hbhbcompany.activity.adapter.WorkIconsAdapter
;
import
com.xx.hbhbcompany.data.http.requst.WorkRequest
;
import
com.xx.hbhbcompany.data.http.requst.WorkRequest
;
...
@@ -18,13 +26,20 @@ import com.xx.hbhbcompany.data.local.LocalData;
...
@@ -18,13 +26,20 @@ import com.xx.hbhbcompany.data.local.LocalData;
import
com.xx.hbhbcompany.data.staticdata.StaticData
;
import
com.xx.hbhbcompany.data.staticdata.StaticData
;
import
com.xx.hbhbcompany.ui.appeal.AppealActivity
;
import
com.xx.hbhbcompany.ui.appeal.AppealActivity
;
import
com.xx.hbhbcompany.ui.appeallist.AppealListActivity
;
import
com.xx.hbhbcompany.ui.appeallist.AppealListActivity
;
import
com.xx.hbhbcompany.ui.home.HomeViewModel
;
import
com.xx.hbhbcompany.ui.merchantaudit.MerchantAuditListActivity
;
import
com.xx.hbhbcompany.ui.merchantaudit.MerchantAuditListActivity
;
import
com.xx.hbhbcompany.ui.order.OrderActivity
;
import
com.xx.hbhbcompany.ui.order.OrderActivity
;
import
com.xx.hbhbcompany.ui.productlist.ProductListActivity
;
import
com.xx.hbhbcompany.ui.productlist.ProductListActivity
;
import
com.xx.xxviewlibrary.comm.CommTextDialog
;
import
com.xx.xxviewlibrary.comm.RefuseDialogBean
;
import
com.xx.xxviewlibrary.model.VersionBean
;
import
com.xx.xxviewlibrary.utils.CommUtilsKt
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
io.reactivex.rxjava3.core.Observer
;
import
io.reactivex.rxjava3.disposables.Disposable
;
import
io.reactivex.rxjava3.disposables.Disposable
;
import
io.reactivex.rxjava3.functions.Consumer
;
import
io.reactivex.rxjava3.functions.Consumer
;
import
me.goldze.mvvmhabit.base.BaseViewModel
;
import
me.goldze.mvvmhabit.base.BaseViewModel
;
...
@@ -34,14 +49,158 @@ import me.goldze.mvvmhabit.http.ApiDisposableObserver;
...
@@ -34,14 +49,158 @@ import me.goldze.mvvmhabit.http.ApiDisposableObserver;
import
me.goldze.mvvmhabit.http.ApiDisposablePageObserver
;
import
me.goldze.mvvmhabit.http.ApiDisposablePageObserver
;
import
me.goldze.mvvmhabit.utils.RxUtils
;
import
me.goldze.mvvmhabit.utils.RxUtils
;
import
me.goldze.mvvmhabit.utils.ToastUtils
;
import
me.goldze.mvvmhabit.utils.ToastUtils
;
import
okhttp3.ResponseBody
;
public
class
WorkViewModel
extends
BaseViewModel
<
WorkRequest
>
{
public
class
WorkViewModel
extends
BaseViewModel
<
WorkRequest
>
{
RxPermissions
rxPermissions
;
public
MutableLiveData
<
String
>
openInstall
=
new
MutableLiveData
<>(
""
);
public
String
merchantStatus
=
"0"
;
public
String
merchantStatus
=
"0"
;
public
int
pageNum
=
1
;
public
int
pageNum
=
1
;
public
MutableLiveData
<
List
<
MerchantBean
>>
mAuditList
=
new
MutableLiveData
<>(
new
ArrayList
<>());
public
MutableLiveData
<
List
<
MerchantBean
>>
mAuditList
=
new
MutableLiveData
<>(
new
ArrayList
<>());
/*四个按钮*/
/*四个按钮*/
public
MutableLiveData
<
List
<
WorkIconBean
>>
workIconsList
=
new
MutableLiveData
<>(
new
ArrayList
<>());
public
MutableLiveData
<
List
<
WorkIconBean
>>
workIconsList
=
new
MutableLiveData
<>(
new
ArrayList
<>());
/**
* 获取最新APK版本号
*
* @param view
*/
public
void
checkVersion
(
View
view
)
{
model
.
checkVersion
().
compose
(
RxUtils
.
schedulersTransformer
())
//线程调度
.
doOnSubscribe
(
WorkViewModel
.
this
)
.
doOnSubscribe
(
new
Consumer
<
Disposable
>()
{
@Override
public
void
accept
(
Disposable
disposable
)
throws
Exception
{
}
}).
subscribe
(
new
ApiDisposableObserver
<
VersionBean
>()
{
@Override
public
void
onSuccess
(
VersionBean
resultBean
)
{
if
(
CommUtilsKt
.
checkVersionUpdata
(
CommUtilsKt
.
getVersion
(
view
.
getContext
()),
resultBean
.
getAppVersion
()))
{
//不强制
if
(
resultBean
.
getPushFlag
().
equals
(
"0"
))
{
showCommTextDialog
(
new
RefuseDialogBean
(
"是否前往更新"
,
"确定"
,
"取消"
,
"更新提示"
),
new
CommTextDialog
.
onAcceptCallBack
()
{
@Override
public
void
refuseBack
()
{
}
@Override
public
void
acceptBack
()
{
rxPermissions
.
request
(
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
)
.
subscribe
(
granted
->
{
if
(
granted
)
{
// Always true pre-M
/* rxPermissions
.request(Manifest.permission.REQUEST_INSTALL_PACKAGES)
.subscribe(granteds -> {
if (granteds) { // Always true pre-M
} else {
ToastUtils.showShort("请允许安装外部来源应用");
openInstall.postValue("1");
}
});*/
updataApk
(
view
.
getContext
(),
resultBean
.
getVersionFile
(),
view
.
getContext
().
getFilesDir
().
getPath
()
+
resultBean
.
getVersionFile
().
substring
(
resultBean
.
getVersionFile
().
lastIndexOf
(
"/"
)));
}
else
{
ToastUtils
.
showShort
(
"请开启文件相关权限"
);
}
});
}
});
}
else
{
showCommTextDialog
(
new
RefuseDialogBean
(
"请前往更新"
,
"确定"
,
null
),
new
CommTextDialog
.
onAcceptCallBack
()
{
@Override
public
void
refuseBack
()
{
finish
();
}
@Override
public
void
acceptBack
()
{
rxPermissions
.
request
(
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
)
.
subscribe
(
granted
->
{
if
(
granted
)
{
// Always true pre-M
updataApk
(
view
.
getContext
(),
resultBean
.
getVersionFile
(),
view
.
getContext
().
getFilesDir
().
getPath
()
+
resultBean
.
getVersionFile
().
substring
(
resultBean
.
getVersionFile
().
lastIndexOf
(
"/"
)));
}
else
{
ToastUtils
.
showShort
(
"请开启文件相关权限"
);
}
});
}
});
}
}
else
{
ToastUtils
.
showShort
(
"版本已是最新!"
);
}
}
@Override
public
void
onError
(
String
Error
)
{
}
});
}
/**
* 下载APK
*
* @param context
* @param url 下载地址
* @param name 文件名字
*/
public
void
updataApk
(
Context
context
,
String
url
,
String
name
)
{
showDialog
();
model
.
downFile
(
url
,
name
).
subscribe
(
new
Observer
<
ResponseBody
>()
{
@Override
public
void
onSubscribe
(
@io
.
reactivex
.
rxjava3
.
annotations
.
NonNull
Disposable
d
)
{
Log
.
e
(
"下载"
,
"onSubscribe"
);
}
@Override
public
void
onNext
(
@io
.
reactivex
.
rxjava3
.
annotations
.
NonNull
ResponseBody
responseBody
)
{
}
@Override
public
void
onError
(
@io
.
reactivex
.
rxjava3
.
annotations
.
NonNull
Throwable
e
)
{
ToastUtils
.
showShort
(
"下载失败"
);
dismissDialog
();
}
@Override
public
void
onComplete
()
{
Log
.
e
(
"下载"
,
"onComplete"
);
dismissDialog
();
ToastUtils
.
showShort
(
"下载成功"
);
installApk
(
context
,
name
);
}
});
}
//跳转安装APP
private
void
installApk
(
Context
context
,
String
path
)
{
Intent
intent
=
new
Intent
(
Intent
.
ACTION_VIEW
);
File
file
=
new
File
(
Uri
.
parse
(
path
).
getPath
());
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
N
)
{
intent
.
setFlags
(
Intent
.
FLAG_GRANT_READ_URI_PERMISSION
);
Uri
uri
=
FileProvider
.
getUriForFile
(
context
,
"com.xx.hbhbcompany.fileProvider"
,
file
);
intent
.
setDataAndType
(
uri
,
"application/vnd.android.package-archive"
);
}
else
{
intent
.
setDataAndType
(
Uri
.
fromFile
(
file
),
"application/vnd.android.package-archive"
);
}
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
// Adding the flag here
context
.
startActivity
(
intent
);
}
/*动态添加四个按钮*/
/*动态添加四个按钮*/
public
void
getWorkList
()
{
public
void
getWorkList
()
{
List
<
WorkIconBean
>
list
=
workIconsList
.
getValue
();
// 获取List对象
List
<
WorkIconBean
>
list
=
workIconsList
.
getValue
();
// 获取List对象
...
...
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