|
33
|
+// }, onError: <#T##((Error) -> Void)?##((Error) -> Void)?##(Error) -> Void#>, onCompleted: <#T##(() -> Void)?##(() -> Void)?##() -> Void#>, onDisposed: <#T##(() -> Void)?##(() -> Void)?##() -> Void#>)
|
|
|
34
|
+// .subscribe(onCompleted: {
|
|
|
35
|
+//
|
|
|
36
|
+// var val = self.item.value
|
|
|
37
|
+// val.comment_num = self.commentItems.value.count
|
|
|
38
|
+// val.thumbup_num = self.thumbupItems.value.count
|
|
|
39
|
+// self.item.accept(val)
|
|
|
40
|
+//
|
|
|
41
|
+// let userInfo = [PhotoItemsOperator.key: PhotoItemsOperator.update(val.photo_id, val)]
|
|
|
42
|
+// NotificationCenter.default.post(name: .PhotoItemsChanged,
|
|
|
43
|
+// object: nil,
|
|
|
44
|
+// userInfo: userInfo)
|
|
|
45
|
+// }).disposed(by: self.disposeBag)
|
|
41
|
46
|
}).disposed(by: disposeBag)
|
|
42
|
47
|
}
|
|
43
|
|
-
|
|
44
|
|
- private func loadThumbupUserItems() -> Completable {
|
|
45
|
|
- return repository.loadThumbups().do(onSuccess: { (items) in
|
|
46
|
|
- self.thumbupItems.accept(items)
|
|
47
|
|
- }).asCompletable()
|
|
|
48
|
+
|
|
|
49
|
+ private func loadThumbupAndComment() {
|
|
|
50
|
+ print(#function)
|
|
|
51
|
+ Single.zip(repository.loadComments(), repository.loadThumbups()).subscribe(onSuccess: {[unowned self] (commentItems, thumbupItems) in
|
|
|
52
|
+ self.commentItems.accept(commentItems)
|
|
|
53
|
+ self.thumbupItems.accept(thumbupItems)
|
|
|
54
|
+ self.update()
|
|
|
55
|
+ }).disposed(by: disposeBag)
|
|
|
56
|
+ }
|
|
|
57
|
+
|
|
|
58
|
+ private func loadThumbupUserItems() -> Single<[PhotoThumbupUserItem]> {
|
|
|
59
|
+ return repository.loadThumbups()
|
|
48
|
60
|
}
|
|
49
|
61
|
|
|
50
|
|
- private func loadCommentItems() -> Completable {
|
|
51
|
|
- return repository.loadComments().do(onSuccess: { (items) in
|
|
52
|
|
- self.commentItems.accept(items)
|
|
53
|
|
- }).asCompletable()
|
|
|
62
|
+ private func loadCommentItems() -> Single<[PhotoCommentItem]> {
|
|
|
63
|
+ return repository.loadComments()
|
|
|
64
|
+ }
|
|
|
65
|
+
|
|
|
66
|
+ private func update() {
|
|
|
67
|
+ var val = self.item.value
|
|
|
68
|
+ val.comment_num = self.commentItems.value.count
|
|
|
69
|
+ val.thumbup_num = self.thumbupItems.value.count
|
|
|
70
|
+ let userInfo = [PhotoItemsOperator.key: PhotoItemsOperator.update(val.photo_id, val)]
|
|
|
71
|
+ NotificationCenter.default.post(name: .PhotoItemsChanged,
|
|
|
72
|
+ object: nil,
|
|
|
73
|
+ userInfo: userInfo)
|
|
54
|
74
|
}
|
|
55
|
75
|
|
|
56
|
76
|
public func submitThumbup() {
|
|
57
|
77
|
repository.submitThumbup().subscribe(onSuccess: { items in
|
|
58
|
78
|
self.thumbupItems.accept(items)
|
|
|
79
|
+ self.update()
|
|
59
|
80
|
}).disposed(by: disposeBag)
|
|
60
|
81
|
}
|
|
61
|
82
|
|
|
62
|
83
|
public func submitComment(text: String) {
|
|
63
|
84
|
repository.submitComment(text: text).subscribe(onSuccess: { (items) in
|
|
64
|
85
|
self.commentItems.accept(items)
|
|
|
86
|
+ self.update()
|
|
65
|
87
|
}).disposed(by: disposeBag)
|
|
66
|
88
|
}
|
|
|
89
|
+
|
|
|
90
|
+
|
|
67
|
91
|
}
|
|
|
|
@@ -127,6 +127,7 @@ public final class PhotoDetailViewModel {
|
|
127
|
127
|
}
|
|
128
|
128
|
|
|
129
|
129
|
public func willShow(index: Int) {
|
|
|
130
|
+ print(index)
|
|
130
|
131
|
currIndex = index
|
|
131
|
132
|
_hasGetPrice.accept(false)
|
|
132
|
133
|
itemViewModel.item.accept(_items.value[index])
|
|
|
|
@@ -125,7 +125,7 @@ public final class WaterfallFlowLayout: UICollectionViewLayout {
|
|
125
|
125
|
}
|
|
126
|
126
|
|
|
127
|
127
|
/// called at collectionView reload
|
|
128
|
|
- func setNeedsLayout() {
|
|
|
128
|
+ public func setNeedsLayout() {
|
|
129
|
129
|
isNeedLayout = true
|
|
130
|
130
|
}
|
|
131
|
131
|
}
|
|
|
|
@@ -31,6 +31,10 @@ final class HomeViewController: UIViewController {
|
|
31
|
31
|
override func viewDidAppear(_ animated: Bool) {
|
|
32
|
32
|
super.viewDidAppear(animated)
|
|
33
|
33
|
}
|
|
|
34
|
+
|
|
|
35
|
+ override func viewDidDisappear(_ animated: Bool) {
|
|
|
36
|
+ super.viewDidDisappear(animated)
|
|
|
37
|
+ }
|
|
34
|
38
|
|
|
35
|
39
|
func initalize() {
|
|
36
|
40
|
collectionView.register(UINib(nibName: "PhotoCell",
|
|
|
|
@@ -95,7 +99,8 @@ fileprivate extension HomeViewController {
|
|
95
|
99
|
|
|
96
|
100
|
func bindViewModelToRefreshing() {
|
|
97
|
101
|
viewModel.isLoading
|
|
98
|
|
- .subscribe(onNext: {[unowned self] flag in
|
|
|
102
|
+ .asDriver(onErrorJustReturn: true)
|
|
|
103
|
+ .drive(onNext: {[unowned self] flag in
|
|
99
|
104
|
if flag {
|
|
100
|
105
|
self.collectionView.endRefreshing(at: .top)
|
|
101
|
106
|
} else {
|