-
Notifications
You must be signed in to change notification settings - Fork 136
[WOOMOB-1068] Add initial implementation of Local Catalog Settings #14717
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
Merged
malinajirka
merged 17 commits into
trunk
from
issue/woomob-1068-woo-poslocal-catalog-implement-sync-section-in-settings
Oct 9, 2025
Merged
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3be1c9c
Add local catalog setting navigation
malinajirka 5f81536
tracking
malinajirka cfa7968
Add dummy catalog VM
malinajirka 5e6a277
Add initial Local Catalog settings screen
malinajirka adeec98
Introduce date formatter
malinajirka 7674a69
Use actual last update dates
malinajirka 079ada9
Run full catalog sync on manual trigger
malinajirka 0e2b6d9
Show local catalog settings only with FF
malinajirka a88e91b
Replace todos with tbd
malinajirka 72e9b4b
Fix detekt
malinajirka 0bee95f
Make WooPosDateFormatter testable
malinajirka 9c461a5
Add tests for WooPosDateFormatter
malinajirka 99219e1
Merge branch 'issue/introduce-pos-date-formatter' into issue/woomob-1…
malinajirka 6be1314
Fix strings
malinajirka 541fce3
Update PosSettingsLocalCatalog state
malinajirka be52b50
Disable refresh catalog button when loading status
malinajirka 240cb05
Fix detekt
malinajirka 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 hidden or 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 hidden or 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 hidden or 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
18 changes: 16 additions & 2 deletions
18
...om/woocommerce/android/ui/woopos/settings/categories/WooPosSettingsCategoriesViewModel.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -1,14 +1,28 @@ | ||
| package com.woocommerce.android.ui.woopos.settings.categories | ||
|
|
||
| import android.content.Context | ||
| import androidx.lifecycle.ViewModel | ||
| import com.woocommerce.android.util.FeatureFlag | ||
| import dagger.hilt.android.lifecycle.HiltViewModel | ||
| import dagger.hilt.android.qualifiers.ApplicationContext | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.StateFlow | ||
| import kotlinx.coroutines.flow.asStateFlow | ||
| import javax.inject.Inject | ||
|
|
||
| @HiltViewModel | ||
| class WooPosSettingsCategoriesViewModel @Inject constructor() : ViewModel() { | ||
| private val _state = MutableStateFlow(WooPosSettingsCategoriesState()) | ||
| class WooPosSettingsCategoriesViewModel @Inject constructor( | ||
| @ApplicationContext private val context: Context | ||
| ) : ViewModel() { | ||
| private val _state = MutableStateFlow(createInitialState()) | ||
| val state: StateFlow<WooPosSettingsCategoriesState> = _state.asStateFlow() | ||
| private fun createInitialState(): WooPosSettingsCategoriesState { | ||
| val allCategories = WooPosSettingsCategory.entries | ||
| val visibleCategories = if (FeatureFlag.WOO_POS_LOCAL_CATALOG_M1.isEnabled(context)) { | ||
| allCategories | ||
| } else { | ||
| allCategories.filter { it != WooPosSettingsCategory.LOCAL_CATALOG } | ||
| } | ||
| return WooPosSettingsCategoriesState(categories = visibleCategories) | ||
| } | ||
| } |
This file contains hidden or 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
290 changes: 290 additions & 0 deletions
290
...merce/android/ui/woopos/settings/details/localcatalog/WooPosSettingsLocalCatalogScreen.kt
This file contains hidden or 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,290 @@ | ||
| package com.woocommerce.android.ui.woopos.settings.details.localcatalog | ||
|
|
||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Column | ||
| 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.padding | ||
| import androidx.compose.foundation.layout.width | ||
| import androidx.compose.foundation.rememberScrollState | ||
| import androidx.compose.foundation.shape.RoundedCornerShape | ||
| import androidx.compose.foundation.verticalScroll | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Switch | ||
| import androidx.compose.material3.SwitchDefaults | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.collectAsState | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.draw.clip | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.text.font.FontWeight | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel | ||
| import com.woocommerce.android.R | ||
| import com.woocommerce.android.ui.woopos.common.composeui.WooPosPreview | ||
| import com.woocommerce.android.ui.woopos.common.composeui.component.WooPosButton | ||
| import com.woocommerce.android.ui.woopos.common.composeui.component.WooPosButtonState | ||
| import com.woocommerce.android.ui.woopos.common.composeui.component.WooPosShimmerBox | ||
| import com.woocommerce.android.ui.woopos.common.composeui.component.WooPosText | ||
| import com.woocommerce.android.ui.woopos.common.composeui.designsystem.WooPosCornerRadius | ||
| import com.woocommerce.android.ui.woopos.common.composeui.designsystem.WooPosSpacing | ||
| import com.woocommerce.android.ui.woopos.common.composeui.designsystem.WooPosTheme | ||
| import com.woocommerce.android.ui.woopos.common.composeui.designsystem.WooPosTypography | ||
|
|
||
| @Composable | ||
| fun WooPosSettingsLocalCatalogScreen( | ||
| modifier: Modifier = Modifier, | ||
| viewModel: WooPosSettingsLocalCatalogViewModel = hiltViewModel() | ||
| ) { | ||
| val state by viewModel.state.collectAsState() | ||
|
|
||
| WooPosSettingsLocalCatalogScreen( | ||
| state = state, | ||
| onToggleCellularData = viewModel::toggleCellularDataUpdate, | ||
| onRefreshCatalog = viewModel::runFullCatalogSync, | ||
| modifier = modifier | ||
| ) | ||
| } | ||
|
|
||
| @Composable | ||
| private fun WooPosSettingsLocalCatalogScreen( | ||
| state: WooPosSettingsLocalCatalogState, | ||
| onToggleCellularData: () -> Unit, | ||
| onRefreshCatalog: () -> Unit, | ||
| modifier: Modifier = Modifier | ||
| ) { | ||
| Column( | ||
| modifier = modifier | ||
| .fillMaxSize() | ||
| .verticalScroll(rememberScrollState()) | ||
| .padding(WooPosSpacing.Medium.value) | ||
| ) { | ||
| CatalogStatusSection( | ||
| catalogStatus = state.catalogStatus, | ||
| isLoading = state.isLoading | ||
| ) | ||
|
|
||
| Spacer(modifier = Modifier.height(WooPosSpacing.Large.value)) | ||
|
|
||
| SettingsSection( | ||
| allowCellularDataUpdate = state.allowCellularDataUpdate, | ||
| onToggleCellularData = onToggleCellularData, | ||
| isLoading = state.isLoading | ||
| ) | ||
|
|
||
| Spacer(modifier = Modifier.height(WooPosSpacing.Large.value)) | ||
|
|
||
| RefreshSection( | ||
| onRefreshCatalog = onRefreshCatalog, | ||
| isRefreshing = state.isRefreshing | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun CatalogStatusSection( | ||
| catalogStatus: CatalogStatus?, | ||
| isLoading: Boolean | ||
| ) { | ||
| Column( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .clip(RoundedCornerShape(WooPosCornerRadius.Large.value)) | ||
| .background(MaterialTheme.colorScheme.surfaceContainerHigh) | ||
| .padding(WooPosSpacing.Medium.value) | ||
| ) { | ||
| SectionTitle(stringResource(R.string.woopos_settings_local_catalog_status)) | ||
|
|
||
| Spacer(modifier = Modifier.height(WooPosSpacing.Medium.value)) | ||
|
|
||
| if (isLoading || catalogStatus == null) { | ||
| StatusRow( | ||
| label = stringResource(R.string.woopos_settings_local_catalog_size), | ||
| value = null, | ||
| isLoading = true | ||
| ) | ||
| StatusRow( | ||
| label = stringResource(R.string.woopos_settings_local_catalog_last_update), | ||
| value = null, | ||
| isLoading = true | ||
| ) | ||
| StatusRow( | ||
| label = stringResource(R.string.woopos_settings_local_catalog_last_full_update), | ||
| value = null, | ||
| isLoading = true | ||
| ) | ||
| } else { | ||
| StatusRow( | ||
| label = stringResource(R.string.woopos_settings_local_catalog_size), | ||
| value = catalogStatus.catalogSize, | ||
| isLoading = false | ||
| ) | ||
| StatusRow( | ||
| label = stringResource(R.string.woopos_settings_local_catalog_last_update), | ||
| value = catalogStatus.lastUpdate, | ||
| isLoading = false | ||
| ) | ||
| StatusRow( | ||
| label = stringResource(R.string.woopos_settings_local_catalog_last_full_update), | ||
| value = catalogStatus.lastFullUpdate, | ||
| isLoading = false | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun SettingsSection( | ||
| allowCellularDataUpdate: Boolean, | ||
| onToggleCellularData: () -> Unit, | ||
| isLoading: Boolean | ||
| ) { | ||
| Column( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .clip(RoundedCornerShape(WooPosCornerRadius.Large.value)) | ||
| .background(MaterialTheme.colorScheme.surfaceContainerHigh) | ||
| .padding(WooPosSpacing.Medium.value) | ||
| ) { | ||
| SectionTitle(stringResource(R.string.woopos_settings_local_catalog_settings)) | ||
|
|
||
| Spacer(modifier = Modifier.height(WooPosSpacing.Medium.value)) | ||
|
|
||
| Row( | ||
| modifier = Modifier.fillMaxWidth(), | ||
| horizontalArrangement = Arrangement.SpaceBetween, | ||
| verticalAlignment = Alignment.CenterVertically | ||
| ) { | ||
| Column( | ||
| modifier = Modifier.weight(1f) | ||
| ) { | ||
| WooPosText( | ||
| text = stringResource(R.string.woopos_settings_local_catalog_cellular_data), | ||
| style = WooPosTypography.BodyLarge, | ||
| color = MaterialTheme.colorScheme.onSurface | ||
| ) | ||
| WooPosText( | ||
| text = stringResource(R.string.woopos_settings_local_catalog_cellular_data_subtitle), | ||
| style = WooPosTypography.BodySmall, | ||
| color = MaterialTheme.colorScheme.onSurfaceVariant, | ||
| modifier = Modifier.padding(top = WooPosSpacing.XSmall.value) | ||
| ) | ||
| } | ||
|
|
||
| Switch( | ||
| checked = allowCellularDataUpdate, | ||
| onCheckedChange = { onToggleCellularData() }, | ||
| enabled = !isLoading, | ||
| colors = SwitchDefaults.colors( | ||
| checkedThumbColor = MaterialTheme.colorScheme.primary, | ||
| checkedTrackColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.5f) | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun RefreshSection( | ||
| onRefreshCatalog: () -> Unit, | ||
| isRefreshing: Boolean | ||
| ) { | ||
| Column( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .clip(RoundedCornerShape(WooPosCornerRadius.Large.value)) | ||
| .background(MaterialTheme.colorScheme.surfaceContainerHigh) | ||
| .padding(WooPosSpacing.Medium.value) | ||
| ) { | ||
| SectionTitle(stringResource(R.string.woopos_settings_local_catalog_actions)) | ||
|
|
||
| Spacer(modifier = Modifier.height(WooPosSpacing.Medium.value)) | ||
|
|
||
| WooPosText( | ||
| text = stringResource(R.string.woopos_settings_local_catalog_refresh_description), | ||
| style = WooPosTypography.BodySmall, | ||
| color = MaterialTheme.colorScheme.onSurfaceVariant, | ||
| modifier = Modifier.padding(bottom = WooPosSpacing.Medium.value) | ||
| ) | ||
|
|
||
| WooPosButton( | ||
| modifier = Modifier.fillMaxWidth(), | ||
| onClick = onRefreshCatalog, | ||
| state = if (isRefreshing) WooPosButtonState.LOADING else WooPosButtonState.ENABLED, | ||
| text = stringResource(R.string.woopos_settings_local_catalog_refresh_button) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun StatusRow( | ||
| label: String, | ||
| value: String?, | ||
| isLoading: Boolean | ||
| ) { | ||
| Row( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .padding(vertical = WooPosSpacing.Small.value), | ||
| horizontalArrangement = Arrangement.SpaceBetween, | ||
| verticalAlignment = Alignment.CenterVertically | ||
| ) { | ||
| WooPosText( | ||
| text = label, | ||
| style = WooPosTypography.BodyMedium, | ||
| color = MaterialTheme.colorScheme.onSurfaceVariant | ||
| ) | ||
|
|
||
| if (isLoading) { | ||
| WooPosShimmerBox( | ||
| modifier = Modifier | ||
| .width(100.dp) | ||
| .height(20.dp), | ||
| ) | ||
| } else { | ||
| WooPosText( | ||
| text = value ?: "-", | ||
| style = WooPosTypography.BodyMedium, | ||
| fontWeight = FontWeight.Medium, | ||
| color = MaterialTheme.colorScheme.onSurface | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun SectionTitle(title: String) { | ||
| WooPosText( | ||
| text = title, | ||
| style = WooPosTypography.BodyXLarge, | ||
| fontWeight = FontWeight.SemiBold, | ||
| color = MaterialTheme.colorScheme.onSurface | ||
| ) | ||
| } | ||
|
|
||
| @WooPosPreview | ||
| @Composable | ||
| fun WooPosSettingsLocalCatalogScreenPreview() { | ||
| WooPosTheme { | ||
| WooPosSettingsLocalCatalogScreen( | ||
| state = WooPosSettingsLocalCatalogState( | ||
| catalogStatus = CatalogStatus( | ||
| catalogSize = "12.5 MB", | ||
| lastUpdate = "2 hours ago", | ||
| lastFullUpdate = "Yesterday at 3:45 PM" | ||
| ), | ||
| allowCellularDataUpdate = true, | ||
| isLoading = false, | ||
| isRefreshing = false | ||
| ), | ||
| onToggleCellularData = {}, | ||
| onRefreshCatalog = {} | ||
| ) | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.