Skip to content

Commit

Permalink
Address detekt issues
Browse files Browse the repository at this point in the history
  • Loading branch information
zwarm committed Jun 9, 2024
1 parent 79a46fb commit a8b7aaf
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand All @@ -228,7 +235,8 @@ fun PreviewReadyToRecordView() {
onMicTap = {},
onStopTap = {},
onRequestPermission = {},
isEligibleForFeature = true)
isEligibleForFeature = true
)
)
VoiceToContentView(state = state, amplitudes = listOf())
}
Expand All @@ -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())
}
Expand All @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,7 +53,7 @@ class VoiceToContentViewModel @Inject constructor(
val amplitudes: LiveData<List<Float>> 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),
Expand All @@ -67,6 +74,7 @@ class VoiceToContentViewModel @Inject constructor(
observeRecordingUpdates()
}

@Suppress("MagicNumber")
fun start() {
val site = selectedSiteRepository.getSelectedSite()
if (site == null || !isVoiceToContentEnabled()) return
Expand All @@ -88,8 +96,9 @@ class VoiceToContentViewModel @Inject constructor(

// Recording
// todo: This doesn't work as expected
@Suppress("MagicNumber")
private fun updateAmplitudes(newAmplitudes: List<Float>) {
_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")
}

Expand Down Expand Up @@ -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",
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<VoiceToContentResult>
// @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<VoiceToContentResult>

/* private val jetpackAIAssistantFeature = JetpackAIAssistantFeature(
hasFeature = true,
Expand Down

0 comments on commit a8b7aaf

Please sign in to comment.