|
@@ -38,8 +38,7 @@ class MemberProfileFragment : ViewBindingFragment<FragmentMemberProfileBinding>(
|
|
}
|
|
}
|
|
|
|
|
|
override fun createViewBinding(
|
|
override fun createViewBinding(
|
|
- inflater: LayoutInflater,
|
|
|
|
- container: ViewGroup?
|
|
|
|
|
|
+ inflater: LayoutInflater, container: ViewGroup?
|
|
): FragmentMemberProfileBinding {
|
|
): FragmentMemberProfileBinding {
|
|
return FragmentMemberProfileBinding.inflate(inflater, container, false)
|
|
return FragmentMemberProfileBinding.inflate(inflater, container, false)
|
|
}
|
|
}
|
|
@@ -48,10 +47,22 @@ class MemberProfileFragment : ViewBindingFragment<FragmentMemberProfileBinding>(
|
|
queryUserInfo()
|
|
queryUserInfo()
|
|
binding.tvChooseAge.setOnClickListener {
|
|
binding.tvChooseAge.setOnClickListener {
|
|
AgeSelectDialog(hostActivity) { index, change ->
|
|
AgeSelectDialog(hostActivity) { index, change ->
|
|
- selectAge = if (index == 0) {
|
|
|
|
- 18
|
|
|
|
- } else {
|
|
|
|
- index + 20
|
|
|
|
|
|
+ selectAge = when (index) {
|
|
|
|
+ 0 -> {
|
|
|
|
+ 0
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 1 -> {
|
|
|
|
+ 18
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 2 -> {
|
|
|
|
+ 20
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ else -> {
|
|
|
|
+ index + 18
|
|
|
|
+ }
|
|
}
|
|
}
|
|
binding.tvChooseAge.text = selectAge.toString()
|
|
binding.tvChooseAge.text = selectAge.toString()
|
|
binding.tvChooseAge.text_color = R.color.register_edit_color
|
|
binding.tvChooseAge.text_color = R.color.register_edit_color
|
|
@@ -79,29 +90,23 @@ class MemberProfileFragment : ViewBindingFragment<FragmentMemberProfileBinding>(
|
|
binding.tvSkipForNow.setOnClickListener {
|
|
binding.tvSkipForNow.setOnClickListener {
|
|
if (binding.tvSkipForNow.text == getString(R.string.sign_out)) {
|
|
if (binding.tvSkipForNow.text == getString(R.string.sign_out)) {
|
|
EventBus.getDefault().post(FinishAtyEvent())
|
|
EventBus.getDefault().post(FinishAtyEvent())
|
|
- FoodDataProvider
|
|
|
|
- .getUserDatabase()
|
|
|
|
- .userInfoDao()
|
|
|
|
|
|
+ FoodDataProvider.getUserDatabase().userInfoDao()
|
|
.deleteUserInfoByUserId(CURRENT_USER_ID)
|
|
.deleteUserInfoByUserId(CURRENT_USER_ID)
|
|
MmkvUtils.save(LOGIN_TAG, false)
|
|
MmkvUtils.save(LOGIN_TAG, false)
|
|
MmkvUtils.clear(API_TOKEN)
|
|
MmkvUtils.clear(API_TOKEN)
|
|
MmkvUtils.save(CURRENT_USER_ID_TAG, 0)
|
|
MmkvUtils.save(CURRENT_USER_ID_TAG, 0)
|
|
FoodDataProvider.getUserDatabase().userInfoDao().deleteAllUserInfo()
|
|
FoodDataProvider.getUserDatabase().userInfoDao().deleteAllUserInfo()
|
|
- parentFragmentManager
|
|
|
|
- .beginTransaction()
|
|
|
|
- .replace(R.id.fl_container, MemberLoginFragment())
|
|
|
|
- .commitAllowingStateLoss()
|
|
|
|
|
|
+ parentFragmentManager.beginTransaction()
|
|
|
|
+ .replace(R.id.fl_container, MemberLoginFragment()).commitAllowingStateLoss()
|
|
} else {
|
|
} else {
|
|
navigateTo(Screens.Main.ENTRANCE_CHOSEN)
|
|
navigateTo(Screens.Main.ENTRANCE_CHOSEN)
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
binding.tvDestroyAccount.setOnClickListener {
|
|
binding.tvDestroyAccount.setOnClickListener {
|
|
- viewModel.cancelAccount().observe(viewLifecycleOwner){
|
|
|
|
|
|
+ viewModel.cancelAccount().observe(viewLifecycleOwner) {
|
|
EventBus.getDefault().post(FinishAtyEvent())
|
|
EventBus.getDefault().post(FinishAtyEvent())
|
|
- FoodDataProvider
|
|
|
|
- .getUserDatabase()
|
|
|
|
- .userInfoDao()
|
|
|
|
|
|
+ FoodDataProvider.getUserDatabase().userInfoDao()
|
|
.deleteUserInfoByUserId(CURRENT_USER_ID)
|
|
.deleteUserInfoByUserId(CURRENT_USER_ID)
|
|
val saveToken: String? = null
|
|
val saveToken: String? = null
|
|
MmkvUtils.save(API_TOKEN, saveToken)
|
|
MmkvUtils.save(API_TOKEN, saveToken)
|
|
@@ -110,10 +115,8 @@ class MemberProfileFragment : ViewBindingFragment<FragmentMemberProfileBinding>(
|
|
MmkvUtils.save(RECORD_ACCOUNT, "")
|
|
MmkvUtils.save(RECORD_ACCOUNT, "")
|
|
MmkvUtils.save(RECORD_PASSWORD, "")
|
|
MmkvUtils.save(RECORD_PASSWORD, "")
|
|
FoodDataProvider.getUserDatabase().userInfoDao().deleteAllUserInfo()
|
|
FoodDataProvider.getUserDatabase().userInfoDao().deleteAllUserInfo()
|
|
- parentFragmentManager
|
|
|
|
- .beginTransaction()
|
|
|
|
- .replace(R.id.fl_container, MemberLoginFragment())
|
|
|
|
- .commitAllowingStateLoss()
|
|
|
|
|
|
+ parentFragmentManager.beginTransaction()
|
|
|
|
+ .replace(R.id.fl_container, MemberLoginFragment()).commitAllowingStateLoss()
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -152,10 +155,7 @@ class MemberProfileFragment : ViewBindingFragment<FragmentMemberProfileBinding>(
|
|
}
|
|
}
|
|
|
|
|
|
private fun saveProfile(
|
|
private fun saveProfile(
|
|
- nickname: String?,
|
|
|
|
- age: Int,
|
|
|
|
- sex: Int,
|
|
|
|
- portrait: Int
|
|
|
|
|
|
+ nickname: String?, age: Int, sex: Int, portrait: Int
|
|
) {
|
|
) {
|
|
if (nickname.isNullOrEmpty()) {
|
|
if (nickname.isNullOrEmpty()) {
|
|
showToast("Please fill in nickname")
|
|
showToast("Please fill in nickname")
|
|
@@ -185,11 +185,7 @@ class MemberProfileFragment : ViewBindingFragment<FragmentMemberProfileBinding>(
|
|
|
|
|
|
private fun saveDatabase(user: User) {
|
|
private fun saveDatabase(user: User) {
|
|
val userInfo = UserInfo(
|
|
val userInfo = UserInfo(
|
|
- user.id.toLong(),
|
|
|
|
- user.nickname.toString(),
|
|
|
|
- user.portrait,
|
|
|
|
- user.gender,
|
|
|
|
- user.age
|
|
|
|
|
|
+ user.id.toLong(), user.nickname.toString(), user.portrait, user.gender, user.age
|
|
)
|
|
)
|
|
MmkvUtils.save(CURRENT_USER_ID_TAG, user.id.toLong())
|
|
MmkvUtils.save(CURRENT_USER_ID_TAG, user.id.toLong())
|
|
FoodDataProvider.getUserDatabase().userInfoDao().updateUserInfo(userInfo)
|
|
FoodDataProvider.getUserDatabase().userInfoDao().updateUserInfo(userInfo)
|
|
@@ -198,8 +194,8 @@ class MemberProfileFragment : ViewBindingFragment<FragmentMemberProfileBinding>(
|
|
private fun queryUserInfo() {
|
|
private fun queryUserInfo() {
|
|
FoodDataProvider.getUserDatabase().runInTransaction {
|
|
FoodDataProvider.getUserDatabase().runInTransaction {
|
|
val userId = MmkvUtils.getLong(CURRENT_USER_ID_TAG)
|
|
val userId = MmkvUtils.getLong(CURRENT_USER_ID_TAG)
|
|
- val userInfo = FoodDataProvider.getUserDatabase().userInfoDao()
|
|
|
|
- .queryUserInfoByUserId(userId)
|
|
|
|
|
|
+ val userInfo =
|
|
|
|
+ FoodDataProvider.getUserDatabase().userInfoDao().queryUserInfoByUserId(userId)
|
|
userInfoLiveData.postValue(userInfo)
|
|
userInfoLiveData.postValue(userInfo)
|
|
}
|
|
}
|
|
}
|
|
}
|