-
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 #13028 from woocommerce/issue/wire-package-network…
…ing-with-UI [Shipping Labels Revamp] Wire package networking with UI
- Loading branch information
Showing
17 changed files
with
449 additions
and
391 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
99 changes: 0 additions & 99 deletions
99
.../android/ui/orders/wooshippinglabels/packages/datasource/FetchCarrierPackagesFromStore.kt
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
...droid/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.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,70 @@ | ||
package com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource | ||
|
||
import com.woocommerce.android.tools.SelectedSite | ||
import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.Carrier | ||
import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageGroup | ||
import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.CarrierPackageSelection | ||
import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData | ||
import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.SavedPackageSelection | ||
import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.StorePredefinedPackages | ||
import javax.inject.Inject | ||
|
||
class FetchPredefinedPackagesFromStore @Inject constructor( | ||
private val selectedSite: SelectedSite, | ||
private val packageRepository: WooShippingLabelPackageRepository | ||
) { | ||
suspend operator fun invoke(): StorePredefinedPackages? { | ||
val storePackages = selectedSite.getOrNull() | ||
?.let { packageRepository.fetchAllStorePackages(it) } | ||
?.takeIf { it.isError.not() } | ||
?.model | ||
?: return null | ||
|
||
return StorePredefinedPackages( | ||
savedPackageSelection = storePackages | ||
.filterSavedData() | ||
.let { SavedPackageSelection(it) }, | ||
carrierPackageSelection = storePackages | ||
.filterCarrierData() | ||
.let { CarrierPackageSelection(it) } | ||
) | ||
} | ||
|
||
private fun StorePackagesDAO.filterSavedData() = | ||
savedPackages.map { packageDAO -> | ||
PackageData( | ||
name = packageDAO.name, | ||
dimensions = packageDAO.dimensions, | ||
isSelected = false, | ||
isLetter = packageDAO.isLetter | ||
) | ||
} | ||
|
||
private fun StorePackagesDAO.filterCarrierData() = mapOf( | ||
carrierPackages | ||
.parseCarrierData(CarrierType.USPS) | ||
.let { Carrier.USPS to it }, | ||
|
||
carrierPackages | ||
.parseCarrierData(CarrierType.DHL) | ||
.let { Carrier.DHL to it } | ||
) | ||
|
||
private fun Map<CarrierType, CarrierDAO>.parseCarrierData( | ||
carrierType: CarrierType | ||
) = get(carrierType)?.let { | ||
it.packageGroup.map { group -> | ||
CarrierPackageGroup( | ||
groupName = group.description, | ||
packages = group.packages.map { packageItem -> | ||
PackageData( | ||
name = packageItem.name, | ||
dimensions = packageItem.dimensions, | ||
isSelected = false, | ||
isLetter = packageItem.isLetter | ||
) | ||
} | ||
) | ||
} | ||
} ?: emptyList() | ||
} |
41 changes: 0 additions & 41 deletions
41
...ce/android/ui/orders/wooshippinglabels/packages/datasource/FetchSavedPackagesFromStore.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.