-
Notifications
You must be signed in to change notification settings - Fork 0
/
TUGTeepsterSearchedResult.swift
292 lines (250 loc) · 12.5 KB
/
TUGTeepsterSearchedResult.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
//
// TUGTeepsterSearchedResult.swift
// Teepso
//
// Created by techugo on 11/05/18.
// Copyright © 2018 TechUgo. All rights reserved.
//
import UIKit
class TUGTeepsterSearchedResult: UIViewController {
@IBOutlet weak var vwHeader: UIView!
@IBOutlet weak var cvMain: UICollectionView!
@IBOutlet weak var txtSocialLinks: UITextView!
@IBOutlet weak var vwAlpha: UIView!
@IBOutlet weak var lblHeading: UILabel!
@IBOutlet weak var vwPopup: UIView!
var teepsterDatabyLoc = [SwipeableProfileData]()
var idArrayString = ""
var indexpathRow = 0
var isSingleUser = false
var toLoadAnimationOfCell = false
var isfirstTimeTransform:Bool = true
override func viewDidLoad() {
super.viewDidLoad()
setUpHeaderView()
setInitialSetup()
getTeepsterProfiles()
// Do any additional setup after loading the view.
}
func getTeepsterProfiles() {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.showProcessingIndicatorOnView(vwBg: self.view, title: APP_NAME)
var request = CYLRequestObject()
let dictBody:[String:Any] = ["userId":idArrayString]
request = CYLServices.requestToGetTeepsterProfile(dict: dictBody as NSDictionary)
CYLServiceMaster.sharedInstance.callWebServiceWithRequest(rqst: request, withResponse:
{ (serviceResponse) -> Void in
if ((serviceResponse?.object?.value(forKey: "status") as! NSNumber) == 200)
{
appDelegate.hideProcessingIndicatorFromView(vwBg: self.view)
if self.isSingleUser == true{
let teeplistSingleUser = SingleUserProfile.init(object: (serviceResponse?.object)!)
self.teepsterDatabyLoc.append(teeplistSingleUser.data!)
self.cvMain.reloadData()
}else{
let teeplistObj = SwipeableProfileModel.init(object: (serviceResponse?.object)!)
self.teepsterDatabyLoc = teeplistObj.data!
self.cvMain.reloadData()
self.toLoadAnimationOfCell = true
let indexp = IndexPath.init(row: self.indexpathRow, section: 0)
self.cvMain.scrollToItem(at: indexp, at: .centeredHorizontally, animated: false)
}
}
else
{
if let msg = serviceResponse?.object?.value(forKey: "message")
{
appDelegate.hideProcessingIndicatorFromView(vwBg: self.view)
TUGHelpers().showAlertWithTitle(alertTitle: APP_NAME, messageBody: msg as! String, controller: self)
}
}
}, withError: { (error) -> Void in
appDelegate.hideProcessingIndicatorFromView(vwBg: self.view)
TUGHelpers().showAlertWithTitle(alertTitle: APP_NAME, messageBody: "Please Try Again.", controller: self)
}) { (isNetworkFailure) -> Void in
appDelegate.hideProcessingIndicatorFromView(vwBg: self.view)
TUGHelpers().showAlertWithTitle(alertTitle: APP_NAME, messageBody: INTERNET_CONNECTION_MESSAGE, controller: self)
}
}
@IBAction func ClickToGo(_ sender: UIButton) {
UIApplication.shared.openURL(URL(string: self.txtSocialLinks.text)!)
}
@IBAction func TappedToHideAlpha(_ sender: UITapGestureRecognizer) {
vwAlpha.isHidden = true
}
func setUpHeaderView()
{
let commonHeader = TUGCommonHeader()
self.vwHeader.addSubview(commonHeader.view)
commonHeader.lblMyProfileHeading.text = "Teepster's Profile"
self.addChildViewController(commonHeader)
commonHeader.setScreenComponentsWithTitleAndFlag(strTitle: "Teepster", menuFlag: "-1")
commonHeader.backBtnAction =
{_ in
self.navigationController!.popViewController(animated: false)
}
commonHeader.loginBtnAction =
{_ in
}
}
func setInitialSetup() {
let nibImageCell = UINib(nibName: "TeepsterListCell", bundle: nil)
self.cvMain.register(nibImageCell, forCellWithReuseIdentifier: "TeepsterListCell")
cvMain.delegate=self
cvMain.dataSource=self
vwPopup.layer.borderWidth = 2.0
vwPopup.layer.borderColor = UIColor.init(colorLiteralRed: 17.0/255.0, green: 163.0/255.0, blue: 168.0/255.0, alpha: 1.0).cgColor
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
extension TUGTeepsterSearchedResult: UICollectionViewDelegateFlowLayout{
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 280, height: collectionView.frame.size.height-50)
}
// func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
//
// return CGSize(width: 300, height: 500)
// }
// func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
//
//// let totalCellWidth = 300 * 5
//// let totalSpacingWidth = 10 * (5 - 1)
////
//// let leftInset = (375*5 - CGFloat(totalCellWidth + totalSpacingWidth)) / 2
//// let rightInset = leftInset
//
// return UIEdgeInsetsMake(0, 35, 0, 35)
// }
// Converted with Swiftify v1.0.6472 - https://objectivec2swift.com/
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
let pageWidth: Float = 280 + 10
// width + space
//let pageWidth: Float = Float(self.cvMain.frame.width/5 + 50)
let currentOffset: Float = Float(scrollView.contentOffset.x)
let targetOffset: Float = Float(targetContentOffset.pointee.x)
var newTargetOffset: Float = 0
if targetOffset > currentOffset {
newTargetOffset = ceilf(currentOffset / pageWidth) * pageWidth
}
else {
newTargetOffset = floorf(currentOffset / pageWidth) * pageWidth
}
if newTargetOffset < 0 {
newTargetOffset = 0
}
else if newTargetOffset > Float(scrollView.contentSize.width) {
newTargetOffset = Float(scrollView.contentSize.width)
}
targetContentOffset.pointee.x = CGFloat(currentOffset)
scrollView.setContentOffset(CGPoint(x: CGFloat(newTargetOffset), y: scrollView.contentOffset.y), animated: true)
// Converted with Swiftify v1.0.6472 - https://objectivec2swift.com/
var index: Int = Int(newTargetOffset / pageWidth)
if index == 0 {
// If first index
var cell: UICollectionViewCell? = self.cvMain.cellForItem(at: IndexPath(item: index, section: 0))
UIView.animate(withDuration: ANIMATION_SPEED, animations: {() -> Void in
cell?.transform = CGAffineTransform.identity
})
cell = self.cvMain.cellForItem(at: IndexPath(item: index + 1, section: 0))
UIView.animate(withDuration: ANIMATION_SPEED, animations: {() -> Void in
cell?.transform = TRANSFORM_CELL_VALUE
})
}
else {
var cell: UICollectionViewCell? = self.cvMain.cellForItem(at: IndexPath(item: index, section: 0))
UIView.animate(withDuration: ANIMATION_SPEED, animations: {() -> Void in
cell?.transform = CGAffineTransform.identity
})
index -= 1
// left
cell = self.cvMain.cellForItem(at: IndexPath(item: index, section: 0))
UIView.animate(withDuration: ANIMATION_SPEED, animations: {() -> Void in
cell?.transform = TRANSFORM_CELL_VALUE
})
index += 1
index += 1
// right
cell = self.cvMain.cellForItem(at: IndexPath(item: index, section: 0))
UIView.animate(withDuration: ANIMATION_SPEED, animations: {() -> Void in
cell?.transform = TRANSFORM_CELL_VALUE
})
}
}
}
extension TUGTeepsterSearchedResult: UICollectionViewDelegate{
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("clicked")
}
}
extension TUGTeepsterSearchedResult:UICollectionViewDataSource,UIScrollViewDelegate{
// MARK: - collection View delegate
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.teepsterDatabyLoc.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TeepsterListCell", for: indexPath)
if let annotateCell = cell as? TeepsterListCell {
annotateCell.bindData(temp: self.teepsterDatabyLoc[indexPath.row])
if self.toLoadAnimationOfCell == true{
if self.indexpathRow == indexPath.row{
self.toLoadAnimationOfCell = false
self.isfirstTimeTransform = false
}else{
cell.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
}
}else{
if (indexPath.row == 0 && isfirstTimeTransform) {
isfirstTimeTransform = false
}else{
cell.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
}
}
annotateCell.sectionClicked = {x in
print(x)
let myspotList = TUGOtherProfilesScreen()
myspotList.spotArray = (self.teepsterDatabyLoc[indexPath.row].region?[x].spots)!
self.navigationController?.pushViewController(myspotList, animated: false)
}
annotateCell.ITeepsClicked = {_ in
CommonClassTeeps().iTeepsAPI(teepid: "\(String(describing: (self.teepsterDatabyLoc[indexPath.row].user?.userId)!))", completionHandler: { (temp) in
if temp{
if annotateCell.imgHeartOut.image == #imageLiteral(resourceName: "heart_fill"){
annotateCell.imgHeartOut.image = #imageLiteral(resourceName: "heart_out")
}else{
annotateCell.imgHeartOut.image = #imageLiteral(resourceName: "heart_fill")
}
}else{
}
})
}
annotateCell.FollowClicked = {_ in
CommonClassTeeps().FollowedAPI(teepid: "\(String(describing: (self.teepsterDatabyLoc[indexPath.row].user?.userId)!))", completionHandler: { (temp) in
if temp{
if annotateCell.imgFollowed.image == #imageLiteral(resourceName: "follow"){
annotateCell.imgFollowed.image = #imageLiteral(resourceName: "follow_filed")
}else{
annotateCell.imgFollowed.image = #imageLiteral(resourceName: "follow")
}
}else{
}
})
}
annotateCell.SocialLinkClicked = {str in
self.txtSocialLinks.text = str
self.vwAlpha.isHidden = false
}
}
return cell
}
}