Skip to content

Commit

Permalink
feat(v4.1): handling configuration for websocket enabled by default (…
Browse files Browse the repository at this point in the history
…WPB-967) (#1899)

* feat: enable websocket by default

* feat: enable websocket by default

* feat: fix detekt

* feat: fix detekt

* chore: kalium ref to tag
  • Loading branch information
yamilmedina authored Jul 3, 2023
1 parent 82aefb9 commit b3cc775
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@

package com.wire.android.di

import android.content.Context
import android.os.Build
import com.wire.android.BuildConfig
import com.wire.android.datastore.GlobalDataStore
import com.wire.android.util.extension.isGoogleServicesAvailable
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import dagger.Module
import dagger.Provides
Expand All @@ -36,7 +38,7 @@ import kotlinx.coroutines.runBlocking
class KaliumConfigsModule {

@Provides
fun provideKaliumConfigs(globalDataStore: GlobalDataStore): KaliumConfigs {
fun provideKaliumConfigs(globalDataStore: GlobalDataStore, context: Context): KaliumConfigs {
return KaliumConfigs(
isChangeEmailEnabled = BuildConfig.ALLOW_CHANGE_OF_EMAIL,
isLoggingEnabled = BuildConfig.LOGGING_ENABLED,
Expand All @@ -56,7 +58,8 @@ class KaliumConfigsModule {
guestRoomLink = BuildConfig.ENABLE_GUEST_ROOM_LINK,
wipeOnCookieInvalid = BuildConfig.WIPE_ON_COOKIE_INVALID,
wipeOnDeviceRemoval = BuildConfig.WIPE_ON_DEVICE_REMOVAL,
wipeOnRootedDevice = BuildConfig.WIPE_ON_ROOTED_DEVICE
wipeOnRootedDevice = BuildConfig.WIPE_ON_ROOTED_DEVICE,
isWebSocketEnabledByDefault = runBlocking { !context.isGoogleServicesAvailable() }
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand All @@ -36,6 +37,7 @@ import com.wire.android.ui.common.topappbar.WireCenterAlignedTopAppBar
import com.wire.android.ui.home.conversations.details.options.ArrowType
import com.wire.android.ui.home.conversations.details.options.GroupConversationOptionsItem
import com.wire.android.ui.home.conversations.details.options.SwitchState
import com.wire.android.util.extension.isGoogleServicesAvailable

@Composable
fun NetworkSettingsScreen(networkSettingsViewModel: NetworkSettingsViewModel = hiltViewModel()) {
Expand All @@ -56,7 +58,6 @@ fun NetworkSettingsScreenContent(
isWebSocketEnabled: Boolean,
setWebSocketState: (Boolean) -> Unit,
backendName: String

) {
Scaffold(topBar = {
WireCenterAlignedTopAppBar(
Expand All @@ -76,16 +77,28 @@ fun NetworkSettingsScreenContent(
R.string.settings_keep_connection_to_websocket_description,
backendName
),
switchState = SwitchState.Enabled(
value = isWebSocketEnabled,
onCheckedChange = setWebSocketState
),
switchState = getSwitchState(isWebSocketEnabled, setWebSocketState),
arrowType = ArrowType.NONE
)
}
}
}

@Composable
private fun getSwitchState(isWebSocketEnabled: Boolean, setWebSocketState: (Boolean) -> Unit): SwitchState {
val context = LocalContext.current
return if (context.isGoogleServicesAvailable()) {
SwitchState.Enabled(
value = isWebSocketEnabled,
onCheckedChange = setWebSocketState
)
} else {
SwitchState.Disabled(
value = isWebSocketEnabled,
)
}
}

@Composable
@Preview
fun PreviewNetworkSettingsScreen() {
Expand Down

0 comments on commit b3cc775

Please sign in to comment.