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