Refactor Composables in HomeActivity

This commit is contained in:
Andrew 2024-06-17 19:13:08 +09:30
parent a1882b83f9
commit 3b283f11f5
4 changed files with 179 additions and 120 deletions

View File

@ -0,0 +1,91 @@
package org.thoughtcrime.securesms.home
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Icon
import androidx.compose.material.Text
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.res.painterResource
import androidx.compose.ui.res.stringResource
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 network.loki.messenger.R
import org.thoughtcrime.securesms.ui.Divider
import org.thoughtcrime.securesms.ui.LocalDimensions
import org.thoughtcrime.securesms.ui.PreviewTheme
import org.thoughtcrime.securesms.ui.SessionColorsParameterProvider
import org.thoughtcrime.securesms.ui.base
import org.thoughtcrime.securesms.ui.color.Colors
import org.thoughtcrime.securesms.ui.color.LocalColors
import org.thoughtcrime.securesms.ui.h4
import org.thoughtcrime.securesms.ui.h8
import org.thoughtcrime.securesms.ui.small
@Composable
internal fun EmptyView(newAccount: Boolean) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.padding(horizontal = LocalDimensions.current.marginHomeEmptyView)
) {
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 = h4,
textAlign = TextAlign.Center
)
Text(
stringResource(R.string.welcome_to_session),
style = base,
color = LocalColors.current.primary,
textAlign = TextAlign.Center
)
}
Divider(modifier = Modifier.padding(vertical = LocalDimensions.current.marginExtraSmall))
Text(
stringResource(R.string.conversationsNone),
style = h8,
textAlign = TextAlign.Center,
modifier = Modifier.padding(bottom = 12.dp))
Text(
stringResource(R.string.onboardingHitThePlusButton),
style = small,
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.weight(2f))
}
}
@Preview
@Composable
fun PreviewEmptyView(
@PreviewParameter(SessionColorsParameterProvider::class) colors: Colors
) {
PreviewTheme(colors) {
EmptyView(newAccount = false)
}
}
@Preview
@Composable
fun PreviewEmptyViewNew(
@PreviewParameter(SessionColorsParameterProvider::class) colors: Colors
) {
PreviewTheme(colors) {
EmptyView(newAccount = true)
}
}

View File

@ -672,125 +672,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
}
}
@Preview
@Composable
fun PreviewSeedReminder(
@PreviewParameter(SessionColorsParameterProvider::class) colors: Colors
) {
PreviewTheme(colors) {
SeedReminder {}
}
}
@Composable
private fun SeedReminder(startRecoveryPasswordActivity: () -> Unit) {
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),
style = h8
)
Spacer(Modifier.requiredWidth(LocalDimensions.current.itemSpacingExtraSmall))
SessionShieldIcon()
}
Text(
stringResource(R.string.save_your_recovery_password_to_make_sure_you_don_t_lose_access_to_your_account),
style = small
)
}
Spacer(Modifier.width(LocalDimensions.current.marginExtraExtraSmall))
SlimOutlineButton(
text = stringResource(R.string.continue_2),
modifier = Modifier
.align(Alignment.CenterVertically)
.contentDescription(R.string.AccessibilityId_reveal_recovery_phrase_button),
color = LocalColors.current.buttonOutline,
onClick = { startRecoveryPasswordActivity() }
)
}
}
}
@Preview
@Composable
fun PreviewEmptyView(
@PreviewParameter(SessionColorsParameterProvider::class) colors: Colors
) {
PreviewTheme(colors) {
EmptyView(newAccount = false)
}
}
@Preview
@Composable
fun PreviewEmptyViewNew(
@PreviewParameter(SessionColorsParameterProvider::class) colors: Colors
) {
PreviewTheme(colors) {
EmptyView(newAccount = true)
}
}
@Composable
private fun EmptyView(newAccount: Boolean) {
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 = h4,
textAlign = TextAlign.Center
)
Text(
stringResource(R.string.welcome_to_session),
style = base,
color = LocalColors.current.primary,
textAlign = TextAlign.Center
)
}
Divider(modifier = Modifier.padding(vertical = LocalDimensions.current.marginExtraSmall))
Text(
stringResource(R.string.conversationsNone),
style = h8,
textAlign = TextAlign.Center,
modifier = Modifier.padding(bottom = 12.dp))
Text(
stringResource(R.string.onboardingHitThePlusButton),
style = small,
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.weight(2f))
}
}
fun Context.startHomeActivity() {
Intent(this, HomeActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK

View File

@ -0,0 +1,86 @@
package org.thoughtcrime.securesms.home
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredWidth
import androidx.compose.foundation.layout.width
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import network.loki.messenger.R
import org.thoughtcrime.securesms.ui.LocalDimensions
import org.thoughtcrime.securesms.ui.PreviewTheme
import org.thoughtcrime.securesms.ui.SessionColorsParameterProvider
import org.thoughtcrime.securesms.ui.SessionShieldIcon
import org.thoughtcrime.securesms.ui.color.Colors
import org.thoughtcrime.securesms.ui.color.LocalColors
import org.thoughtcrime.securesms.ui.components.SlimOutlineButton
import org.thoughtcrime.securesms.ui.contentDescription
import org.thoughtcrime.securesms.ui.h8
import org.thoughtcrime.securesms.ui.small
@Composable
internal fun SeedReminder(startRecoveryPasswordActivity: () -> Unit) {
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),
style = h8
)
Spacer(Modifier.requiredWidth(LocalDimensions.current.itemSpacingExtraSmall))
SessionShieldIcon()
}
Text(
stringResource(R.string.save_your_recovery_password_to_make_sure_you_don_t_lose_access_to_your_account),
style = small
)
}
Spacer(Modifier.width(LocalDimensions.current.marginExtraExtraSmall))
SlimOutlineButton(
text = stringResource(R.string.continue_2),
modifier = Modifier
.align(Alignment.CenterVertically)
.contentDescription(R.string.AccessibilityId_reveal_recovery_phrase_button),
color = LocalColors.current.buttonOutline,
onClick = { startRecoveryPasswordActivity() }
)
}
}
}
@Preview
@Composable
private fun PreviewSeedReminder(
@PreviewParameter(SessionColorsParameterProvider::class) colors: Colors
) {
PreviewTheme(colors) {
SeedReminder {}
}
}

View File

@ -21,5 +21,6 @@ data class Dimensions(
val marginLarge: Dp = 64.dp,
val dividerIndent: Dp = 80.dp,
val appBarHeight: Dp = 64.dp,
val minScrollableViewHeight: Dp = 200.dp
val minScrollableViewHeight: Dp = 200.dp,
val marginHomeEmptyView: Dp = 50.dp
)