-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13188 from woocommerce/issue/13163-logic-to-save-…
…hidden-sites Issue/13163 logic to save hidden sites
- Loading branch information
Showing
14 changed files
with
219 additions
and
44 deletions.
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
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
19 changes: 19 additions & 0 deletions
19
...rc/main/kotlin/com/woocommerce/android/ui/sitepicker/sitevisibility/GetWooVisibleSites.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,19 @@ | ||
package com.woocommerce.android.ui.sitepicker.sitevisibility | ||
|
||
import com.woocommerce.android.ui.sitepicker.SitePickerRepository | ||
import kotlinx.coroutines.flow.first | ||
import org.wordpress.android.fluxc.model.SiteModel | ||
import javax.inject.Inject | ||
|
||
class GetWooVisibleSites @Inject constructor( | ||
private val sitePickerRepository: SitePickerRepository, | ||
private val visibleSitesDataStore: VisibleWooSitesDataStore | ||
) { | ||
suspend operator fun invoke(): List<SiteModel> = | ||
sitePickerRepository.getSites() | ||
.filter { it.hasWooCommerce && isSiteVisible(it.siteId) } | ||
|
||
private suspend fun isSiteVisible(siteId: Long): Boolean { | ||
return visibleSitesDataStore.isSiteVisible(siteId).first() | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...n/kotlin/com/woocommerce/android/ui/sitepicker/sitevisibility/VisibleWooSitesDataStore.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,35 @@ | ||
package com.woocommerce.android.ui.sitepicker.sitevisibility | ||
|
||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.booleanPreferencesKey | ||
import androidx.datastore.preferences.core.edit | ||
import com.woocommerce.android.datastore.DataStoreQualifier | ||
import com.woocommerce.android.datastore.DataStoreType | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
import javax.inject.Inject | ||
|
||
class VisibleWooSitesDataStore @Inject constructor( | ||
@DataStoreQualifier(DataStoreType.SITE_PICKER_WOO_VISIBLE_SITES) private val dataStore: DataStore<Preferences> | ||
) { | ||
suspend fun updateSiteVisibilityStatus(siteIds: Map<Long, Boolean>) { | ||
siteIds.forEach { (siteId, isVisible) -> | ||
updateSiteVisibility(siteId, isVisible) | ||
} | ||
} | ||
|
||
fun isSiteVisible(siteId: Long): Flow<Boolean> { | ||
return dataStore.data.map { prefs -> prefs[booleanPreferencesKey(siteId.toString())] != false } | ||
} | ||
|
||
suspend fun clearAll() { | ||
dataStore.edit { it.clear() } | ||
} | ||
|
||
private suspend fun updateSiteVisibility(siteId: Long, isVisible: Boolean) { | ||
dataStore.edit { preferences -> | ||
preferences[booleanPreferencesKey(siteId.toString())] = isVisible | ||
} | ||
} | ||
} |
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
Oops, something went wrong.