mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-09 13:59:48 +01:00
try to avoid crash in conversation info
could not reproduce. Code copied from Julius' PR https://github.com/nextcloud/talk-android/pull/5004/ Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
78a88a9ce5
commit
a559fd5ea6
@ -423,6 +423,7 @@ class ConversationInfoActivity :
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("Detekt.TooGenericExceptionCaught")
|
||||
private fun initViewStateObserver() {
|
||||
viewModel.viewState.observe(this) { state ->
|
||||
when (state) {
|
||||
@ -443,8 +444,10 @@ class ConversationInfoActivity :
|
||||
)
|
||||
}
|
||||
|
||||
if (conversation!!.type == ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) {
|
||||
viewModel.getProfileData(conversationUser, conversation!!.name)
|
||||
conversation?.let {
|
||||
if (it.type == ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) {
|
||||
viewModel.getProfileData(conversationUser, it.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -459,28 +462,48 @@ class ConversationInfoActivity :
|
||||
viewModel.getProfileViewState.observe(this) { state ->
|
||||
when (state) {
|
||||
is ConversationInfoViewModel.GetProfileSuccessState -> {
|
||||
val profile = state.profile
|
||||
val pronouns = profile.pronouns ?: ""
|
||||
binding.pronouns.text = pronouns
|
||||
try {
|
||||
// Pronouns
|
||||
val profile = state.profile
|
||||
val pronouns = profile.pronouns ?: ""
|
||||
binding.pronouns.text = pronouns
|
||||
|
||||
val concat1 = if (profile.role != null && profile.company != null) " @ " else ""
|
||||
val role = profile.role ?: ""
|
||||
val company = profile.company ?: ""
|
||||
val professionCompanyText = "$role$concat1$company"
|
||||
binding.professionCompany.text = professionCompanyText
|
||||
// Role @ Organization
|
||||
val concat1 = if (profile.role != null && profile.company != null) " @ " else ""
|
||||
val role = profile.role ?: ""
|
||||
val company = profile.company ?: ""
|
||||
val professionCompanyText = "$role$concat1$company"
|
||||
binding.professionCompany.text = professionCompanyText
|
||||
|
||||
val profileZoneOffset = ZoneOffset.ofTotalSeconds(0)
|
||||
val secondsToAdd = profile.timezoneOffset?.toLong() ?: 0
|
||||
val localTime = ZonedDateTime.ofInstant(Instant.now().plusSeconds(secondsToAdd), profileZoneOffset)
|
||||
val localTimeString = localTime.format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT))
|
||||
val concat2 = if (profile.address != null) " · " else ""
|
||||
val address = profile.address ?: ""
|
||||
val localTimeLocation = "$localTimeString$concat2$address"
|
||||
binding.locationTime.text = resources.getString(R.string.local_time, localTimeLocation)
|
||||
// Local Time: xX:xX · Address
|
||||
val profileZoneOffset = ZoneOffset.ofTotalSeconds(0)
|
||||
val secondsToAdd = profile.timezoneOffset?.toLong() ?: 0
|
||||
val localTime = ZonedDateTime.ofInstant(
|
||||
Instant.now().plusSeconds(secondsToAdd),
|
||||
profileZoneOffset
|
||||
)
|
||||
val localTimeString = localTime.format(
|
||||
DateTimeFormatter
|
||||
.ofLocalizedTime(FormatStyle.SHORT)
|
||||
.withLocale(Locale.getDefault())
|
||||
)
|
||||
val concat2 = if (profile.address != null) " · " else ""
|
||||
val address = profile.address ?: ""
|
||||
val localTimeLocation = "$localTimeString$concat2$address"
|
||||
binding.locationTime.text = resources.getString(R.string.local_time, localTimeLocation)
|
||||
|
||||
binding.pronouns.visibility = VISIBLE
|
||||
binding.professionCompany.visibility = if (professionCompanyText.isNotEmpty()) VISIBLE else GONE
|
||||
binding.locationTime.visibility = VISIBLE
|
||||
binding.pronouns.visibility = VISIBLE
|
||||
binding.professionCompany.visibility = if (professionCompanyText.isNotEmpty()) VISIBLE else GONE
|
||||
binding.locationTime.visibility = VISIBLE
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Exception getting profile information", e)
|
||||
Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
|
||||
is ConversationInfoViewModel.GetProfileErrorState -> {
|
||||
Log.e(TAG, "Network error occurred getting profile information")
|
||||
Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
else -> {}
|
||||
|
Loading…
Reference in New Issue
Block a user