Changes for code review

This commit is contained in:
Andrew 2024-06-17 12:50:24 +09:30
parent 46650ef678
commit 253fe9136d
8 changed files with 65 additions and 35 deletions

View File

@ -8,4 +8,14 @@ interface NewConversationDelegate {
fun onDialogBackPressed() fun onDialogBackPressed()
fun onDialogClosePressed() fun onDialogClosePressed()
fun onInviteFriend() 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() {}
} }

View File

@ -48,16 +48,14 @@ class NewConversationHomeFragment : Fragment() {
@Inject @Inject
lateinit var textSecurePreferences: TextSecurePreferences lateinit var textSecurePreferences: TextSecurePreferences
var delegate = MutableStateFlow<NewConversationDelegate?>(null) var delegate = MutableStateFlow<NewConversationDelegate>(NullNewConversationDelegate)
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater,
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View = createThemedComposeView { ): View = createThemedComposeView {
// Warning, brittle code, NewConversationScreen will not be visible if no delegate is set delegate.collectAsState().value.let {
// before onCreateView is called.
delegate.collectAsState().value?.let {
NewConversationScreen( NewConversationScreen(
accountId = TextSecurePreferences.getLocalNumber(requireContext())!!, accountId = TextSecurePreferences.getLocalNumber(requireContext())!!,
delegate = it delegate = it
@ -74,15 +72,7 @@ fun PreviewNewConversationScreen(
PreviewTheme(colors) { PreviewTheme(colors) {
NewConversationScreen( NewConversationScreen(
accountId = "059287129387123", accountId = "059287129387123",
object: NewConversationDelegate { NullNewConversationDelegate
override fun onNewMessageSelected() {}
override fun onCreateGroupSelected() {}
override fun onJoinCommunitySelected() {}
override fun onContactSelected(address: String) {}
override fun onDialogBackPressed() {}
override fun onDialogClosePressed() {}
override fun onInviteFriend() {}
}
) )
} }
} }

View File

@ -117,7 +117,7 @@ class LandingActivity: BaseActionBarActivity() {
} }
Column { Column {
Column(modifier = Modifier /*Column(modifier = Modifier
.weight(1f) .weight(1f)
.padding(horizontal = LocalDimensions.current.marginMedium)) { .padding(horizontal = LocalDimensions.current.marginMedium)) {
Spacer(modifier = Modifier.weight(1f)) Spacer(modifier = Modifier.weight(1f))
@ -149,7 +149,7 @@ class LandingActivity: BaseActionBarActivity() {
} }
Spacer(modifier = Modifier.weight(1f)) Spacer(modifier = Modifier.weight(1f))
} }*/
Column(modifier = Modifier.padding(horizontal = LocalDimensions.current.marginLarge)) { Column(modifier = Modifier.padding(horizontal = LocalDimensions.current.marginLarge)) {
PrimaryFillButton( PrimaryFillButton(

View File

@ -61,8 +61,8 @@ class LoadingActivity: BaseActionBarActivity() {
lifecycleScope.launch { lifecycleScope.launch {
viewModel.eventFlow.collect { viewModel.eventFlow.collect {
when (it) { when (it) {
Event.TIMEOUT -> register(skipped = true) Event.TIMEOUT -> register(loadFailed = true)
Event.SUCCESS -> register(skipped = false) Event.SUCCESS -> register(loadFailed = false)
} }
} }
} }

View File

@ -109,7 +109,6 @@ fun <T> OptionsCard(card: OptionsCard<T>, callbacks: Callbacks<T>) {
} }
} }
@Composable @Composable
fun ItemButton( fun ItemButton(
@StringRes textId: Int, @StringRes textId: Int,
@ -126,7 +125,6 @@ fun ItemButtonWithDrawable(
@StringRes textId: Int, @StringRes textId: Int,
@DrawableRes icon: Int, @DrawableRes icon: Int,
colors: ButtonColors = transparentButtonColors(), colors: ButtonColors = transparentButtonColors(),
@StringRes contentDescription: Int = textId,
onClick: () -> Unit onClick: () -> Unit
) { ) {
val context = LocalContext.current val context = LocalContext.current
@ -136,7 +134,7 @@ fun ItemButtonWithDrawable(
icon = { icon = {
Image( Image(
painter = rememberDrawablePainter(drawable = AppCompatResources.getDrawable(context, icon)), painter = rememberDrawablePainter(drawable = AppCompatResources.getDrawable(context, icon)),
contentDescription = stringResource(contentDescription), contentDescription = null,
modifier = Modifier.align(Alignment.Center) modifier = Modifier.align(Alignment.Center)
) )
}, },

View File

@ -35,15 +35,21 @@ import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextAlign 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.dp
import androidx.compose.ui.unit.sp
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filter
import network.loki.messenger.R import network.loki.messenger.R
import org.thoughtcrime.securesms.ui.GetString import org.thoughtcrime.securesms.ui.GetString
import org.thoughtcrime.securesms.ui.LaunchedEffectAsync 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.color.LocalColors
import org.thoughtcrime.securesms.ui.baseBold 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.radioButtonColors
import org.thoughtcrime.securesms.ui.color.slimOutlineButton import org.thoughtcrime.securesms.ui.color.slimOutlineButton
import org.thoughtcrime.securesms.ui.contentDescription import org.thoughtcrime.securesms.ui.contentDescription
@ -100,7 +106,7 @@ fun Button(
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
content: @Composable RowScope.() -> Unit content: @Composable RowScope.() -> Unit
) { ) {
size.applyConstraints { size.applyButtonConstraints {
androidx.compose.material.Button( androidx.compose.material.Button(
onClick, onClick,
modifier.heightIn(min = size.minHeight), modifier.heightIn(min = size.minHeight),
@ -109,9 +115,13 @@ fun Button(
elevation, elevation,
shape, shape,
border, border,
colors, colors
content = content ) {
) // Button sets LocalTextStyle, so text style is applied inside to override that.
size.applyTextConstraints {
content()
}
}
} }
} }
@ -362,3 +372,22 @@ fun NotificationRadioButton(
val MutableInteractionSource.releases val MutableInteractionSource.releases
get() = interactions.filter { it is PressInteraction.Release } 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 {}
}
}
}

View File

@ -15,25 +15,31 @@ import org.thoughtcrime.securesms.ui.extraSmallBold
interface ButtonSize { interface ButtonSize {
@OptIn(ExperimentalMaterialApi::class) @OptIn(ExperimentalMaterialApi::class)
@SuppressLint("ComposableNaming") @SuppressLint("ComposableNaming")
@Composable fun applyConstraints(content: @Composable () -> Unit) { @Composable fun applyButtonConstraints(content: @Composable () -> Unit) {
CompositionLocalProvider( CompositionLocalProvider(
LocalMinimumInteractiveComponentEnforcement provides false, 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 val minHeight: Dp
object Large: ButtonSize { object Large: ButtonSize {
override val textStyle @Composable get() = baseBold override val textStyle = baseBold
override val minHeight = 41.dp override val minHeight = 41.dp
} }
object Slim: ButtonSize { object Slim: ButtonSize {
override val textStyle @Composable get() = extraSmallBold override val textStyle = extraSmallBold
override val minHeight = 29.dp override val minHeight = 29.dp
} }

View File

@ -1,7 +1,6 @@
package org.session.libsession.utilities package org.session.libsession.utilities
import android.content.Context import android.content.Context
import android.graphics.Color
import android.hardware.Camera import android.hardware.Camera
import android.net.Uri import android.net.Uri
import android.provider.Settings import android.provider.Settings
@ -14,7 +13,6 @@ import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asSharedFlow
import org.session.libsession.R 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.AUTOPLAY_AUDIO_MESSAGES
import org.session.libsession.utilities.TextSecurePreferences.Companion.CALL_NOTIFICATIONS_ENABLED import org.session.libsession.utilities.TextSecurePreferences.Companion.CALL_NOTIFICATIONS_ENABLED
import org.session.libsession.utilities.TextSecurePreferences.Companion.CLASSIC_DARK 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.LEGACY_PREF_KEY_SELECTED_UI_MODE
import org.session.libsession.utilities.TextSecurePreferences.Companion.OCEAN_DARK 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.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_ACCENT_COLOR
import org.session.libsession.utilities.TextSecurePreferences.Companion.SELECTED_STYLE import org.session.libsession.utilities.TextSecurePreferences.Companion.SELECTED_STYLE
import org.session.libsession.utilities.TextSecurePreferences.Companion.SHOWN_CALL_NOTIFICATION import org.session.libsession.utilities.TextSecurePreferences.Companion.SHOWN_CALL_NOTIFICATION