mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 12:09:45 +01:00
Merge pull request #1926 from nextcloud/bugfix/1908/nullHardening
Move to a more hardened null-handling profile data handling
This commit is contained in:
commit
0123cbbdbf
@ -189,25 +189,7 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders
|
|||||||
showVoiceMessageLoading()
|
showVoiceMessageLoading()
|
||||||
WorkManager.getInstance(context!!).getWorkInfoByIdLiveData(workInfo.id)
|
WorkManager.getInstance(context!!).getWorkInfoByIdLiveData(workInfo.id)
|
||||||
.observeForever { info: WorkInfo? ->
|
.observeForever { info: WorkInfo? ->
|
||||||
if (info != null) {
|
updateDownloadState(info)
|
||||||
|
|
||||||
when (info.state) {
|
|
||||||
WorkInfo.State.RUNNING -> {
|
|
||||||
Log.d(TAG, "WorkInfo.State.RUNNING in ViewHolder")
|
|
||||||
showVoiceMessageLoading()
|
|
||||||
}
|
|
||||||
WorkInfo.State.SUCCEEDED -> {
|
|
||||||
Log.d(TAG, "WorkInfo.State.SUCCEEDED in ViewHolder")
|
|
||||||
showPlayButton()
|
|
||||||
}
|
|
||||||
WorkInfo.State.FAILED -> {
|
|
||||||
Log.d(TAG, "WorkInfo.State.FAILED in ViewHolder")
|
|
||||||
showPlayButton()
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,6 +200,28 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateDownloadState(info: WorkInfo?) {
|
||||||
|
if (info != null) {
|
||||||
|
when (info.state) {
|
||||||
|
WorkInfo.State.RUNNING -> {
|
||||||
|
Log.d(TAG, "WorkInfo.State.RUNNING in ViewHolder")
|
||||||
|
showVoiceMessageLoading()
|
||||||
|
}
|
||||||
|
WorkInfo.State.SUCCEEDED -> {
|
||||||
|
Log.d(TAG, "WorkInfo.State.SUCCEEDED in ViewHolder")
|
||||||
|
showPlayButton()
|
||||||
|
}
|
||||||
|
WorkInfo.State.FAILED -> {
|
||||||
|
Log.d(TAG, "WorkInfo.State.FAILED in ViewHolder")
|
||||||
|
showPlayButton()
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
Log.d(TAG, "WorkInfo.State unused in ViewHolder")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun showPlayButton() {
|
private fun showPlayButton() {
|
||||||
binding.playPauseBtn.visibility = View.VISIBLE
|
binding.playPauseBtn.visibility = View.VISIBLE
|
||||||
binding.progressBar.visibility = View.GONE
|
binding.progressBar.visibility = View.GONE
|
||||||
|
@ -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,60 +352,63 @@ 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()
|
||||||
result.add(
|
|
||||||
UserInfoDetailsItem(
|
if (userInfo != null) {
|
||||||
R.drawable.ic_user,
|
result.add(
|
||||||
userInfo!!.displayName!!,
|
UserInfoDetailsItem(
|
||||||
resources!!.getString(R.string.user_info_displayname),
|
R.drawable.ic_user,
|
||||||
Field.DISPLAYNAME,
|
userInfo.displayName,
|
||||||
userInfo.displayNameScope
|
resources!!.getString(R.string.user_info_displayname),
|
||||||
|
Field.DISPLAYNAME,
|
||||||
|
userInfo.displayNameScope
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
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
|
)
|
||||||
)
|
)
|
||||||
)
|
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
|
)
|
||||||
)
|
)
|
||||||
)
|
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
|
)
|
||||||
)
|
)
|
||||||
)
|
result.add(
|
||||||
result.add(
|
UserInfoDetailsItem(
|
||||||
UserInfoDetailsItem(
|
R.drawable.ic_web,
|
||||||
R.drawable.ic_web,
|
DisplayUtils.beautifyURL(userInfo.website),
|
||||||
DisplayUtils.beautifyURL(userInfo.website),
|
resources!!.getString(R.string.user_info_website),
|
||||||
resources!!.getString(R.string.user_info_website),
|
Field.WEBSITE,
|
||||||
Field.WEBSITE,
|
userInfo.websiteScope
|
||||||
userInfo.websiteScope
|
)
|
||||||
)
|
)
|
||||||
)
|
result.add(
|
||||||
result.add(
|
UserInfoDetailsItem(
|
||||||
UserInfoDetailsItem(
|
R.drawable.ic_twitter,
|
||||||
R.drawable.ic_twitter,
|
DisplayUtils.beautifyTwitterHandle(userInfo.twitter),
|
||||||
DisplayUtils.beautifyTwitterHandle(userInfo.twitter),
|
resources!!.getString(R.string.user_info_twitter),
|
||||||
resources!!.getString(R.string.user_info_twitter),
|
Field.TWITTER,
|
||||||
Field.TWITTER,
|
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?
|
||||||
|
Loading…
Reference in New Issue
Block a user