-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTabBarViewController.m
128 lines (97 loc) · 4.74 KB
/
TabBarViewController.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
//
// TabBarViewController.m
// Raketto
//
// Created by Adam Groom on 21/11/2014.
// Copyright (c) 2014 Team Awesome. All rights reserved.
//
#import "TabBarViewController.h"
#import "WhoAreYouViewController.h"
#import "ProfileViewController.h"
#import "User.h"
#import "Match.h"
@interface TabBarViewController ()
@property (strong,nonatomic) User *userUsingThisApp;
@end
@implementation TabBarViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:50.0/255.0 green:50.0/255.0 blue:50.0/255.0 alpha:1.0]];
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
UITabBarItem *profileTab = [self.tabBar.items objectAtIndex:0];
profileTab.image = [[UIImage imageNamed:@"profile"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
profileTab.selectedImage = [UIImage imageNamed:@"profile"];
UITabBarItem *feedTab = [self.tabBar.items objectAtIndex:1];
feedTab.image = [[UIImage imageNamed:@"feed"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
feedTab.selectedImage = [UIImage imageNamed:@"feed"];
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(getFeed) userInfo:nil repeats:YES];
}
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)viewDidAppear:(BOOL)animated
{
self.userUsingThisApp = [[User alloc] init];
[self.userUsingThisApp buildFromFile];
if ([self.userUsingThisApp.username isEqual:@""]) {
WhoAreYouViewController *whoAreYouViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"whoAreYou"];
[self presentViewController:whoAreYouViewController animated:YES completion:nil];
} else {
UINavigationController *profileViewNavController = [[self viewControllers] objectAtIndex:0];
ProfileViewController *profileViewController = [[profileViewNavController viewControllers] objectAtIndex:0];
profileViewController.avatar.image = self.userUsingThisApp.largeImage;
profileViewController.name.text = self.userUsingThisApp.username;
}
}
-(void) getFeed
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"Getting feed...");
// NSURL *baseUrl = [[[NSFileManager alloc] init] containerURLForSecurityApplicationGroupIdentifier:@"group.adam"];
// NSURL *url = [NSURL URLWithString:@"matches/current_match" relativeToURL:baseUrl];
//
// NSFileManager *fileManager = [[NSFileManager alloc] init];
// NSArray *files = [fileManager contentsOfDirectoryAtURL:url includingPropertiesForKeys:nil options:0 error:nil];
//
// NSMutableDictionary *matches = [[NSMutableDictionary alloc] init];
// if(files != nil){
// for(NSString *file in files) {
// Match *match = [[Match alloc] initWithID:file];
// if (match != nil) {
// [matches setObject:match forKey:file];
// }
// }
//
// [self updateFeedViewController:matches];
// }
NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.adam"];
NSInteger myScore = [[sharedDefaults valueForKey:@"MyScore"] integerValue];
NSInteger theirScore = [[sharedDefaults valueForKey:@"TheirScore"] integerValue];
NSString *myUsername = [sharedDefaults valueForKey:@"MyUsername"];
NSString *theirUsername = [sharedDefaults valueForKey:@"TheirUsername"];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInteger:myScore], @"MyScore", [NSNumber numberWithInteger:theirScore], @"TheirScore", myUsername, @"MyUsername", theirUsername, @"TheirUsername" , nil];
[self updateFeedViewController:dict];
});
}
-(void) updateFeedViewController:(NSDictionary *) withMatches {
NSNotification *notification =
[NSNotification
notificationWithName:@"MATCHES"
object:nil
userInfo: [NSDictionary dictionaryWithObjectsAndKeys:withMatches,@"matches", nil]];
[[NSNotificationCenter defaultCenter] postNotification:notification];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end