-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functionality in call menu options to start/stop transcriptions
- Loading branch information
1 parent
b53deeb
commit d9a138c
Showing
11 changed files
with
384 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 75 additions & 32 deletions
107
demo-app/src/main/kotlin/io/getstream/video/android/ui/menu/TranscriptionUiState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,83 @@ | ||
/* | ||
* Copyright (c) 2014-2024 Stream.io Inc. All rights reserved. | ||
* | ||
* Licensed under the Stream License; | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://github.com/GetStream/stream-video-android/blob/main/LICENSE | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.getstream.video.android.ui.menu | ||
|
||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Transcribe | ||
import androidx.compose.material.icons.filled.Description | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import io.getstream.video.android.core.TranscriptionState | ||
import org.openapitools.client.models.TranscriptionSettingsResponse | ||
|
||
sealed class TranscriptionUiState( | ||
val text: String, | ||
val icon: ImageVector, // Assuming it's a drawable resource ID | ||
val highlight: Boolean, | ||
val isButtonEnabled: Boolean, | ||
) | ||
|
||
/** | ||
* Stop Transcription | ||
* Start Transcription | ||
* Transcription is disabled | ||
* Transcription failed | ||
*/ | ||
|
||
data object TranscriptionAvailableUiState : TranscriptionUiState( | ||
text = "Transcribe the call", | ||
icon = Icons.Default.Description, | ||
highlight = false, | ||
isButtonEnabled = true, | ||
) | ||
|
||
data object TranscriptionStoppedUiState : TranscriptionUiState( | ||
text = "Stop Transcription", | ||
icon = Icons.Default.Description, | ||
highlight = true, | ||
isButtonEnabled = false, | ||
) | ||
|
||
data object TranscriptionDisabledUiState : TranscriptionUiState( | ||
text = "Transcription not available", | ||
icon = Icons.Default.Description, | ||
highlight = false, | ||
isButtonEnabled = false, | ||
) | ||
|
||
data object TranscriptionFailedUiState : TranscriptionUiState( | ||
text = "Transcription failed", | ||
icon = Icons.Default.Description, | ||
highlight = false, | ||
isButtonEnabled = false, | ||
) | ||
|
||
fun TranscriptionSettingsResponse.Mode.mapToUiState(): TranscriptionUiState { | ||
return when (this) { | ||
TranscriptionSettingsResponse.Mode.Available -> TranscriptionAvailableUiState | ||
TranscriptionSettingsResponse.Mode.Disabled -> TranscriptionDisabledUiState | ||
TranscriptionSettingsResponse.Mode.AutoOn -> TranscriptionStoppedUiState | ||
else -> TranscriptionFailedUiState | ||
} | ||
} | ||
|
||
data class TranscriptionUiState(val text: String, | ||
val icon: ImageVector, // Assuming it's a drawable resource ID | ||
val isButtonEnabled: Boolean) | ||
|
||
fun TranscriptionState.mapTouUiState(): TranscriptionUiState { | ||
return when(this){ | ||
is TranscriptionState.CallTranscriptionInitialState -> TranscriptionUiState( | ||
text = "Transcription Not Ready", | ||
icon = Icons.Default.Transcribe, | ||
isButtonEnabled = false | ||
) | ||
is TranscriptionState.CallTranscriptionReadyState -> TranscriptionUiState( | ||
text = "Transcription is ready", | ||
icon = Icons.Default.Transcribe, | ||
isButtonEnabled = true | ||
) | ||
is TranscriptionState.CallTranscriptionStartedState -> TranscriptionUiState( | ||
text = "Transcription in progress", | ||
icon = Icons.Default.Transcribe, | ||
isButtonEnabled = true | ||
) | ||
is TranscriptionState.CallTranscriptionStoppedState -> TranscriptionUiState( | ||
text = "Transcription stopped", | ||
icon = Icons.Default.Transcribe, | ||
isButtonEnabled = true | ||
) | ||
is TranscriptionState.CallTranscriptionFailedState -> TranscriptionUiState( | ||
text = "Transcription failed", | ||
icon = Icons.Default.Transcribe, | ||
isButtonEnabled = false | ||
) | ||
fun TranscriptionState.mapToUiState(): TranscriptionUiState { | ||
return when (this) { | ||
is TranscriptionState.CallTranscriptionStartedState -> TranscriptionStoppedUiState | ||
is TranscriptionState.CallTranscriptionStoppedState -> TranscriptionAvailableUiState | ||
is TranscriptionState.CallTranscriptionFailedState -> TranscriptionFailedUiState | ||
is TranscriptionState.CallTranscriptionInitialState -> TranscriptionDisabledUiState | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...in/io/getstream/video/android/ui/menu/transcriptions/RestApiTranscriptionStateStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2014-2024 Stream.io Inc. All rights reserved. | ||
* | ||
* Licensed under the Stream License; | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://github.com/GetStream/stream-video-android/blob/main/LICENSE | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.getstream.video.android.ui.menu.transcriptions | ||
|
||
import io.getstream.video.android.ui.menu.TranscriptionAvailableUiState | ||
import io.getstream.video.android.ui.menu.TranscriptionDisabledUiState | ||
import io.getstream.video.android.ui.menu.TranscriptionStoppedUiState | ||
import io.getstream.video.android.ui.menu.TranscriptionUiState | ||
import io.getstream.video.android.ui.menu.mapToUiState | ||
import org.openapitools.client.models.TranscriptionSettingsResponse | ||
|
||
class RestApiTranscriptionStateStrategy( | ||
private val isCurrentlyTranscribing: Boolean, | ||
private val transcriptionModeFromRest: TranscriptionSettingsResponse.Mode, | ||
) : TranscriptionStateStrategy { | ||
override fun mapToUiState(): TranscriptionUiState { | ||
return iosStrategy() | ||
} | ||
|
||
fun iosStrategy(): TranscriptionUiState { | ||
return when (transcriptionModeFromRest) { | ||
TranscriptionSettingsResponse.Mode.Available, TranscriptionSettingsResponse.Mode.AutoOn -> { | ||
if (isCurrentlyTranscribing) { | ||
TranscriptionStoppedUiState | ||
} else { | ||
TranscriptionAvailableUiState | ||
} | ||
} | ||
|
||
else -> TranscriptionDisabledUiState | ||
} | ||
} | ||
|
||
fun anotherStrategy(): TranscriptionUiState { | ||
return if (isCurrentlyTranscribing) { | ||
TranscriptionStoppedUiState | ||
} else { | ||
transcriptionModeFromRest.mapToUiState() | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...in/kotlin/io/getstream/video/android/ui/menu/transcriptions/TranscriptionStateStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2014-2024 Stream.io Inc. All rights reserved. | ||
* | ||
* Licensed under the Stream License; | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://github.com/GetStream/stream-video-android/blob/main/LICENSE | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.getstream.video.android.ui.menu.transcriptions | ||
|
||
import io.getstream.video.android.ui.menu.TranscriptionUiState | ||
|
||
interface TranscriptionStateStrategy { | ||
fun mapToUiState(): TranscriptionUiState | ||
} |
Oops, something went wrong.