parent
6a3d5594ea
commit
86bc47ca7f
|
|
@ -112,6 +112,8 @@ class MainActivity : ComponentActivity(), LoadingCallback {
|
||||||
generalViewModel = ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(application))[GeneralViewModel::class.java]
|
generalViewModel = ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(application))[GeneralViewModel::class.java]
|
||||||
// isGlobalLoading请勿前置,会导致初始化问题
|
// isGlobalLoading请勿前置,会导致初始化问题
|
||||||
val isGlobalLoading by generalViewModel.isLoading.collectAsState()
|
val isGlobalLoading by generalViewModel.isLoading.collectAsState()
|
||||||
|
// 退出登录
|
||||||
|
var isLogout by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
// 软件更新提示
|
// 软件更新提示
|
||||||
var showUpdateDialog by remember { mutableStateOf(false) }
|
var showUpdateDialog by remember { mutableStateOf(false) }
|
||||||
|
|
@ -182,6 +184,9 @@ class MainActivity : ComponentActivity(), LoadingCallback {
|
||||||
is LoginBindEvent.Login -> {
|
is LoginBindEvent.Login -> {
|
||||||
if(!event.isLogin){
|
if(!event.isLogin){
|
||||||
loginViewModel.reset()
|
loginViewModel.reset()
|
||||||
|
isLogout = true
|
||||||
|
}else{
|
||||||
|
isLogout = false
|
||||||
}
|
}
|
||||||
loginViewModel.requestUserConfig()
|
loginViewModel.requestUserConfig()
|
||||||
}
|
}
|
||||||
|
|
@ -284,7 +289,8 @@ class MainActivity : ComponentActivity(), LoadingCallback {
|
||||||
if(showSplash){
|
if(showSplash){
|
||||||
val token = PreferenceUtil.getAccessToken()
|
val token = PreferenceUtil.getAccessToken()
|
||||||
// 未登录,显示登录页
|
// 未登录,显示登录页
|
||||||
if (token.isNullOrEmpty() && loginViewModel.userConfigResult.value == null) {
|
//if (token.isNullOrEmpty() && loginViewModel.userConfigResult.value == null) {
|
||||||
|
if(isLogout){// 退出登录后,显示登录页
|
||||||
// 同意隐私协议政策,检验是否有一键登录权限
|
// 同意隐私协议政策,检验是否有一键登录权限
|
||||||
loginViewModel.oneKeyLoginForGeTuiSdk(context as Activity) { isAllowShowOneKeyScreen ->
|
loginViewModel.oneKeyLoginForGeTuiSdk(context as Activity) { isAllowShowOneKeyScreen ->
|
||||||
if (isAllowShowOneKeyScreen) {
|
if (isAllowShowOneKeyScreen) {
|
||||||
|
|
|
||||||
|
|
@ -88,14 +88,13 @@ fun MineScreen(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(loginViewModel.userConfigResult.value) {
|
LaunchedEffect(loginViewModel.userInfoResult.value) {
|
||||||
if(loginViewModel.userConfigResult.value != null){
|
if(loginViewModel.userInfoResult.value != null){
|
||||||
// 等待200ms,确保用户配置已经刷新
|
// 等待200ms,确保用户配置已经刷新
|
||||||
delay(200)
|
delay(200)
|
||||||
userInfo = PreferenceUtil.getUserInfo()
|
userInfo = PreferenceUtil.getUserInfo()
|
||||||
|
|
||||||
Log.i(TAG,"-------------->MineScreen页面,用户配置已经刷新")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
|
|
@ -116,7 +115,16 @@ fun MineScreen(
|
||||||
) {
|
) {
|
||||||
// 头像和登录/注册
|
// 头像和登录/注册
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clickable(
|
||||||
|
indication = null,
|
||||||
|
interactionSource = remember { MutableInteractionSource() }
|
||||||
|
) {
|
||||||
|
if(PreferenceUtil.getUserConfig()?.temp == true){
|
||||||
|
doLogin(generalViewModel, navController)
|
||||||
|
}
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
if(userInfo == null){
|
if(userInfo == null){
|
||||||
Image(
|
Image(
|
||||||
|
|
@ -131,6 +139,9 @@ fun MineScreen(
|
||||||
interactionSource = remember { MutableInteractionSource() }
|
interactionSource = remember { MutableInteractionSource() }
|
||||||
) {
|
) {
|
||||||
// 处理点击事件(头像)
|
// 处理点击事件(头像)
|
||||||
|
if(PreferenceUtil.getUserConfig()?.temp == true){
|
||||||
|
doLogin(generalViewModel, navController)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}else{
|
}else{
|
||||||
|
|
@ -146,6 +157,9 @@ fun MineScreen(
|
||||||
interactionSource = remember { MutableInteractionSource() }
|
interactionSource = remember { MutableInteractionSource() }
|
||||||
) {
|
) {
|
||||||
// 处理点击事件(头像)
|
// 处理点击事件(头像)
|
||||||
|
if(PreferenceUtil.getUserConfig()?.temp == true){
|
||||||
|
doLogin(generalViewModel, navController)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
fallback = painterResource(id = R.mipmap.ic_user_avatar_default),
|
fallback = painterResource(id = R.mipmap.ic_user_avatar_default),
|
||||||
error = painterResource(id = R.mipmap.ic_user_avatar_default)
|
error = painterResource(id = R.mipmap.ic_user_avatar_default)
|
||||||
|
|
@ -160,10 +174,7 @@ fun MineScreen(
|
||||||
interactionSource = remember { MutableInteractionSource() }
|
interactionSource = remember { MutableInteractionSource() }
|
||||||
) {
|
) {
|
||||||
if (userInfo == null) {
|
if (userInfo == null) {
|
||||||
// 隐藏TabBar
|
doLogin(generalViewModel, navController)
|
||||||
generalViewModel.setNavigationBarVisible(false)
|
|
||||||
// 跳转登录页面
|
|
||||||
navController.navigate("login?type=${LoginViewModel.JumpLoginType.NORMAL.type}")
|
|
||||||
} else {
|
} else {
|
||||||
// 已登录,跳转个人信息页面
|
// 已登录,跳转个人信息页面
|
||||||
//navController.navigate("userInfo")
|
//navController.navigate("userInfo")
|
||||||
|
|
@ -175,7 +186,16 @@ fun MineScreen(
|
||||||
fontSize = 18.sp,
|
fontSize = 18.sp,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
color = Color(0xFF1A1A1A),
|
color = Color(0xFF1A1A1A),
|
||||||
modifier = Modifier.wrapContentSize()
|
modifier = Modifier
|
||||||
|
.wrapContentSize()
|
||||||
|
.clickable(
|
||||||
|
indication = null,
|
||||||
|
interactionSource = remember { MutableInteractionSource() }
|
||||||
|
){
|
||||||
|
if(PreferenceUtil.getUserConfig()?.temp == true){
|
||||||
|
doLogin(generalViewModel, navController)
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|
@ -566,6 +586,13 @@ fun MineScreen(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun doLogin(generalViewModel: GeneralViewModel, navController: NavHostController){
|
||||||
|
// 隐藏TabBar
|
||||||
|
generalViewModel.setNavigationBarVisible(false)
|
||||||
|
// 跳转登录页面
|
||||||
|
navController.navigate("login?type=${LoginViewModel.JumpLoginType.FROM_ADD.type}")
|
||||||
|
}
|
||||||
|
|
||||||
@Preview(showBackground = true)
|
@Preview(showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
private fun PreviewMineScreen(){
|
private fun PreviewMineScreen(){
|
||||||
|
|
|
||||||
|
|
@ -263,48 +263,51 @@ fun SettingScreen(navController: NavHostController, loginViewModel: LoginViewMod
|
||||||
.align(Alignment.CenterVertically)
|
.align(Alignment.CenterVertically)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Box(
|
if(PreferenceUtil.getUserConfig()?.temp == false){
|
||||||
modifier = Modifier.fillMaxWidth().height(0.5.dp).padding(horizontal = 12.dp).background(
|
|
||||||
Color(0x4DBBBBBB)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(52.dp)
|
|
||||||
.clickable(
|
|
||||||
indication = null,
|
|
||||||
interactionSource = remember { MutableInteractionSource() }
|
|
||||||
) {
|
|
||||||
// 跳转注销账号页面
|
|
||||||
navController.navigate("deleteAccount")
|
|
||||||
},
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier.weight(1f)
|
modifier = Modifier.fillMaxWidth().height(0.5.dp).padding(horizontal = 12.dp).background(
|
||||||
){
|
Color(0x4DBBBBBB)
|
||||||
Text(
|
)
|
||||||
text = "注销账号",
|
)
|
||||||
fontSize = 14.sp,
|
Row(
|
||||||
fontWeight = FontWeight.Bold,
|
modifier = Modifier
|
||||||
color = Color(0xFF1A1A1A),
|
.fillMaxWidth()
|
||||||
|
.height(52.dp)
|
||||||
|
.clickable(
|
||||||
|
indication = null,
|
||||||
|
interactionSource = remember { MutableInteractionSource() }
|
||||||
|
) {
|
||||||
|
// 跳转注销账号页面
|
||||||
|
navController.navigate("deleteAccount")
|
||||||
|
},
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier.weight(1f)
|
||||||
|
){
|
||||||
|
Text(
|
||||||
|
text = "注销账号",
|
||||||
|
fontSize = 14.sp,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = Color(0xFF1A1A1A),
|
||||||
|
modifier = Modifier
|
||||||
|
.wrapContentSize()
|
||||||
|
.padding(start = 8.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Image(
|
||||||
|
painter = painterResource(id = R.mipmap.ic_arrow_right),
|
||||||
|
contentDescription = null,
|
||||||
|
contentScale = ContentScale.FillWidth,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.wrapContentSize()
|
.wrapContentSize()
|
||||||
.padding(start = 8.dp)
|
.padding(end = 12.dp)
|
||||||
|
.align(Alignment.CenterVertically)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.mipmap.ic_arrow_right),
|
|
||||||
contentDescription = null,
|
|
||||||
contentScale = ContentScale.FillWidth,
|
|
||||||
modifier = Modifier
|
|
||||||
.wrapContentSize()
|
|
||||||
.padding(end = 12.dp)
|
|
||||||
.align(Alignment.CenterVertically)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(PreferenceUtil.getUserConfig()?.temp == false){
|
if(PreferenceUtil.getUserConfig()?.temp == false){
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,9 @@ private fun ListItem(item: UserInfoEntity, onChange: (UserInfoEntity) -> Unit){
|
||||||
interactionSource = remember { MutableInteractionSource() }
|
interactionSource = remember { MutableInteractionSource() }
|
||||||
) {
|
) {
|
||||||
// 切换账号
|
// 切换账号
|
||||||
onChange(item)
|
if(PreferenceUtil.getUserInfo()?.user_id != item.user_id){
|
||||||
|
onChange(item)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
|
|
@ -239,7 +241,9 @@ private fun ListItem(item: UserInfoEntity, onChange: (UserInfoEntity) -> Unit){
|
||||||
Checkbox(
|
Checkbox(
|
||||||
checked = isLogin,
|
checked = isLogin,
|
||||||
onCheckedChange = { isChecked ->
|
onCheckedChange = { isChecked ->
|
||||||
//viewModel.setIsPolicyAgreement(isChecked)
|
if(isChecked){
|
||||||
|
onChange(item)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(16.dp)
|
.size(16.dp)
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import com.img.rabbit.bean.local.OnekeyPreLogin
|
||||||
import com.img.rabbit.bean.local.toAlipayResult
|
import com.img.rabbit.bean.local.toAlipayResult
|
||||||
import com.img.rabbit.bean.response.LoginInfoEntity
|
import com.img.rabbit.bean.response.LoginInfoEntity
|
||||||
import com.img.rabbit.bean.response.UserConfigEntity
|
import com.img.rabbit.bean.response.UserConfigEntity
|
||||||
|
import com.img.rabbit.bean.response.UserInfoEntity
|
||||||
import com.img.rabbit.components.CenterToast
|
import com.img.rabbit.components.CenterToast
|
||||||
import com.img.rabbit.provider.api.ApiManager
|
import com.img.rabbit.provider.api.ApiManager
|
||||||
import com.img.rabbit.provider.api.ResultVo
|
import com.img.rabbit.provider.api.ResultVo
|
||||||
|
|
@ -75,10 +76,10 @@ class LoginViewModel : BaseViewModel() {
|
||||||
|
|
||||||
// 登录获取结果
|
// 登录获取结果
|
||||||
val loginResult = mutableStateOf<ResultVo<LoginInfoEntity>?>(null)
|
val loginResult = mutableStateOf<ResultVo<LoginInfoEntity>?>(null)
|
||||||
|
|
||||||
// 用户配置获取结果
|
// 用户配置获取结果
|
||||||
val userConfigResult = mutableStateOf<ResultVo<UserConfigEntity>?>(null)
|
val userConfigResult = mutableStateOf<ResultVo<UserConfigEntity>?>(null)
|
||||||
|
// 用户信息获取结果
|
||||||
|
val userInfoResult = mutableStateOf<ResultVo<UserInfoEntity>?>(null)
|
||||||
// 错误状态
|
// 错误状态
|
||||||
val errorState = mutableStateOf<ErrorBean?>(null)
|
val errorState = mutableStateOf<ErrorBean?>(null)
|
||||||
|
|
||||||
|
|
@ -123,8 +124,6 @@ class LoginViewModel : BaseViewModel() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//以下是刷新状态
|
|
||||||
// applicationContext?.let { GlobalStateManager(it) }?.storeGlobalUserConfigNotify(true)
|
|
||||||
}else{
|
}else{
|
||||||
Log.w("LoginViewModel", "获取配置失败: code=${response.code}, message=${response.message}")
|
Log.w("LoginViewModel", "获取配置失败: code=${response.code}, message=${response.message}")
|
||||||
}
|
}
|
||||||
|
|
@ -397,6 +396,7 @@ class LoginViewModel : BaseViewModel() {
|
||||||
|
|
||||||
//请求登录
|
//请求登录
|
||||||
private fun requestLogin(jsonObject: JsonObject, loginType: LoginScreenType){
|
private fun requestLogin(jsonObject: JsonObject, loginType: LoginScreenType){
|
||||||
|
setLoading(true)
|
||||||
mLaunch {
|
mLaunch {
|
||||||
val response = ApiManager.serviceVo.login(jsonObject.toString().toRequestBody())
|
val response = ApiManager.serviceVo.login(jsonObject.toString().toRequestBody())
|
||||||
if (response.status) {
|
if (response.status) {
|
||||||
|
|
@ -407,6 +407,7 @@ class LoginViewModel : BaseViewModel() {
|
||||||
}else{
|
}else{
|
||||||
errorState.value = ErrorBean(response.code.toString(), response.message.ifEmpty { "登录失败" })
|
errorState.value = ErrorBean(response.code.toString(), response.message.ifEmpty { "登录失败" })
|
||||||
}
|
}
|
||||||
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -416,6 +417,7 @@ class LoginViewModel : BaseViewModel() {
|
||||||
val response = ApiManager.serviceVo.userInfo()
|
val response = ApiManager.serviceVo.userInfo()
|
||||||
if(response.status){
|
if(response.status){
|
||||||
PreferenceUtil.saveUserInfo(response.data)
|
PreferenceUtil.saveUserInfo(response.data)
|
||||||
|
userInfoResult.value = response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue