Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: status bar colour during theme change #WPB-11158 #3494

Merged
merged 2 commits into from
Oct 10, 2024
Merged
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
112 changes: 88 additions & 24 deletions app/src/main/kotlin/com/wire/android/ui/WireActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,7 @@ class WireActivity : AppCompatActivity() {
setContent {
val snackbarHostState = remember { SnackbarHostState() }

LaunchedEffect(viewModel.globalAppState.themeOption) {
when (viewModel.globalAppState.themeOption) {
ThemeOption.SYSTEM -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
ThemeOption.LIGHT -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
ThemeOption.DARK -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
}
}
HandleThemeChanges(viewModel.globalAppState.themeOption)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good one 🍇


CompositionLocalProvider(
LocalFeatureVisibilityFlags provides FeatureVisibilityFlags,
Expand All @@ -229,19 +223,30 @@ class WireActivity : AppCompatActivity() {
Column(modifier = Modifier.statusBarsPadding()) {
val navigator = rememberNavigator(this@WireActivity::finish)
CommonTopAppBar(
themeOption = viewModel.globalAppState.themeOption,
commonTopAppBarState = commonTopAppBarViewModel.state,
onReturnToCallClick = { establishedCall ->
getOngoingCallIntent(this@WireActivity, establishedCall.conversationId.toString()).run {
getOngoingCallIntent(
this@WireActivity,
establishedCall.conversationId.toString()
).run {
startActivity(this)
}
},
onReturnToIncomingCallClick = {
getIncomingCallIntent(this@WireActivity, it.conversationId.toString(), null).run {
getIncomingCallIntent(
this@WireActivity,
it.conversationId.toString(),
null
).run {
startActivity(this)
}
},
onReturnToOutgoingCallClick = {
getOutgoingCallIntent(this@WireActivity, it.conversationId.toString()).run {
getOutgoingCallIntent(
this@WireActivity,
it.conversationId.toString()
).run {
startActivity(this)
}
}
Expand All @@ -264,6 +269,21 @@ class WireActivity : AppCompatActivity() {
}
}

@Composable
private fun HandleThemeChanges(themeOption: ThemeOption) {
LaunchedEffect(themeOption) {
val themeNightMode = when (themeOption) {
ThemeOption.SYSTEM -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
ThemeOption.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
ThemeOption.DARK -> AppCompatDelegate.MODE_NIGHT_YES
}
val currentNightMode = AppCompatDelegate.getDefaultNightMode()
if (themeNightMode != currentNightMode) {
AppCompatDelegate.setDefaultNightMode(themeNightMode)
}
}
}

@Composable
private fun SetUpNavigation(
navigator: Navigator,
Expand Down Expand Up @@ -291,14 +311,17 @@ class WireActivity : AppCompatActivity() {
}

DisposableEffect(navigator.navController) {
val updateScreenSettingsListener = NavController.OnDestinationChangedListener { _, _, _ ->
currentKeyboardController?.hide()
}
val updateScreenSettingsListener =
NavController.OnDestinationChangedListener { _, _, _ ->
currentKeyboardController?.hide()
}
navigator.navController.addOnDestinationChangedListener(updateScreenSettingsListener)
navigator.navController.addOnDestinationChangedListener(currentScreenManager)

onDispose {
navigator.navController.removeOnDestinationChangedListener(updateScreenSettingsListener)
navigator.navController.removeOnDestinationChangedListener(
updateScreenSettingsListener
)
navigator.navController.removeOnDestinationChangedListener(currentScreenManager)
}
}
Expand All @@ -320,7 +343,9 @@ class WireActivity : AppCompatActivity() {
private fun HandleDialogs(navigate: (NavigationCommand) -> Unit) {
val context = LocalContext.current
val callFeedbackSheetState =
rememberWireModalSheetState<Unit>(onDismissAction = { featureFlagNotificationViewModel.skipCallFeedback(false) })
rememberWireModalSheetState<Unit>(onDismissAction = {
featureFlagNotificationViewModel.skipCallFeedback(false)
})
with(featureFlagNotificationViewModel.featureFlagState) {
if (shouldShowTeamAppLockDialog) {
TeamAppLockFeatureFlagDialog(
Expand Down Expand Up @@ -400,7 +425,13 @@ class WireActivity : AppCompatActivity() {

if (shouldShowE2eiCertificateRevokedDialog) {
E2EICertificateRevokedDialog(
onLogout = { logoutOptionsDialogState.show(LogoutOptionsDialogState(shouldWipeData = true)) },
onLogout = {
logoutOptionsDialogState.show(
LogoutOptionsDialogState(
shouldWipeData = true
)
)
},
onContinue = featureFlagNotificationViewModel::dismissE2EICertificateRevokedDialog,
)
}
Expand Down Expand Up @@ -495,7 +526,9 @@ class WireActivity : AppCompatActivity() {

if (startGettingE2EICertificate) {
GetE2EICertificateUI(
enrollmentResultHandler = { featureFlagNotificationViewModel.handleE2EIEnrollmentResult(it) },
enrollmentResultHandler = {
featureFlagNotificationViewModel.handleE2EIEnrollmentResult(it)
},
isNewClient = false
)
}
Expand Down Expand Up @@ -572,14 +605,25 @@ class WireActivity : AppCompatActivity() {
) {
return
} else {
val navigate: (NavigationCommand) -> Unit = { lifecycleScope.launch { navigationCommands.emit(it) } }
val navigate: (NavigationCommand) -> Unit =
{ lifecycleScope.launch { navigationCommands.emit(it) } }
viewModel.handleDeepLink(
intent = intent,
onOpenConversation = {
if (it.switchedAccount) {
navigate(NavigationCommand(HomeScreenDestination, BackStackMode.CLEAR_WHOLE))
navigate(
NavigationCommand(
HomeScreenDestination,
BackStackMode.CLEAR_WHOLE
)
)
}
navigate(NavigationCommand(ConversationScreenDestination(it.conversationId), BackStackMode.UPDATE_EXISTED))
navigate(
NavigationCommand(
ConversationScreenDestination(it.conversationId),
BackStackMode.UPDATE_EXISTED
)
)
},
onIsSharingIntent = {
navigate(
Expand Down Expand Up @@ -608,16 +652,36 @@ class WireActivity : AppCompatActivity() {
}
},
onMigrationLogin = {
navigate(NavigationCommand(LoginScreenDestination(it.userHandle), BackStackMode.UPDATE_EXISTED))
navigate(
NavigationCommand(
LoginScreenDestination(it.userHandle),
BackStackMode.UPDATE_EXISTED
)
)
},
onOpenOtherUserProfile = {
if (it.switchedAccount) {
navigate(NavigationCommand(HomeScreenDestination, BackStackMode.CLEAR_WHOLE))
navigate(
NavigationCommand(
HomeScreenDestination,
BackStackMode.CLEAR_WHOLE
)
)
}
navigate(NavigationCommand(OtherUserProfileScreenDestination(it.userId), BackStackMode.UPDATE_EXISTED))
navigate(
NavigationCommand(
OtherUserProfileScreenDestination(it.userId),
BackStackMode.UPDATE_EXISTED
)
)
},
onSSOLogin = {
navigate(NavigationCommand(LoginScreenDestination(ssoLoginResult = it), BackStackMode.UPDATE_EXISTED))
navigate(
NavigationCommand(
LoginScreenDestination(ssoLoginResult = it),
BackStackMode.UPDATE_EXISTED
)
)
}
)
intent.putExtra(HANDLED_DEEPLINK_FLAG, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.IntSize
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.wire.android.R
import com.wire.android.ui.theme.ThemeOption
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireColorScheme
import com.wire.android.ui.theme.wireDimensions
Expand All @@ -54,13 +55,16 @@ import com.wire.kalium.logic.data.id.ConversationId

@Composable
fun CommonTopAppBar(
themeOption: ThemeOption,
commonTopAppBarState: CommonTopAppBarState,
onReturnToCallClick: (ConnectivityUIState.EstablishedCall) -> Unit,
onReturnToIncomingCallClick: (ConnectivityUIState.IncomingCall) -> Unit,
onReturnToOutgoingCallClick: (ConnectivityUIState.OutgoingCall) -> Unit
onReturnToOutgoingCallClick: (ConnectivityUIState.OutgoingCall) -> Unit,
modifier: Modifier = Modifier,
) {
Column {
Column(modifier = modifier) {
ConnectivityStatusBar(
themeOption = themeOption,
connectivityInfo = commonTopAppBarState.connectivityState,
onReturnToCallClick = onReturnToCallClick,
onReturnToIncomingCallClick = onReturnToIncomingCallClick,
Expand All @@ -82,23 +86,30 @@ fun getBackgroundColor(connectivityInfo: ConnectivityUIState): Color {

@Composable
private fun ConnectivityStatusBar(
themeOption: ThemeOption,
connectivityInfo: ConnectivityUIState,
onReturnToCallClick: (ConnectivityUIState.EstablishedCall) -> Unit,
onReturnToIncomingCallClick: (ConnectivityUIState.IncomingCall) -> Unit,
onReturnToOutgoingCallClick: (ConnectivityUIState.OutgoingCall) -> Unit
) {
val isVisible = connectivityInfo !is ConnectivityUIState.None
val backgroundColor = getBackgroundColor(connectivityInfo)
if (!isVisible) {
clearStatusBarColor()
}

if (isVisible) {
val darkIcons = MaterialTheme.wireColorScheme.connectivityBarShouldUseDarkIcons
rememberSystemUiController().setStatusBarColor(
val systemUiController = rememberSystemUiController()
systemUiController.setStatusBarColor(
color = backgroundColor,
darkIcons = darkIcons
)
LaunchedEffect(themeOption) {
systemUiController.setStatusBarColor(
color = backgroundColor,
darkIcons = darkIcons
)
}
} else {
ClearStatusBarColor()
}

val barModifier = Modifier
Expand Down Expand Up @@ -219,16 +230,6 @@ private fun StatusLabelWithValue(
)
}

@Composable
fun StatusLabel(message: String, color: Color = MaterialTheme.wireColorScheme.onPrimary) {
Text(
text = message,
textAlign = TextAlign.Center,
color = color,
style = MaterialTheme.wireTypography.title03,
)
}

@Composable
private fun CameraIcon(tint: Color = MaterialTheme.wireColorScheme.onPositive) {
Icon(
Expand Down Expand Up @@ -261,7 +262,7 @@ private fun MicrophoneIcon(
}

@Composable
private fun clearStatusBarColor() {
private fun ClearStatusBarColor() {
val backgroundColor = MaterialTheme.wireColorScheme.background
val darkIcons = MaterialTheme.wireColorScheme.useDarkSystemBarIcons

Expand All @@ -274,7 +275,7 @@ private fun clearStatusBarColor() {
@Composable
private fun PreviewCommonTopAppBar(connectivityUIState: ConnectivityUIState) {
WireTheme {
CommonTopAppBar(CommonTopAppBarState(connectivityUIState), {}, {}, {})
CommonTopAppBar(ThemeOption.SYSTEM, CommonTopAppBarState(connectivityUIState), {}, {}, {})
}
}

Expand Down
Loading