Skip to content

Instantly share code, notes, and snippets.

@Ajimi
Last active December 1, 2018 19:40
Show Gist options
  • Save Ajimi/ad3624e3392db8ffbedfbba3d60ddfcb to your computer and use it in GitHub Desktop.
Save Ajimi/ad3624e3392db8ffbedfbba3d60ddfcb to your computer and use it in GitHub Desktop.
class PavilionCollectionViewCell: UICollectionViewCell , Configurable {
@IBOutlet weak var image : UIImageView!
@IBOutlet weak var label : UILabel!
func configure(with pavilion: Pavilion) {
self.label.text = pavilion.name
// TODO ADD IMAGE
}
}
viewModel.updateUI()
// Pavilion
viewModel.uiPavilionState.bindAndFire(listener: { (uiModel) in
if (uiModel.showProgress) {
print("In progress")
}
if let showError = uiModel.showError, !showError.consumed, let errorMessage = showError.consume() {
print("there Was an error \(errorMessage)")
}
if let showSucces = uiModel.showSuccess, !showSucces.consumed, let productsResponse = showSucces.consume() {
print(productsResponse)
}
})
/// PavilionUI
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return viewmodel.pavilions.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = categoryCollectionView.dequeueReusableCell(withReuseIdentifier: categoryReuseIdentifier, for: indexPath) as! CategoryCollectionViewCell
cell.configure(with: pavilions[indexPath.row])
return cell
}
/////
class TrendingProductCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var image: UIImageView!
// TODO ADD @IBOUTLET
func configure(with product: Product){
// TODO ADD IMAGE
}
}
/////
class DiscountedProductCollectionViewCell: UICollectionViewCell , Configurable{
@IBOutlet weak var image: UIImageView!
func configure(with product: Product){
// TODO ADD IMAGE
}
}
// ///
class PavilionHomeCollectionViewCell: UICollectionViewCell, Configurable {
@IBOutlet weak var image: UIImageView!
@IBOutlet weak var name: UILabel!
func configure(with pavilion: Pavilion){
self.name = pavilion.name
// TODO ALAMOFIRE IMAGE
}
}
// ViewController
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if (collectionView == self.pavilionsCollectionView){
return viewmodel.trendingProducts.count
}
else if (collectionView == self.trendingProductCollectionView){
return viewmodel.trendingProducts.count
}
else{
return viewmodel.discountedProducts.count
}
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if (collectionView == self.pavilionsCollectionView){
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: pavilionsHomeReuseIdentifier, for: indexPath) as! PavilionHomeCollectionViewCell
cell.configure(with: viewmodel.trendingProducts[indexPath.row])
return cell;
}
else if (collectionView == self.trendingProductCollectionView){
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: productHomeTrendingReuseIdentifier, for: indexPath) as! TrendingProductCollectionViewCell
cell.configure(with: viewmodel.trendingProducts[indexPath.row])
return cell;
}
else{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: productHomeDiscountedReuseIdentifier, for: indexPath) as! DiscountedProductCollectionViewCell
cell.configure(with: viewmodel.discountedProducts[indexPath.row])
return cell;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment