Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shipping Labels Onboarding: Pre-install screen #6797

Merged
merged 12 commits into from
Jun 22, 2022
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import com.woocommerce.android.ui.orders.shippinglabels.ShippingLabelRefundFragm
import com.woocommerce.android.ui.orders.simplepayments.TakePaymentViewModel
import com.woocommerce.android.ui.orders.tracking.AddOrderShipmentTrackingFragment
import com.woocommerce.android.ui.refunds.RefundSummaryFragment
import com.woocommerce.android.ui.shipping.InstallWcShippingFlowViewModel
import com.woocommerce.android.ui.shipping.InstallWCShippingViewModel
import com.woocommerce.android.util.CurrencyFormatter
import com.woocommerce.android.util.DateUtils
import com.woocommerce.android.util.FeatureFlag
Expand Down Expand Up @@ -265,7 +265,7 @@ class OrderDetailFragment : BaseFragment(R.layout.fragment_order_detail), OrderP
is TakePaymentViewModel.SharePaymentUrl -> {
sharePaymentUrl(event.storeName, event.paymentUrl)
}
is InstallWcShippingFlowViewModel.InstallWcShipping -> navigateToInstallWcShippingFlow()
is InstallWCShippingViewModel.InstallWcShipping -> navigateToInstallWcShippingFlow()
else -> event.isHandled = false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import com.woocommerce.android.ui.orders.OrderNavigationTarget.ViewPrintingInstr
import com.woocommerce.android.ui.orders.OrderNavigationTarget.ViewRefundedProducts
import com.woocommerce.android.ui.orders.simplepayments.TakePaymentViewModel
import com.woocommerce.android.ui.products.addons.AddonRepository
import com.woocommerce.android.ui.shipping.InstallWcShippingFlowViewModel
import com.woocommerce.android.ui.shipping.InstallWCShippingViewModel
import com.woocommerce.android.util.CoroutineDispatchers
import com.woocommerce.android.util.WooLog
import com.woocommerce.android.util.WooLog.T
Expand Down Expand Up @@ -264,7 +264,7 @@ final class OrderDetailViewModel @Inject constructor(
}

fun onGetWcShippingClicked() {
triggerEvent(InstallWcShippingFlowViewModel.InstallWcShipping)
triggerEvent(InstallWCShippingViewModel.InstallWcShipping)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
package com.woocommerce.android.ui.shipping

import androidx.compose.animation.core.CubicBezierEasing
import androidx.compose.animation.core.Transition
import androidx.compose.animation.core.animateInt
import androidx.compose.animation.core.tween
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Info
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.woocommerce.android.R
import com.woocommerce.android.ui.compose.component.WCColoredButton
import com.woocommerce.android.ui.compose.component.WCTextButton
import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground
import com.woocommerce.android.ui.shipping.InstallWCShippingViewModel.ViewState.InstallationState
import com.woocommerce.android.ui.shipping.InstallWCShippingViewModel.ViewState.InstallationState.PreInstallation

@Composable
fun InstallWCShippingFlow(viewState: InstallationState, transition: Transition<Boolean>? = null) {
when (viewState) {
is PreInstallation -> PreInstallationContent(viewState, transition)
}
}

@Composable
private fun PreInstallationContent(viewState: PreInstallation, transition: Transition<Boolean>? = null) {
val offset by transition?.animateInt(
transitionSpec = {
tween(
durationMillis = 500,
delayMillis = 500,
// Ensure a bit of elasticity at the end of the animation
easing = CubicBezierEasing(0.7f, 0.6f, 0.74f, 1.3f)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

)
},
label = "offset"
) {
if (it) 0 else 120
} ?: remember { mutableStateOf(0) }

Column(
modifier = Modifier
.fillMaxSize()
.padding(
horizontal = dimensionResource(id = R.dimen.major_100),
vertical = dimensionResource(id = R.dimen.major_150)
)
) {
Column(
verticalArrangement = Arrangement.Center,
modifier = Modifier
.weight(1f)
.verticalScroll(rememberScrollState())
.offset(y = -offset.dp)
) {
WCTextButton(onClick = viewState.onCancelClick) {
Text(text = stringResource(id = R.string.cancel))
}
SpacerWithMinHeight(1f, dimensionResource(id = R.dimen.major_100))
Box(
modifier = Modifier
.clip(CircleShape)
.border(
width = dimensionResource(id = R.dimen.major_75),
color = colorResource(id = R.color.woo_purple_20),
shape = CircleShape
)
.size(dimensionResource(id = R.dimen.image_major_120))
) {
Icon(
painter = painterResource(id = R.drawable.ic_arrow_forward_rounded),
contentDescription = null,
tint = colorResource(id = R.color.woo_purple_50),
modifier = Modifier
.align(Alignment.Center)
.size(dimensionResource(id = R.dimen.image_major_64))
)
}
Spacer(modifier = Modifier.height(dimensionResource(id = R.dimen.major_150)))
Text(
text = stringResource(id = R.string.install_wc_shipping_preinstall_title),
style = MaterialTheme.typography.h4,
fontWeight = FontWeight.Bold
)
Text(
text = stringResource(id = viewState.extensionsName),
style = MaterialTheme.typography.h4,
fontWeight = FontWeight.Bold,
color = colorResource(id = R.color.woo_purple_50)
)
Spacer(modifier = Modifier.height(dimensionResource(id = R.dimen.major_150)))
Text(
text = viewState.siteName,
style = MaterialTheme.typography.h4
)
SpacerWithMinHeight(0.75f, dimensionResource(id = R.dimen.major_100))
Row(
horizontalArrangement = Arrangement.spacedBy(dimensionResource(id = R.dimen.minor_100)),
modifier = Modifier
.clickable(onClick = viewState.onInfoClick)
) {
Icon(
imageVector = Icons.Outlined.Info,
contentDescription = null,
tint = colorResource(id = R.color.link_text)
)
Text(
style = MaterialTheme.typography.subtitle1,
color = colorResource(id = R.color.link_text),
text = stringResource(id = R.string.install_wc_shipping_installation_info),
)
}
SpacerWithMinHeight(0.75f, dimensionResource(id = R.dimen.major_100))
}
WCColoredButton(
onClick = viewState.onProceedClick,
modifier = Modifier
.fillMaxWidth()
.offset(y = offset.dp)
) {
Text(text = stringResource(id = R.string.install_wc_shipping_proceed_button))
}
}
}

@Composable
private fun ColumnScope.SpacerWithMinHeight(weight: Float, minHeight: Dp) {
Spacer(modifier = Modifier.height(minHeight))
Spacer(modifier = Modifier.weight(weight))
}

@Preview
@Composable
private fun PreInstallationPreview() {
WooThemeWithBackground {
PreInstallationContent(
viewState = PreInstallation(
extensionsName = R.string.install_wc_shipping_extension_name,
siteName = "Site",
onCancelClick = {},
onProceedClick = {},
onInfoClick = {}
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import androidx.navigation.fragment.findNavController
import com.woocommerce.android.ui.base.BaseFragment
import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground
import com.woocommerce.android.ui.main.AppBarStatus
import com.woocommerce.android.ui.shipping.InstallWcShippingFlowViewModel.InstallWcShippingFlowEvent.ExitInstallFlowEvent
import com.woocommerce.android.ui.shipping.InstallWcShippingFlowViewModel.InstallWcShippingFlowEvent.OpenLinkEvent
import com.woocommerce.android.ui.shipping.InstallWCShippingViewModel.OpenLinkEvent
import com.woocommerce.android.util.ChromeCustomTabUtils
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event.Exit
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class InstallWcShippingFlowFragment : BaseFragment() {
class InstallWCShippingFragment : BaseFragment() {
override val activityAppBarStatus: AppBarStatus
get() = AppBarStatus.Hidden

private val viewModel: InstallWcShippingFlowViewModel by viewModels()
private val viewModel: InstallWCShippingViewModel by viewModels()

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -34,7 +34,7 @@ class InstallWcShippingFlowFragment : BaseFragment() {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
WooThemeWithBackground {
InstallWcShippingOnboardingScreen(viewModel)
InstallWCShippingScreen(viewModel)
}
}
}
Expand All @@ -45,7 +45,7 @@ class InstallWcShippingFlowFragment : BaseFragment() {

viewModel.event.observe(viewLifecycleOwner) { event ->
when (event) {
is ExitInstallFlowEvent -> findNavController().navigateUp()
is Exit -> findNavController().navigateUp()
is OpenLinkEvent -> openInBrowser(event.url)
}
}
Expand Down
Loading