-
Notifications
You must be signed in to change notification settings - Fork 136
[WOOMOB-1446] Implement cellular data preference for WooPos local catalog sync #14725
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
Changes from 4 commits
2a3f049
2b9c5b4
4baf2db
75835c5
ffe5515
12bed58
9628fb1
0a68755
8ab0277
e54cf5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,15 @@ import androidx.lifecycle.viewModelScope | |
| import com.woocommerce.android.tools.SelectedSite | ||
| import com.woocommerce.android.ui.woopos.localcatalog.PosLocalCatalogSyncResult | ||
| import com.woocommerce.android.ui.woopos.localcatalog.WooPosLocalCatalogSyncRepository | ||
| import com.woocommerce.android.ui.woopos.localcatalog.WooPosLocalCatalogSyncScheduler | ||
| import com.woocommerce.android.ui.woopos.util.datastore.WooPosPreferencesRepository | ||
| import com.woocommerce.android.ui.woopos.util.datastore.WooPosSyncTimestampManager | ||
| import com.woocommerce.android.ui.woopos.util.format.WooPosDateFormatter | ||
| import dagger.hilt.android.lifecycle.HiltViewModel | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.StateFlow | ||
| import kotlinx.coroutines.flow.asStateFlow | ||
| import kotlinx.coroutines.flow.first | ||
| import kotlinx.coroutines.flow.update | ||
| import kotlinx.coroutines.launch | ||
| import javax.inject.Inject | ||
|
|
@@ -21,6 +24,8 @@ class WooPosSettingsLocalCatalogViewModel @Inject constructor( | |
| private val localCatalogSyncRepository: WooPosLocalCatalogSyncRepository, | ||
| private val selectedSite: SelectedSite, | ||
| private val dateFormatter: WooPosDateFormatter, | ||
| private val preferencesRepository: WooPosPreferencesRepository, | ||
| private val syncScheduler: WooPosLocalCatalogSyncScheduler, | ||
| ) : ViewModel() { | ||
| private val _state = MutableStateFlow(WooPosSettingsLocalCatalogState()) | ||
| val state: StateFlow<WooPosSettingsLocalCatalogState> = _state.asStateFlow() | ||
|
|
@@ -47,18 +52,25 @@ class WooPosSettingsLocalCatalogViewModel @Inject constructor( | |
| lastFullUpdate = formattedTimestamp // TBD local catalog: Replace with full sync timestamp | ||
| ) | ||
|
|
||
| val allowCellularDataUpdate = preferencesRepository.allowCellularDataUpdate.first() | ||
|
||
|
|
||
| _state.update { | ||
| it.copy(catalogStatus = catalogStatus) | ||
| it.copy( | ||
| catalogStatus = catalogStatus, | ||
| allowCellularDataUpdate = allowCellularDataUpdate | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun toggleCellularDataUpdate() { | ||
| viewModelScope.launch { | ||
| val newValue = !_state.value.allowCellularDataUpdate | ||
| _state.update { | ||
| it.copy(allowCellularDataUpdate = !it.allowCellularDataUpdate) | ||
| it.copy(allowCellularDataUpdate = newValue) | ||
| } | ||
| // TBD local catalog: Save preference to shared preferences or data store | ||
| preferencesRepository.setAllowCellularDataUpdate(newValue) | ||
| syncScheduler.updateWorkConstraints() | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.