Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on opening a room on Android 5.0 and 5.1 - Regression with Voice message #3903

Merged
merged 2 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3897.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Crash on opening a room on Android 5.0 and 5.1 - Regression with Voice message
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ import kotlin.math.floor
/**
* Encapsulates the voice message recording view and animations.
*/
class VoiceMessageRecorderView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr), VoiceMessagePlaybackTracker.Listener {
class VoiceMessageRecorderView: ConstraintLayout, VoiceMessagePlaybackTracker.Listener {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same reason with the first comment.


interface Callback {
// Return true if the recording is started
Expand All @@ -54,7 +50,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
fun onVoicePlaybackButtonClicked()
}

private val views: ViewVoiceMessageRecorderBinding
private lateinit var views: ViewVoiceMessageRecorderBinding

var callback: Callback? = null
var voiceMessagePlaybackTracker: VoiceMessagePlaybackTracker? = null
Expand All @@ -80,7 +76,17 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
private val distanceToCancel = dimensionConverter.dpToPx(120).toFloat()
private val rtlXMultiplier = context.resources.getInteger(R.integer.rtl_x_multiplier)

init {
// Don't convert to primary constructor.
// We need to define views as lateinit var to be able to check if initialized for the bug fix on api 21 and 22.
@JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : super(context, attrs, defStyleAttr) {
initialize()
}

fun initialize() {
Comment on lines +79 to +89
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, views has to be lateinit var to be able to use isInitialized. When we initialize views in init, lint says it is redundant to mark as lateinit...

inflate(context, R.layout.view_voice_message_recorder, this)
views = ViewVoiceMessageRecorderBinding.bind(this)

Expand All @@ -90,6 +96,9 @@ class VoiceMessageRecorderView @JvmOverloads constructor(

override fun onVisibilityChanged(changedView: View, visibility: Int) {
super.onVisibilityChanged(changedView, visibility)
// onVisibilityChanged is called by constructor on api 21 and 22.
if (!this::views.isInitialized) return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bmarty Were you able to reproduce the error on Android 5 and verify if this patch works?


if (changedView == this && visibility == VISIBLE) {
views.voiceMessageMicButton.contentDescription = context.getString(R.string.a11y_start_voice_message)
} else {
Expand Down