diff --git a/WordPress/src/main/java/org/wordpress/android/ui/voicetocontent/MicToStopIcon.kt b/WordPress/src/main/java/org/wordpress/android/ui/voicetocontent/MicToStopIcon.kt index d02459df998d..f15a233edefe 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/voicetocontent/MicToStopIcon.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/voicetocontent/MicToStopIcon.kt @@ -12,11 +12,16 @@ import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.isSystemInDarkTheme -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.ContentAlpha import androidx.compose.material.MaterialTheme -import androidx.compose.runtime.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color diff --git a/WordPress/src/main/java/org/wordpress/android/ui/voicetocontent/VoiceToContentScreen.kt b/WordPress/src/main/java/org/wordpress/android/ui/voicetocontent/VoiceToContentScreen.kt index 2f1b60114b4d..e8e28477cbb9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/voicetocontent/VoiceToContentScreen.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/voicetocontent/VoiceToContentScreen.kt @@ -206,10 +206,17 @@ fun PreviewInitializingView() { val state = VoiceToContentUiState( uiStateType = VoiceToContentUIStateType.INITIALIZING, header = HeaderUIModel(label = R.string.voice_to_content_base_header_label, onClose = { }), - secondaryHeader = SecondaryHeaderUIModel(label = R.string.voice_to_content_secondary_header_label, isProgressIndicatorVisible = true), - recordingPanel = RecordingPanelUIModel(actionLabel = R.string.voice_to_content_begin_recording_label, isEnabled = false, hasPermission = false) + secondaryHeader = SecondaryHeaderUIModel( + label = R.string.voice_to_content_secondary_header_label, + isProgressIndicatorVisible = true + ), + recordingPanel = RecordingPanelUIModel( + actionLabel = R.string.voice_to_content_begin_recording_label, + isEnabled = false, + hasPermission = false + ) ) - VoiceToContentView(state = state, amplitudes = listOf()) + VoiceToContentView(state = state, amplitudes = listOf()) } } @@ -228,7 +235,8 @@ fun PreviewReadyToRecordView() { onMicTap = {}, onStopTap = {}, onRequestPermission = {}, - isEligibleForFeature = true) + isEligibleForFeature = true + ) ) VoiceToContentView(state = state, amplitudes = listOf()) } @@ -247,7 +255,8 @@ fun PreviewNotEligibleToRecordView() { actionLabel = R.string.voice_to_content_begin_recording_label, isEnabled = false, isEligibleForFeature = false, - urlLink = "https://www.wordpress.com") + urlLink = "https://www.wordpress.com" + ) ) VoiceToContentView(state = state, amplitudes = listOf()) } @@ -269,9 +278,21 @@ fun PreviewRecordingView() { onMicTap = {}, onStopTap = {}, onRequestPermission = {}, - isEligibleForFeature = true) + isEligibleForFeature = true + ) + ) + VoiceToContentView( + state = state, + amplitudes = listOf( + 1.1f, + 2.2f, + 3.3f, + 4.4f, + 2.2f, + 3.3f, + 1.1f + ) ) - VoiceToContentView(state = state, amplitudes = listOf(1.1f, 2.2f, 3.3f, 4.4f, 2.2f, 3.3f, 1.1f, 2.2f, 3.3f, 4.4f, 2.2f, 3.3f, 1.1f, 2.2f, 3.3f, 4.4f, 2.2f, 3.3f)) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/voicetocontent/VoiceToContentViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/voicetocontent/VoiceToContentViewModel.kt index 015c5913867d..18aeab9273b8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/voicetocontent/VoiceToContentViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/voicetocontent/VoiceToContentViewModel.kt @@ -20,6 +20,13 @@ import org.wordpress.android.ui.mysite.SelectedSiteRepository import org.wordpress.android.util.audio.IAudioRecorder import org.wordpress.android.viewmodel.ContextProvider import org.wordpress.android.viewmodel.ScopedViewModel +import org.wordpress.android.ui.voicetocontent.VoiceToContentUIStateType.INITIALIZING +import org.wordpress.android.ui.voicetocontent.VoiceToContentUIStateType.READY_TO_RECORD +import org.wordpress.android.ui.voicetocontent.VoiceToContentUIStateType.RECORDING +import org.wordpress.android.ui.voicetocontent.VoiceToContentUIStateType.ERROR +import org.wordpress.android.ui.voicetocontent.VoiceToContentUIStateType.INELIGIBLE_FOR_FEATURE +import org.wordpress.android.ui.voicetocontent.VoiceToContentUIStateType.PROCESSING + import java.io.File import javax.inject.Inject import javax.inject.Named @@ -46,7 +53,7 @@ class VoiceToContentViewModel @Inject constructor( val amplitudes: LiveData> get() = _amplitudes private val _state = MutableStateFlow(VoiceToContentUiState( - uiStateType = VoiceToContentUIStateType.INITIALIZING, + uiStateType = INITIALIZING, header = HeaderUIModel( label = R.string.voice_to_content_base_header_label, onClose = ::onClose), @@ -67,6 +74,7 @@ class VoiceToContentViewModel @Inject constructor( observeRecordingUpdates() } + @Suppress("MagicNumber") fun start() { val site = selectedSiteRepository.getSelectedSite() if (site == null || !isVoiceToContentEnabled()) return @@ -88,8 +96,9 @@ class VoiceToContentViewModel @Inject constructor( // Recording // todo: This doesn't work as expected + @Suppress("MagicNumber") private fun updateAmplitudes(newAmplitudes: List) { - _amplitudes.value = listOf(1.1f, 2.2f, 4.4f, 3.2f, 1.1f, 2.2f, 1.0f, 3.5f) + _amplitudes.value = listOf(1.1f, 2.2f, 4.4f, 3.2f, 1.1f, 2.2f, 1.0f, 3.5f) Log.d(javaClass.simpleName, "Update amplitudes: $newAmplitudes") } @@ -191,21 +200,25 @@ class VoiceToContentViewModel @Inject constructor( val requestsAvailable = voiceToContentFeatureUtils.getRequestLimit(model) val currentState = _state.value _state.value = currentState.copy( - uiStateType = if (isEligibleForFeature) VoiceToContentUIStateType.READY_TO_RECORD else VoiceToContentUIStateType.INELIGIBLE_FOR_FEATURE, - secondaryHeader = currentState.secondaryHeader?.copy(requestsAvailable = requestsAvailable.toString(), isProgressIndicatorVisible = false), + uiStateType = if (isEligibleForFeature) READY_TO_RECORD else INELIGIBLE_FOR_FEATURE, + secondaryHeader = currentState.secondaryHeader?.copy( + requestsAvailable = requestsAvailable.toString(), + isProgressIndicatorVisible = false + ), recordingPanel = currentState.recordingPanel?.copy( isEnabled = isEligibleForFeature, isEligibleForFeature = isEligibleForFeature, onMicTap = ::onMicTap, onRequestPermission = ::onRequestPermission, - hasPermission = hasAllPermissionsForRecording()) + hasPermission = hasAllPermissionsForRecording() + ) ) } private fun transitionToRecording() { val currentState = _state.value _state.value = currentState.copy( - uiStateType = VoiceToContentUIStateType.RECORDING, + uiStateType = RECORDING, header = currentState.header.copy(label = R.string.voice_to_content_recording_label), secondaryHeader = currentState.secondaryHeader?.copy( timeElapsed = "00:00:00", @@ -221,7 +234,7 @@ class VoiceToContentViewModel @Inject constructor( private fun transitionToProcessing() { val currentState = _state.value _state.value = currentState.copy( - uiStateType = VoiceToContentUIStateType.PROCESSING, + uiStateType = PROCESSING, header = currentState.header.copy(label = R.string.voice_to_content_processing), secondaryHeader = null, recordingPanel = null @@ -232,7 +245,7 @@ class VoiceToContentViewModel @Inject constructor( private fun transitionToError() { val currentState = _state.value _state.value = currentState.copy( - uiStateType = VoiceToContentUIStateType.ERROR, + uiStateType = ERROR, header = currentState.header.copy( label = R.string.voice_to_content_ready_to_record), secondaryHeader = null, recordingPanel = null diff --git a/WordPress/src/test/java/org/wordpress/android/ui/voicetocontent/VoiceToContentViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/voicetocontent/VoiceToContentViewModelTest.kt index d4574af26ea1..9b44f797b362 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/voicetocontent/VoiceToContentViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/voicetocontent/VoiceToContentViewModelTest.kt @@ -1,46 +1,31 @@ package org.wordpress.android.ui.voicetocontent import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.flow.flow -import kotlinx.coroutines.test.runTest -import org.assertj.core.api.Assertions.assertThat -import org.junit.Before -import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mock import org.mockito.junit.MockitoJUnitRunner -import org.mockito.kotlin.any -import org.mockito.kotlin.verify -import org.mockito.kotlin.verifyNoInteractions -import org.mockito.kotlin.whenever import org.wordpress.android.BaseUnitTest -import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.fluxc.store.jetpackai.JetpackAIStore -import org.wordpress.android.ui.mysite.SelectedSiteRepository -import org.wordpress.android.util.audio.RecordingUpdate -import java.io.File @ExperimentalCoroutinesApi @RunWith(MockitoJUnitRunner::class) class VoiceToContentViewModelTest : BaseUnitTest() { - @Mock - lateinit var voiceToContentFeatureUtils: VoiceToContentFeatureUtils - - @Mock - lateinit var voiceToContentUseCase: VoiceToContentUseCase - - @Mock - lateinit var recordingUseCase: RecordingUseCase - - @Mock - lateinit var selectedSiteRepository: SelectedSiteRepository - - @Mock - lateinit var jetpackAIStore: JetpackAIStore - - private lateinit var viewModel: VoiceToContentViewModel - - private lateinit var uiState: MutableList +// @Mock +// lateinit var voiceToContentFeatureUtils: VoiceToContentFeatureUtils +// +// @Mock +// lateinit var voiceToContentUseCase: VoiceToContentUseCase +// +// @Mock +// lateinit var recordingUseCase: RecordingUseCase +// +// @Mock +// lateinit var selectedSiteRepository: SelectedSiteRepository +// +// @Mock +// lateinit var jetpackAIStore: JetpackAIStore +// +// private lateinit var viewModel: VoiceToContentViewModel +// +// private lateinit var uiState: MutableList /* private val jetpackAIAssistantFeature = JetpackAIAssistantFeature( hasFeature = true,