move to a more hardened null-handling profile data handling

Fixes #1908

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-04-19 17:34:52 +02:00
parent 5166cc5a84
commit c93041d402
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B

View File

@ -259,7 +259,7 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
})
}
private fun isAllEmpty(items: Array<String>): Boolean {
private fun isAllEmpty(items: Array<String?>): Boolean {
for (item in items) {
if (!TextUtils.isEmpty(item)) {
return false
@ -277,19 +277,19 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
binding.userinfoBaseurl.text = Uri.parse(currentUser!!.baseUrl).host
}
DisplayUtils.loadAvatarImage(currentUser, binding.avatarImage, false)
if (!TextUtils.isEmpty(userInfo!!.displayName)) {
binding.userinfoFullName.text = userInfo!!.displayName
if (!TextUtils.isEmpty(userInfo?.displayName)) {
binding.userinfoFullName.text = userInfo?.displayName
}
binding.loadingContent.visibility = View.VISIBLE
adapter!!.setData(createUserInfoDetails(userInfo))
if (isAllEmpty(
arrayOf(
userInfo!!.displayName!!,
userInfo!!.phone!!,
userInfo!!.email!!,
userInfo!!.address!!,
userInfo!!.twitter!!,
userInfo!!.website!!
userInfo?.displayName,
userInfo?.phone,
userInfo?.email,
userInfo?.address,
userInfo?.twitter,
userInfo?.website
)
)
) {
@ -352,10 +352,12 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
private fun createUserInfoDetails(userInfo: UserProfileData?): List<UserInfoDetailsItem> {
val result: MutableList<UserInfoDetailsItem> = LinkedList()
if (userInfo != null) {
result.add(
UserInfoDetailsItem(
R.drawable.ic_user,
userInfo!!.displayName!!,
userInfo.displayName,
resources!!.getString(R.string.user_info_displayname),
Field.DISPLAYNAME,
userInfo.displayNameScope
@ -364,7 +366,7 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
result.add(
UserInfoDetailsItem(
R.drawable.ic_phone,
userInfo.phone!!,
userInfo.phone,
resources!!.getString(R.string.user_info_phone),
Field.PHONE,
userInfo.phoneScope
@ -373,7 +375,7 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
result.add(
UserInfoDetailsItem(
R.drawable.ic_email,
userInfo.email!!,
userInfo.email,
resources!!.getString(R.string.user_info_email),
Field.EMAIL,
userInfo.emailScope
@ -382,7 +384,7 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
result.add(
UserInfoDetailsItem(
R.drawable.ic_map_marker,
userInfo.address!!,
userInfo.address,
resources!!.getString(R.string.user_info_address),
Field.ADDRESS,
userInfo.addressScope
@ -406,6 +408,7 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
userInfo.twitterScope
)
)
}
return result
}
@ -622,7 +625,7 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
class UserInfoDetailsItem(
@field:DrawableRes @param:DrawableRes var icon: Int,
var text: String,
var text: String?,
var hint: String,
val field: Field,
var scope: Scope?