Renaming
This commit is contained in:
parent
6283846108
commit
a52d5f6d12
|
@ -17,7 +17,6 @@
|
||||||
package im.vector.app.core.utils
|
package im.vector.app.core.utils
|
||||||
|
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import timber.log.Timber
|
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import java.util.concurrent.atomic.AtomicLong
|
import java.util.concurrent.atomic.AtomicLong
|
||||||
|
|
|
@ -51,8 +51,8 @@ class VoiceMessageHelper @Inject constructor(
|
||||||
|
|
||||||
private val amplitudeList = mutableListOf<Int>()
|
private val amplitudeList = mutableListOf<Int>()
|
||||||
|
|
||||||
private var amplitudeTimer: CountUpTimer? = null
|
private var amplitudeTicker: CountUpTimer? = null
|
||||||
private var playbackTimer: CountUpTimer? = null
|
private var playbackTicker: CountUpTimer? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (!outputDirectory.exists()) {
|
if (!outputDirectory.exists()) {
|
||||||
|
@ -162,27 +162,27 @@ class VoiceMessageHelper @Inject constructor(
|
||||||
seekTo(currentPlaybackTime)
|
seekTo(currentPlaybackTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
startPlaybackTimer(id)
|
startPlaybackTicker(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stopPlayback() {
|
private fun stopPlayback() {
|
||||||
mediaPlayer?.stop()
|
mediaPlayer?.stop()
|
||||||
stopPlaybackTimer()
|
stopPlaybackTicker()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startRecordingAmplitudes() {
|
private fun startRecordingAmplitudes() {
|
||||||
amplitudeTimer?.stop()
|
amplitudeTicker?.stop()
|
||||||
amplitudeTimer = CountUpTimer(100).apply {
|
amplitudeTicker = CountUpTimer(100).apply {
|
||||||
tickListener = object : CountUpTimer.TickListener {
|
tickListener = object : CountUpTimer.TickListener {
|
||||||
override fun onTick(milliseconds: Long) {
|
override fun onTick(milliseconds: Long) {
|
||||||
onAmplitudeTimerTick()
|
onAmplitudeTick()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resume()
|
resume()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onAmplitudeTimerTick() {
|
private fun onAmplitudeTick() {
|
||||||
try {
|
try {
|
||||||
val maxAmplitude = mediaRecorder.maxAmplitude
|
val maxAmplitude = mediaRecorder.maxAmplitude
|
||||||
amplitudeList.add(maxAmplitude)
|
amplitudeList.add(maxAmplitude)
|
||||||
|
@ -197,36 +197,36 @@ class VoiceMessageHelper @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stopRecordingAmplitudes() {
|
private fun stopRecordingAmplitudes() {
|
||||||
amplitudeTimer?.stop()
|
amplitudeTicker?.stop()
|
||||||
amplitudeTimer = null
|
amplitudeTicker = null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startPlaybackTimer(id: String) {
|
private fun startPlaybackTicker(id: String) {
|
||||||
playbackTimer?.stop()
|
playbackTicker?.stop()
|
||||||
playbackTimer = CountUpTimer().apply {
|
playbackTicker = CountUpTimer().apply {
|
||||||
tickListener = object : CountUpTimer.TickListener {
|
tickListener = object : CountUpTimer.TickListener {
|
||||||
override fun onTick(milliseconds: Long) {
|
override fun onTick(milliseconds: Long) {
|
||||||
onPlaybackTimerTick(id)
|
onPlaybackTick(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resume()
|
resume()
|
||||||
}
|
}
|
||||||
onPlaybackTimerTick(id)
|
onPlaybackTick(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onPlaybackTimerTick(id: String) {
|
private fun onPlaybackTick(id: String) {
|
||||||
if (mediaPlayer?.isPlaying.orFalse()) {
|
if (mediaPlayer?.isPlaying.orFalse()) {
|
||||||
val currentPosition = mediaPlayer?.currentPosition ?: 0
|
val currentPosition = mediaPlayer?.currentPosition ?: 0
|
||||||
playbackTracker.updateCurrentPlaybackTime(id, currentPosition)
|
playbackTracker.updateCurrentPlaybackTime(id, currentPosition)
|
||||||
} else {
|
} else {
|
||||||
playbackTracker.stopPlayback(id)
|
playbackTracker.stopPlayback(id)
|
||||||
stopPlaybackTimer()
|
stopPlaybackTicker()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stopPlaybackTimer() {
|
private fun stopPlaybackTicker() {
|
||||||
playbackTimer?.stop()
|
playbackTicker?.stop()
|
||||||
playbackTimer = null
|
playbackTicker = null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stopAllVoiceActions() {
|
fun stopAllVoiceActions() {
|
||||||
|
|
|
@ -67,7 +67,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
|
||||||
private var lastX: Float = 0f
|
private var lastX: Float = 0f
|
||||||
private var lastY: Float = 0f
|
private var lastY: Float = 0f
|
||||||
|
|
||||||
private var recordingTimer: CountUpTimer? = null
|
private var recordingTicker: CountUpTimer? = null
|
||||||
|
|
||||||
private val dimensionConverter = DimensionConverter(context.resources)
|
private val dimensionConverter = DimensionConverter(context.resources)
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
|
||||||
|
|
||||||
fun initVoiceRecordingViews() {
|
fun initVoiceRecordingViews() {
|
||||||
hideRecordingViews(animationDuration = 0)
|
hideRecordingViews(animationDuration = 0)
|
||||||
stopRecordingTimer()
|
stopRecordingTicker()
|
||||||
|
|
||||||
views.voiceMessageMicButton.isVisible = true
|
views.voiceMessageMicButton.isVisible = true
|
||||||
views.voiceMessageSendButton.isVisible = false
|
views.voiceMessageSendButton.isVisible = false
|
||||||
|
@ -89,7 +89,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
|
||||||
|
|
||||||
private fun initListeners() {
|
private fun initListeners() {
|
||||||
views.voiceMessageSendButton.setOnClickListener {
|
views.voiceMessageSendButton.setOnClickListener {
|
||||||
stopRecordingTimer()
|
stopRecordingTicker()
|
||||||
hideRecordingViews(animationDuration = 0)
|
hideRecordingViews(animationDuration = 0)
|
||||||
views.voiceMessageSendButton.isVisible = false
|
views.voiceMessageSendButton.isVisible = false
|
||||||
recordingState = RecordingState.NONE
|
recordingState = RecordingState.NONE
|
||||||
|
@ -97,7 +97,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
views.voiceMessageDeletePlayback.setOnClickListener {
|
views.voiceMessageDeletePlayback.setOnClickListener {
|
||||||
stopRecordingTimer()
|
stopRecordingTicker()
|
||||||
hideRecordingViews(animationDuration = 0)
|
hideRecordingViews(animationDuration = 0)
|
||||||
views.voiceMessageSendButton.isVisible = false
|
views.voiceMessageSendButton.isVisible = false
|
||||||
recordingState = RecordingState.NONE
|
recordingState = RecordingState.NONE
|
||||||
|
@ -120,7 +120,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
|
||||||
MotionEvent.ACTION_DOWN -> {
|
MotionEvent.ACTION_DOWN -> {
|
||||||
val recordingStarted = callback?.onVoiceRecordingStarted().orFalse()
|
val recordingStarted = callback?.onVoiceRecordingStarted().orFalse()
|
||||||
if (recordingStarted) {
|
if (recordingStarted) {
|
||||||
startRecordingTimer()
|
startRecordingTicker()
|
||||||
renderToast(context.getString(R.string.voice_message_release_to_send_toast))
|
renderToast(context.getString(R.string.voice_message_release_to_send_toast))
|
||||||
recordingState = RecordingState.STARTED
|
recordingState = RecordingState.STARTED
|
||||||
showRecordingViews()
|
showRecordingViews()
|
||||||
|
@ -134,7 +134,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
MotionEvent.ACTION_UP -> {
|
MotionEvent.ACTION_UP -> {
|
||||||
if (recordingState != RecordingState.LOCKED) {
|
if (recordingState != RecordingState.LOCKED) {
|
||||||
stopRecordingTimer()
|
stopRecordingTicker()
|
||||||
val isCancelled = recordingState == RecordingState.NONE || recordingState == RecordingState.CANCELLED
|
val isCancelled = recordingState == RecordingState.NONE || recordingState == RecordingState.CANCELLED
|
||||||
callback?.onVoiceRecordingEnded(isCancelled)
|
callback?.onVoiceRecordingEnded(isCancelled)
|
||||||
recordingState = RecordingState.NONE
|
recordingState = RecordingState.NONE
|
||||||
|
@ -230,27 +230,27 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
|
||||||
return abs(views.voiceMessageLockImage.y + views.voiceMessageLockImage.height - views.voiceMessageLockArrow.y) < 10
|
return abs(views.voiceMessageLockImage.y + views.voiceMessageLockImage.height - views.voiceMessageLockArrow.y) < 10
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startRecordingTimer() {
|
private fun startRecordingTicker() {
|
||||||
recordingTimer?.stop()
|
recordingTicker?.stop()
|
||||||
recordingTimer = CountUpTimer().apply {
|
recordingTicker = CountUpTimer().apply {
|
||||||
tickListener = object : CountUpTimer.TickListener {
|
tickListener = object : CountUpTimer.TickListener {
|
||||||
override fun onTick(milliseconds: Long) {
|
override fun onTick(milliseconds: Long) {
|
||||||
onRecordingTimerTick(milliseconds)
|
onRecordingTick(milliseconds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resume()
|
resume()
|
||||||
}
|
}
|
||||||
onRecordingTimerTick(0L)
|
onRecordingTick(0L)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onRecordingTimerTick(milliseconds: Long) {
|
private fun onRecordingTick(milliseconds: Long) {
|
||||||
renderRecordingTimer(milliseconds / 1_000)
|
renderRecordingTimer(milliseconds / 1_000)
|
||||||
val timeDiffToRecordingLimit = BuildConfig.VOICE_MESSAGE_DURATION_LIMIT_MS - milliseconds
|
val timeDiffToRecordingLimit = BuildConfig.VOICE_MESSAGE_DURATION_LIMIT_MS - milliseconds
|
||||||
if (timeDiffToRecordingLimit <= 0) {
|
if (timeDiffToRecordingLimit <= 0) {
|
||||||
views.voiceMessageRecordingLayout.post {
|
views.voiceMessageRecordingLayout.post {
|
||||||
recordingState = RecordingState.PLAYBACK
|
recordingState = RecordingState.PLAYBACK
|
||||||
showPlaybackViews()
|
showPlaybackViews()
|
||||||
stopRecordingTimer()
|
stopRecordingTicker()
|
||||||
}
|
}
|
||||||
} else if (timeDiffToRecordingLimit in 10_000..10_999) {
|
} else if (timeDiffToRecordingLimit in 10_000..10_999) {
|
||||||
views.voiceMessageRecordingLayout.post {
|
views.voiceMessageRecordingLayout.post {
|
||||||
|
@ -298,9 +298,9 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stopRecordingTimer() {
|
private fun stopRecordingTicker() {
|
||||||
recordingTimer?.stop()
|
recordingTicker?.stop()
|
||||||
recordingTimer = null
|
recordingTicker = null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showRecordingViews() {
|
private fun showRecordingViews() {
|
||||||
|
|
Loading…
Reference in New Issue