diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationDelegate.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationDelegate.kt index bed15d7a93..16266948b6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationDelegate.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationDelegate.kt @@ -8,4 +8,14 @@ interface NewConversationDelegate { fun onDialogBackPressed() fun onDialogClosePressed() fun onInviteFriend() +} + +object NullNewConversationDelegate: NewConversationDelegate { + override fun onNewMessageSelected() {} + override fun onCreateGroupSelected() {} + override fun onJoinCommunitySelected() {} + override fun onContactSelected(address: String) {} + override fun onDialogBackPressed() {} + override fun onDialogClosePressed() {} + override fun onInviteFriend() {} } \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationHomeFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationHomeFragment.kt index 5c5d79b71d..a60e08d18a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationHomeFragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationHomeFragment.kt @@ -48,16 +48,14 @@ class NewConversationHomeFragment : Fragment() { @Inject lateinit var textSecurePreferences: TextSecurePreferences - var delegate = MutableStateFlow(null) + var delegate = MutableStateFlow(NullNewConversationDelegate) override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View = createThemedComposeView { - // Warning, brittle code, NewConversationScreen will not be visible if no delegate is set - // before onCreateView is called. - delegate.collectAsState().value?.let { + delegate.collectAsState().value.let { NewConversationScreen( accountId = TextSecurePreferences.getLocalNumber(requireContext())!!, delegate = it @@ -74,15 +72,7 @@ fun PreviewNewConversationScreen( PreviewTheme(colors) { NewConversationScreen( accountId = "059287129387123", - object: NewConversationDelegate { - override fun onNewMessageSelected() {} - override fun onCreateGroupSelected() {} - override fun onJoinCommunitySelected() {} - override fun onContactSelected(address: String) {} - override fun onDialogBackPressed() {} - override fun onDialogClosePressed() {} - override fun onInviteFriend() {} - } + NullNewConversationDelegate ) } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LandingActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LandingActivity.kt index 0cefbfcd2c..880380c707 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LandingActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LandingActivity.kt @@ -117,7 +117,7 @@ class LandingActivity: BaseActionBarActivity() { } Column { - Column(modifier = Modifier + /*Column(modifier = Modifier .weight(1f) .padding(horizontal = LocalDimensions.current.marginMedium)) { Spacer(modifier = Modifier.weight(1f)) @@ -149,7 +149,7 @@ class LandingActivity: BaseActionBarActivity() { } Spacer(modifier = Modifier.weight(1f)) - } + }*/ Column(modifier = Modifier.padding(horizontal = LocalDimensions.current.marginLarge)) { PrimaryFillButton( diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/LoadingActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/LoadingActivity.kt index de4ac404c1..a1b1f9b267 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/LoadingActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/LoadingActivity.kt @@ -61,8 +61,8 @@ class LoadingActivity: BaseActionBarActivity() { lifecycleScope.launch { viewModel.eventFlow.collect { when (it) { - Event.TIMEOUT -> register(skipped = true) - Event.SUCCESS -> register(skipped = false) + Event.TIMEOUT -> register(loadFailed = true) + Event.SUCCESS -> register(loadFailed = false) } } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt index 12802d5452..d48ad75b2d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt @@ -109,7 +109,6 @@ fun OptionsCard(card: OptionsCard, callbacks: Callbacks) { } } - @Composable fun ItemButton( @StringRes textId: Int, @@ -126,7 +125,6 @@ fun ItemButtonWithDrawable( @StringRes textId: Int, @DrawableRes icon: Int, colors: ButtonColors = transparentButtonColors(), - @StringRes contentDescription: Int = textId, onClick: () -> Unit ) { val context = LocalContext.current @@ -136,7 +134,7 @@ fun ItemButtonWithDrawable( icon = { Image( painter = rememberDrawablePainter(drawable = AppCompatResources.getDrawable(context, icon)), - contentDescription = stringResource(contentDescription), + contentDescription = null, modifier = Modifier.align(Alignment.Center) ) }, diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/components/Button.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/components/Button.kt index 3d02c5f799..47582f2d18 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/components/Button.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/components/Button.kt @@ -35,15 +35,21 @@ import androidx.compose.ui.graphics.Shape import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.filter import network.loki.messenger.R import org.thoughtcrime.securesms.ui.GetString import org.thoughtcrime.securesms.ui.LaunchedEffectAsync +import org.thoughtcrime.securesms.ui.PreviewTheme +import org.thoughtcrime.securesms.ui.SessionColorsParameterProvider import org.thoughtcrime.securesms.ui.color.LocalColors import org.thoughtcrime.securesms.ui.baseBold +import org.thoughtcrime.securesms.ui.color.Colors import org.thoughtcrime.securesms.ui.color.radioButtonColors import org.thoughtcrime.securesms.ui.color.slimOutlineButton import org.thoughtcrime.securesms.ui.contentDescription @@ -100,7 +106,7 @@ fun Button( interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, content: @Composable RowScope.() -> Unit ) { - size.applyConstraints { + size.applyButtonConstraints { androidx.compose.material.Button( onClick, modifier.heightIn(min = size.minHeight), @@ -109,9 +115,13 @@ fun Button( elevation, shape, border, - colors, - content = content - ) + colors + ) { + // Button sets LocalTextStyle, so text style is applied inside to override that. + size.applyTextConstraints { + content() + } + } } } @@ -362,3 +372,22 @@ fun NotificationRadioButton( val MutableInteractionSource.releases get() = interactions.filter { it is PressInteraction.Release } + +@Preview +@Composable +private fun VariousButtons( + @PreviewParameter(SessionColorsParameterProvider::class) colors: Colors +) { + PreviewTheme(colors) { + Column( + modifier = Modifier.padding(8.dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(8.dp) + ) { + PrimaryFillButton("Primary Fill") {} + OutlineButton(text = "Outline Button") {} + SlimOutlineButton(text = "Slim Outline") {} + SlimOutlineCopyButton {} + } + } +} diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/components/ButtonSize.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/components/ButtonSize.kt index 25335593f7..ef3b2a6e7c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/components/ButtonSize.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/components/ButtonSize.kt @@ -15,25 +15,31 @@ import org.thoughtcrime.securesms.ui.extraSmallBold interface ButtonSize { @OptIn(ExperimentalMaterialApi::class) @SuppressLint("ComposableNaming") - @Composable fun applyConstraints(content: @Composable () -> Unit) { + @Composable fun applyButtonConstraints(content: @Composable () -> Unit) { CompositionLocalProvider( LocalMinimumInteractiveComponentEnforcement provides false, - LocalTextStyle provides textStyle, - ) { - content() - } + content = content + ) } - val textStyle: TextStyle @Composable get + @SuppressLint("ComposableNaming") + @Composable fun applyTextConstraints(content: @Composable () -> Unit) { + CompositionLocalProvider( + LocalTextStyle provides textStyle, + content = content + ) + } + + val textStyle: TextStyle val minHeight: Dp object Large: ButtonSize { - override val textStyle @Composable get() = baseBold + override val textStyle = baseBold override val minHeight = 41.dp } object Slim: ButtonSize { - override val textStyle @Composable get() = extraSmallBold + override val textStyle = extraSmallBold override val minHeight = 29.dp } diff --git a/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt b/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt index 6c0708510d..85580929c8 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt @@ -1,7 +1,6 @@ package org.session.libsession.utilities import android.content.Context -import android.graphics.Color import android.hardware.Camera import android.net.Uri import android.provider.Settings @@ -14,7 +13,6 @@ import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow import org.session.libsession.R -import org.session.libsession.utilities.TextSecurePreferences.Companion import org.session.libsession.utilities.TextSecurePreferences.Companion.AUTOPLAY_AUDIO_MESSAGES import org.session.libsession.utilities.TextSecurePreferences.Companion.CALL_NOTIFICATIONS_ENABLED import org.session.libsession.utilities.TextSecurePreferences.Companion.CLASSIC_DARK @@ -25,7 +23,6 @@ import org.session.libsession.utilities.TextSecurePreferences.Companion.LAST_VAC import org.session.libsession.utilities.TextSecurePreferences.Companion.LEGACY_PREF_KEY_SELECTED_UI_MODE import org.session.libsession.utilities.TextSecurePreferences.Companion.OCEAN_DARK import org.session.libsession.utilities.TextSecurePreferences.Companion.OCEAN_LIGHT -import org.session.libsession.utilities.TextSecurePreferences.Companion.ORANGE_ACCENT import org.session.libsession.utilities.TextSecurePreferences.Companion.SELECTED_ACCENT_COLOR import org.session.libsession.utilities.TextSecurePreferences.Companion.SELECTED_STYLE import org.session.libsession.utilities.TextSecurePreferences.Companion.SHOWN_CALL_NOTIFICATION