Skip to content

Commit

Permalink
Connect catalog module to watch target
Browse files Browse the repository at this point in the history
Add example UI
  • Loading branch information
Юрий Лебедев committed Jan 23, 2018
1 parent d74c6da commit 0cc4b0a
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 12 deletions.
Expand Up @@ -10,17 +10,32 @@ class CatalogInterfaceController: WKInterfaceController {
let interactor: CatalogBusinessLogic
var state: Catalog.ViewControllerState

init(interactor: CatalogBusinessLogic, initialState: Catalog.ViewControllerState = .loading) {
@IBOutlet var statusLabel: WKInterfaceLabel!
@IBOutlet var catalogTable: WKInterfaceTable!

override init() {
let presenter = CatalogPresenter()
let interactor = CatalogInteractor(presenter: presenter)
self.interactor = interactor
self.state = initialState
self.state = .loading
super.init()
presenter.viewController = self
}

override func awake(withContext context: Any?) {
super.awake(withContext: context)
display(newState: state)
}

func setupTable(_ items: [CatalogViewModel]) {
catalogTable.setNumberOfRows(items.count, withRowType: "CatalogCell")
items.enumerated().forEach { (index, item) in
if let row = catalogTable.rowController(at: index) as? CatalogCell {
row.titleLabel.setText(item.title)
}
}
}

// MARK: Fetching
func fetchItems() {
let request = Catalog.ShowItems.Request()
Expand All @@ -37,13 +52,16 @@ extension CatalogInterfaceController: CatalogDisplayLogic {
state = newState
switch state {
case .loading:
statusLabel.setText("Loading...")
fetchItems()
case let .error(message):
print("error \(message)")
statusLabel.setText("Error: \(message)")
case let .result(items):
print("result: \(items)")
statusLabel.setHidden(true)
catalogTable.setHidden(false)
setupTable(items)
case .emptyResult:
print("empty result")
statusLabel.setText("Empty")
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions WATCH Extension/New Group/Catalog/View/CatalogCell.swift
@@ -0,0 +1,6 @@
import WatchKit

class CatalogCell: NSObject {
@IBOutlet var titleLabel: WKInterfaceLabel!
}

38 changes: 32 additions & 6 deletions WATCH/Base.lproj/Interface.storyboard
@@ -1,14 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="AgC-eL-Hgc">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="13771" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="AgC-eL-Hgc">
<device id="watch38" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="11055"/>
<deployment identifier="watchOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="13756"/>
</dependencies>
<scenes>
<!--Interface Controller-->
<!--Catalog Interface Controller-->
<scene sceneID="aou-V4-d1y">
<objects>
<controller id="AgC-eL-Hgc" customClass="InterfaceController" customModuleProvider="target"/>
<controller id="AgC-eL-Hgc" customClass="CatalogInterfaceController" customModule="WATCH_Extension">
<items>
<label width="1" height="1" alignment="left" text="Status" textAlignment="center" id="ZUe-Fb-hv4"/>
<table alignment="left" hidden="YES" id="J89-HB-iLA">
<items>
<tableRow identifier="CatalogCell" id="Yz1-Sf-Kso" customClass="CatalogCell" customModule="WATCH_Extension">
<group key="rootItem" width="1" alignment="left" id="ds3-wn-wtB">
<items>
<label width="1" height="1" alignment="left" text="Label" id="yix-8x-tNq"/>
</items>
</group>
<connections>
<outlet property="titleLabel" destination="yix-8x-tNq" id="xuf-wi-Xug"/>
</connections>
</tableRow>
</items>
</table>
</items>
<connections>
<outlet property="catalogTable" destination="J89-HB-iLA" id="gqi-eX-pVu"/>
<outlet property="statusLabel" destination="ZUe-Fb-hv4" id="SVo-S9-KaK"/>
</connections>
</controller>
</objects>
</scene>
</scenes>
Expand Down
31 changes: 30 additions & 1 deletion YARCH.xcodeproj/project.pbxproj
Expand Up @@ -64,6 +64,7 @@
BAA9B4E2201733C4001235D6 /* UniqueIdentifiable.swift in Sources */ = {isa = PBXBuildFile; fileRef = B33011881FC3017000488D77 /* UniqueIdentifiable.swift */; };
BAA9B4E3201733CB001235D6 /* APIClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45420A211FDC841700613DB5 /* APIClient.swift */; };
BAA9B4E4201733D3001235D6 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70AF80A01FE8E17700BDFEF6 /* Result.swift */; };
BAA9B4EA20173905001235D6 /* CatalogCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAA9B4E920173905001235D6 /* CatalogCell.swift */; };
CB797E62A19181E405CB5295 /* CatalogModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC0656544F203B79E54A10CD /* CatalogModelTests.swift */; };
CD5FD9D2A810A3927D12248B /* CatalogInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 125082CCBAEF6CF386656798 /* CatalogInteractor.swift */; };
D4231FCF5A2D96579179A5E7 /* Pods_YARCHTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 591D8014D21B11140D2C8C17 /* Pods_YARCHTests.framework */; };
Expand Down Expand Up @@ -177,6 +178,7 @@
BAA9B4C92017336B001235D6 /* ExtensionDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtensionDelegate.swift; sourceTree = "<group>"; };
BAA9B4CB2017336B001235D6 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
BAA9B4CD2017336B001235D6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
BAA9B4E920173905001235D6 /* CatalogCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CatalogCell.swift; sourceTree = "<group>"; };
C5348E8FD18C8061BA81CAB8 /* CatalogView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = CatalogView.swift; sourceTree = "<group>"; };
CC0656544F203B79E54A10CD /* CatalogModelTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = CatalogModelTests.swift; sourceTree = "<group>"; };
CC488560F7C4E708D4F9CDE6 /* CatalogInteractorTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = CatalogInteractorTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -382,14 +384,40 @@
BAA9B4C62017336B001235D6 /* WATCH Extension */ = {
isa = PBXGroup;
children = (
BAA9B4C72017336B001235D6 /* CatalogInterfaceController.swift */,
BAA9B4C92017336B001235D6 /* ExtensionDelegate.swift */,
BAA9B4E52017346E001235D6 /* Modules */,
BAA9B4CB2017336B001235D6 /* Assets.xcassets */,
BAA9B4CD2017336B001235D6 /* Info.plist */,
);
path = "WATCH Extension";
sourceTree = "<group>";
};
BAA9B4E52017346E001235D6 /* Modules */ = {
isa = PBXGroup;
children = (
BAA9B4E620173482001235D6 /* Catalog */,
);
name = Modules;
path = "New Group";
sourceTree = "<group>";
};
BAA9B4E620173482001235D6 /* Catalog */ = {
isa = PBXGroup;
children = (
BAA9B4C72017336B001235D6 /* CatalogInterfaceController.swift */,
BAA9B4E72017348F001235D6 /* View */,
);
path = Catalog;
sourceTree = "<group>";
};
BAA9B4E72017348F001235D6 /* View */ = {
isa = PBXGroup;
children = (
BAA9B4E920173905001235D6 /* CatalogCell.swift */,
);
path = View;
sourceTree = "<group>";
};
C1C367C98DE1247730984730 /* Pods */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -787,6 +815,7 @@
BAA9B4CA2017336B001235D6 /* ExtensionDelegate.swift in Sources */,
BAA9B4E4201733D3001235D6 /* Result.swift in Sources */,
BAA9B4C82017336B001235D6 /* CatalogInterfaceController.swift in Sources */,
BAA9B4EA20173905001235D6 /* CatalogCell.swift in Sources */,
BAA9B4DC201733AA001235D6 /* CatalogModel.swift in Sources */,
BAA9B4D9201733A7001235D6 /* CatalogInteractor.swift in Sources */,
BAA9B4DF201733AE001235D6 /* CatalogProvider.swift in Sources */,
Expand Down

0 comments on commit 0cc4b0a

Please sign in to comment.