Skip to content

Commit

Permalink
Fix to updating viewModelControllers. Build and release v1.2.1 build 15
Browse files Browse the repository at this point in the history
  • Loading branch information
themisterholliday committed Nov 6, 2017
1 parent 1b11ff8 commit cd1c246
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ DEPENDENCIES:
- Disk (~> 0.3.1)
- Eureka (~> 4.0.1)
- Fabric (~> 1.7.2)
- IQKeyboardManagerSwift (~> 5.0.4)
- IQKeyboardManagerSwift (~> 5.0.5)
- KoalaTeaFlowLayout (~> 0.3.1)
- KoalaTeaPlayer (~> 0.1.7)
- KTResponsiveUI (~> 0.2.4)
Expand All @@ -68,7 +68,7 @@ DEPENDENCIES:
- SwifterSwift (~> 4.0.1)
- SwiftGen (~> 5.2.1)
- SwiftIcons (from `https://github.com/themisterholliday/SwiftIcons.git`, branch `swift-4`)
- SwiftSoup (~> 1.5.6)
- SwiftSoup (~> 1.5.8)
- SwiftyBeaver (~> 1.4.2)
- SwiftyJSON (~> 3.1.4)
- Tabman (~> 1.0.5)
Expand Down Expand Up @@ -116,6 +116,6 @@ SPEC CHECKSUMS:
Tabman: 9f87244fdbbd070fe6a518f445880b2b4a56ea1b
UIFontComplete: 7e3ce7f0a12d2529fb07f537e262aabfa87df280

PODFILE CHECKSUM: e649cc76c00874f9e66c64ebc934a8e08528822d
PODFILE CHECKSUM: eda67d2e802f0442870d2d12c35e79ee9fe94cc0

COCOAPODS: 1.3.1
6 changes: 6 additions & 0 deletions SEDaily-IOS/GeneralCollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,14 @@ class GeneralCollectionViewController: UICollectionViewController {
if let viewModel = podcastViewModelController.viewModel(at: indexPath.row) {
let vc = PodcastDetailViewController()
vc.model = viewModel
vc.delegate = self
self.navigationController?.pushViewController(vc, animated: true)
}
}
}

extension GeneralCollectionViewController: PodcastDetailViewControllerDelegate {
func modelDidChange(viewModel: PodcastViewModel) {
self.podcastViewModelController.update(with: viewModel)
}
}
10 changes: 10 additions & 0 deletions SEDaily-IOS/HeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
import UIKit
import SwiftIcons

protocol HeaderViewDelegate {
func modelDidChange(viewModel: PodcastViewModel)
}

class HeaderView: UIView {
var delegate: HeaderViewDelegate?

var model = PodcastViewModel()

let titleLabel = UILabel()
Expand Down Expand Up @@ -196,18 +202,22 @@ extension HeaderView {
self.setUpvoteTo(active)
guard active != false else {
self.setScoreTo(self.model.score - 1)
self.delegate?.modelDidChange(viewModel: self.model)
return
}
self.setScoreTo(self.model.score + 1)
self.delegate?.modelDidChange(viewModel: self.model)
}

func subtractScore(active: Bool) {
self.setDownvoteTo(active)
guard active != false else {
self.setScoreTo(self.model.score + 1)
self.delegate?.modelDidChange(viewModel: self.model)
return
}
self.setScoreTo(self.model.score - 1)
self.delegate?.modelDidChange(viewModel: self.model)
}

func setUpvoteTo(_ bool: Bool) {
Expand Down
2 changes: 1 addition & 1 deletion SEDaily-IOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.2.1</string>
<key>CFBundleVersion</key>
<string>13</string>
<string>15</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
Expand Down
12 changes: 12 additions & 0 deletions SEDaily-IOS/PodcastDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@

import UIKit

protocol PodcastDetailViewControllerDelegate {
func modelDidChange(viewModel: PodcastViewModel)
}

class PodcastDetailViewController: UIViewController {
var delegate: PodcastDetailViewControllerDelegate?

var model = PodcastViewModel()

Expand All @@ -23,6 +28,7 @@ class PodcastDetailViewController: UIViewController {

let headerView = HeaderView(width: 375, height: 200)
headerView.setupHeader(model: model)
headerView.delegate = self
self.scrollView.addSubview(headerView)

let view = PodcastDescriptionView(origin: headerView.bottomLeftPoint(),width: 375, height: 20)
Expand All @@ -37,3 +43,9 @@ class PodcastDetailViewController: UIViewController {
// Dispose of any resources that can be recreated.
}
}

extension PodcastDetailViewController: HeaderViewDelegate {
func modelDidChange(viewModel: PodcastViewModel) {
self.delegate?.modelDidChange(viewModel: viewModel)
}
}
9 changes: 9 additions & 0 deletions SEDaily-IOS/PodcastViewModelController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public class PodcastViewModelController {
self.viewModels.removeAll()
}

func update(with podcast: PodcastViewModel) {
let index = self.viewModels.index { (item) -> Bool in
return item?._id == podcast._id
}
guard let modelsIndex = index else { return }
self.viewModels.remove(at: modelsIndex)
self.viewModels.insert(podcast, at: modelsIndex)
}

func fetchData(type: String = "",
createdAtBefore beforeDate: String = "",
tags: [Int] = [],
Expand Down

0 comments on commit cd1c246

Please sign in to comment.