Theme for Toast

This commit is contained in:
Benoit Marty 2021-07-09 20:58:56 +02:00
parent a2671bc0d3
commit 2c1335a2f5
9 changed files with 69 additions and 16 deletions

View File

@ -60,4 +60,6 @@ dependencies {
implementation 'com.github.vector-im:PFLockScreen-Android:1.0.0-beta12'
// dialpad dimen
implementation 'im.dlg:android-dialer:1.2.5'
// AudioRecordView attr
implementation 'com.github.Armen101:AudioRecordView:1.0.5'
}

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#F00" />
<corners android:radius="8dp" />
</shape>

View File

@ -144,4 +144,8 @@
<color name="vctr_voice_message_recording_playback_background_light">#FFE3E8F0</color>
<color name="vctr_voice_message_recording_playback_background_dark">#FF394049</color>
<attr name="vctr_voice_message_toast_background" format="color" />
<color name="vctr_voice_message_toast_background_light">@color/palette_black_900</color>
<color name="vctr_voice_message_toast_background_dark">@color/palette_gray_450</color>
</resources>

View File

@ -12,4 +12,15 @@
<item name="direction">leftToRight</item>
</style>
<style name="Widget.Vector.TextView.Caption.Toast">
<item name="android:paddingTop">8dp</item>
<item name="android:paddingBottom">8dp</item>
<item name="android:paddingStart">12dp</item>
<item name="android:paddingEnd">12dp</item>
<item name="android:background">@drawable/bg_round_corner_8dp</item>
<item name="android:backgroundTint">?vctr_voice_message_toast_background</item>
<item name="android:textColor">@color/palette_white</item>
<item name="android:gravity">center</item>
</style>
</resources>

View File

@ -140,6 +140,7 @@
<item name="vctr_voice_message_playback_background">@color/vctr_voice_message_playback_background_dark</item>
<item name="vctr_voice_message_play_pause_button_background">@color/vctr_voice_message_play_pause_button_background_dark</item>
<item name="vctr_voice_message_recording_playback_background">@color/vctr_voice_message_recording_playback_background_dark</item>
<item name="vctr_voice_message_toast_background">@color/vctr_voice_message_toast_background_dark</item>
</style>
<style name="Theme.Vector.Dark" parent="Base.Theme.Vector.Dark" />

View File

@ -142,6 +142,7 @@
<item name="vctr_voice_message_playback_background">@color/vctr_voice_message_playback_background_light</item>
<item name="vctr_voice_message_play_pause_button_background">@color/vctr_voice_message_play_pause_button_background_light</item>
<item name="vctr_voice_message_recording_playback_background">@color/vctr_voice_message_recording_playback_background_light</item>
<item name="vctr_voice_message_toast_background">@color/vctr_voice_message_toast_background_light</item>
</style>
<style name="Theme.Vector.Light" parent="Base.Theme.Vector.Light" />

View File

@ -595,12 +595,14 @@ class RoomDetailFragment @Inject constructor(
views.voiceMessageRecorderView.voiceMessagePlaybackTracker = voiceMessagePlaybackTracker
views.voiceMessageRecorderView.callback = object : VoiceMessageRecorderView.Callback {
override fun onVoiceRecordingStarted() {
if (checkPermissions(PERMISSIONS_FOR_AUDIO_IP_CALL, requireActivity(), 0)) {
override fun onVoiceRecordingStarted(): Boolean {
return if (checkPermissions(PERMISSIONS_FOR_AUDIO_IP_CALL, requireActivity(), 0)) {
views.composerLayout.isInvisible = true
roomDetailViewModel.handle(RoomDetailAction.StartRecordingVoiceMessage)
context?.toast(R.string.voice_message_release_to_send_toast)
vibrate(requireContext())
true
} else {
false
}
}

View File

@ -21,19 +21,15 @@ import android.text.format.DateUtils
import android.util.AttributeSet
import android.util.TypedValue
import android.view.MotionEvent
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.Px
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isVisible
import com.visualizer.amplitude.AudioRecordView
import im.vector.app.BuildConfig
import im.vector.app.R
import im.vector.app.core.hardware.vibrate
import im.vector.app.core.utils.toast
import im.vector.app.databinding.ViewVoiceMessageRecorderBinding
import im.vector.app.features.home.room.detail.timeline.helper.VoiceMessagePlaybackTracker
import org.matrix.android.sdk.api.extensions.orFalse
import timber.log.Timber
import java.util.Timer
import java.util.TimerTask
@ -50,7 +46,8 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
) : ConstraintLayout(context, attrs, defStyleAttr), VoiceMessagePlaybackTracker.Listener {
interface Callback {
fun onVoiceRecordingStarted()
// Return true if the recording is started
fun onVoiceRecordingStarted(): Boolean
fun onVoiceRecordingEnded(isCancelled: Boolean)
fun onVoiceRecordingPlaybackModeOn()
fun onVoicePlaybackButtonClicked()
@ -122,7 +119,10 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
return@setOnTouchListener when (event.action) {
MotionEvent.ACTION_DOWN -> {
startRecordingTimer()
callback?.onVoiceRecordingStarted()
val recordingStarted = callback?.onVoiceRecordingStarted().orFalse()
if (recordingStarted) {
renderToast(context.getString(R.string.voice_message_release_to_send_toast))
}
recordingState = RecordingState.STARTED
showRecordingViews()
@ -245,7 +245,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
}
} else if (timeDiffToRecordingLimit in 10000..10999) {
views.voiceMessageRecordingLayout.post {
context.toast(context.getString(R.string.voice_message_n_seconds_warning_toast, floor(timeDiffToRecordingLimit / 1000f).toInt()))
renderToast(context.getString(R.string.voice_message_n_seconds_warning_toast, floor(timeDiffToRecordingLimit / 1000f).toInt()))
vibrate(context)
}
}
@ -254,6 +254,17 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
recordingTimer.scheduleAtFixedRate(recordingTimerTask, 0, 1000)
}
private fun renderToast(message: String) {
views.voiceMessageToast.removeCallbacks(hideToastRunnable)
views.voiceMessageToast.text = message
views.voiceMessageToast.isVisible = true
views.voiceMessageToast.postDelayed(hideToastRunnable, 2_000)
}
private val hideToastRunnable = Runnable {
views.voiceMessageToast.isVisible = false
}
private fun showRecordingTimer() {
val formattedTimerText = DateUtils.formatElapsedTime((recordingTime).toLong())
if (recordingState == RecordingState.LOCKED) {
@ -325,7 +336,7 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
views.voiceMessagePlaybackTimerIndicator.isVisible = true
views.voicePlaybackControlButton.isVisible = false
views.voiceMessageSendButton.isVisible = true
context.toast(R.string.voice_message_tap_to_stop_toast)
renderToast(context.getString(R.string.voice_message_tap_to_stop_toast))
}
private fun showPlaybackViews() {
@ -355,15 +366,15 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
override fun onUpdate(state: VoiceMessagePlaybackTracker.Listener.State) {
when (state) {
is VoiceMessagePlaybackTracker.Listener.State.Recording -> {
is VoiceMessagePlaybackTracker.Listener.State.Recording -> {
this.amplitudeList = state.amplitudeList
}
is VoiceMessagePlaybackTracker.Listener.State.Playing -> {
is VoiceMessagePlaybackTracker.Listener.State.Playing -> {
views.voicePlaybackControlButton.setImageResource(R.drawable.ic_play_pause_pause)
val formattedTimerText = DateUtils.formatElapsedTime((state.playbackTime / 1000).toLong())
views.voicePlaybackTime.setText(formattedTimerText)
}
is VoiceMessagePlaybackTracker.Listener.State.Idle -> {
is VoiceMessagePlaybackTracker.Listener.State.Idle -> {
views.voicePlaybackControlButton.setImageResource(R.drawable.ic_play_pause_play)
}
}

View File

@ -42,7 +42,7 @@
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:layout_marginBottom="320dp"
tools:layout_marginBottom="180dp"
tools:visibility="visible" />
<ImageView
@ -211,4 +211,17 @@
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/voiceMessageToast"
style="@style/Widget.Vector.TextView.Caption.Toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="84dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:text="@string/voice_message_release_to_send_toast"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>