Rebuild LandingActivity

This commit is contained in:
andrew
2023-10-17 00:56:55 +10:30
parent eb691eded9
commit fc3063140e
9 changed files with 162 additions and 314 deletions

View File

@@ -1,79 +0,0 @@
package org.thoughtcrime.securesms.onboarding
import android.animation.FloatEvaluator
import android.animation.ValueAnimator
import android.content.Context
import android.os.Handler
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.ScrollView
import network.loki.messenger.R
import network.loki.messenger.databinding.ViewFakeChatBinding
import org.thoughtcrime.securesms.util.disableClipping
class FakeChatView : ScrollView {
private lateinit var binding: ViewFakeChatBinding
// region Settings
private val spacing = context.resources.getDimension(R.dimen.medium_spacing)
private val startDelay: Long = 1000
private val delayBetweenMessages: Long = 1500
private val animationDuration: Long = 400
// endregion
// region Lifecycle
constructor(context: Context) : super(context) {
setUpViewHierarchy()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
setUpViewHierarchy()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
setUpViewHierarchy()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
setUpViewHierarchy()
}
private fun setUpViewHierarchy() {
binding = ViewFakeChatBinding.inflate(LayoutInflater.from(context), this, true)
binding.root.disableClipping()
isVerticalScrollBarEnabled = false
}
// endregion
// region Animation
fun startAnimating() {
listOf( binding.bubble1, binding.bubble2, binding.bubble3, binding.bubble4, binding.bubble5 ).forEach { it.alpha = 0.0f }
fun show(bubble: View) {
val animation = ValueAnimator.ofObject(FloatEvaluator(), 0.0f, 1.0f)
animation.duration = animationDuration
animation.addUpdateListener { animator ->
bubble.alpha = animator.animatedValue as Float
}
animation.start()
}
Handler().postDelayed({
show(binding.bubble1)
Handler().postDelayed({
show(binding.bubble2)
Handler().postDelayed({
show(binding.bubble3)
smoothScrollTo(0, (binding.bubble1.height + spacing).toInt())
Handler().postDelayed({
show(binding.bubble4)
smoothScrollTo(0, (binding.bubble1.height + spacing).toInt() + (binding.bubble2.height + spacing).toInt())
Handler().postDelayed({
show(binding.bubble5)
smoothScrollTo(0, (binding.bubble1.height + spacing).toInt() + (binding.bubble2.height + spacing).toInt() + (binding.bubble3.height + spacing).toInt())
}, delayBetweenMessages)
}, delayBetweenMessages)
}, delayBetweenMessages)
}, delayBetweenMessages)
}, startDelay)
}
// endregion
}

View File

@@ -1,37 +1,130 @@
package org.thoughtcrime.securesms.onboarding
import android.content.Intent
import android.os.Bundle
import network.loki.messenger.databinding.ActivityLandingBinding
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
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.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
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.platform.ComposeView
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import org.session.libsession.utilities.TextSecurePreferences
import org.thoughtcrime.securesms.BaseActionBarActivity
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
import org.thoughtcrime.securesms.onboarding.pickname.startPickDisplayNameActivity
import org.thoughtcrime.securesms.service.KeyCachingService
import org.thoughtcrime.securesms.util.push
import org.thoughtcrime.securesms.ui.AppTheme
import org.thoughtcrime.securesms.ui.BorderlessButton
import org.thoughtcrime.securesms.ui.FilledButton
import org.thoughtcrime.securesms.ui.OutlineButton
import org.thoughtcrime.securesms.ui.classicDarkColors
import org.thoughtcrime.securesms.ui.session_accent
import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo
class LandingActivity : BaseActionBarActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = ActivityLandingBinding.inflate(layoutInflater)
setContentView(binding.root)
setUpActionBarSessionLogo(true)
with(binding) {
fakeChatView.startAnimating()
registerButton.setOnClickListener { startPickDisplayNameActivity() }
restoreButton.setOnClickListener { link() }
linkButton.setOnClickListener { link() }
}
ComposeView(this)
.apply { setContent { LandingScreen() } }
.let(::setContentView)
IdentityKeyUtil.generateIdentityKeyPair(this)
TextSecurePreferences.setPasswordDisabled(this, true)
// AC: This is a temporary workaround to trick the old code that the screen is unlocked.
KeyCachingService.setMasterSecret(applicationContext, Object())
}
private fun link() {
val intent = Intent(this, LinkDeviceActivity::class.java)
push(intent)
@Preview
@Composable
private fun LandingScreen() {
AppTheme {
Column(modifier = Modifier.padding(horizontal = 36.dp)) {
Spacer(modifier = Modifier.weight(1f))
Text("Privacy in your pocket.", modifier = Modifier.align(Alignment.CenterHorizontally), style = MaterialTheme.typography.h4, textAlign = TextAlign.Center)
Spacer(modifier = Modifier.height(24.dp))
IncomingText("Welcome to Session \uD83D\uDC4B")
Spacer(modifier = Modifier.height(14.dp))
OutgoingText("Session is engineered\nto protect your privacy.")
Spacer(modifier = Modifier.height(14.dp))
IncomingText("You dont even need a phone number to sign up. ")
Spacer(modifier = Modifier.height(14.dp))
OutgoingText("Creating an account is \ninstant, free, and \nanonymous \uD83D\uDC47")
Spacer(modifier = Modifier.weight(1f))
OutlineButton(text = "Create account", modifier = Modifier
.width(262.dp)
.align(Alignment.CenterHorizontally)) { startPickDisplayNameActivity() }
Spacer(modifier = Modifier.height(14.dp))
FilledButton(text = "I have an account", modifier = Modifier
.width(262.dp)
.align(Alignment.CenterHorizontally)) { startLinkDeviceActivity() }
Spacer(modifier = Modifier.height(8.dp))
BorderlessButton(
text = "By using this service, you agree to our Terms of Service and Privacy Policy",
modifier = Modifier
.width(262.dp)
.align(Alignment.CenterHorizontally),
fontSize = 11.sp,
lineHeight = 13.sp
) { }
Spacer(modifier = Modifier.height(8.dp))
}
}
}
}
@Composable
private fun IncomingText(text: String) {
ChatText(
text,
color = classicDarkColors[2]
)
}
@Composable
private fun ColumnScope.OutgoingText(text: String) {
ChatText(
text,
color = session_accent,
textColor = MaterialTheme.colors.primary,
modifier = Modifier.align(Alignment.End)
)
}
@Composable
private fun ChatText(
text: String,
color: Color,
textColor: Color = Color.Unspecified,
modifier: Modifier = Modifier
) {
Text(
text,
fontSize = 16.sp,
lineHeight = 19.sp,
color = textColor,
modifier = modifier
.fillMaxWidth(0.666f)
.background(
color = color,
shape = RoundedCornerShape(size = 13.dp)
)
.padding(horizontal = 16.dp, vertical = 12.dp)
)
}
}

View File

@@ -1,6 +1,7 @@
package org.thoughtcrime.securesms.onboarding
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.text.InputType
import android.view.LayoutInflater
@@ -149,3 +150,7 @@ class RecoveryPhraseFragment : Fragment() {
}
}
// endregion
fun Context.startLinkDeviceActivity() {
Intent(this, LinkDeviceActivity::class.java).let(::startActivity)
}

View File

@@ -38,6 +38,7 @@ import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import com.google.accompanist.pager.HorizontalPagerIndicator
@@ -58,11 +59,50 @@ fun OutlineButton(text: String, modifier: Modifier = Modifier, onClick: () -> Un
contentColor = LocalExtraColors.current.prominentButtonColor,
backgroundColor = MaterialTheme.colors.background
)
){
) {
Text(text = text)
}
}
@Composable
fun FilledButton(text: String, modifier: Modifier = Modifier, onClick: () -> Unit) {
OutlinedButton(
modifier = modifier.size(108.dp, 34.dp),
onClick = onClick,
shape = RoundedCornerShape(50), // = 50% percent
colors = ButtonDefaults.outlinedButtonColors(
contentColor = MaterialTheme.colors.background,
backgroundColor = LocalExtraColors.current.prominentButtonColor
)
) {
Text(text = text)
}
}
@Composable
fun BorderlessButton(
text: String,
modifier: Modifier = Modifier,
fontSize: TextUnit = TextUnit.Unspecified,
lineHeight: TextUnit = TextUnit.Unspecified,
onClick: () -> Unit) {
TextButton(
onClick = onClick,
modifier = modifier,
shape = RoundedCornerShape(50), // = 50% percent
colors = ButtonDefaults.outlinedButtonColors(
contentColor = MaterialTheme.colors.onBackground,
backgroundColor = MaterialTheme.colors.background
)
) {
Text(
text = text,
fontSize = fontSize,
lineHeight = lineHeight
)
}
}
@Composable
fun ItemButton(
text: String,