diff options
author | Andy Scherzinger <info@andy-scherzinger.de> | 2022-04-19 18:34:52 +0300 |
---|---|---|
committer | Andy Scherzinger <info@andy-scherzinger.de> | 2022-04-19 18:40:14 +0300 |
commit | c93041d40244bb0e4e92484945d25dbb102c6376 (patch) | |
tree | 6193b002553ce45225ebad9422fc03a9918d588c /app/src/main | |
parent | 5166cc5a847eb3ceb5ac3d19c08c5f41259256ac (diff) |
move to a more hardened null-handling profile data handling
Fixes #1908
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/com/nextcloud/talk/controllers/ProfileController.kt | 119 |
1 files changed, 61 insertions, 58 deletions
diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ProfileController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ProfileController.kt index 241bc3efa..a1f8ed98c 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ProfileController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ProfileController.kt @@ -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,60 +352,63 @@ class ProfileController : NewBaseController(R.layout.controller_profile) { private fun createUserInfoDetails(userInfo: UserProfileData?): List<UserInfoDetailsItem> { val result: MutableList<UserInfoDetailsItem> = LinkedList() - result.add( - UserInfoDetailsItem( - R.drawable.ic_user, - userInfo!!.displayName!!, - resources!!.getString(R.string.user_info_displayname), - Field.DISPLAYNAME, - userInfo.displayNameScope + + if (userInfo != null) { + result.add( + UserInfoDetailsItem( + R.drawable.ic_user, + userInfo.displayName, + resources!!.getString(R.string.user_info_displayname), + Field.DISPLAYNAME, + userInfo.displayNameScope + ) ) - ) - result.add( - UserInfoDetailsItem( - R.drawable.ic_phone, - userInfo.phone!!, - resources!!.getString(R.string.user_info_phone), - Field.PHONE, - userInfo.phoneScope + result.add( + UserInfoDetailsItem( + R.drawable.ic_phone, + userInfo.phone, + resources!!.getString(R.string.user_info_phone), + Field.PHONE, + userInfo.phoneScope + ) ) - ) - result.add( - UserInfoDetailsItem( - R.drawable.ic_email, - userInfo.email!!, - resources!!.getString(R.string.user_info_email), - Field.EMAIL, - userInfo.emailScope + result.add( + UserInfoDetailsItem( + R.drawable.ic_email, + userInfo.email, + resources!!.getString(R.string.user_info_email), + Field.EMAIL, + userInfo.emailScope + ) ) - ) - result.add( - UserInfoDetailsItem( - R.drawable.ic_map_marker, - userInfo.address!!, - resources!!.getString(R.string.user_info_address), - Field.ADDRESS, - userInfo.addressScope + result.add( + UserInfoDetailsItem( + R.drawable.ic_map_marker, + userInfo.address, + resources!!.getString(R.string.user_info_address), + Field.ADDRESS, + userInfo.addressScope + ) ) - ) - result.add( - UserInfoDetailsItem( - R.drawable.ic_web, - DisplayUtils.beautifyURL(userInfo.website), - resources!!.getString(R.string.user_info_website), - Field.WEBSITE, - userInfo.websiteScope + result.add( + UserInfoDetailsItem( + R.drawable.ic_web, + DisplayUtils.beautifyURL(userInfo.website), + resources!!.getString(R.string.user_info_website), + Field.WEBSITE, + userInfo.websiteScope + ) ) - ) - result.add( - UserInfoDetailsItem( - R.drawable.ic_twitter, - DisplayUtils.beautifyTwitterHandle(userInfo.twitter), - resources!!.getString(R.string.user_info_twitter), - Field.TWITTER, - userInfo.twitterScope + result.add( + UserInfoDetailsItem( + R.drawable.ic_twitter, + DisplayUtils.beautifyTwitterHandle(userInfo.twitter), + resources!!.getString(R.string.user_info_twitter), + Field.TWITTER, + 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? |