-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
389 additions
and
9 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// ReleaseCell.swift | ||
// SwiftHub | ||
// | ||
// Created by Sygnoos9 on 4/12/19. | ||
// Copyright © 2019 Khoren Markosyan. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class ReleaseCell: DetailedTableViewCell { | ||
|
||
override func makeUI() { | ||
super.makeUI() | ||
leftImageView.cornerRadius = 25 | ||
secondDetailLabel.numberOfLines = 0 | ||
} | ||
|
||
func bind(to viewModel: ReleaseCellViewModel) { | ||
viewModel.title.drive(titleLabel.rx.text).disposed(by: rx.disposeBag) | ||
viewModel.detail.drive(detailLabel.rx.text).disposed(by: rx.disposeBag) | ||
viewModel.secondDetail.drive(secondDetailLabel.rx.text).disposed(by: rx.disposeBag) | ||
viewModel.imageUrl.drive(leftImageView.rx.imageURL).disposed(by: rx.disposeBag) | ||
viewModel.imageUrl.drive(onNext: { [weak self] (url) in | ||
if let url = url { | ||
self?.leftImageView.hero.id = url.absoluteString | ||
} | ||
}).disposed(by: rx.disposeBag) | ||
viewModel.badge.drive(badgeImageView.rx.image).disposed(by: rx.disposeBag) | ||
viewModel.badgeColor.drive(badgeImageView.rx.tintColor).disposed(by: rx.disposeBag) | ||
|
||
leftImageView.rx.tap().map { _ in viewModel.release.author }.filterNil() | ||
.bind(to: viewModel.userSelected).disposed(by: cellDisposeBag) | ||
} | ||
} |
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,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> | ||
<device id="retina6_1" orientation="portrait"> | ||
<adaptation id="fullscreen"/> | ||
</device> | ||
<dependencies> | ||
<deployment identifier="iOS"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/> | ||
<capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<objects> | ||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | ||
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="ReleaseCell" id="KGk-i7-Jjw" customClass="ReleaseCell" customModule="SwiftHub" customModuleProvider="target"> | ||
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/> | ||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> | ||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM"> | ||
<rect key="frame" x="0.0" y="0.0" width="320" height="43.5"/> | ||
<autoresizingMask key="autoresizingMask"/> | ||
</tableViewCellContentView> | ||
<viewLayoutGuide key="safeArea" id="njF-e1-oar"/> | ||
</tableViewCell> | ||
</objects> | ||
</document> |
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,34 @@ | ||
// | ||
// ReleaseCellViewModel.swift | ||
// SwiftHub | ||
// | ||
// Created by Sygnoos9 on 4/12/19. | ||
// Copyright © 2019 Khoren Markosyan. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import RxSwift | ||
import RxCocoa | ||
|
||
class ReleaseCellViewModel { | ||
let title: Driver<String> | ||
let detail: Driver<String> | ||
let secondDetail: Driver<String> | ||
let imageUrl: Driver<URL?> | ||
let badge: Driver<UIImage?> | ||
let badgeColor: Driver<UIColor> | ||
|
||
let release: Release | ||
|
||
let userSelected = PublishSubject<User>() | ||
|
||
init(with release: Release) { | ||
self.release = release | ||
title = Driver.just("\(release.tagName ?? "") - \(release.name ?? "")") | ||
detail = Driver.just("\(release.publishedAt?.toRelative() ?? "")") | ||
secondDetail = Driver.just("\(release.body ?? "")") | ||
imageUrl = Driver.just(release.author?.avatarUrl?.url) | ||
badge = Driver.just(R.image.icon_cell_badge_tag()?.template) | ||
badgeColor = Driver.just(UIColor.flatGreenDark) | ||
} | ||
} |
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,66 @@ | ||
// | ||
// ReleasesViewController.swift | ||
// SwiftHub | ||
// | ||
// Created by Sygnoos9 on 4/12/19. | ||
// Copyright © 2019 Khoren Markosyan. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import RxSwift | ||
import RxCocoa | ||
import RxDataSources | ||
|
||
private let reuseIdentifier = R.reuseIdentifier.releaseCell.identifier | ||
|
||
class ReleasesViewController: TableViewController { | ||
|
||
var viewModel: ReleasesViewModel! | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
// Do any additional setup after loading the view. | ||
} | ||
|
||
override func makeUI() { | ||
super.makeUI() | ||
|
||
tableView.register(R.nib.releaseCell) | ||
} | ||
|
||
override func bindViewModel() { | ||
super.bindViewModel() | ||
|
||
let refresh = Observable.of(Observable.just(()), headerRefreshTrigger).merge() | ||
let input = ReleasesViewModel.Input(headerRefresh: refresh, | ||
footerRefresh: footerRefreshTrigger, | ||
selection: tableView.rx.modelSelected(ReleaseCellViewModel.self).asDriver()) | ||
let output = viewModel.transform(input: input) | ||
|
||
viewModel.loading.asObservable().bind(to: isLoading).disposed(by: rx.disposeBag) | ||
viewModel.headerLoading.asObservable().bind(to: isHeaderLoading).disposed(by: rx.disposeBag) | ||
viewModel.footerLoading.asObservable().bind(to: isFooterLoading).disposed(by: rx.disposeBag) | ||
|
||
output.navigationTitle.drive(onNext: { [weak self] (title) in | ||
self?.navigationTitle = title | ||
}).disposed(by: rx.disposeBag) | ||
|
||
output.items.asDriver(onErrorJustReturn: []) | ||
.drive(tableView.rx.items(cellIdentifier: reuseIdentifier, cellType: ReleaseCell.self)) { tableView, viewModel, cell in | ||
cell.bind(to: viewModel) | ||
}.disposed(by: rx.disposeBag) | ||
|
||
output.releaseSelected.drive(onNext: { [weak self] (url) in | ||
self?.navigator.show(segue: .webController(url), sender: self) | ||
}).disposed(by: rx.disposeBag) | ||
|
||
output.userSelected.drive(onNext: { [weak self] (viewModel) in | ||
self?.navigator.show(segue: .userDetails(viewModel: viewModel), sender: self) | ||
}).disposed(by: rx.disposeBag) | ||
|
||
viewModel.error.asDriver().drive(onNext: { [weak self] (error) in | ||
self?.showAlert(title: R.string.localizable.commonError.key.localized(), message: error.localizedDescription) | ||
}).disposed(by: rx.disposeBag) | ||
} | ||
} |
Oops, something went wrong.