Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ sealed interface AudioPlayerState {
data class Ready(
val readyState: ReadyState,
val progressPercentage: ProgressPercentage = ProgressPercentage(0f),
val durationMillis: Int = 0,
) : AudioPlayerState {
sealed interface ReadyState {
object NotStarted : ReadyState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ private class AndroidMediaPlayer(
override val isPlaying: Boolean
get() = mediaPlayer.isPlaying

override val duration: Int
get() = mediaPlayer.duration

override fun pause() {
mediaPlayer.pause()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.hedvig.audio.player.data.ProgressPercentage

interface CommonMediaPlayer {
val isPlaying: Boolean
val duration: Int

fun pause()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,24 @@ private class AudioPlayerImpl(
_audioPlayerState.update { AudioPlayerState.Failed }
true
}
setOnPreparedListener { _audioPlayerState.update { AudioPlayerState.Ready.notStarted() } }
setOnCompletionListener { _audioPlayerState.update { AudioPlayerState.Ready.done() } }
setOnPreparedListener {
_audioPlayerState.update {
AudioPlayerState.Ready(
readyState = AudioPlayerState.Ready.ReadyState.NotStarted,
progressPercentage = ProgressPercentage(0f),
durationMillis = duration,
)
}
}
setOnCompletionListener {
_audioPlayerState.update {
AudioPlayerState.Ready(
readyState = AudioPlayerState.Ready.ReadyState.Done,
progressPercentage = ProgressPercentage(1f),
durationMillis = duration,
)
}
}
prepareAsync()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import kotlin.math.absoluteValue
import kotlin.math.roundToInt
import kotlin.random.Random

private const val waveWidthPercentOfSpaceAvailable = 0.5f
internal const val waveWidthPercentOfSpaceAvailable = 0.5f

@Composable
internal fun FakeAudioWaves(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ actual fun CommonMediaPlayer(dataSourceUrl: String): CommonMediaPlayer {
override val isPlaying: Boolean
get() = false

override val duration: Int
get() = 0

override fun pause() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,32 @@ class AndroidAccessTokenProviderTest {
}

@Test
fun `when the access token is expired, and the refresh token is not expired, refresh and return new token`() = runTest {
val clock = TestClock()
val authTokenStorage = authTokenStorage(clock)
authTokenStorage.updateTokens(
AccessToken("", 10.minutes.inWholeSeconds),
RefreshToken("", 1.hours.inWholeSeconds),
)
val authRepository = FakeAuthRepository()
val authTokenService = authTokenService(authTokenStorage, authRepository)
val accessTokenProvider = AndroidAccessTokenProvider(authTokenService, clock)
fun `when the access token is expired, and the refresh token is not expired, refresh and return new token`() =
runTest {
val clock = TestClock()
val authTokenStorage = authTokenStorage(clock)
authTokenStorage.updateTokens(
AccessToken("", 10.minutes.inWholeSeconds),
RefreshToken("", 1.hours.inWholeSeconds),
)
val authRepository = FakeAuthRepository()
val authTokenService = authTokenService(authTokenStorage, authRepository)
val accessTokenProvider = AndroidAccessTokenProvider(authTokenService, clock)

clock.advanceTimeBy(30.minutes)
authRepository.exchangeResponse.add(
AuthTokenResult.Success(
AccessToken("refreshedToken", 10.minutes.inWholeSeconds),
RefreshToken("refreshedRefreshToken", 0),
),
)
val token = accessTokenProvider.provide()
clock.advanceTimeBy(30.minutes)
authRepository.exchangeResponse.add(
AuthTokenResult.Success(
AccessToken("refreshedToken", 10.minutes.inWholeSeconds),
RefreshToken("refreshedRefreshToken", 0),
),
)
val token = accessTokenProvider.provide()

val storedAuthTokens = authTokenStorage.getTokens().first()!!
assertThat(storedAuthTokens.accessToken.token).isEqualTo("refreshedToken")
assertThat(storedAuthTokens.refreshToken.token).isEqualTo("refreshedRefreshToken")
assertThat(token).isEqualTo("refreshedToken")
}
val storedAuthTokens = authTokenStorage.getTokens().first()!!
assertThat(storedAuthTokens.accessToken.token).isEqualTo("refreshedToken")
assertThat(storedAuthTokens.refreshToken.token).isEqualTo("refreshedRefreshToken")
assertThat(token).isEqualTo("refreshedToken")
}

@Test
fun `when the access token and the refresh token are expired, clear tokens and return null`() = runTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import io.ktor.client.request.header
import io.ktor.serialization.kotlinx.json.json
import kotlinx.serialization.json.Json

internal fun buildKtorClient(
additionalHttpHeadersProvider: () -> Map<String, String>,
): HttpClient {
internal fun buildKtorClient(additionalHttpHeadersProvider: () -> Map<String, String>): HttpClient {
val httpClientConfig: HttpClientConfig<*>.() -> Unit = {
commonKtorConfiguration(additionalHttpHeadersProvider).invoke(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ interface AppBuildConfig {
enum class Flavor {
Production,
Staging,
Develop
Develop,
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ private fun makeUserAgent(languageBCP47: String, appBuildConfig: AppBuildConfig)

private interface UrlHolder {
fun urlGraphqlOctopus(flavor: Flavor): String

fun urlBaseWeb(flavor: Flavor): String

fun urlOdyssey(flavor: Flavor): String

fun urlBotService(flavor: Flavor): String

fun urlClaimsService(flavor: Flavor): String

fun deepLinkHosts(flavor: Flavor): List<String>
}

Expand Down Expand Up @@ -125,6 +130,7 @@ private class AppConfigUrlHolder(private val appBuildConfig: AppBuildConfig) : U
}

private fun deepLinkDomainPathPrefix(): String = "/deeplink"

private fun deepLinkDomainHostOld(flavor: Flavor): String = when (flavor) {
Production -> "hedvig.page.link"
Staging -> "hedvigtest.page.link"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.hedvig.android.core.datastore
import kotlinx.coroutines.flow.firstOrNull

internal class AndroidDeviceIdFetcher(
private val deviceIdDataStore: DeviceIdDataStore
private val deviceIdDataStore: DeviceIdDataStore,
) : DeviceIdFetcher {
override suspend fun fetch(): String? {
return deviceIdDataStore.observeDeviceId().firstOrNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.hedvig.android.core.datastore
import kotlinx.coroutines.flow.firstOrNull

internal class JvmDeviceIdFetcher(
private val deviceIdDataStore: DeviceIdDataStore
private val deviceIdDataStore: DeviceIdDataStore,
) : DeviceIdFetcher {
override suspend fun fetch(): String? {
return deviceIdDataStore.observeDeviceId().firstOrNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.PreviewParameter
import com.hedvig.android.compose.ui.preview.BooleanCollectionPreviewParameterProvider
import com.hedvig.android.core.locale.previewCommonLocale
import com.hedvig.android.core.locale.CommonLocale
import com.hedvig.android.core.locale.previewCommonLocale
import com.hedvig.android.design.system.hedvig.ButtonDefaults.ButtonSize.Medium
import com.hedvig.android.design.system.hedvig.api.HedvigDisplayMode
import com.hedvig.android.design.system.hedvig.api.HedvigSelectableDates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ enum class FigmaShapeDirection {
All,
TopOnly,
BottomOnly,
EndOnly
EndOnly,
}

private fun RoundedPolygon.toPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ internal sealed interface ClaimChatEvent {

data class RedoRecording(override val id: StepId) : AudioRecording

data class ShowFreeText(override val id: StepId) : AudioRecording
data class SwitchToFreeText(override val id: StepId) : AudioRecording

data class ShowAudioRecording(override val id: StepId) : AudioRecording
data class SwitchToAudioRecording(override val id: StepId) : AudioRecording
}

data class UpdateFreeText(val text: String?) : ClaimChatEvent
Expand Down Expand Up @@ -367,7 +367,7 @@ internal class ClaimChatPresenter(
}
}

is ClaimChatEvent.AudioRecording.ShowFreeText -> {
is ClaimChatEvent.AudioRecording.SwitchToFreeText -> {
val currentContent = currentStep?.stepContent as? StepContent.AudioRecording
?: return@CollectEvents
val textTooShort = freeText?.length?.let {
Expand All @@ -387,7 +387,7 @@ internal class ClaimChatPresenter(
}
}

is ClaimChatEvent.AudioRecording.ShowAudioRecording -> {
is ClaimChatEvent.AudioRecording.SwitchToAudioRecording -> {
steps.updateStepWithSuccess<StepContent.AudioRecording>(event.id) { step, content ->
step.copy(stepContent = content.copy(recordingState = AudioRecording.NotRecording))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ internal sealed interface StepContent {
}

sealed interface AudioRecordingStepState {
data object NonDefined : AudioRecordingStepState

data class FreeTextDescription(
val showOverlay: Boolean,
val errorType: FreeTextErrorType?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private fun ClaimIntentStepContentFragment.toStepContent(locale: CommonLocale):
is AudioRecordingFragment -> StepContent.AudioRecording(
uploadUri = uploadUri,
isSkippable = isSkippable,
recordingState = AudioRecordingStepState.NonDefined,
recordingState = AudioRecordingStepState.AudioRecording.NotRecording,
freeTextMinLength = freeTextMinLength,
freeTextMaxLength = freeTextMaxLength,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,9 @@ private fun ClaimChatScrollableContent(
contentType = { it.stepContent::class },
) { item ->
val isCurrentStep = item.id == uiState.steps.lastOrNull()?.id
val showAnimationSequence = isCurrentStep
&& item.stepContent !is StepContent.Task
&& !uiState.stepsWithShownAnimations.contains(item.id)
val showAnimationSequence = isCurrentStep &&
item.stepContent !is StepContent.Task &&
!uiState.stepsWithShownAnimations.contains(item.id)
val isLastItem = item == uiState.steps.lastOrNull()

val heightModifier = if (isLastItem) {
Expand Down Expand Up @@ -822,10 +822,10 @@ private fun StepBottomContent(
item = stepItem,
stepContent = stepItem.stepContent,
onShowFreeText = {
onEvent(ClaimChatEvent.AudioRecording.ShowFreeText(stepItem.id))
onEvent(ClaimChatEvent.AudioRecording.SwitchToFreeText(stepItem.id))
},
onShowAudioRecording = {
onEvent(ClaimChatEvent.AudioRecording.ShowAudioRecording(stepItem.id))
onSwitchToAudioRecording = {
onEvent(ClaimChatEvent.AudioRecording.SwitchToAudioRecording(stepItem.id))
},
onLaunchFullScreenEditText = { restrictions ->
onEvent(ClaimChatEvent.OpenFreeTextOverlay(restrictions))
Expand Down Expand Up @@ -1387,7 +1387,7 @@ private fun AudioRecordingStep(
freeText: String?,
stepContent: StepContent.AudioRecording,
onShowFreeText: () -> Unit,
onShowAudioRecording: () -> Unit,
onSwitchToAudioRecording: () -> Unit,
onLaunchFullScreenEditText: (restrictions: FreeTextRestrictions) -> Unit,
submitFreeText: () -> Unit,
submitAudioFile: () -> Unit,
Expand Down Expand Up @@ -1418,8 +1418,8 @@ private fun AudioRecordingStep(
openAppSettings = openAppSettings,
freeTextAvailable = true,
submitFreeText = submitFreeText,
onShowFreeText = onShowFreeText,
onShowAudioRecording = onShowAudioRecording,
onSwitchToFreeText = onShowFreeText,
onSwitchToAudioRecording = onSwitchToAudioRecording,
onLaunchFullScreenEditText = {
onLaunchFullScreenEditText(
FreeTextRestrictions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -988,8 +988,8 @@ private fun PreviewClaimChatComponents() {
openAppSettings = {},
freeTextAvailable = true,
submitFreeText = {},
onShowFreeText = {},
onShowAudioRecording = {},
onSwitchToFreeText = {},
onSwitchToAudioRecording = {},
onLaunchFullScreenEditText = {},
canSkip = true,
onSkip = {},
Expand Down
Loading
Loading