Remove manual theming and fix background colors

This commit is contained in:
Andrew 2024-06-13 12:26:51 +09:30
parent 9721dbbd9e
commit 96157d65a6
11 changed files with 153 additions and 172 deletions

View File

@ -19,6 +19,7 @@ import org.thoughtcrime.securesms.conversation.disappearingmessages.ui.UiState
import org.thoughtcrime.securesms.database.RecipientDatabase
import org.thoughtcrime.securesms.database.ThreadDatabase
import org.thoughtcrime.securesms.ui.SessionMaterialTheme
import org.thoughtcrime.securesms.ui.setContentWithTheme
import javax.inject.Inject
@AndroidEntryPoint
@ -45,7 +46,7 @@ class DisappearingMessagesActivity: PassphraseRequiredActionBarActivity() {
setUpToolbar()
binding.container.setContent { DisappearingMessagesScreen() }
binding.container.setContentWithTheme { DisappearingMessagesScreen() }
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
@ -87,8 +88,6 @@ class DisappearingMessagesActivity: PassphraseRequiredActionBarActivity() {
@Composable
fun DisappearingMessagesScreen() {
val uiState by viewModel.uiState.collectAsState(UiState())
SessionMaterialTheme {
DisappearingMessages(uiState, callbacks = viewModel)
}
DisappearingMessages(uiState, callbacks = viewModel)
}
}

View File

@ -14,14 +14,11 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material.MaterialTheme
import androidx.compose.material.primarySurface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
@ -50,7 +47,6 @@ import org.thoughtcrime.securesms.ui.LocalDimensions
import org.thoughtcrime.securesms.ui.PreviewTheme
import org.thoughtcrime.securesms.ui.SessionColors
import org.thoughtcrime.securesms.ui.SessionColorsParameterProvider
import org.thoughtcrime.securesms.ui.SessionMaterialTheme
import org.thoughtcrime.securesms.ui.components.AppBar
import org.thoughtcrime.securesms.ui.components.BorderlessButtonWithIcon
import org.thoughtcrime.securesms.ui.components.MaybeScanQrCode
@ -59,6 +55,7 @@ import org.thoughtcrime.securesms.ui.components.SessionButtonText
import org.thoughtcrime.securesms.ui.components.SessionOutlinedTextField
import org.thoughtcrime.securesms.ui.components.SessionTabRow
import org.thoughtcrime.securesms.ui.contentDescription
import org.thoughtcrime.securesms.ui.onCreateView
class NewMessageFragment : Fragment() {
@ -79,20 +76,16 @@ class NewMessageFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View = ComposeView(requireContext()).apply {
setContent {
SessionMaterialTheme {
val uiState by viewModel.state.collectAsState(State())
NewMessage(
uiState,
viewModel.qrErrors,
viewModel,
onClose = { delegate.onDialogClosePressed() },
onBack = { delegate.onDialogBackPressed() },
onHelp = { requireContext().showOpenUrlDialog("https://sessionapp.zendesk.com/hc/en-us/articles/4439132747033-How-do-Session-ID-usernames-work") }
)
}
}
): View = onCreateView {
val uiState by viewModel.state.collectAsState(State())
NewMessage(
uiState,
viewModel.qrErrors,
viewModel,
onClose = { delegate.onDialogClosePressed() },
onBack = { delegate.onDialogBackPressed() },
onHelp = { requireContext().showOpenUrlDialog("https://sessionapp.zendesk.com/hc/en-us/articles/4439132747033-How-do-Session-ID-usernames-work") }
)
}
private fun createPrivateChat(hexEncodedPublicKey: String) {
@ -130,7 +123,7 @@ private fun NewMessage(
) {
val pagerState = rememberPagerState { TITLES.size }
Column(modifier = Modifier.background(MaterialTheme.colors.primarySurface)) {
Column(modifier = Modifier.background(LocalColors.current.backgroundSecondary)) {
AppBar(stringResource(R.string.messageNew), onClose = onClose, onBack = onBack)
SessionTabRow(pagerState, TITLES)
HorizontalPager(pagerState) {

View File

@ -77,6 +77,7 @@ import org.thoughtcrime.securesms.ui.baseMonospace
import org.thoughtcrime.securesms.ui.blackAlpha40
import org.thoughtcrime.securesms.ui.components.SessionButtonText
import org.thoughtcrime.securesms.ui.destructiveButtonColors
import org.thoughtcrime.securesms.ui.setComposeContent
import javax.inject.Inject
@AndroidEntryPoint
@ -103,9 +104,7 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() {
viewModel.timestamp = intent.getLongExtra(MESSAGE_TIMESTAMP, -1L)
ComposeView(this)
.apply { setContent { MessageDetailsScreen() } }
.let(::setContentView)
setComposeContent { MessageDetailsScreen() }
lifecycleScope.launch {
viewModel.eventFlow.collect {
@ -122,16 +121,14 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() {
@Composable
private fun MessageDetailsScreen() {
val state by viewModel.stateFlow.collectAsState()
SessionMaterialTheme {
MessageDetails(
state = state,
onReply = if (state.canReply) { { setResultAndFinish(ON_REPLY) } } else null,
onResend = state.error?.let { { setResultAndFinish(ON_RESEND) } },
onDelete = { setResultAndFinish(ON_DELETE) },
onClickImage = { viewModel.onClickImage(it) },
onAttachmentNeedsDownload = viewModel::onAttachmentNeedsDownload,
)
}
MessageDetails(
state = state,
onReply = if (state.canReply) { { setResultAndFinish(ON_REPLY) } } else null,
onResend = state.error?.let { { setResultAndFinish(ON_RESEND) } },
onDelete = { setResultAndFinish(ON_DELETE) },
onClickImage = { viewModel.onClickImage(it) },
onAttachmentNeedsDownload = viewModel::onAttachmentNeedsDownload,
)
}
private fun setResultAndFinish(code: Int) {

View File

@ -26,6 +26,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
@ -105,6 +106,7 @@ import org.thoughtcrime.securesms.ui.base
import org.thoughtcrime.securesms.ui.components.OutlineButton
import org.thoughtcrime.securesms.ui.contentDescription
import org.thoughtcrime.securesms.ui.h8
import org.thoughtcrime.securesms.ui.setContentWithTheme
import org.thoughtcrime.securesms.ui.small
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
import org.thoughtcrime.securesms.util.IP2Country
@ -206,7 +208,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
binding.sessionToolbar.disableClipping()
// Set up seed reminder view
lifecycleScope.launchWhenStarted {
binding.seedReminderView.setContent {
binding.seedReminderView.setContentWithTheme {
if (!textSecurePreferences.getHasViewedSeed()) SeedReminder()
}
}
@ -223,7 +225,9 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
}
// Set up empty state view
binding.emptyStateContainer.setContent { EmptyView(ApplicationContext.getInstance(this).newAccount) }
binding.emptyStateContainer.setContentWithTheme {
EmptyView(ApplicationContext.getInstance(this).newAccount)
}
IP2Country.configureIfNeeded(this@HomeActivity)
@ -371,93 +375,89 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
@Composable
private fun SeedReminder() {
SessionMaterialTheme {
Column {
// Color Strip
Box(
Modifier
.fillMaxWidth()
.height(4.dp)
.background(MaterialTheme.colors.secondary)
)
Row(
Modifier
.background(MaterialTheme.colors.surface)
.padding(
horizontal = LocalDimensions.current.marginSmall,
vertical = LocalDimensions.current.marginExtraSmall
)
) {
Column(Modifier.weight(1f)) {
Row {
Text(
stringResource(R.string.save_your_recovery_password),
style = MaterialTheme.typography.h8
)
Spacer(Modifier.requiredWidth(LocalDimensions.current.itemSpacingExtraSmall))
SessionShieldIcon()
}
Column {
// Color Strip
Box(
Modifier
.fillMaxWidth()
.height(4.dp)
.background(LocalColors.current.primary)
)
Row(
Modifier
.background(LocalColors.current.backgroundSecondary)
.padding(
horizontal = LocalDimensions.current.marginSmall,
vertical = LocalDimensions.current.marginExtraSmall
)
) {
Column(Modifier.weight(1f)) {
Row {
Text(
stringResource(R.string.save_your_recovery_password_to_make_sure_you_don_t_lose_access_to_your_account),
style = MaterialTheme.typography.small
stringResource(R.string.save_your_recovery_password),
style = MaterialTheme.typography.h8
)
Spacer(Modifier.requiredWidth(LocalDimensions.current.itemSpacingExtraSmall))
SessionShieldIcon()
}
Spacer(Modifier.width(LocalDimensions.current.marginExtraExtraSmall))
OutlineButton(
textId = R.string.continue_2,
modifier = Modifier
.align(Alignment.CenterVertically)
.contentDescription(R.string.AccessibilityId_reveal_recovery_phrase_button),
onClick = { start<RecoveryPasswordActivity>() }
Text(
stringResource(R.string.save_your_recovery_password_to_make_sure_you_don_t_lose_access_to_your_account),
style = MaterialTheme.typography.small
)
}
Spacer(Modifier.width(LocalDimensions.current.marginExtraExtraSmall))
OutlineButton(
textId = R.string.continue_2,
modifier = Modifier
.align(Alignment.CenterVertically)
.contentDescription(R.string.AccessibilityId_reveal_recovery_phrase_button),
onClick = { start<RecoveryPasswordActivity>() }
)
}
}
}
@Composable
private fun EmptyView(newAccount: Boolean) {
SessionMaterialTheme {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.padding(horizontal = 50.dp)
.padding(bottom = 12.dp)
) {
Spacer(modifier = Modifier.weight(1f))
Icon(
painter = painterResource(id = if (newAccount) R.drawable.emoji_tada_large else R.drawable.ic_logo_large),
contentDescription = null,
tint = Color.Unspecified
)
if (newAccount) {
Text(
stringResource(R.string.onboardingAccountCreated),
style = MaterialTheme.typography.h4,
textAlign = TextAlign.Center
)
Text(
stringResource(R.string.welcome_to_session),
style = MaterialTheme.typography.base,
color = LocalColors.current.primary,
textAlign = TextAlign.Center
)
}
Divider(modifier = Modifier.padding(vertical = LocalDimensions.current.marginExtraSmall))
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.padding(horizontal = 50.dp)
.padding(bottom = 12.dp)
) {
Spacer(modifier = Modifier.weight(1f))
Icon(
painter = painterResource(id = if (newAccount) R.drawable.emoji_tada_large else R.drawable.ic_logo_large),
contentDescription = null,
tint = Color.Unspecified
)
if (newAccount) {
Text(
stringResource(R.string.conversationsNone),
style = MaterialTheme.typography.h8,
textAlign = TextAlign.Center,
modifier = Modifier.padding(bottom = 12.dp))
Text(
stringResource(R.string.onboardingHitThePlusButton),
style = MaterialTheme.typography.small,
stringResource(R.string.onboardingAccountCreated),
style = MaterialTheme.typography.h4,
textAlign = TextAlign.Center
)
Text(
stringResource(R.string.welcome_to_session),
style = MaterialTheme.typography.base,
color = LocalColors.current.primary,
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.weight(2f))
}
Divider(modifier = Modifier.padding(vertical = LocalDimensions.current.marginExtraSmall))
Text(
stringResource(R.string.conversationsNone),
style = MaterialTheme.typography.h8,
textAlign = TextAlign.Center,
modifier = Modifier.padding(bottom = 12.dp))
Text(
stringResource(R.string.onboardingHitThePlusButton),
style = MaterialTheme.typography.small,
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.weight(2f))
}
}

View File

@ -43,6 +43,7 @@ import org.thoughtcrime.securesms.ui.components.OutlineButton
import org.thoughtcrime.securesms.ui.components.SessionOutlinedTextField
import org.thoughtcrime.securesms.ui.components.SessionTabRow
import org.thoughtcrime.securesms.ui.contentDescription
import org.thoughtcrime.securesms.ui.setComposeContent
import org.thoughtcrime.securesms.util.start
import javax.inject.Inject
@ -75,14 +76,10 @@ class LinkDeviceActivity : BaseActionBarActivity() {
}
}
ComposeView(this).apply {
setContent {
val state by viewModel.stateFlow.collectAsState()
SessionMaterialTheme {
LoadAccountScreen(state, viewModel::onChange, viewModel::onContinue, viewModel::onScanQrCode)
}
}
}.let(::setContentView)
setComposeContent {
val state by viewModel.stateFlow.collectAsState()
LoadAccountScreen(state, viewModel::onChange, viewModel::onContinue, viewModel::onScanQrCode)
}
}
@OptIn(ExperimentalFoundationApi::class)

View File

@ -34,6 +34,7 @@ import org.thoughtcrime.securesms.ui.SessionMaterialTheme
import org.thoughtcrime.securesms.ui.base
import org.thoughtcrime.securesms.ui.contentDescription
import org.thoughtcrime.securesms.ui.h7
import org.thoughtcrime.securesms.ui.setComposeContent
import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo
import javax.inject.Inject
@ -71,9 +72,7 @@ class LoadingActivity: BaseActionBarActivity() {
ApplicationContext.getInstance(this).newAccount = false
ComposeView(this)
.apply { setContent { LoadingScreen() } }
.let(::setContentView)
setComposeContent { LoadingScreen() }
setUpActionBarSessionLogo(true)
@ -103,23 +102,21 @@ class LoadingActivity: BaseActionBarActivity() {
)
}
SessionMaterialTheme {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Spacer(modifier = Modifier.weight(1f))
ProgressArc(
animatable.value,
modifier = Modifier.contentDescription(R.string.AccessibilityId_loading_animation)
)
Text(
stringResource(R.string.waitOneMoment),
style = MaterialTheme.typography.h7
)
Text(
stringResource(R.string.loadAccountProgressMessage),
style = MaterialTheme.typography.base
)
Spacer(modifier = Modifier.weight(2f))
}
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Spacer(modifier = Modifier.weight(1f))
ProgressArc(
animatable.value,
modifier = Modifier.contentDescription(R.string.AccessibilityId_loading_animation)
)
Text(
stringResource(R.string.waitOneMoment),
style = MaterialTheme.typography.h7
)
Text(
stringResource(R.string.loadAccountProgressMessage),
style = MaterialTheme.typography.base
)
Spacer(modifier = Modifier.weight(2f))
}
}
}

View File

@ -47,6 +47,7 @@ import org.thoughtcrime.securesms.ui.components.OutlineButton
import org.thoughtcrime.securesms.ui.contentDescription
import org.thoughtcrime.securesms.ui.h8
import org.thoughtcrime.securesms.ui.h9
import org.thoughtcrime.securesms.ui.setComposeContent
import org.thoughtcrime.securesms.ui.small
import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo
import javax.inject.Inject
@ -63,18 +64,13 @@ class MessageNotificationsActivity : BaseActionBarActivity() {
setUpActionBarSessionLogo(true)
TextSecurePreferences.setHasSeenWelcomeScreen(this, true)
ComposeView(this)
.apply { setContent { MessageNotificationsScreen() } }
.let(::setContentView)
setComposeContent { MessageNotificationsScreen() }
}
@Composable
private fun MessageNotificationsScreen() {
val state by viewModel.stateFlow.collectAsState()
SessionMaterialTheme {
MessageNotificationsScreen(state, viewModel::setEnabled, ::register)
}
MessageNotificationsScreen(state, viewModel::setEnabled, ::register)
}
private fun register() {

View File

@ -49,6 +49,7 @@ import org.thoughtcrime.securesms.ui.components.SmallButtons
import org.thoughtcrime.securesms.ui.contentDescription
import org.thoughtcrime.securesms.ui.extraSmallMonospace
import org.thoughtcrime.securesms.ui.h8
import org.thoughtcrime.securesms.ui.setComposeContent
class RecoveryPasswordActivity : BaseActionBarActivity() {
@ -58,14 +59,12 @@ class RecoveryPasswordActivity : BaseActionBarActivity() {
super.onCreate(savedInstanceState)
supportActionBar!!.title = resources.getString(R.string.sessionRecoveryPassword)
ComposeView(this).apply {
setContent {
RecoveryPasswordScreen(
viewModel.seed,
{ viewModel.copySeed(context) }
) { onHide() }
}
}.let(::setContentView)
setComposeContent {
RecoveryPasswordScreen(
viewModel.seed,
{ viewModel.copySeed(this) }
) { onHide() }
}
}
private fun onHide() {
@ -109,18 +108,16 @@ fun RecoveryPasswordScreen(
copySeed:() -> Unit = {},
onHide:() -> Unit = {}
) {
SessionMaterialTheme {
Column(
verticalArrangement = Arrangement.spacedBy(LocalDimensions.current.marginExtraSmall),
modifier = Modifier
.contentDescription(R.string.AccessibilityId_recovery_password)
.verticalScroll(rememberScrollState())
.padding(bottom = LocalDimensions.current.marginExtraSmall)
) {
SmallButtons {
RecoveryPasswordCell(seed, copySeed)
HideRecoveryPasswordCell(onHide)
}
Column(
verticalArrangement = Arrangement.spacedBy(LocalDimensions.current.marginExtraSmall),
modifier = Modifier
.contentDescription(R.string.AccessibilityId_recovery_password)
.verticalScroll(rememberScrollState())
.padding(bottom = LocalDimensions.current.marginExtraSmall)
) {
SmallButtons {
RecoveryPasswordCell(seed, copySeed)
HideRecoveryPasswordCell(onHide)
}
}
}

View File

@ -82,6 +82,7 @@ import org.thoughtcrime.securesms.ui.SessionMaterialTheme
import org.thoughtcrime.securesms.ui.components.OutlineButton
import org.thoughtcrime.securesms.ui.components.OutlineCopyButton
import org.thoughtcrime.securesms.ui.destructiveButtonColors
import org.thoughtcrime.securesms.ui.setContentWithTheme
import org.thoughtcrime.securesms.util.BitmapDecodingException
import org.thoughtcrime.securesms.util.BitmapUtil
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
@ -132,10 +133,8 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
versionTextView.text = String.format(getString(R.string.version_s), "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE} - $gitCommitFirstSixChars)")
}
binding.composeView.setContent {
SessionMaterialTheme {
Buttons()
}
binding.composeView.setContentWithTheme {
Buttons()
}
}

View File

@ -95,7 +95,7 @@ val primaryYellow = Color(0xFFFAD657)
val dangerDark = Color(0xFFFF3A3A)
val dangerLight = Color(0xFFE12D19)
val disabledDark = Color(0xFFA1A2A1)
val disabledLioht = Color(0xFF6D6D6D)
val disabledLight = Color(0xFF6D6D6D)
fun sessionColors(
isLight: Boolean,
@ -128,7 +128,7 @@ val classicLight = SessionColors(
isLight = true,
primary = primaryGreen,
danger = dangerLight,
disabled = disabledLioht,
disabled = disabledLight,
background = Color.White,
backgroundSecondary = classicLight5,
text = Color.Black,
@ -158,7 +158,7 @@ val oceanLight = SessionColors(
isLight = true,
primary = primaryBlue,
danger = dangerLight,
disabled = disabledLioht,
disabled = disabledLight,
background = oceanLight7,
backgroundSecondary = oceanLight6,
text = oceanLight1,

View File

@ -18,3 +18,9 @@ fun Fragment.onCreateView(content: @Composable () -> Unit): ComposeView = Compos
}
}
}
fun ComposeView.setContentWithTheme(content: @Composable () -> Unit) = setContent {
SessionMaterialTheme {
content()
}
}