Skip to content
This repository has been archived by the owner on Jan 11, 2019. It is now read-only.

Commit

Permalink
adds store demo
Browse files Browse the repository at this point in the history
  • Loading branch information
icanzilb committed Jul 11, 2017
1 parent b5d43d1 commit 763267c
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 25 deletions.
40 changes: 34 additions & 6 deletions Example/RealmContent/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -322,26 +322,26 @@
<size key="itemSize" width="100" height="100"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="6" minY="6" maxX="0.0" maxY="0.0"/>
<inset key="sectionInset" minX="4" minY="20" maxX="4" maxY="4"/>
</collectionViewFlowLayout>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="ProductCell" id="yRW-xH-LAr" customClass="ProductCellView" customModule="RealmContent_Example" customModuleProvider="target">
<rect key="frame" x="6" y="6" width="100" height="100"/>
<rect key="frame" x="4" y="20" width="100" height="100"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="100" height="100"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="6Sv-La-HIH">
<view clipsSubviews="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="6Sv-La-HIH">
<rect key="frame" x="0.0" y="0.0" width="100" height="100"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="lpc-DY-M8a">
<view clipsSubviews="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="lpc-DY-M8a">
<rect key="frame" x="3" y="3" width="94" height="94"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Uc8-4I-h0K">
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Uc8-4I-h0K">
<rect key="frame" x="2" y="2" width="90" height="90"/>
</imageView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="KXN-sE-aFC">
<view clipsSubviews="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="KXN-sE-aFC">
<rect key="frame" x="3" y="67" width="88" height="24"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="h94-xe-dio">
Expand All @@ -357,6 +357,13 @@
<constraint firstAttribute="height" constant="24" id="Q0V-zc-x1f"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Price" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="5Q9-5Z-QU9">
<rect key="frame" x="5" y="4" width="78" height="13"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" name="HelveticaNeue-CondensedBlack" family="Helvetica Neue" pointSize="11"/>
<color key="textColor" red="1" green="0.29382037425283214" blue="0.22353632309155735" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
Expand Down Expand Up @@ -390,16 +397,33 @@
<connections>
<outlet property="image" destination="Uc8-4I-h0K" id="rCB-Pv-zZF"/>
<outlet property="label" destination="h94-xe-dio" id="gos-jW-JlR"/>
<outlet property="price" destination="5Q9-5Z-QU9" id="mOe-Fh-ONm"/>
</connections>
</collectionViewCell>
</cells>
<connections>
<outlet property="dataSource" destination="uEg-e8-a6d" id="6lk-us-1CT"/>
<outlet property="delegate" destination="uEg-e8-a6d" id="M7a-2x-64R"/>
</connections>
</collectionView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="PRODUCT CATALOGUE" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="WWO-Ev-PfE">
<rect key="frame" x="14" y="307.5" width="361" height="27"/>
<constraints>
<constraint firstAttribute="height" constant="27" id="3Tx-6F-1q5"/>
</constraints>
<fontDescription key="fontDescription" name="HelveticaNeue" family="Helvetica Neue" pointSize="13"/>
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="9da-T9-C8a" firstAttribute="top" secondItem="VrQ-x2-bfn" secondAttribute="bottom" id="IiV-6j-nwn"/>
<constraint firstItem="VrQ-x2-bfn" firstAttribute="top" secondItem="ER8-Bs-lB7" secondAttribute="bottom" id="Ilk-KM-4dd"/>
<constraint firstAttribute="trailing" secondItem="WWO-Ev-PfE" secondAttribute="trailing" id="LIm-SM-hhE"/>
<constraint firstItem="WWO-Ev-PfE" firstAttribute="top" secondItem="ER8-Bs-lB7" secondAttribute="bottom" constant="-26" id="TcS-mv-QEY"/>
<constraint firstAttribute="trailing" secondItem="ER8-Bs-lB7" secondAttribute="trailing" id="XQw-7E-ihG"/>
<constraint firstItem="WWO-Ev-PfE" firstAttribute="leading" secondItem="hok-AL-22p" secondAttribute="leading" constant="14" id="bAf-Va-quU"/>
<constraint firstItem="VrQ-x2-bfn" firstAttribute="leading" secondItem="hok-AL-22p" secondAttribute="leading" id="cdt-m2-7Ms"/>
<constraint firstAttribute="trailing" secondItem="VrQ-x2-bfn" secondAttribute="trailing" id="kFE-DA-k40"/>
<constraint firstItem="ER8-Bs-lB7" firstAttribute="top" secondItem="hok-AL-22p" secondAttribute="top" id="pm8-NQ-Gx4"/>
Expand All @@ -408,6 +432,10 @@
</constraints>
</view>
<navigationItem key="navigationItem" title="Store App" id="9Le-xP-9Mp"/>
<connections>
<outlet property="collectionView" destination="VrQ-x2-bfn" id="1ld-k1-1jj"/>
<outlet property="tableView" destination="ER8-Bs-lB7" id="rhr-3E-UBt"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="7i1-Fy-xRd" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
Expand Down
59 changes: 49 additions & 10 deletions Example/RealmContent/DemoData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,75 @@ struct DemoData {
realm.deleteAll()

// store offers
let offer1 = ContentPage(value: ["title": "This weekend everything is 20% off", "tag": "offer", "mainColor": "f25192"])
let offer1 = ContentPage(value: ["title": "This weekend everything is 20% off", "tag": "offer", "priority": 10, "mainColor": "#D34CA3"])
let elements1: [ContentElement] = [
ContentElement(value: ["type": "h1", "content": "Big weekend sale!"]),
ContentElement(value: ["type": "h2", "content": "This weekend everything is 20% off"]),
ContentElement(value: ["type": "p", "content": "Use promo code 'bigsummersale20' to get your discount at checkout"]),
ContentElement(value: ["type": "img", "content": "http://realm.io/assets/img/news/2016-05-17-realm-rxswift/rx.png", "url": "https://news.realm.io/news/marin-todorov-realm-rxswift/"])
ContentElement(value: ["type": "img", "content": "https://raw.githubusercontent.com/realm-demos/RealmContent/master/assets/pexels-photo-248797.jpg", "url": "https://news.realm.io/news/marin-todorov-realm-rxswift/"]),
ContentElement(value: ["type": "p", "content": "Use promo code 'bigsummersale20' to get your discount at checkout"])
]
offer1.elements.append(objectsIn: elements1)

let offer2 = ContentPage(value: ["title": "Buy 4 garden gnomes, pay 5!", "tag": "offer", "mainColor": "f25192"])
let offer2 = ContentPage(value: ["title": "Buy 4 garden gnomes, pay 5!", "tag": "offer", "priority": 8, "mainColor": "#9A50A5"])
let elements2: [ContentElement] = [
ContentElement(value: ["type": "h1", "content": "Big spring sale!"]),
ContentElement(value: ["type": "h2", "content": "Buy 4 garden gnomes, pay 5!"]),
ContentElement(value: ["type": "p", "content": "Use promo code '4for5supergnome' to get your discount at checkout"]),
ContentElement(value: ["type": "img", "content": "http://realm.io/assets/img/news/2016-05-17-realm-rxswift/rx.png", "url": "https://news.realm.io/news/marin-todorov-realm-rxswift/"])
ContentElement(value: ["type": "img", "content": "https://raw.githubusercontent.com/realm-demos/RealmContent/master/assets/pexels-photo-296230.jpg", "url": "https://news.realm.io/news/marin-todorov-realm-rxswift/"]),
ContentElement(value: ["type": "p", "content": "Use promo code '4for5supergnome' to get your discount at checkout"])
]
offer2.elements.append(objectsIn: elements2)

let offer3 = ContentPage(value: ["title": "Get our fidelity card for a chance to win!", "tag": "offer", "mainColor": "f25192"])
let offer3 = ContentPage(value: ["title": "Get our fidelity card for a chance to win!", "tag": "offer", "priority": 6, "mainColor": "#59569E"])
let elements3: [ContentElement] = [
ContentElement(value: ["type": "h1", "content": "Get the card, win the prizes! Do it now!"]),
ContentElement(value: ["type": "p", "content": "Not only you will get permanent discount of 5% on all products, but you can also win big time!"]),
ContentElement(value: ["type": "img", "content": "http://realm.io/assets/img/news/2016-05-17-realm-rxswift/rx.png", "url": "https://news.realm.io/news/marin-todorov-realm-rxswift/"])
ContentElement(value: ["type": "h3", "content": "Not only you will get permanent discount of 5% on all products, but you can also win big time!"]),
ContentElement(value: ["type": "img", "content": "https://raw.githubusercontent.com/realm-demos/RealmContent/master/assets/pexels-photo.jpg", "url": "https://news.realm.io/news/marin-todorov-realm-rxswift/"])
]
offer3.elements.append(objectsIn: elements3)


realm.add([offer1, offer2, offer3])

let product1 = ContentPage(value: ["title": "Fujifilm Camera", "tag": "product"])
let productEls1: [ContentElement] = [
ContentElement(value: ["type": "img", "content": "https://raw.githubusercontent.com/realm-demos/RealmContent/master/assets/pexels-photo-90946.jpeg"]),
ContentElement(value: ["type": "price", "content": "USD 559.95"]),
ContentElement(value: ["type": "h2", "content": "Fujifilm Camera"]),
ContentElement(value: ["type": "p", "content": "Use promo code '1checkout' for your first purchase"]),
ContentElement(value: ["type": "h3", "content": "Add to Cart", "url": "app://addtocart/1435/"+"Fujifilm Camera".addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!])
]
product1.elements.append(objectsIn: productEls1)

let product2 = ContentPage(value: ["title": "Nikon Lens", "tag": "product"])
let productEls2: [ContentElement] = [
ContentElement(value: ["type": "img", "content": "https://raw.githubusercontent.com/realm-demos/RealmContent/master/assets/pexels-photo-279906.jpeg"]),
ContentElement(value: ["type": "price", "content": "USD 205.45"]),
ContentElement(value: ["type": "h2", "content": "Nikon Lens"]),
ContentElement(value: ["type": "p", "content": "Use promo code '1checkout' for your first purchase"]),
ContentElement(value: ["type": "h3", "content": "Add to Cart", "url": "app://addtocart/"+"Nikon Lens".addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!])
]
product2.elements.append(objectsIn: productEls2)

let product3 = ContentPage(value: ["title": "Nikon Zoom Lens", "tag": "product"])
let productEls3: [ContentElement] = [
ContentElement(value: ["type": "img", "content": "https://raw.githubusercontent.com/realm-demos/RealmContent/master/assets/light-night-lens-shadow.jpg"]),
ContentElement(value: ["type": "price", "content": "USD 428.95"]),
ContentElement(value: ["type": "h2", "content": "Nikon Zoom Lens"]),
ContentElement(value: ["type": "p", "content": "Use promo code '1checkout' for your first purchase"]),
ContentElement(value: ["type": "h3", "content": "Add to Cart", "url": "app://addtocart/"+"Nikon Zoom Lens".addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!])
]
product3.elements.append(objectsIn: productEls3)

let product4 = ContentPage(value: ["title": "Retro Smena Camera", "tag": "product"])
let productEls4: [ContentElement] = [
ContentElement(value: ["type": "img", "content": "https://raw.githubusercontent.com/realm-demos/RealmContent/master/assets/pexels-photo-50924.jpeg"]),
ContentElement(value: ["type": "price", "content": "USD 95.59"]),
ContentElement(value: ["type": "h2", "content": "Retro Smena Camera"]),
ContentElement(value: ["type": "p", "content": "Use promo code '1checkout' for your first purchase"]),
ContentElement(value: ["type": "h3", "content": "Add to Cart", "url": "app://addtocart/"+"Retro Smena Camera".addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!])
]
product4.elements.append(objectsIn: productEls4)

realm.add([product2, product3, product4, product1])
}
}

Expand Down
19 changes: 14 additions & 5 deletions Example/RealmContent/ProductCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,28 @@ class ProductCellView: UICollectionViewCell {

@IBOutlet var image: UIImageView!
@IBOutlet var label: UILabel!
@IBOutlet var price: UILabel!

func populate(with page: ContentPage) {
label.text = page.title

// expects the top element in the page to be an image,
// grabs it, and shows it in the cell

if let imageElement = page.elements.first,
imageElement.type == ContentElement.Kind.img.rawValue,
let urlString = imageElement.url,
let url = URL(string: urlString) {
imageElement.type == ContentElement.Kind.img.rawValue {

image.kf.setImage(with: URL(string: imageElement.content))

}

image.kf.setImage(with: url)
// checks if second element is a price (custom type)
if page.elements.count > 1,
page.elements[1].type == "price" {
price.text = page.elements[1].content
} else {
price.text = nil
}

}
}
Loading

0 comments on commit 763267c

Please sign in to comment.