Skip to content

Commit

Permalink
feat: Add UI for typing indicator on privacy settings screen [WPB-459…
Browse files Browse the repository at this point in the history
…2] (#2240)
  • Loading branch information
gongracr committed Sep 18, 2023
1 parent ca89841 commit 6e6aabc
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 18 deletions.
10 changes: 10 additions & 0 deletions app/src/main/kotlin/com/wire/android/di/CoreLogicModule.kt
Expand Up @@ -998,6 +998,16 @@ class UseCaseModule {
fun providePersistReadReceiptsStatusConfig(@KaliumCoreLogic coreLogic: CoreLogic, @CurrentAccount currentAccount: UserId) =
coreLogic.getSessionScope(currentAccount).users.persistReadReceiptsStatusConfig

@ViewModelScoped
@Provides
fun provideObserveTypingIndicatorEnabled(@KaliumCoreLogic coreLogic: CoreLogic, @CurrentAccount currentAccount: UserId) =
coreLogic.getSessionScope(currentAccount).users.observeTypingIndicatorEnabled

@ViewModelScoped
@Provides
fun providePersistTypingIndicatorStatusConfig(@KaliumCoreLogic coreLogic: CoreLogic, @CurrentAccount currentAccount: UserId) =
coreLogic.getSessionScope(currentAccount).users.persistTypingIndicatorStatusConfig

@ViewModelScoped
@Provides
fun provideObserveIfAppFreshEnoughUseCase(@KaliumCoreLogic coreLogic: CoreLogic) =
Expand Down
Expand Up @@ -48,8 +48,10 @@ fun PrivacySettingsConfigScreen(
) {
with(viewModel) {
PrivacySettingsScreenContent(
isReadReceiptsEnabled = state.isReadReceiptsEnabled,
areReadReceiptsEnabled = state.areReadReceiptsEnabled,
setReadReceiptsState = ::setReadReceiptsState,
isTypingIndicatorEnabled = state.isTypingIndicatorEnabled,
setTypingIndicatorState = ::setTypingIndicatorState,
screenshotCensoringConfig = state.screenshotCensoringConfig,
setScreenshotCensoringConfig = ::setScreenshotCensoringConfig,
onBackPressed = navigator::navigateBack
Expand All @@ -59,8 +61,10 @@ fun PrivacySettingsConfigScreen(

@Composable
fun PrivacySettingsScreenContent(
isReadReceiptsEnabled: Boolean,
areReadReceiptsEnabled: Boolean,
setReadReceiptsState: (Boolean) -> Unit,
isTypingIndicatorEnabled: Boolean,
setTypingIndicatorState: (Boolean) -> Unit,
screenshotCensoringConfig: ScreenshotCensoringConfig,
setScreenshotCensoringConfig: (Boolean) -> Unit,
onBackPressed: () -> Unit
Expand All @@ -79,7 +83,7 @@ fun PrivacySettingsScreenContent(
) {
GroupConversationOptionsItem(
title = stringResource(R.string.settings_send_read_receipts),
switchState = SwitchState.Enabled(value = isReadReceiptsEnabled, onCheckedChange = setReadReceiptsState),
switchState = SwitchState.Enabled(value = areReadReceiptsEnabled, onCheckedChange = setReadReceiptsState),
arrowType = ArrowType.NONE,
subtitle = stringResource(id = R.string.settings_send_read_receipts_description)
)
Expand All @@ -103,12 +107,18 @@ fun PrivacySettingsScreenContent(
}
)
)
GroupConversationOptionsItem(
title = stringResource(R.string.settings_show_typing_indicator_title),
switchState = SwitchState.Enabled(value = isTypingIndicatorEnabled, onCheckedChange = setTypingIndicatorState),
arrowType = ArrowType.NONE,
subtitle = stringResource(id = R.string.settings_send_read_receipts_description)
)
}
}
}

@Composable
@Preview
fun PreviewSendReadReceipts() {
PrivacySettingsScreenContent(true, {}, ScreenshotCensoringConfig.DISABLED, {}, {})
PrivacySettingsScreenContent(true, {}, true, {}, ScreenshotCensoringConfig.DISABLED, {}, {})
}
Expand Up @@ -21,7 +21,8 @@
package com.wire.android.ui.home.settings.privacy

data class PrivacySettingsState(
val isReadReceiptsEnabled: Boolean = true,
val areReadReceiptsEnabled: Boolean = true,
val isTypingIndicatorEnabled: Boolean = true,
val screenshotCensoringConfig: ScreenshotCensoringConfig = ScreenshotCensoringConfig.ENABLED_BY_USER
)

Expand Down
Expand Up @@ -34,6 +34,9 @@ import com.wire.kalium.logic.feature.user.screenshotCensoring.ObserveScreenshotC
import com.wire.kalium.logic.feature.user.screenshotCensoring.ObserveScreenshotCensoringConfigUseCase
import com.wire.kalium.logic.feature.user.screenshotCensoring.PersistScreenshotCensoringConfigResult
import com.wire.kalium.logic.feature.user.screenshotCensoring.PersistScreenshotCensoringConfigUseCase
import com.wire.kalium.logic.feature.user.typingIndicator.ObserveTypingIndicatorEnabledUseCase
import com.wire.kalium.logic.feature.user.typingIndicator.PersistTypingIndicatorStatusConfigUseCase
import com.wire.kalium.logic.feature.user.typingIndicator.TypingIndicatorConfigResult
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch
Expand All @@ -46,7 +49,9 @@ class PrivacySettingsViewModel @Inject constructor(
private val persistReadReceiptsStatusConfig: PersistReadReceiptsStatusConfigUseCase,
private val observeReadReceiptsEnabled: ObserveReadReceiptsEnabledUseCase,
private val persistScreenshotCensoringConfig: PersistScreenshotCensoringConfigUseCase,
private val observeScreenshotCensoringConfig: ObserveScreenshotCensoringConfigUseCase
private val observeScreenshotCensoringConfig: ObserveScreenshotCensoringConfigUseCase,
private val persistTypingIndicatorStatusConfig: PersistTypingIndicatorStatusConfigUseCase,
private val observeTypingIndicatorEnabled: ObserveTypingIndicatorEnabledUseCase
) : ViewModel() {

var state by mutableStateOf(PrivacySettingsState())
Expand All @@ -56,11 +61,13 @@ class PrivacySettingsViewModel @Inject constructor(
viewModelScope.launch {
combine(
observeReadReceiptsEnabled(),
observeTypingIndicatorEnabled(),
observeScreenshotCensoringConfig(),
::Pair
).collect { (readReceiptsEnabled, screenshotCensoringConfig) ->
::Triple
).collect { (readReceiptsEnabled, typingIndicatorEnabled, screenshotCensoringConfig) ->
state = state.copy(
isReadReceiptsEnabled = readReceiptsEnabled,
areReadReceiptsEnabled = readReceiptsEnabled,
isTypingIndicatorEnabled = typingIndicatorEnabled,
screenshotCensoringConfig = when (screenshotCensoringConfig) {
ObserveScreenshotCensoringConfigResult.Disabled ->
ScreenshotCensoringConfig.DISABLED
Expand All @@ -78,16 +85,35 @@ class PrivacySettingsViewModel @Inject constructor(

fun setReadReceiptsState(isEnabled: Boolean) {
viewModelScope.launch {
when (withContext(dispatchers.io()) { persistReadReceiptsStatusConfig(isEnabled) }) {
is ReadReceiptStatusConfigResult.Failure -> {
appLogger.e("Something went wrong while updating read receipts config")
state = state.copy(isReadReceiptsEnabled = !isEnabled)
state =
when (withContext(dispatchers.io()) { persistReadReceiptsStatusConfig(isEnabled) }) {
is ReadReceiptStatusConfigResult.Failure -> {
appLogger.e("Something went wrong while updating read receipts config")
state.copy(areReadReceiptsEnabled = !isEnabled)
}

is ReadReceiptStatusConfigResult.Success -> {
appLogger.d("Read receipts config changed")
state.copy(areReadReceiptsEnabled = isEnabled)
}
}
is ReadReceiptStatusConfigResult.Success -> {
appLogger.d("Read receipts config changed")
state = state.copy(isReadReceiptsEnabled = isEnabled)
}
}

fun setTypingIndicatorState(isEnabled: Boolean) {
viewModelScope.launch {
state =
when (withContext(dispatchers.io()) { persistTypingIndicatorStatusConfig(isEnabled) }) {
is TypingIndicatorConfigResult.Failure -> {
appLogger.e("Something went wrong while updating typing indicator config")
state.copy(isTypingIndicatorEnabled = !isEnabled)
}

is TypingIndicatorConfigResult.Success -> {
appLogger.d("Typing indicator configuration changed successfully")
state.copy(isTypingIndicatorEnabled = isEnabled)
}
}
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -882,6 +882,8 @@
<string name="settings_censor_screenshots">Censor screenshots</string>
<string name="settings_censor_screenshots_description">If this is ON, then the content of the messages will not be visible on the screenshot or screen recording.</string>
<string name="settings_censor_screenshots_enforced_by_team_description">This is enforced by the self-deleting message team setting and cannot be changed.\nThe content of the messages will not be visible on the screenshot or screen recording.</string>
<string name="settings_show_typing_indicator_title">Typing indicator</string>
<string name="settings_show_typing_indicator_description">When this is off, you won\'t be able to see when other people are typing, and others won\'t see when you are typing. This setting applies to all conversations on this device.</string>
<!--Devices -->
<string name="devices_title">Your Devices</string>
<string name="current_device_label">Current Device</string>
Expand Down
2 changes: 1 addition & 1 deletion kalium
Submodule kalium updated 40 files
+2 βˆ’2 cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/MLSClientImpl.kt
+24 βˆ’6 cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/MLSClientImpl.kt
+1 βˆ’3 cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/MLSClient.kt
+4 βˆ’4 cryptography/src/commonTest/kotlin/com/wire/kalium/cryptography/MLSClientTest.kt
+1 βˆ’1 cryptography/src/jsMain/kotlin/com/wire/kalium/cryptography/MLSClientImpl.kt
+1 βˆ’1 gradle/libs.versions.toml
+10 βˆ’1 logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/UserConfigRepository.kt
+1 βˆ’1 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/asset/Asset.kt
+44 βˆ’0 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/DecryptedMessageBundleMapper.kt
+85 βˆ’26 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepository.kt
+14 βˆ’1 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/Event.kt
+33 βˆ’8 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventMapper.kt
+4 βˆ’0 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/id/IdMappers.kt
+23 βˆ’0 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/properties/UserPropertyRepository.kt
+5 βˆ’4 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt
+3 βˆ’1 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/asset/ScheduleNewAssetMessageUseCase.kt
+12 βˆ’5 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/conversation/JoinExistingMLSConversationUseCase.kt
+16 βˆ’5 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/conversation/JoinSubconversationUseCase.kt
+12 βˆ’0 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/UserScope.kt
+47 βˆ’0 ...ommonMain/kotlin/com/wire/kalium/logic/feature/user/typingIndicator/ObserveTypingIndicatorEnabledUseCase.kt
+58 βˆ’0 ...Main/kotlin/com/wire/kalium/logic/feature/user/typingIndicator/PersistTypingIndicatorStatusConfigUseCase.kt
+24 βˆ’0 logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/UserPropertiesEventReceiver.kt
+43 βˆ’0 .../src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/MLSMessageFailureHandler.kt
+42 βˆ’76 logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/MLSMessageUnpacker.kt
+27 βˆ’37 logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/NewMessageEventHandler.kt
+37 βˆ’5 logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepositoryTest.kt
+89 βˆ’0 logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/asset/ScheduleNewAssetMessageUseCaseTest.kt
+35 βˆ’5 .../src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/JoinExistingMLSConversationUseCaseTest.kt
+6 βˆ’1 logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/JoinSubconversationUseCaseTest.kt
+106 βˆ’0 ...nTest/kotlin/com/wire/kalium/logic/feature/user/typingIndicator/ObserveTypingIndicatorEnabledUseCaseTest.kt
+114 βˆ’0 .../kotlin/com/wire/kalium/logic/feature/user/typingIndicator/PersistTypingIndicatorStatusConfigUseCaseTest.kt
+2 βˆ’1 logic/src/commonTest/kotlin/com/wire/kalium/logic/framework/TestEvent.kt
+27 βˆ’42 logic/src/commonTest/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/MLSMessageUnpackerTest.kt
+2 βˆ’2 ...rc/commonTest/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/NewMessageEventHandlerTest.kt
+7 βˆ’0 network/src/appleMain/kotlin/com/wire/kalium/network/defaultHttpEngine.kt
+48 βˆ’45 network/src/commonJvmAndroid/kotlin/com/wire/kalium/network/HttpEngine.kt
+2 βˆ’1 network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/properties/PropertiesApi.kt
+43 βˆ’18 persistence/src/commonMain/kotlin/com/wire/kalium/persistence/config/UserConfigStorage.kt
+1 βˆ’1 persistence/src/commonTest/kotlin/com/wire/kalium/persistence/config/UserConfigStorageTest.kt
+2 βˆ’2 testservice/Jenkinsfile

0 comments on commit 6e6aabc

Please sign in to comment.