-
Notifications
You must be signed in to change notification settings - Fork 0
/
PFAboutMeVC.swift
440 lines (357 loc) · 18.1 KB
/
PFAboutMeVC.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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
//
// PFAboutMeVC.swift
// PocketFriend
//
// Created by Manish Parihar on 16/11/16.
//
import UIKit
class PFAboutMeVC: BaseViewController,UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout,UITableViewDelegate,UITableViewDataSource {
enum ViewType : Int {
case EmotionsBubbleViewType
case DetailViewType
case SummaryViewType
}
let padding:CGFloat = 10;
var arrSummary:NSArray = NSArray()
@IBOutlet weak var flowLayout: UICollectionViewFlowLayout!
@IBOutlet weak var txtView: UITextView!
@IBOutlet weak var vwFooter: UIView!
@IBOutlet weak var vwSummary: UIView!
@IBOutlet weak var tblSummary: UITableView!
@IBOutlet weak var btnMore: UIButton!
@IBOutlet weak var vwInfo: UIView!
@IBOutlet weak var vwEmotionBubble: UIView!
@IBOutlet weak var lblSummary: UILabel!
@IBOutlet weak var vwInfoSubContainer: UIView!
var arrMore:NSMutableArray = NSMutableArray()
@IBOutlet weak var btnAboutMe: UIButton!
@IBOutlet weak var btnYou: UIButton!
@IBOutlet weak var TitleLabel: UILabel!
@IBOutlet weak var detailLabel: UILabel!
var timeSpan:TimeSpan = .Last7DaysTimeSpan
var currentSelectedEmotion:PFAboutEmotionsInfo!
var onView:ViewType = .EmotionsBubbleViewType
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var lblErrorMessage: UILabel!
var percentPixel:CGFloat = 10;
var arrEmotions : NSMutableArray!
var totalRecordCount:NSInteger = 0
var strChosenRange:String = ""
var selectedEmotionView:UIView!
@IBOutlet weak var lblChosenRange: UILabel!
@IBOutlet weak var emotionsCollectionView: UICollectionView!
@IBOutlet weak var timeSpanSegmentControl: UISegmentedControl!
//#MARK: - View Controller Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.screenDesigningOfAboutMe()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//#MARK: - ScreenDesigning
func screenDesigningOfAboutMe(){
rightHeaderButton.setTitle("Send mail", for: .normal)
let view:UIButton = vwInfoSubContainer.viewWithTag(11101) as! UIButton
view.layer.cornerRadius = 18
btnYou.isUserInteractionEnabled=false
emotionsCollectionView.register(ChatCollectionViewCell.self, forCellWithReuseIdentifier: ChatCollectionViewCellIdentifier)
flowLayout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
flowLayout.minimumInteritemSpacing = 0
flowLayout.minimumLineSpacing = 0
emotionsCollectionView!.collectionViewLayout = flowLayout
let pixel:CGFloat = emotionsCollectionView.frame.size.width/5
//screenWidth/2 //
percentPixel = pixel/100
self.tblSummary.estimatedRowHeight = 100
self.tblSummary.rowHeight = UITableViewAutomaticDimension
// self.tblSummary.register(CustomTableViewCell.self, forCellReuseIdentifier: "CustomTableViewCell")
self.timeSpanChanged(timeSpanSegmentControl)
}
//#MARK: - Operational Methods
func calculateTotalRecordCount(){
totalRecordCount=0
for recordCount in 0...arrEmotions.count-1
{
let emoInfo:PFAboutEmotionsInfo = arrEmotions.object(at: recordCount) as! PFAboutEmotionsInfo
totalRecordCount += emoInfo.subTrack_recordCount
}
}
@IBAction func timeSpanChanged(_ sender: UISegmentedControl){
if timeSpanSegmentControl.selectedSegmentIndex==0{
timeSpan = .Last7DaysTimeSpan
strChosenRange = "last 7 days"
}
else if timeSpanSegmentControl.selectedSegmentIndex==1{
timeSpan = .Last30DaysTimeSpan
strChosenRange = "last 30 days"
}
else if timeSpanSegmentControl.selectedSegmentIndex==2{
timeSpan = .HalfYearTimeSpan
strChosenRange = "last 6 months"
}
else if timeSpanSegmentControl.selectedSegmentIndex==3{
timeSpan = .YearTimeSpan
strChosenRange = "this year"
}
if arrEmotions != nil{
arrEmotions.removeAllObjects()
}
arrEmotions = PFModelManager.getInstance().getEmotionsOfUser(userID: appDelegate.userInfo.UserID, timeSpan: timeSpan)
if arrEmotions.count != 0 {
self.calculateTotalRecordCount()
}
if totalRecordCount==0{
scrollView.isHidden=true
lblErrorMessage.isHidden=false
btnYou.isUserInteractionEnabled=false
btnMore.isHidden=true
}
else{
scrollView.isHidden=false
lblErrorMessage.isHidden=true
btnMore.isHidden=true
lblChosenRange.text = "This is what your \(strChosenRange) looks like:"
}
if onView == .DetailViewType {
self.goToDetailView()
}
else if onView == .SummaryViewType {
self.goToSummaryView()
}
else{
emotionsCollectionView.reloadData()
}
GlobalSwift.animateView(transitionType: kCATransitionFade, transitionSubType: kCATransitionFromRight, view: emotionsCollectionView, duration: 0.5)
}
@IBAction func moreButtonClicked(_ sender: AnyObject) {
self.goToSummaryView()
}
override func leftHeaderButtonClicked(_ sender: UIButton) {
self.navigationController?.popToRootViewController(animated: true)
}
override func rightHeaderButtonClicked(_ sender: UIButton) {
let pfShareVC:PFSendMailVC = self.storyboard?.instantiateViewController(withIdentifier: "PFSendMailVC") as! PFSendMailVC
self.navigationController?.pushViewController(pfShareVC, animated: true)
}
@IBAction func youButtonClicked(_ sender: AnyObject) {
if self.onView == .SummaryViewType {
self.onView = .DetailViewType
self.goToDetailView()
}
else if (self.onView == .DetailViewType) {
self.onView = .EmotionsBubbleViewType
self.goToEmotionView()
}
}
func goToEmotionView(){
btnYou.isUserInteractionEnabled=false
vwEmotionBubble.isHidden=false;
vwInfo.isHidden=true
vwSummary.isHidden=true
GlobalSwift.animateView(transitionType: kCATransitionFade, transitionSubType: kCATransitionFromBottom, view: scrollView, duration: 0.5)
}
func goToDetailView(){
self.onView = .DetailViewType
btnYou.isUserInteractionEnabled=true
vwEmotionBubble.isHidden=true;
vwInfo.isHidden=false
scrollView.isHidden=false
vwSummary.isHidden=true
// let superView:UIView = TitleLabel.superview!
// if superView.layer.cornerRadius != 60{
// superView.layer.cornerRadius = 60;
// //superView.layer.masksToBounds=true
//
// superView.layer.shadowColor = UIColor.black.cgColor
// superView.layer.shadowOffset = CGSize(width: 1, height: 1)
// superView.layer.shadowOpacity = 0.7
// superView.layer.shadowRadius = 1.0
//
// let frame = superView.bounds
// // frame.origin.x -= 50
// // frame.origin.x -= 50
// // frame.size.height -= 20
// // frame.size.width -= 20
// let gradient = GlobalSwift.gradientColor(gradientColors: [UIColor(red:141/255, green:212/255, blue:249/255, alpha:1.0),UIColor(red:10/255, green:98/255, blue:144/255, alpha:1.0)],frame:frame)
// gradient.cornerRadius = (frame.size.height)/2
// gradient.masksToBounds = true
// superView.layer.insertSublayer(gradient, at: 0)
//
// }
let stringTitle:String = currentSelectedEmotion.subTrack_description
TitleLabel.text = stringTitle
detailLabel.text=""
let mutableString:NSMutableAttributedString = NSMutableAttributedString()
// let normalFontAttribute = [NSFontAttributeName: UIFont.systemFont(ofSize: 15)]
let mutableString2 = NSAttributedString(string: "You felt ", attributes: [NSFontAttributeName: UIFont.systemFont(ofSize: 15)])
mutableString.append(mutableString2)
let fontAttribute = [NSFontAttributeName: UIFont.boldSystemFont(ofSize: 15)]
var descDetail:String = "\(stringTitle) \(currentSelectedEmotion.subTrack_recordCount) times in \(strChosenRange).\n"
let mutableString1 = NSAttributedString(string: descDetail, attributes: fontAttribute)
detailLabel.attributedText = mutableString1
mutableString.append(mutableString1)
// var yAxis = detailLabel.frame.origin.y
arrMore.removeAllObjects()
arrMore = PFModelManager.getInstance().getDescriptionOfEmotion(subtrackID: currentSelectedEmotion.subTrack_id,userID: appDelegate.userInfo.UserID,timeSpan: timeSpan)
var count=0
if arrMore.count>0{
count = arrMore.count-1
if count > 1{
count = 1
}
descDetail = "\nYou typically describe \(stringTitle) with words such as \n\n"
for recordCount in 0...count
{
descDetail += "• "
descDetail += arrMore.object(at: recordCount) as! String
descDetail += "\n\n"
}
// let myAttribute = [NSForegroundColorAttributeName: textDarkColor]
let mutableString1 = NSAttributedString(string: descDetail, attributes: [NSForegroundColorAttributeName:textDarkColor,NSFontAttributeName:UIFont.systemFont(ofSize: 15)])
mutableString.append(mutableString1)
}
else{
let mutableString1 = NSAttributedString(string: "\n\n", attributes: [NSForegroundColorAttributeName:textDarkColor,NSFontAttributeName:UIFont.systemFont(ofSize: 15)])
mutableString.append(mutableString1)
mutableString.append(mutableString1)
}
if currentSelectedEmotion.subTrack_recordCount>=2{
let day:String = PFModelManager.getInstance().getDayOfMaxSelectedSubtrack(subTrackID: currentSelectedEmotion.subTrack_id, userID: appDelegate.userInfo.UserID, timeSpan: timeSpan)
let time:String = PFModelManager.getInstance().getTimeOfMaxSelectedSubtrack(subTrackID: currentSelectedEmotion.subTrack_id, userID: appDelegate.userInfo.UserID, timeSpan: timeSpan)
let string:String = GlobalSwift.getDateFormat(dateString: time, from: "HH", to: "hh a")
descDetail = "You feel \(stringTitle) mostly on \(day), and often around \(string)"
//let myAttribute = [NSForegroundColorAttributeName: themeColor]
let mutableString1 = NSAttributedString(string: descDetail, attributes: [NSForegroundColorAttributeName:themeColor,NSFontAttributeName:UIFont.boldSystemFont(ofSize: 15)])
mutableString.append(mutableString1)
}
detailLabel.attributedText = mutableString
txtView.attributedText = mutableString
print(detailLabel.attributedText)
let sizeOfString:CGSize = mutableString.boundingRect(
with: CGSize(width: detailLabel.frame.size.width, height: CGFloat.infinity),
options: [NSStringDrawingOptions.usesDeviceMetrics,NSStringDrawingOptions.usesFontLeading,NSStringDrawingOptions.usesLineFragmentOrigin],
context: nil).size
detailLabel.frame = CGRect(x:detailLabel.frame.origin.x, y: detailLabel.frame.origin.y, width: detailLabel.frame.size.width, height: sizeOfString.height)
// yAxis = detailLabel.frame.origin.y + sizeOfString.height
btnMore.isHidden=true
// if count<arrMore.count-1
// {
// btnMore.isHidden=false
//// var frame = btnMore.frame
//// frame.origin.y = yAxis
//// btnMore.frame = frame
//// yAxis += frame.size.height
// }
if arrMore.count>0{
btnMore.isHidden=false
}
//
//
// vwInfoSubContainer.frame.size.height = yAxis
// scrollView.contentSize.height = yAxis
GlobalSwift.animateView(transitionType: kCATransitionFade, transitionSubType: kCATransitionFromTop, view: vwInfo, duration: 0.5)
}
func goToSummaryView(){
self.onView = .SummaryViewType
btnYou.isUserInteractionEnabled=true
vwEmotionBubble.isHidden=true;
vwInfo.isHidden=false
scrollView.isHidden=true
vwSummary.isHidden=false
arrSummary = PFModelManager.getInstance().getDatesOfEmotion(subtrackID: currentSelectedEmotion.subTrack_id, userID: appDelegate.userInfo.UserID, timeSpan: timeSpan)
tblSummary.reloadData()
tblSummary.setNeedsLayout()
tblSummary.layoutIfNeeded()
GlobalSwift.animateView(transitionType: kCATransitionFade, transitionSubType: kCATransitionFromTop, view: vwSummary, duration: 0.5)
}
//MARK: - Collection View Delegate & Data Source
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
if arrEmotions==nil{
return 0
}
return arrEmotions.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell: ChatCollectionViewCell? = collectionView.dequeueReusableCell(withReuseIdentifier: ChatCollectionViewCellIdentifier, for: indexPath) as? ChatCollectionViewCell
for view in (cell?.contentView.subviews)!{
view.removeFromSuperview()
}
let emoInfo : PFAboutEmotionsInfo = arrEmotions.object(at: indexPath.item) as! PFAboutEmotionsInfo
cell?.initContent(optionText:emoInfo.subTrack_description,bgColor: UIColor.clear,textColor: textThemeColor,BGImage:UIImage(named:"BlueShadowedCircle"))
return cell!;
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// handle tap events
let cell:UICollectionViewCell = collectionView.cellForItem(at: indexPath)!
// selectedEmotionView = collectionView.cellForItem(at: indexPath)
let startFrame:CGRect = cell.convert(cell.bounds, to: vwEmotionBubble)
let finalFrame:CGRect = btnYou.convert(btnYou.bounds, to: vwEmotionBubble)
let snapShot:UIView = GlobalSwift.snapshotOfView(inputView: cell)
snapShot.frame = startFrame
vwEmotionBubble.addSubview(snapShot)
// let center = cell.center
// snapShot.center = center
cell.alpha = 0.0
UIView.animate(withDuration: 0.5, delay: 0, options: .curveLinear, animations: {
snapShot.transform = CGAffineTransform(scaleX: 1.1, y: 1.1)
}) { (Bool) in
UIView.animate(withDuration: 0.4, delay: 0, options: .curveLinear, animations: {
snapShot.frame = finalFrame
snapShot.alpha = 0
}) { (Bool) in
cell.alpha = 1
snapShot.removeFromSuperview()
self.currentSelectedEmotion = self.arrEmotions.object(at: indexPath.item) as! PFAboutEmotionsInfo
self.goToDetailView()
}
}
//print("You selected cell #\(indexPath.item)!")
}
// For Setting Collection View Layout
// func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets
// {
// return UIEdgeInsets(top: 10, left: 10, bottom: 0, right: 0)
// }
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let emoInfo : PFAboutEmotionsInfo = arrEmotions.object(at: indexPath.item) as! PFAboutEmotionsInfo
let size = (emoInfo.subTrack_recordCount*100/totalRecordCount)+30
var pix:Int = Int(CGFloat(size) * percentPixel)+10
if pix<60{
pix = 60
}
return CGSize(width: pix, height: pix);
}
//MARK: - Table View Delegate & Data Source
func numberOfSections(in tableView: UITableView) -> Int {
let count:NSInteger = arrSummary.count
return count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let objPFDetail:PFDetailObj = arrSummary.object(at: section) as! PFDetailObj
let arr:NSArray = objPFDetail.arrDetails
let count:NSInteger = arr.count
return count
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?{
let objPFDetail:PFDetailObj = arrSummary.object(at: section) as! PFDetailObj
let string:String = GlobalSwift.getDateFormat(dateString: objPFDetail.dateString, from: "yyyy-MM-dd", to: "dd MMMM yyyy")
return string
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "CustomTableViewCell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! CustomTableViewCell
let objPFDetail:PFDetailObj = arrSummary.object(at: indexPath.section) as! PFDetailObj
let arr:NSArray = objPFDetail.arrDetails
let detailChildObj : PFEmotionSubDetailObj = arr.object(at: indexPath.row) as! PFEmotionSubDetailObj
cell.lblTitle.text = detailChildObj.descriptionString
let string:String = GlobalSwift.getDateFormat(dateString: detailChildObj.timeString, from: "HH:mm:ss", to: "hh:mm a")
cell.lblSubTitle.text = string
cell.backgroundColor=UIColor.clear
return cell
}
}