Replace FeatureFlags.ShowMediaUploadingFlow by FeatureFlags.LocationSharing because it has more chance to be disabled.
I do not want to remove all our feature flags...
This commit is contained in:
parent
062e7553db
commit
cd3e6c42e2
8 changed files with 64 additions and 50 deletions
|
|
@ -83,7 +83,7 @@ internal fun AttachmentsBottomSheet(
|
||||||
onDismissRequest = { isVisible = false }
|
onDismissRequest = { isVisible = false }
|
||||||
) {
|
) {
|
||||||
AttachmentSourcePickerMenu(
|
AttachmentSourcePickerMenu(
|
||||||
eventSink = state.eventSink,
|
state = state,
|
||||||
onSendLocationClicked = onSendLocationClicked,
|
onSendLocationClicked = onSendLocationClicked,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -93,7 +93,7 @@ internal fun AttachmentsBottomSheet(
|
||||||
@OptIn(ExperimentalMaterialApi::class)
|
@OptIn(ExperimentalMaterialApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
internal fun AttachmentSourcePickerMenu(
|
internal fun AttachmentSourcePickerMenu(
|
||||||
eventSink: (MessageComposerEvents) -> Unit,
|
state: MessageComposerState,
|
||||||
onSendLocationClicked: () -> Unit,
|
onSendLocationClicked: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
|
|
@ -102,33 +102,35 @@ internal fun AttachmentSourcePickerMenu(
|
||||||
// .navigationBarsPadding() - FIXME after https://issuetracker.google.com/issues/275849044
|
// .navigationBarsPadding() - FIXME after https://issuetracker.google.com/issues/275849044
|
||||||
) {
|
) {
|
||||||
ListItem(
|
ListItem(
|
||||||
modifier = Modifier.clickable { eventSink(MessageComposerEvents.PickAttachmentSource.FromGallery) },
|
modifier = Modifier.clickable { state.eventSink(MessageComposerEvents.PickAttachmentSource.FromGallery) },
|
||||||
icon = { Icon(Icons.Default.Collections, null) },
|
icon = { Icon(Icons.Default.Collections, null) },
|
||||||
text = { Text(stringResource(R.string.screen_room_attachment_source_gallery)) },
|
text = { Text(stringResource(R.string.screen_room_attachment_source_gallery)) },
|
||||||
)
|
)
|
||||||
ListItem(
|
ListItem(
|
||||||
modifier = Modifier.clickable { eventSink(MessageComposerEvents.PickAttachmentSource.FromFiles) },
|
modifier = Modifier.clickable { state.eventSink(MessageComposerEvents.PickAttachmentSource.FromFiles) },
|
||||||
icon = { Icon(Icons.Default.AttachFile, null) },
|
icon = { Icon(Icons.Default.AttachFile, null) },
|
||||||
text = { Text(stringResource(R.string.screen_room_attachment_source_files)) },
|
text = { Text(stringResource(R.string.screen_room_attachment_source_files)) },
|
||||||
)
|
)
|
||||||
ListItem(
|
ListItem(
|
||||||
modifier = Modifier.clickable { eventSink(MessageComposerEvents.PickAttachmentSource.PhotoFromCamera) },
|
modifier = Modifier.clickable { state.eventSink(MessageComposerEvents.PickAttachmentSource.PhotoFromCamera) },
|
||||||
icon = { Icon(Icons.Default.PhotoCamera, null) },
|
icon = { Icon(Icons.Default.PhotoCamera, null) },
|
||||||
text = { Text(stringResource(R.string.screen_room_attachment_source_camera_photo)) },
|
text = { Text(stringResource(R.string.screen_room_attachment_source_camera_photo)) },
|
||||||
)
|
)
|
||||||
ListItem(
|
ListItem(
|
||||||
modifier = Modifier.clickable { eventSink(MessageComposerEvents.PickAttachmentSource.VideoFromCamera) },
|
modifier = Modifier.clickable { state.eventSink(MessageComposerEvents.PickAttachmentSource.VideoFromCamera) },
|
||||||
icon = { Icon(Icons.Default.Videocam, null) },
|
icon = { Icon(Icons.Default.Videocam, null) },
|
||||||
text = { Text(stringResource(R.string.screen_room_attachment_source_camera_video)) },
|
text = { Text(stringResource(R.string.screen_room_attachment_source_camera_video)) },
|
||||||
)
|
)
|
||||||
ListItem(
|
if (state.canShareLocation) {
|
||||||
modifier = Modifier.clickable {
|
ListItem(
|
||||||
eventSink(MessageComposerEvents.PickAttachmentSource.Location)
|
modifier = Modifier.clickable {
|
||||||
onSendLocationClicked()
|
state.eventSink(MessageComposerEvents.PickAttachmentSource.Location)
|
||||||
},
|
onSendLocationClicked()
|
||||||
icon = { Icon(Icons.Default.LocationOn, null) },
|
},
|
||||||
text = { Text(stringResource(R.string.screen_room_attachment_source_location)) },
|
icon = { Icon(Icons.Default.LocationOn, null) },
|
||||||
)
|
text = { Text(stringResource(R.string.screen_room_attachment_source_location)) },
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,7 +138,9 @@ internal fun AttachmentSourcePickerMenu(
|
||||||
@Composable
|
@Composable
|
||||||
internal fun AttachmentSourcePickerMenuPreview() = ElementPreview {
|
internal fun AttachmentSourcePickerMenuPreview() = ElementPreview {
|
||||||
AttachmentSourcePickerMenu(
|
AttachmentSourcePickerMenu(
|
||||||
eventSink = {},
|
state = aMessageComposerState(
|
||||||
|
canShareLocation = true,
|
||||||
|
),
|
||||||
onSendLocationClicked = {},
|
onSendLocationClicked = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,11 @@ class MessageComposerPresenter @Inject constructor(
|
||||||
mutableStateOf<AttachmentsState>(AttachmentsState.None)
|
mutableStateOf<AttachmentsState>(AttachmentsState.None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var canShareLocation = false
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
canShareLocation = featureFlagService.isFeatureEnabled(FeatureFlags.LocationSharing)
|
||||||
|
}
|
||||||
|
|
||||||
val galleryMediaPicker = mediaPickerProvider.registerGalleryPicker { uri, mimeType ->
|
val galleryMediaPicker = mediaPickerProvider.registerGalleryPicker { uri, mimeType ->
|
||||||
handlePickedMedia(attachmentsState, uri, mimeType)
|
handlePickedMedia(attachmentsState, uri, mimeType)
|
||||||
}
|
}
|
||||||
|
|
@ -140,23 +145,23 @@ class MessageComposerPresenter @Inject constructor(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
MessageComposerEvents.AddAttachment -> localCoroutineScope.launchIfMediaPickerEnabled {
|
MessageComposerEvents.AddAttachment -> localCoroutineScope.launch {
|
||||||
showAttachmentSourcePicker = true
|
showAttachmentSourcePicker = true
|
||||||
}
|
}
|
||||||
MessageComposerEvents.DismissAttachmentMenu -> showAttachmentSourcePicker = false
|
MessageComposerEvents.DismissAttachmentMenu -> showAttachmentSourcePicker = false
|
||||||
MessageComposerEvents.PickAttachmentSource.FromGallery -> localCoroutineScope.launchIfMediaPickerEnabled {
|
MessageComposerEvents.PickAttachmentSource.FromGallery -> localCoroutineScope.launch {
|
||||||
showAttachmentSourcePicker = false
|
showAttachmentSourcePicker = false
|
||||||
galleryMediaPicker.launch()
|
galleryMediaPicker.launch()
|
||||||
}
|
}
|
||||||
MessageComposerEvents.PickAttachmentSource.FromFiles -> localCoroutineScope.launchIfMediaPickerEnabled {
|
MessageComposerEvents.PickAttachmentSource.FromFiles -> localCoroutineScope.launch {
|
||||||
showAttachmentSourcePicker = false
|
showAttachmentSourcePicker = false
|
||||||
filesPicker.launch()
|
filesPicker.launch()
|
||||||
}
|
}
|
||||||
MessageComposerEvents.PickAttachmentSource.PhotoFromCamera -> localCoroutineScope.launchIfMediaPickerEnabled {
|
MessageComposerEvents.PickAttachmentSource.PhotoFromCamera -> localCoroutineScope.launch {
|
||||||
showAttachmentSourcePicker = false
|
showAttachmentSourcePicker = false
|
||||||
cameraPhotoPicker.launch()
|
cameraPhotoPicker.launch()
|
||||||
}
|
}
|
||||||
MessageComposerEvents.PickAttachmentSource.VideoFromCamera -> localCoroutineScope.launchIfMediaPickerEnabled {
|
MessageComposerEvents.PickAttachmentSource.VideoFromCamera -> localCoroutineScope.launch {
|
||||||
showAttachmentSourcePicker = false
|
showAttachmentSourcePicker = false
|
||||||
cameraVideoPicker.launch()
|
cameraVideoPicker.launch()
|
||||||
}
|
}
|
||||||
|
|
@ -173,17 +178,12 @@ class MessageComposerPresenter @Inject constructor(
|
||||||
hasFocus = hasFocus.value,
|
hasFocus = hasFocus.value,
|
||||||
mode = messageComposerContext.composerMode,
|
mode = messageComposerContext.composerMode,
|
||||||
showAttachmentSourcePicker = showAttachmentSourcePicker,
|
showAttachmentSourcePicker = showAttachmentSourcePicker,
|
||||||
|
canShareLocation = canShareLocation,
|
||||||
attachmentsState = attachmentsState.value,
|
attachmentsState = attachmentsState.value,
|
||||||
eventSink = ::handleEvents
|
eventSink = ::handleEvents
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CoroutineScope.launchIfMediaPickerEnabled(action: suspend () -> Unit) = launch {
|
|
||||||
if (featureFlagService.isFeatureEnabled(FeatureFlags.ShowMediaUploadingFlow)) {
|
|
||||||
action()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun CoroutineScope.sendMessage(
|
private fun CoroutineScope.sendMessage(
|
||||||
text: String,
|
text: String,
|
||||||
updateComposerMode: (newComposerMode: MessageComposerMode) -> Unit,
|
updateComposerMode: (newComposerMode: MessageComposerMode) -> Unit,
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ data class MessageComposerState(
|
||||||
val hasFocus: Boolean,
|
val hasFocus: Boolean,
|
||||||
val mode: MessageComposerMode,
|
val mode: MessageComposerMode,
|
||||||
val showAttachmentSourcePicker: Boolean,
|
val showAttachmentSourcePicker: Boolean,
|
||||||
|
val canShareLocation: Boolean,
|
||||||
val attachmentsState: AttachmentsState,
|
val attachmentsState: AttachmentsState,
|
||||||
val eventSink: (MessageComposerEvents) -> Unit
|
val eventSink: (MessageComposerEvents) -> Unit
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,21 @@ open class MessageComposerStateProvider : PreviewParameterProvider<MessageCompos
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun aMessageComposerState() = MessageComposerState(
|
fun aMessageComposerState(
|
||||||
text = "",
|
text: String = "",
|
||||||
isFullScreen = false,
|
isFullScreen: Boolean = false,
|
||||||
hasFocus = false,
|
hasFocus: Boolean = false,
|
||||||
mode = MessageComposerMode.Normal(content = ""),
|
mode: MessageComposerMode = MessageComposerMode.Normal(content = ""),
|
||||||
showAttachmentSourcePicker = false,
|
showAttachmentSourcePicker: Boolean = false,
|
||||||
attachmentsState = AttachmentsState.None,
|
canShareLocation: Boolean = true,
|
||||||
eventSink = {}
|
attachmentsState: AttachmentsState = AttachmentsState.None,
|
||||||
|
) = MessageComposerState(
|
||||||
|
text = text,
|
||||||
|
isFullScreen = isFullScreen,
|
||||||
|
hasFocus = hasFocus,
|
||||||
|
mode = mode,
|
||||||
|
showAttachmentSourcePicker = showAttachmentSourcePicker,
|
||||||
|
canShareLocation = canShareLocation,
|
||||||
|
attachmentsState = attachmentsState,
|
||||||
|
eventSink = {},
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ class MessageComposerPresenterTest {
|
||||||
givenResult(mockk()) // Uri is not available in JVM, so the only way to have a non-null Uri is using Mockk
|
givenResult(mockk()) // Uri is not available in JVM, so the only way to have a non-null Uri is using Mockk
|
||||||
}
|
}
|
||||||
private val featureFlagService = FakeFeatureFlagService(
|
private val featureFlagService = FakeFeatureFlagService(
|
||||||
mapOf(FeatureFlags.ShowMediaUploadingFlow.key to true)
|
mapOf(FeatureFlags.LocationSharing.key to true)
|
||||||
)
|
)
|
||||||
private val mediaPreProcessor = FakeMediaPreProcessor()
|
private val mediaPreProcessor = FakeMediaPreProcessor()
|
||||||
private val snackbarDispatcher = SnackbarDispatcher()
|
private val snackbarDispatcher = SnackbarDispatcher()
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@ enum class FeatureFlags(
|
||||||
override val description: String? = null,
|
override val description: String? = null,
|
||||||
override val defaultValue: Boolean = true
|
override val defaultValue: Boolean = true
|
||||||
) : Feature {
|
) : Feature {
|
||||||
ShowMediaUploadingFlow(
|
LocationSharing(
|
||||||
key = "feature.showmediauploadingflow",
|
key = "feature.locationsharing",
|
||||||
title = "Show media uploading flow",
|
title = "Allow user to share location",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ class BuildtimeFeatureFlagProvider @Inject constructor() :
|
||||||
override suspend fun isFeatureEnabled(feature: Feature): Boolean {
|
override suspend fun isFeatureEnabled(feature: Feature): Boolean {
|
||||||
return if (feature is FeatureFlags) {
|
return if (feature is FeatureFlags) {
|
||||||
when (feature) {
|
when (feature) {
|
||||||
FeatureFlags.ShowMediaUploadingFlow -> false
|
FeatureFlags.LocationSharing -> false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
|
|
||||||
|
|
@ -26,14 +26,14 @@ class DefaultFeatureFlagServiceTest {
|
||||||
@Test
|
@Test
|
||||||
fun `given service without provider when feature is checked then it returns the default value`() = runTest {
|
fun `given service without provider when feature is checked then it returns the default value`() = runTest {
|
||||||
val featureFlagService = DefaultFeatureFlagService(emptySet())
|
val featureFlagService = DefaultFeatureFlagService(emptySet())
|
||||||
val isFeatureEnabled = featureFlagService.isFeatureEnabled(FeatureFlags.ShowMediaUploadingFlow)
|
val isFeatureEnabled = featureFlagService.isFeatureEnabled(FeatureFlags.LocationSharing)
|
||||||
assertThat(isFeatureEnabled).isEqualTo(FeatureFlags.ShowMediaUploadingFlow.defaultValue)
|
assertThat(isFeatureEnabled).isEqualTo(FeatureFlags.LocationSharing.defaultValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given service without provider when set enabled feature is called then it returns false`() = runTest {
|
fun `given service without provider when set enabled feature is called then it returns false`() = runTest {
|
||||||
val featureFlagService = DefaultFeatureFlagService(emptySet())
|
val featureFlagService = DefaultFeatureFlagService(emptySet())
|
||||||
val result = featureFlagService.setFeatureEnabled(FeatureFlags.ShowMediaUploadingFlow, true)
|
val result = featureFlagService.setFeatureEnabled(FeatureFlags.LocationSharing, true)
|
||||||
assertThat(result).isEqualTo(false)
|
assertThat(result).isEqualTo(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,7 +41,7 @@ class DefaultFeatureFlagServiceTest {
|
||||||
fun `given service with a runtime provider when set enabled feature is called then it returns true`() = runTest {
|
fun `given service with a runtime provider when set enabled feature is called then it returns true`() = runTest {
|
||||||
val featureFlagProvider = FakeRuntimeFeatureFlagProvider(0)
|
val featureFlagProvider = FakeRuntimeFeatureFlagProvider(0)
|
||||||
val featureFlagService = DefaultFeatureFlagService(setOf(featureFlagProvider))
|
val featureFlagService = DefaultFeatureFlagService(setOf(featureFlagProvider))
|
||||||
val result = featureFlagService.setFeatureEnabled(FeatureFlags.ShowMediaUploadingFlow, true)
|
val result = featureFlagService.setFeatureEnabled(FeatureFlags.LocationSharing, true)
|
||||||
assertThat(result).isEqualTo(true)
|
assertThat(result).isEqualTo(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,10 +49,10 @@ class DefaultFeatureFlagServiceTest {
|
||||||
fun `given service with a runtime provider and feature enabled when feature is checked then it returns the correct value`() = runTest {
|
fun `given service with a runtime provider and feature enabled when feature is checked then it returns the correct value`() = runTest {
|
||||||
val featureFlagProvider = FakeRuntimeFeatureFlagProvider(0)
|
val featureFlagProvider = FakeRuntimeFeatureFlagProvider(0)
|
||||||
val featureFlagService = DefaultFeatureFlagService(setOf(featureFlagProvider))
|
val featureFlagService = DefaultFeatureFlagService(setOf(featureFlagProvider))
|
||||||
featureFlagService.setFeatureEnabled(FeatureFlags.ShowMediaUploadingFlow, true)
|
featureFlagService.setFeatureEnabled(FeatureFlags.LocationSharing, true)
|
||||||
assertThat(featureFlagService.isFeatureEnabled(FeatureFlags.ShowMediaUploadingFlow)).isEqualTo(true)
|
assertThat(featureFlagService.isFeatureEnabled(FeatureFlags.LocationSharing)).isEqualTo(true)
|
||||||
featureFlagService.setFeatureEnabled(FeatureFlags.ShowMediaUploadingFlow, false)
|
featureFlagService.setFeatureEnabled(FeatureFlags.LocationSharing, false)
|
||||||
assertThat(featureFlagService.isFeatureEnabled(FeatureFlags.ShowMediaUploadingFlow)).isEqualTo(false)
|
assertThat(featureFlagService.isFeatureEnabled(FeatureFlags.LocationSharing)).isEqualTo(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -60,8 +60,8 @@ class DefaultFeatureFlagServiceTest {
|
||||||
val lowPriorityfeatureFlagProvider = FakeRuntimeFeatureFlagProvider(LOW_PRIORITY)
|
val lowPriorityfeatureFlagProvider = FakeRuntimeFeatureFlagProvider(LOW_PRIORITY)
|
||||||
val highPriorityfeatureFlagProvider = FakeRuntimeFeatureFlagProvider(HIGH_PRIORITY)
|
val highPriorityfeatureFlagProvider = FakeRuntimeFeatureFlagProvider(HIGH_PRIORITY)
|
||||||
val featureFlagService = DefaultFeatureFlagService(setOf(lowPriorityfeatureFlagProvider, highPriorityfeatureFlagProvider))
|
val featureFlagService = DefaultFeatureFlagService(setOf(lowPriorityfeatureFlagProvider, highPriorityfeatureFlagProvider))
|
||||||
lowPriorityfeatureFlagProvider.setFeatureEnabled(FeatureFlags.ShowMediaUploadingFlow, false)
|
lowPriorityfeatureFlagProvider.setFeatureEnabled(FeatureFlags.LocationSharing, false)
|
||||||
highPriorityfeatureFlagProvider.setFeatureEnabled(FeatureFlags.ShowMediaUploadingFlow, true)
|
highPriorityfeatureFlagProvider.setFeatureEnabled(FeatureFlags.LocationSharing, true)
|
||||||
assertThat(featureFlagService.isFeatureEnabled(FeatureFlags.ShowMediaUploadingFlow)).isEqualTo(true)
|
assertThat(featureFlagService.isFeatureEnabled(FeatureFlags.LocationSharing)).isEqualTo(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue