-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMyProfilePageVC.swift
190 lines (162 loc) · 7.18 KB
/
MyProfilePageVC.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//
// MyProfilePageVC.swift
// Commun
//
// Created by Chung Tran on 10/29/19.
// Copyright © 2019 Commun Limited. All rights reserved.
//
import Foundation
class MyProfilePageVC: UserProfilePageVC {
// MARK: - Properties
var shouldHideBackButton = true
// MARK: - Subviews
lazy var changeCoverButton: UIButton = {
let button = UIButton.changeCoverButton
button.touchAreaEdgeInsets = UIEdgeInsets(inset: -10)
return button
}()
// MARK: - Initializers
override func createViewModel() -> ProfileViewModel<ResponseAPIContentGetProfile> {
MyProfilePageViewModel(userId: userId)
}
init() {
super.init(userId: Config.currentUser?.id ?? "")
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - Custom Functions
override func setUp() {
super.setUp()
// hide back button
if shouldHideBackButton {
backButton.alpha = 0
backButton.isUserInteractionEnabled = false
}
// layout subview
view.addSubview(changeCoverButton)
changeCoverButton.autoPinEdge(.bottom, to: .bottom, of: coverImageView, withOffset: -60)
changeCoverButton.autoPinEdge(.trailing, to: .trailing, of: coverImageView, withOffset: -16)
changeCoverButton.addTarget(self, action: #selector(changeCoverBtnDidTouch(_:)), for: .touchUpInside)
// wallet
let tap = UITapGestureRecognizer(target: self, action: #selector(walletDidTouch))
(headerView as! MyProfileHeaderView).walletView.isUserInteractionEnabled = true
(headerView as! MyProfileHeaderView).walletView.addGestureRecognizer(tap)
}
override func bind() {
super.bind()
bindBalances()
let offSetY = tableView.rx.contentOffset
.map {$0.y}.share()
offSetY
.map { $0 < -140 }
.subscribe(onNext: { show in
self.changeCoverButton.isHidden = !show
})
.disposed(by: disposeBag)
offSetY
.map { $0 < -43 }
.subscribe(onNext: { showNavBar in
self.optionsButton.tintColor = !showNavBar ? .appBlackColor : .white
self.title = !showNavBar ? self.username : nil
})
.disposed(by: disposeBag)
}
override func setUp(profile: ResponseAPIContentGetProfile) {
super.setUp(profile: profile)
ResponseAPIContentGetProfile.current = profile
if profile.createdCommunities == nil {
RestAPIManager.instance.getCreatedCommunities()
.subscribe(onSuccess: { (result) in
var profile = ResponseAPIContentGetProfile.current
profile?.createdCommunities = result.communities
ResponseAPIContentGetProfile.current = profile
})
.disposed(by: disposeBag)
}
}
override func createHeaderView() -> UserProfileHeaderView {
let headerView = MyProfileHeaderView(tableView: tableView)
headerView.changeAvatarButton.addTarget(self, action: #selector(changeAvatarBtnDidTouch(_:)), for: .touchUpInside)
headerView.addBioButton.addTarget(self, action: #selector(addBioButtonDidTouch(_:)), for: .touchUpInside)
headerView.descriptionLabel.isUserInteractionEnabled = true
let tap = UITapGestureRecognizer(target: self, action: #selector(bioLabelDidTouch(_:)))
headerView.descriptionLabel.addGestureRecognizer(tap)
return headerView
}
override func actionsForMoreButton() -> [CMActionSheet.Action] {
guard let profile = viewModel.profile.value else { return []}
return [
.iconFirst(
title: "share".localized().uppercaseFirst,
iconName: "icon-share-circle-white",
handle: {
ShareHelper.share(urlString: self.shareWith(name: profile.username ?? "", userID: profile.userId))
},
bottomMargin: 15
),
.iconFirst(
title: "saved souls".localized().uppercaseFirst,
iconName: "profile_options_referral",
handle: {
let vc = ReferralUsersVC()
vc.title = "saved souls".localized().uppercaseFirst
self.navigationItem.backBarButtonItem = UIBarButtonItem(customView: UIView(backgroundColor: .clear))
self.show(vc, sender: self)
},
showNextButton: true
),
.iconFirst(
title: "liked".localized().uppercaseFirst,
iconName: "profile_options_liked",
handle: {
let vc = PostsViewController(filter: PostsListFetcher.Filter(type: .voted, sortBy: .time, userId: Config.currentUser?.id))
vc.title = "liked".localized().uppercaseFirst
self.navigationItem.backBarButtonItem = UIBarButtonItem(customView: UIView(backgroundColor: .clear))
self.show(vc, sender: self)
},
showNextButton: true
),
.iconFirst(
title: "blacklist".localized().uppercaseFirst,
iconName: "profile_options_blacklist",
handle: {
self.show(MyProfileBlacklistVC(), sender: self)
},
bottomMargin: 15,
showNextButton: true
),
.iconFirst(
title: "settings".localized().uppercaseFirst,
iconName: "profile_options_settings",
handle: {
let vc = MyProfileSettingsVC()
self.show(vc, sender: self)
},
showNextButton: true
)
]
}
override func handleListEmpty() {
var title = "empty"
var description = "not found"
switch (viewModel as! UserProfilePageViewModel).segmentedItem.value {
case .posts:
title = "no posts".localized().uppercaseFirst
description = "you haven't created any posts yet".localized().uppercaseFirst
tableView.addEmptyPlaceholderFooterView(title: title, description: description, buttonLabel: String(format: "%@ %@", "create".localized().uppercaseFirst, "post".localized())) {
if let tabBarVC = self.tabBarController as? TabBarVC {
tabBarVC.buttonAddTapped()
}
}
case .comments:
title = "no comments".localized().uppercaseFirst
description = "you haven't created any comments yet".localized().uppercaseFirst
tableView.addEmptyPlaceholderFooterView(title: title, description: description)
case .about:
title = "no info".localized().uppercaseFirst
description = "you haven't added any information about your self yet".localized().uppercaseFirst
tableView.addEmptyPlaceholderFooterView(title: title, description: description)
}
}
}