mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 10:05:15 +00:00
Changes for code review
This commit is contained in:
parent
46650ef678
commit
253fe9136d
@ -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() {}
|
||||
}
|
@ -48,16 +48,14 @@ class NewConversationHomeFragment : Fragment() {
|
||||
@Inject
|
||||
lateinit var textSecurePreferences: TextSecurePreferences
|
||||
|
||||
var delegate = MutableStateFlow<NewConversationDelegate?>(null)
|
||||
var delegate = MutableStateFlow<NewConversationDelegate>(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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +109,6 @@ fun <T> OptionsCard(card: OptionsCard<T>, callbacks: Callbacks<T>) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@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)
|
||||
)
|
||||
},
|
||||
|
@ -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 {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user