-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYouViewController.m
161 lines (132 loc) · 8.03 KB
/
YouViewController.m
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
//
// YouViewController.m
// DinerRouge
//
// Created by Adrian Holzer on 26.02.15.
// Copyright (c) 2015 Adrian Holzer. All rights reserved.
//
#import "YouViewController.h"
#import "GAI.h"
#import "InfoViewController.h"
#import "GAIDictionaryBuilder.h"
#import "GAIFields.h"
#import "BillManager.h"
#define DONE_BUTTON_WIDTH 80
#define SEND_BUTTON_PADDING 5
#define INPUTVIEW_HEIGHT 115
#define INPUT_LEFT_PADDING 10
#define INPUT_TOP_PADDING 5
#define INPUT_HEIGHT 30
#define SIDE_PADDING 15
@interface YouViewController ()
@end
@implementation YouViewController
@synthesize q1View, q2View, q3View, q4View, q5View,q2ViewIndicator, q3ViewIndicator, q4ViewIndicator, q5ViewIndicator, country,distributionView,distributionLabel,q2ViewIndicatorLabel, q3ViewIndicatorLabel, q4ViewIndicatorLabel, q5ViewIndicatorLabel;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor=[[BillManager sharedBillManager] maincolor];
// instructionView.text=NSLocalizedString(@"INFO_HOW", nil) ;
//setup nav bar title
UINavigationItem *navigationItem = [super navigationItem];
UILabel *customLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120.0f, 44.0f)];
customLabel.backgroundColor= [UIColor clearColor];
customLabel.textAlignment = NSTextAlignmentCenter;
customLabel.textColor = [[BillManager sharedBillManager] secondarycolor];
navigationItem.titleView = customLabel;
[customLabel setFont:[UIFont fontWithName:[[BillManager sharedBillManager] fontNameBold] size:[[BillManager sharedBillManager] largeFont]]];
customLabel.text=[NSLocalizedString(@"Your table", nil) uppercaseString];
self.giniLabel.text=[NSString stringWithFormat:@"%.f", [[[BillManager sharedBillManager] gini] floatValue] ];
self.giniLabel.textColor=[[BillManager sharedBillManager] buttonTextColor];
self.giniLabel.backgroundColor=[[BillManager sharedBillManager] buttoncolor];
// BACK BUTTON
UIButton *newBackButton = [UIButton buttonWithType:UIButtonTypeCustom];
[newBackButton setImage:[[BillManager sharedBillManager]backBoutonImage] forState:UIControlStateNormal];
[newBackButton addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
newBackButton.frame = CGRectMake(5, 5, 30, 30);
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:newBackButton];
[self.giniLabel setFont:[UIFont fontWithName:[[BillManager sharedBillManager] fontNameBold] size: 65]];
[self.whatLabel setFont:[UIFont fontWithName:[[BillManager sharedBillManager] fontNameBold] size:[[BillManager sharedBillManager] largeFont]]];
[self.giniInfo setFont:[UIFont fontWithName:[[BillManager sharedBillManager] fontNameBold] size:[[BillManager sharedBillManager] smallFont]]];
[self.distributionLabel setFont:[UIFont fontWithName:[[BillManager sharedBillManager] fontNameBold] size:[[BillManager sharedBillManager] smallFont]]];
[self.inequalityLabel setFont:[UIFont fontWithName:[[BillManager sharedBillManager] fontNameBold] size:[[BillManager sharedBillManager] smallFont]]];
[self.incomeInfo setFont:[UIFont fontWithName:[[BillManager sharedBillManager] fontNameBold] size:[[BillManager sharedBillManager] smallFont]]];
// Go To Button
UIButton * goToInequalityButton = [UIButton buttonWithType:UIButtonTypeCustom];
goToInequalityButton.backgroundColor=[[BillManager sharedBillManager] buttoncolor] ;
[goToInequalityButton setTitleColor:[[BillManager sharedBillManager] buttonTextColor] forState:UIControlStateNormal];
[goToInequalityButton setTitleColor: [UIColor whiteColor] forState:UIControlStateHighlighted];
[goToInequalityButton.titleLabel setFont:[UIFont fontWithName:[[BillManager sharedBillManager] fontNameBold] size:[[BillManager sharedBillManager] mediumFont]]];
[goToInequalityButton addTarget:self action:@selector(goToCountries:) forControlEvents:UIControlEventTouchUpInside];
[goToInequalityButton setTitle:NSLocalizedString(@"SEE COUNTRIES", nil) forState:UIControlStateNormal];
goToInequalityButton.frame = CGRectMake(SIDE_PADDING, self.view.frame.size.height-(INPUT_HEIGHT+SIDE_PADDING) , self.view.frame.size.width-(2*SIDE_PADDING) , INPUT_HEIGHT);
goToInequalityButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
[self.view addSubview:goToInequalityButton];
// NSString* type = NSLocalizedString(@"INCOME", nil);
self.whatLabel.text=NSLocalizedString(@"GINI", nil) ;
self.whatLabel.backgroundColor= [[BillManager sharedBillManager] buttoncolor];
self.whatLabel.textColor= [[BillManager sharedBillManager] buttonTextColor];
self.giniInfo.text=[NSString stringWithFormat: NSLocalizedString(@"INFO_GINI", nil),[NSString stringWithFormat:@"%.f", [[[BillManager sharedBillManager] gini] floatValue]], [[Country inequalityWithGini:[[BillManager sharedBillManager] gini]] lowercaseString]];
self.distributionLabel.text= NSLocalizedString(@"TOTAL_INCOME_OF_THE_TABLE", nil);
self.distributionLabel.textColor=[[BillManager sharedBillManager] buttonTextColor];
//Get the number of friends
//for each friend give a size of a new component,
//for each firend ga
self.inequalityLabel.text=[country inequality:NSLocalizedString(@"INCOME", nil)];
self.distributionView.backgroundColor= [[BillManager sharedBillManager] buttoncolor];
self.inequalityLabel.textColor= [[BillManager sharedBillManager] buttonTextColor];
long numberOfFriends=[[[BillManager sharedBillManager] friends] count];
float friendNumber=1;
float x=0;
float totalIncome = [[[BillManager sharedBillManager] totalIncome] floatValue];
self.incomeInfo.text=NSLocalizedString(@"TABLE_ONE_PERSON_ONLY_INFO", nil);
self.incomeInfo.textColor= [[BillManager sharedBillManager] secondarycolor];
self.giniInfo.textColor= [[BillManager sharedBillManager] secondarycolor];
for (Friend* friend in [self sortedFriends]){
UIView* friendView = [[UIView alloc] initWithFrame:q5View.frame];
CGRect frm = friendView.frame;
frm.size.width= ([friend.income floatValue]/totalIncome)*q5View.frame.size.width;
frm.origin.x=frm.origin.x+x;
x+=frm.size.width;
friendView.frame = frm;
float alpha=0.8*(1-(friendNumber/numberOfFriends));
[friendView setBackgroundColor:[UIColor colorWithRed:70.0/255.0 green:70.0/255.0 blue:70.0/255.0 alpha:alpha]];
[self.distributionView addSubview:friendView];
if (friendNumber==2) {
self.incomeInfo.text=[NSString stringWithFormat: NSLocalizedString(@"TABLE_INFO", nil), [NSString stringWithFormat:@"%.f", ([friend.income floatValue]/totalIncome)*100]];
}
friendNumber++;
}
}
- (void)goToCountries:(NSNotification*) notification{
[self performSegueWithIdentifier:@"CountrySegue" sender:self];
}
-(NSArray*)sortedFriends{
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"income" ascending:NO];
NSMutableArray *sortDescriptors = [NSMutableArray arrayWithObject:sortDescriptor];
return [[[[BillManager sharedBillManager] friends] mutableCopy] sortedArrayUsingDescriptors:sortDescriptors];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)viewDidAppear:(BOOL)animated{
if ([[BillManager sharedBillManager] styleIsCommunist]) {
[[[GAI sharedInstance] defaultTracker] set:kGAIScreenName value:@"Table Inequality Screen-C"];
[[[GAI sharedInstance] defaultTracker] send:[[GAIDictionaryBuilder createAppView] build]];
}else{
[[[GAI sharedInstance] defaultTracker] set:kGAIScreenName value:@"Table Inequality Screen-NC"];
[[[GAI sharedInstance] defaultTracker] send:[[GAIDictionaryBuilder createAppView] build]];
}
}
@end