-
Notifications
You must be signed in to change notification settings - Fork 731
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
Supporting rotation during voice recordings #4556
Conversation
…rotation - this means we need to be extra careful about releasing any listeners
@@ -158,22 +162,23 @@ class VoiceMessageRecorderView @JvmOverloads constructor( | |||
dragState = newDragState | |||
} | |||
|
|||
private fun startRecordingTicker() { | |||
private fun startRecordingTicker(startFromLocked: Boolean, startAt: Long) { | |||
val startMs = ((System.currentTimeMillis() - startAt)).coerceAtLeast(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally we'd have a Clock
abstraction to avoid directly calling into the system time, would help out massively for testing
what do people think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added 7d2c8e6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I did not test it though.
@@ -158,22 +162,23 @@ class VoiceMessageRecorderView @JvmOverloads constructor( | |||
dragState = newDragState | |||
} | |||
|
|||
private fun startRecordingTicker() { | |||
private fun startRecordingTicker(startFromLocked: Boolean, startAt: Long) { | |||
val startMs = ((System.currentTimeMillis() - startAt)).coerceAtLeast(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
- had to keep track of the recording start time in order to maintain the current length counter
7d2c8e6
to
5d18120
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update. 2 more remarks but you can merge the PR whenever you want.
|
||
class DefaultClock @Inject constructor() : Clock { | ||
override fun epochMillis(): Long { | ||
return System.currentTimeMillis() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit out of scope of this PR, but we will probably want to replace all System.currentTimeMillis()
usages by this new Clock?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 that would be the dream! I'll create an issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import javax.inject.Inject | ||
|
||
interface Clock { | ||
fun epochMillis(): Long |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's worth noting that the current impl rely on the system date, which can be set by the user (and at any time).
This can lead to bugs...
Also when the clock change automatically (Winter?Summer time) we can have bugs (my experience is talking here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unless we use a server time is there a way to avoid this? analytics SDKs will rely on a mix of server received at timestamps and client sent at
the currentTimeMillis
epoch is UTC, unless a user sets a custom time using their local time (eg UTC+11) but with UTC+0 timezone 😅
it's becoming rarer for users to misconfigure their time due to automatic network times and a lot apps/websites start complaining about SSL errors if the current time/date is wildly wrong
EDIT: I'll add some java doc to explain this time could be incorrect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have this issue on Element v1.4.32 (2022-08-10) from F-Droid. |
Fixes #4067 Allows the device to rotate whilst recording a voice message
VoiceMessagePlaybackTracker
a singleton to avoid losing any state on activity destruction (means we need to be extra careful with releasing the listeners)