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