-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Shipping Labels Revamp] Introduce hazmat initial navigation and screen #13784
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b846032
Add Hazmat notice click event UI wiring
ThomazFB 35232fb
Define Hazmat Form click event and call function
ThomazFB 0933a9f
Declare WooShippingLabelHazmatFormFragment with compose scaffold
ThomazFB 502efb0
Define navigation route between the Label Creation fragment and Hazma…
ThomazFB 4dec8f1
Define WooShippingLabelHazmatFormScreen.kt
ThomazFB f6d7edc
Define WooShippingLabelHazmatFormScreen main UI elements and behaviors
ThomazFB 95f80b1
Define WooShippingLabelHazmatFormViewModel with initial ViewState
ThomazFB fab3fcd
Add ViewModel main interface with the Composable UI
ThomazFB 047a928
Wire the Hazmat full call path between Fragment, Composable and ViewM…
ThomazFB 97738e4
Add proper event trigger for the onSelectCategoryClick function call
ThomazFB 1662e7e
Fix missing injection into WooShippingLabelHazmatFormViewModel
ThomazFB e812c34
Introduce WooShippingLabelHazmatFormViewModelTest coverage
ThomazFB d3f1866
Fix lint issues
ThomazFB 0a0373e
Add Preview to WooShippingLabelHazmatFormScreen
ThomazFB 9b6bfe2
Declare and assign proper string resources to the WooShippingLabelHaz…
ThomazFB 2770463
Add proper spacing to the WooShippingLabelHazmatFormScreen
ThomazFB 1c7780a
Add missing Hazmat click event wiring
ThomazFB cb73765
Move away from Material3 surface for now
ThomazFB 2d3ecf6
Add Dark mode support and vertical scrolling to WooShippingLabelHazma…
ThomazFB 385d7d3
Remove redundant isNotNull check from WooShippingLabelHazmatFormViewM…
ThomazFB 0344978
Update onSurface color for WooShippingLabelHazmatFormScreen texts
ThomazFB 02d4beb
Merge branch 'trunk' into issue/introduce-hazmat-initial-navigation
ThomazFB e4e5012
Fix WooShippingLabelHazmatFormScreen checkbox color
ThomazFB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...commerce/android/ui/orders/wooshippinglabels/hazmat/WooShippingLabelHazmatFormFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.woocommerce.android.ui.orders.wooshippinglabels.hazmat | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.compose.material.Surface | ||
import androidx.compose.ui.platform.ComposeView | ||
import androidx.compose.ui.platform.ViewCompositionStrategy | ||
import androidx.fragment.app.viewModels | ||
import com.woocommerce.android.ui.base.BaseFragment | ||
import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class WooShippingLabelHazmatFormFragment : BaseFragment() { | ||
private val viewModel: WooShippingLabelHazmatFormViewModel by viewModels() | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
return ComposeView(requireContext()).apply { | ||
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) | ||
setContent { | ||
WooThemeWithBackground { | ||
Surface { | ||
WooShippingLabelHazmatFormScreen(viewModel) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
...oocommerce/android/ui/orders/wooshippinglabels/hazmat/WooShippingLabelHazmatFormScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.woocommerce.android.ui.orders.wooshippinglabels.hazmat | ||
|
||
import android.content.res.Configuration | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material3.Checkbox | ||
import androidx.compose.material3.CheckboxDefaults | ||
import androidx.compose.material3.HorizontalDivider | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.livedata.observeAsState | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.colorResource | ||
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 com.woocommerce.android.R | ||
import com.woocommerce.android.ui.compose.component.WCColoredButton | ||
import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground | ||
|
||
@Composable | ||
fun WooShippingLabelHazmatFormScreen(viewModel: WooShippingLabelHazmatFormViewModel) { | ||
val viewState by viewModel.viewState.observeAsState() | ||
WooShippingLabelHazmatFormScreen( | ||
containsHazmatChecked = viewState?.containsHazmatChecked == true, | ||
onContainsHazmatChanged = viewModel::onContainsHazmatChanged, | ||
onSelectCategoryClick = viewModel::onSelectCategoryClick | ||
) | ||
} | ||
|
||
@Composable | ||
fun WooShippingLabelHazmatFormScreen( | ||
containsHazmatChecked: Boolean, | ||
onContainsHazmatChanged: (Boolean) -> Unit, | ||
onSelectCategoryClick: () -> Unit, | ||
modifier: Modifier = Modifier | ||
) { | ||
Column( | ||
verticalArrangement = Arrangement.spacedBy(8.dp), | ||
modifier = modifier | ||
.fillMaxSize() | ||
.padding(16.dp) | ||
.verticalScroll(rememberScrollState()) | ||
) { | ||
Text( | ||
text = stringResource(R.string.woo_shipping_labels_hazmat_info_title), | ||
style = MaterialTheme.typography.titleLarge, | ||
fontWeight = FontWeight.Bold, | ||
color = colorResource(id = R.color.color_on_surface) | ||
) | ||
Row( | ||
horizontalArrangement = Arrangement.Absolute.SpaceBetween, | ||
modifier = modifier | ||
.fillMaxWidth() | ||
.padding(vertical = 8.dp) | ||
) { | ||
Text( | ||
text = stringResource(R.string.woo_shipping_labels_hazmat_info_contains_hazmat), | ||
style = MaterialTheme.typography.bodyLarge, | ||
color = colorResource(id = R.color.color_on_surface), | ||
modifier = modifier | ||
.align(Alignment.CenterVertically) | ||
.weight(1f) | ||
) | ||
Checkbox( | ||
checked = containsHazmatChecked, | ||
onCheckedChange = onContainsHazmatChanged, | ||
colors = CheckboxDefaults.colors( | ||
checkedColor = MaterialTheme.colorScheme.primary, | ||
uncheckedColor = colorResource(id = R.color.color_on_surface_disabled), | ||
) | ||
) | ||
} | ||
WCColoredButton( | ||
text = stringResource(R.string.woo_shipping_labels_hazmat_info_select_category), | ||
onClick = onSelectCategoryClick, | ||
enabled = containsHazmatChecked, | ||
modifier = modifier.fillMaxWidth() | ||
) | ||
|
||
HorizontalDivider(modifier = modifier.padding(vertical = 8.dp)) | ||
|
||
Text( | ||
text = stringResource(R.string.woo_shipping_labels_hazmat_info_full_description), | ||
style = MaterialTheme.typography.bodyMedium, | ||
color = colorResource(id = R.color.color_on_surface), | ||
) | ||
} | ||
} | ||
|
||
@Preview | ||
@Preview("Dark Theme", uiMode = Configuration.UI_MODE_NIGHT_YES) | ||
@Composable | ||
fun WooShippingLabelHazmatFormScreenPreview() { | ||
WooThemeWithBackground { | ||
WooShippingLabelHazmatFormScreen( | ||
containsHazmatChecked = false, | ||
onContainsHazmatChanged = {}, | ||
onSelectCategoryClick = {} | ||
) | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...ommerce/android/ui/orders/wooshippinglabels/hazmat/WooShippingLabelHazmatFormViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.woocommerce.android.ui.orders.wooshippinglabels.hazmat | ||
|
||
import android.os.Parcelable | ||
import androidx.lifecycle.SavedStateHandle | ||
import androidx.lifecycle.asLiveData | ||
import androidx.lifecycle.viewModelScope | ||
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event | ||
import com.woocommerce.android.viewmodel.ScopedViewModel | ||
import com.woocommerce.android.viewmodel.getStateFlow | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.update | ||
import kotlinx.parcelize.Parcelize | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class WooShippingLabelHazmatFormViewModel @Inject constructor( | ||
savedState: SavedStateHandle | ||
) : ScopedViewModel(savedState) { | ||
|
||
private val _viewState = savedState.getStateFlow( | ||
scope = viewModelScope, | ||
initialValue = ViewState() | ||
) | ||
val viewState = _viewState.asLiveData() | ||
|
||
fun onContainsHazmatChanged(containsHazmatChecked: Boolean) { | ||
_viewState.update { | ||
_viewState.value.copy(containsHazmatChecked = containsHazmatChecked) | ||
} | ||
} | ||
|
||
fun onSelectCategoryClick() { | ||
triggerEvent(OnSelectCategoryClicked) | ||
} | ||
|
||
@Parcelize | ||
data class ViewState( | ||
val containsHazmatChecked: Boolean = false | ||
) : Parcelable | ||
|
||
data object OnSelectCategoryClicked : Event() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...rce/android/ui/orders/wooshippinglabels/hazmat/WooShippingLabelHazmatFormViewModelTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.woocommerce.android.ui.orders.wooshippinglabels.hazmat | ||
|
||
import androidx.lifecycle.SavedStateHandle | ||
import com.woocommerce.android.viewmodel.BaseUnitTest | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
class WooShippingLabelHazmatFormViewModelTest : BaseUnitTest() { | ||
private lateinit var viewModel: WooShippingLabelHazmatFormViewModel | ||
|
||
@Before | ||
fun setup() { | ||
viewModel = WooShippingLabelHazmatFormViewModel(SavedStateHandle()) | ||
} | ||
|
||
@Test | ||
fun `when initialized, then containsHazmatChecked is false by default`() = testBlocking { | ||
// Given/When | ||
var capturedViewState: WooShippingLabelHazmatFormViewModel.ViewState? = null | ||
viewModel.viewState.observeForever { | ||
capturedViewState = it | ||
} | ||
|
||
// Then | ||
assertThat(capturedViewState?.containsHazmatChecked).isFalse() | ||
} | ||
|
||
@Test | ||
fun `when onContainsHazmatChanged is called with true, then viewState is updated accordingly`() = testBlocking { | ||
// Given | ||
var capturedViewState: WooShippingLabelHazmatFormViewModel.ViewState? = null | ||
viewModel.viewState.observeForever { | ||
capturedViewState = it | ||
} | ||
|
||
// When | ||
viewModel.onContainsHazmatChanged(true) | ||
|
||
// Then | ||
assertThat(capturedViewState?.containsHazmatChecked).isTrue() | ||
} | ||
|
||
@Test | ||
fun `when onContainsHazmatChanged is called with false, then viewState is updated accordingly`() = testBlocking { | ||
// Given | ||
var capturedViewState: WooShippingLabelHazmatFormViewModel.ViewState? = null | ||
viewModel.viewState.observeForever { | ||
capturedViewState = it | ||
} | ||
|
||
// When | ||
viewModel.onContainsHazmatChanged(false) | ||
|
||
// Then | ||
assertThat(capturedViewState?.containsHazmatChecked).isFalse() | ||
} | ||
|
||
@Test | ||
fun `when onSelectCategoryClick is called, then OnSelectCategoryClicked event is triggered`() = testBlocking { | ||
// Given | ||
var capturedEvent: WooShippingLabelHazmatFormViewModel.OnSelectCategoryClicked? = null | ||
viewModel.event.observeForever { | ||
capturedEvent = it as? WooShippingLabelHazmatFormViewModel.OnSelectCategoryClicked | ||
} | ||
|
||
// When | ||
viewModel.onSelectCategoryClick() | ||
|
||
// Then | ||
assertThat(capturedEvent).isInstanceOf(WooShippingLabelHazmatFormViewModel.OnSelectCategoryClicked::class.java) | ||
} | ||
|
||
@Test | ||
fun `when multiple calls to onContainsHazmatChanged, then viewState reflects latest value`() = testBlocking { | ||
// Given | ||
var capturedViewState: WooShippingLabelHazmatFormViewModel.ViewState? = null | ||
viewModel.viewState.observeForever { | ||
capturedViewState = it | ||
} | ||
|
||
// When | ||
viewModel.onContainsHazmatChanged(true) | ||
viewModel.onContainsHazmatChanged(false) | ||
viewModel.onContainsHazmatChanged(true) | ||
|
||
// Then | ||
assertThat(capturedViewState?.containsHazmatChecked).isTrue() | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / Android Lint
material and material3 are separate, incompatible design system libraries Warning