PageRenderTime 51ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/WHAMBUSH/wbData.m

https://gitlab.com/urbanjunglestudio/whambush-ios
Objective C | 763 lines | 517 code | 92 blank | 154 comment | 106 complexity | f48b84c99ca0596b93f24bb36bc026f4 MD5 | raw file
  1. //
  2. // wbData.m
  3. // WHAMBUSH
  4. //
  5. // Created by Jari Kalinainen on 26/11/13.
  6. // Copyright (c) 2013 Jari Kalinainen. All rights reserved.
  7. //
  8. #import "wbData.h"
  9. #import <sys/utsname.h>
  10. @implementation wbData
  11. @synthesize singleVideoData;
  12. //@synthesize hasMissions;
  13. //@synthesize hasUserpage;
  14. @synthesize launchedFromPush;
  15. @synthesize pushData;
  16. @synthesize thumbSize;
  17. @synthesize feeds;
  18. @synthesize missionFeeds;
  19. @synthesize num_of_unreadActivities;
  20. @synthesize supportMessage;
  21. @synthesize activityString;
  22. @synthesize activityLabel;
  23. @synthesize rankNumber;
  24. //@synthesize videoCells;
  25. @synthesize rootTVChannel;
  26. @synthesize selectedMissionCountry;
  27. @synthesize launchWithMission;
  28. -(id) init
  29. {
  30. self = [super init];
  31. // hasMissions = NO;
  32. // hasUserpage = NO;
  33. launchedFromPush = NO;
  34. // fetching = [[NSMutableDictionary alloc] init];
  35. // videoCells = [[NSMutableDictionary alloc] init];
  36. rankNumber = 0;
  37. numberOfCountries = 1000;
  38. DPRINTCLASS;
  39. return self;
  40. }
  41. + (id)sharedData
  42. {
  43. static dispatch_once_t pred = 0;
  44. __strong static id _sharedObject = nil;
  45. dispatch_once(&pred, ^{
  46. _sharedObject = [[self alloc] init];
  47. });
  48. return _sharedObject;
  49. }
  50. -(NSString*)description
  51. {
  52. return [super description];
  53. }
  54. -(void)setNum_of_unreadActivities:(NSNumber*)_num_of_unreadActivities
  55. {
  56. num_of_unreadActivities = _num_of_unreadActivities;
  57. if (activityLabel == nil) {
  58. activityLabel = [[wbLabel alloc] init];
  59. }
  60. activityString = [NSString stringWithFormat:NSLocalizedString(@"USER_ACTIVITY",@""),[NSString stringWithFormat:NSLocalizedString(@"USER_COUNT",@""),[num_of_unreadActivities integerValue]]];
  61. [activityLabel setText:activityString];
  62. [activityLabel sizeToFit];
  63. }
  64. ///////////////////////////////
  65. -(void)getTvChannels
  66. {
  67. [[wbAPI sharedAPI] getJSONWithURL:[[wbAPI sharedAPI] urlWithEndpoint:kCHANNELSAPI]
  68. response:^(id resultArray){
  69. [self saveTvChannels:[resultArray objectForKey:@"results"] firstTime:YES];
  70. DCMSG(resultArray);
  71. }];
  72. }
  73. -(void)saveTvChannels:(NSArray*)channels firstTime:(BOOL)first
  74. {
  75. if ([[wbUser sharedUser] userReady] || [[wbAPI sharedAPI] is_guest]) {
  76. if (tvChannels == nil) {
  77. tvChannels = [[NSMutableDictionary alloc] init];
  78. }
  79. if (tvChannelsData == nil) {
  80. tvChannelsData = [[NSMutableDictionary alloc] init];
  81. [tvChannelsData setObject:channels forKey:@0];
  82. rootTVChannel = 0;
  83. [kROOTVC performSelector:@selector(setDefaultTvChannel:) withObject:[NSNumber numberWithInteger:rootTVChannel]];
  84. }
  85. for (int i = 0; i < [channels count]; i++) {
  86. NSMutableDictionary *channel = [[NSMutableDictionary alloc] initWithDictionary:[channels objectAtIndex:i]];
  87. if (first) {
  88. [channel setObject:@NO forKey:@"has_parent"];
  89. } else {
  90. [channel setObject:@YES forKey:@"has_parent"];
  91. }
  92. if (/*![[channel objectForKey:@"channel_type"] boolValue]*/first) {
  93. if ([[channel objectForKey:@"country"] isEqualToString:[[[wbAPI sharedAPI] currentCountry] objectForKey:@"country"]] ||
  94. (![[[[wbAPI sharedAPI] currentCountry] valueForKey:@"supported"] boolValue] && [[channel objectForKey:@"country"] isEqualToString:@"ZZ"])) {
  95. rootTVChannel = [[channel objectForKey:@"id"] integerValue];
  96. [kROOTVC performSelector:@selector(setDefaultTvChannel:) withObject:[NSNumber numberWithInteger:rootTVChannel]];
  97. }
  98. }
  99. [tvChannelsData setObject:channel forKey:[channel objectForKey:@"id"]];
  100. if ([[channel objectForKey:@"children"] count] > 0) {
  101. [self saveTvChannels:[channel objectForKey:@"children"] firstTime:NO];
  102. }
  103. }
  104. //NSLog(@"%@\n%ld",tvChannelsData,(long)rootTVChannel);
  105. } else {
  106. double delayInSeconds = 0.2;
  107. dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
  108. dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
  109. //code to be executed on the main queue after delay
  110. [self saveTvChannels:channels firstTime:first];
  111. });
  112. }
  113. }
  114. -(void)getTvChannelWithId:(NSInteger)channelId delegate:(id)delegate
  115. {
  116. if (tvChannelsData != nil) {
  117. //DCMSG(tvChannelsData);
  118. [delegate performSelector:@selector(gotTvChannel:) withObject:[tvChannelsData objectForKey:[NSNumber numberWithInteger:channelId]]];
  119. } else {
  120. double delayInSeconds = 0.2;
  121. dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
  122. dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
  123. //code to be executed on the main queue after delay
  124. [self getTvChannelWithId:channelId delegate:delegate];
  125. });
  126. }
  127. }
  128. ///////////////////////////////
  129. -(void)getAllCountries:(NSString*)next
  130. {
  131. if (allCountriesData == nil || next != nil) {
  132. NSURL *endpoint;
  133. if (next == nil) {
  134. endpoint = [[wbAPI sharedAPI] urlWithEndpoint:kCOUNTRIESAPI];
  135. } else {
  136. endpoint = [NSURL URLWithString:next];
  137. }
  138. [[wbAPI sharedAPI] getJSONWithURL:endpoint
  139. response:^(id resultArray){
  140. if (allCountriesData == nil) {
  141. allCountriesData = [[NSMutableArray alloc] init];
  142. }
  143. numberOfCountries = [[resultArray valueForKey:@"count"] integerValue];
  144. [allCountriesData addObjectsFromArray:[resultArray objectForKey:@"results"]];
  145. if ([[resultArray objectForKey:@"next"] isKindOfClass:[NSString class]]) {
  146. [self getAllCountries:[resultArray objectForKey:@"next"]];
  147. }
  148. }];
  149. }
  150. }
  151. -(void)getAllCountries
  152. {
  153. if (allCountriesData == nil) {
  154. [self getAllCountries:nil];
  155. }
  156. }
  157. -(void)getCountriesData:(id)delegate
  158. {
  159. if (allCountriesData != nil && [allCountriesData count] >= numberOfCountries) {
  160. [delegate performSelector:@selector(gotCountries:) withObject:allCountriesData];
  161. } else {
  162. double delayInSeconds = 0.2;
  163. dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
  164. dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
  165. //code to be executed on the main queue after delay
  166. [self getCountriesData:delegate];
  167. });
  168. }
  169. }
  170. ///////////////////////////////
  171. -(void)getAllMissionFeeds
  172. {
  173. if ([[wbUser sharedUser] userReady] || [[wbAPI sharedAPI] is_guest]) {
  174. if ([[[[wbAPI sharedAPI] currentCountry] valueForKey:@"supported"] boolValue]) {
  175. [self getAllCountryMissionFeeds:[[[wbAPI sharedAPI] currentCountry] objectForKey:@"country"]];
  176. } else {
  177. [self getAllCountryMissionFeeds:@"ZZ"];
  178. }
  179. } else {
  180. double delayInSeconds = 0.2;
  181. dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
  182. dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
  183. //code to be executed on the main queue after delay
  184. [self getAllMissionFeeds];
  185. });
  186. }
  187. }
  188. -(void)getAllCountryMissionFeeds:(NSString*)country
  189. {
  190. if (missionsData == nil) {
  191. missionsData = [[NSMutableDictionary alloc] init];
  192. } else {
  193. [missionsData removeAllObjects];
  194. }
  195. selectedMissionCountry = country;
  196. NSString *missionCountry;
  197. missionCountry = [NSString stringWithFormat:@"%@,ZZ",country];
  198. NSMutableDictionary *active = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
  199. @"MISSIONS_ACTIVE_FEED",@"name",
  200. @"1",@"id",
  201. @"" ,@"icon_url",
  202. [NSString stringWithFormat:@"%@?country=%@",kACTIVEMISSIONAPI,missionCountry],@"endpoint",
  203. @"star.png",@"icon",
  204. @"missions",@"type",
  205. @"1",@"default",
  206. nil];
  207. NSMutableDictionary *archive = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
  208. @"MISSIONS_ARCHIVE_FEED",@"name",
  209. @"2",@"id",
  210. @"" ,@"icon_url",
  211. [NSString stringWithFormat:@"%@&country=%@",kOLDMISSIONAPI,missionCountry],@"endpoint",
  212. @"latest.png",@"icon",
  213. @"missions",@"type",
  214. @"0",@"default",
  215. nil];
  216. NSDictionary *defaultM = [[NSDictionary alloc] initWithDictionary:active];
  217. if (missionFeeds == nil) {
  218. missionFeeds = [[NSMutableDictionary alloc] init ];
  219. } else {
  220. [missionFeeds removeAllObjects];
  221. }
  222. [missionFeeds setObject:defaultM forKey:@"default"];
  223. [missionFeeds setObject:archive forKey:@"MISSIONS_ARCHIVE_FEED"];
  224. [missionFeeds setObject:active forKey:@"MISSIONS_ACTIVE_FEED"];
  225. //WithObjectsAndKeys:defaultM,@"default",active,@"MISSIONS_ACTIVE_FEED",archive,@"MISSIONS_ARCHIVE_FEED",nil];
  226. DCMSG(missionFeeds);
  227. [self getAllMissions];
  228. }
  229. -(void)getAllMissions
  230. {
  231. //missionsData = [[NSMutableDictionary alloc] init];
  232. NSAssert([missionFeeds objectForKey:@"default"] != nil, @"default missing");
  233. for (NSString* key in missionFeeds) {
  234. [[wbAPI sharedAPI] getJSONWithURL:[[wbAPI sharedAPI] urlWithEndpoint:[[missionFeeds objectForKey:key] objectForKey:@"endpoint"]]
  235. response:^(id resultArray){
  236. //NSAssert([missionFeeds objectForKey:@"default"] != nil, @"default missing");
  237. if (![key isEqualToString:@"default"]) {
  238. [missionsData setObject:[NSMutableDictionary dictionaryWithDictionary:resultArray] forKey:[[missionFeeds objectForKey:key] objectForKey:@"name"]];
  239. for (NSDictionary *dict in [resultArray objectForKey:@"results"]) {
  240. [self saveMission:dict];
  241. }
  242. }
  243. }];
  244. }
  245. }
  246. -(void)saveMission:(NSDictionary*)data
  247. {
  248. if (whambushMissions == nil) {
  249. whambushMissions = [[NSMutableDictionary alloc] init];
  250. }
  251. [self saveWhambushUser:[data objectForKey:@"added_by"]];
  252. if ([whambushMissions objectForKey:[NSNumber numberWithInteger:[[data objectForKey:@"id"] integerValue]]] == nil) {
  253. wbMission *mission = [[wbMission alloc] init];
  254. [mission setMissionWithDictionary:data];
  255. [whambushMissions setObject:mission forKey:[NSNumber numberWithInteger:[[data objectForKey:@"id"] integerValue]]];
  256. } else {
  257. [(wbMission*)[whambushMissions objectForKey:[NSNumber numberWithInteger:[[data objectForKey:@"id"] integerValue]]] setMissionWithDictionary:data];
  258. }
  259. }
  260. -(wbMission*)getMissionWithId:(NSNumber*)missionid
  261. {
  262. if (whambushMissions == nil) {
  263. whambushMissions = [[NSMutableDictionary alloc] init];
  264. }
  265. if ([whambushMissions objectForKey:missionid] == nil) {
  266. wbMission *mission = [[wbMission alloc] init];
  267. [[wbAPI sharedAPI] getJSONWithURL:[[wbAPI sharedAPI] urlWithEndpoint:[NSString stringWithFormat:@"%@%@/",kACTIVEMISSIONAPI,missionid]]
  268. response:^(id data){
  269. [mission setMissionWithDictionary:data];
  270. [whambushMissions setObject:mission forKey:[NSNumber numberWithInteger:[[data objectForKey:@"id"] integerValue]]];
  271. }];
  272. return mission;
  273. } else {
  274. return [whambushMissions objectForKey:missionid];
  275. }
  276. }
  277. -(void)refreshMissionData:(NSString*)name delegate:(id)delegate
  278. {
  279. if ([name isEqualToString:@"default"]) {
  280. if ([missionFeeds objectForKey:@"default"]) {
  281. name = [[missionFeeds objectForKey:@"default"] objectForKey:@"name"];
  282. }
  283. }
  284. NSString *endpoint = [[missionFeeds objectForKey:name] objectForKey:@"endpoint"];
  285. //NSAssert(endpoint != nil, @"Endpoint nil");
  286. if (endpoint != nil) {
  287. [[wbAPI sharedAPI] getJSONWithURL:[[wbAPI sharedAPI] urlWithEndpoint:endpoint]
  288. response:^(id resultArray){
  289. [missionsData setObject:resultArray forKey:name];
  290. for (NSDictionary *dict in [resultArray objectForKey:@"results"]) {
  291. [self saveMission:dict];
  292. }
  293. [self getMissionsData:name delegate:delegate];
  294. }];
  295. } else {
  296. [self getMissionsData:name delegate:delegate];
  297. }
  298. }
  299. -(void)getMissionsData:(NSString*)name delegate:(id)delegate
  300. {
  301. if ([name isEqualToString:@"default"] || name == nil) {
  302. if ([missionFeeds objectForKey:@"default"]) {
  303. name = [[missionFeeds objectForKey:@"default"] objectForKey:@"name"];
  304. } else {
  305. name = @"MISSIONS_ACTIVE_FEED";
  306. }
  307. }
  308. if ([missionsData objectForKey:name]) {
  309. if ([delegate respondsToSelector:@selector(setCurrentFeed:)]) {
  310. [delegate performSelector:@selector(setCurrentFeed:) withObject:[missionFeeds objectForKey:name]];
  311. }
  312. [delegate performSelector:@selector(dataReady:) withObject:[missionsData objectForKey:name]];
  313. } else {
  314. double delayInSeconds = 0.2;
  315. dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
  316. dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
  317. //code to be executed on the main queue after delay
  318. [self getMissionsData:name delegate:delegate];
  319. });
  320. }
  321. }
  322. ///////////////////////////////
  323. ///////////////////
  324. //
  325. //-(void)getRanking
  326. //{
  327. // NSString *urlString = @"http://178.62.88.135/1/code/rank";
  328. //
  329. // AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  330. // manager.requestSerializer = [AFJSONRequestSerializer serializer];
  331. // manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions: NSJSONReadingMutableContainers];
  332. //
  333. // manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json",nil];
  334. //
  335. // [manager.requestSerializer setValue:@"178.62.88.135" forHTTPHeaderField:@"X-Coronium-APP-ID"];
  336. // [manager.requestSerializer setValue:@"4a1739e8-6aac-47ea-86e2-1c1c22c3e4c2" forHTTPHeaderField:@"X-Coronium-API-KEY"];
  337. //
  338. // NSDictionary *parameters = [NSDictionary dictionaryWithObject:[[wbUser sharedUser] username] forKey:@"username"];
  339. //
  340. // [manager POST:urlString parameters:parameters
  341. // success:^(AFHTTPRequestOperation *operation, id responseObject) {
  342. // DCMSG(responseObject);
  343. // }
  344. // failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  345. // DCMSG(error);
  346. // }];
  347. //
  348. //}
  349. //
  350. ///////////////////
  351. -(void)getAllFeeds
  352. {
  353. [allFeedData removeAllObjects];
  354. [[wbAPI sharedAPI] getJSONWithURL:[[wbAPI sharedAPI] urlWithEndpoint:kFEEDSAPI]
  355. response:^(id resultArray){
  356. //DCMSG(resultArray);
  357. NSArray *rawFeeds = [resultArray objectForKey:@"results"];
  358. NSInteger count = [[resultArray valueForKey:@"count"] integerValue];
  359. NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
  360. for (int i = 0; i < count; i++) {
  361. NSMutableDictionary *content = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
  362. [[rawFeeds objectAtIndex:i] objectForKey:@"name"],@"name",
  363. [[rawFeeds objectAtIndex:i] objectForKey:@"id"],@"id",
  364. [[rawFeeds objectAtIndex:i] objectForKey:@"icon_url"],@"icon_url",
  365. [[[rawFeeds objectAtIndex:i] objectForKey:@"endpoint_url"]
  366. stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] ,@"endpoint",
  367. [self parseIcon:[[[rawFeeds objectAtIndex:i] objectForKey:@"default_icon"]integerValue]],@"icon",
  368. @"normal",@"type",
  369. nil];
  370. if ([[resultArray objectForKey:@"default"] integerValue] == [[[rawFeeds objectAtIndex:i] objectForKey:@"id"] integerValue]) {
  371. [content setObject:@"1" forKey:@"default"];
  372. [data setObject:content forKey:@"default"];
  373. } else {
  374. [content setObject:@"0" forKey:@"default"];
  375. }
  376. [data setObject:content forKey:[content objectForKey:@"name"]];
  377. }
  378. [self setFeeds:data];
  379. }];
  380. }
  381. -(void)setFeeds:(NSMutableDictionary*)_feeds
  382. {
  383. feeds = _feeds;
  384. DCMSG(feeds);
  385. if (allFeedData == nil) {
  386. allFeedData = [[NSMutableDictionary alloc] init];
  387. }
  388. for (NSString* key in feeds) {
  389. if (![key isEqualToString:@"default"]) {
  390. if ([[wbAPI sharedAPI] checkIfNetworkAvailable]) {
  391. [[wbAPI sharedAPI] getJSONWithURL:[[wbAPI sharedAPI] urlWithEndpoint:[[feeds objectForKey:key] objectForKey:@"endpoint"]]
  392. response:^(id resultArray){
  393. [allFeedData setObject:resultArray forKey:key];
  394. //DCMSG(allFeedData);
  395. }];
  396. }
  397. }
  398. }
  399. }
  400. //-(NSMutableDictionary*)videoResultArray:(NSMutableDictionary*)resultArray
  401. //{
  402. // NSMutableDictionary *tmpDictionary = [[NSMutableDictionary alloc] initWithDictionary:resultArray];
  403. // //[tmpDictionary removeObjectForKey:@"results"];
  404. // NSArray *data = [resultArray objectForKey:@"results"];
  405. // NSInteger count = [[resultArray objectForKey:@"results"] count];
  406. // NSMutableArray *tmpArray = [[NSMutableArray alloc] init];
  407. // for (int i = 0; i < count; i++) {
  408. // [tmpArray addObject:[wbVideo initVideoObjectWithData:[data objectAtIndex:i]]];
  409. // }
  410. // [tmpDictionary setObject:tmpArray forKey:@"videos"];
  411. //
  412. // return tmpDictionary;
  413. //}
  414. -(void)refreshFeedData:(NSString*)name delegate:(id)delegate
  415. {
  416. NSString *endpoint = [[feeds objectForKey:name] objectForKey:@"endpoint"];
  417. [allFeedData removeObjectForKey:name];
  418. [[wbAPI sharedAPI] getJSONWithURL:[[wbAPI sharedAPI] urlWithEndpoint:endpoint]
  419. response:^(id resultArray){
  420. [allFeedData setObject:resultArray forKey:name];
  421. if (delegate != nil) {
  422. [self getFeedData:name delegate:delegate];
  423. }
  424. }];
  425. }
  426. -(void)getFeedData:(NSString*)name delegate:(id)delegate
  427. {
  428. if ([name isEqualToString:@"default"]) {
  429. if ([feeds objectForKey:@"default"]) {
  430. name = [[feeds objectForKey:@"default"] objectForKey:@"name"];
  431. }
  432. }
  433. if ([allFeedData objectForKey:name]) {
  434. [delegate performSelector:@selector(setCurrentFeed:) withObject:[feeds objectForKey:name]];
  435. [delegate performSelector:@selector(dataReady:) withObject:[allFeedData objectForKey:name]];
  436. } else {
  437. double delayInSeconds = 0.2;
  438. dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
  439. dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
  440. //code to be executed on the main queue after delay
  441. [self getFeedData:name delegate:delegate];
  442. });
  443. }
  444. }
  445. ///////////////////////////////
  446. -(void)getAllActivity
  447. {
  448. [self refreshActivityData:nil];
  449. }
  450. -(void)refreshActivityData:(id)delegate
  451. {
  452. [[wbAPI sharedAPI] getJSONWithURL:[[wbAPI sharedAPI] urlWithEndpoint:kACTIVITYAPI]
  453. response:^(id resultArray){
  454. activityData = [NSMutableDictionary dictionaryWithDictionary:resultArray];
  455. //DCMSG(activityData);
  456. if (delegate != nil) {
  457. [self getActivityData:delegate];
  458. }
  459. }];
  460. }
  461. -(void)getActivityData:(id)delegate
  462. {
  463. if (activityData != nil) {
  464. [delegate performSelector:@selector(dataReady:) withObject:activityData];
  465. } else {
  466. [self performSelector:@selector(getActivityData:) withObject:delegate afterDelay:1];
  467. }
  468. }
  469. ///////////////////////////////
  470. -(NSString*)parseIcon:(NSInteger)number
  471. {
  472. NSString *iconName;
  473. switch (number) {
  474. case 1:
  475. iconName = @"following.png";
  476. break;
  477. case 2:
  478. iconName = @"popular.png";
  479. break;
  480. case 3:
  481. iconName = @"latest.png";
  482. break;
  483. case 4:
  484. iconName = @"myvideos.png";
  485. break;
  486. case 5:
  487. iconName = @"star.png";
  488. break;
  489. case 6:
  490. iconName = @"eye.png";
  491. break;
  492. case 7:
  493. iconName = @"banana_active.png";
  494. break;
  495. case 8:
  496. iconName = @"shit_active.png";
  497. break;
  498. case 9:
  499. iconName = @"wait.png";
  500. break;
  501. case 10:
  502. iconName = @"random.png";
  503. break;
  504. case 11:
  505. iconName = @"tv_feed.png";
  506. break;
  507. default:
  508. iconName = @"default_icon.png";
  509. break;
  510. }
  511. return iconName;
  512. }
  513. ///////////////////////////////
  514. -(void)saveWhambushUser:(NSDictionary*)userArray
  515. {
  516. if (whambushUsers == nil) {
  517. whambushUsers = [[NSMutableDictionary alloc] init];
  518. if (![[wbAPI sharedAPI] is_guest]) {
  519. [whambushUsers setObject:[wbUser sharedUser] forKey:[[wbUser sharedUser] userURL]];
  520. }
  521. }
  522. if ([whambushUsers objectForKey:[userArray objectForKey:@"url"]] == nil)
  523. {
  524. wbUser *user = [[wbUser alloc] init];
  525. //[user setUserDetails:userArray];
  526. [user performSelectorOnMainThread:@selector(setUserDetails:) withObject:userArray waitUntilDone:YES];
  527. [whambushUsers setObject:user forKey:[NSString stringWithString:[userArray objectForKey:@"url"]]];
  528. }
  529. }
  530. -(wbUser*)getWhambushUser:(NSString*)path
  531. {
  532. //DCMSG(whambushUsers);
  533. if (whambushUsers == nil) {
  534. whambushUsers = [[NSMutableDictionary alloc] init];
  535. if (![[wbAPI sharedAPI] is_guest]) {
  536. [whambushUsers setObject:[wbUser sharedUser] forKey:[[wbUser sharedUser] userURL]];
  537. }
  538. }
  539. if ([whambushUsers objectForKey:path] == nil)
  540. {
  541. wbUser *user = [[wbUser alloc] init];
  542. [user getUserData:path];
  543. [whambushUsers setObject:user forKey:[NSString stringWithString:path]];
  544. return user;
  545. } else {
  546. return [whambushUsers objectForKey:path];
  547. }
  548. }
  549. -(wbUser*)getWhambushUserWithId:(NSInteger)userid
  550. {
  551. NSString *path = [NSString stringWithFormat:@"%@/users/%ld/",kWHAMBUSHAPIURL,(long)userid];
  552. return [self getWhambushUser:path];
  553. }
  554. -(wbUser*)getWhambushUserWithUsername:(NSString*)username
  555. {
  556. wbUser *user = [[wbUser alloc] init];
  557. [[wbAPI sharedAPI] getJSONWithURL:[[wbAPI sharedAPI] urlWithEndpoint:[NSString stringWithFormat:kUSERSEARCHAPI,username]] response:^(id data){
  558. [user setUserDetails:[[data objectForKey:@"results"] firstObject]];
  559. [self saveWhambushUser:[[data objectForKey:@"results"] firstObject]];
  560. }];
  561. return user;
  562. //NSString *path = [NSString stringWithFormat:@"%@/users/%ld/",kWHAMBUSHAPIURL,(long)userid];
  563. //return [self getWhambushUser:path];
  564. }
  565. //-(void)saveVideo:(NSDictionary*)data
  566. //{
  567. // if (allVideoData == nil) {
  568. // allVideoData = [[NSMutableDictionary alloc] init];
  569. // }
  570. // if ([allVideoData objectForKey:[data objectForKey:@"id"]] == nil) {
  571. // [allVideoData setObject:[wbVideo initVideoObjectWithData:data] forKey:[data objectForKey:@"id"]];
  572. // }
  573. //}
  574. //
  575. //-(wbVideo*)getVideoWithId:(NSNumber*)videoid
  576. //{
  577. // if (allVideoData == nil) {
  578. // allVideoData = [[NSMutableDictionary alloc] init];
  579. // }
  580. // if ([allVideoData objectForKey:@"vidoid"] == nil) {
  581. // [allVideoData setObject:[wbVideo initVideoObjectWithId:[videoid integerValue]] forKey:videoid];
  582. // }
  583. // return [allVideoData objectForKey:videoid];
  584. //}
  585. //
  586. //////////////
  587. -(void)clearUserData
  588. {
  589. [whambushUsers removeAllObjects];
  590. whambushUsers= nil;
  591. }
  592. -(void)clearData
  593. {
  594. /* [whambushUsers removeAllObjects];
  595. whambushUsers = nil;
  596. [singleVideoData removeAllObjects];
  597. singleVideoData = nil;
  598. [activityData removeAllObjects];
  599. activityData = nil;
  600. [missionsData removeAllObjects];
  601. missionsData = nil;
  602. [allFeedData removeAllObjects];
  603. allFeedData = nil;
  604. // [fetching removeAllObjects];
  605. // fetching = nil;
  606. [feeds removeAllObjects];
  607. feeds = nil;
  608. [missionFeeds removeAllObjects];
  609. missionFeeds = nil;
  610. // hasMissions = NO;
  611. // hasUserpage = NO;
  612. supportMessage = @"";
  613. */
  614. }
  615. -(void)clearMemory
  616. {
  617. /* if (whambushUsers != nil) {
  618. DCMSG(@"clearMemory - users");
  619. whambushUsers = nil;
  620. }*/
  621. }
  622. -(NSDictionary*)tvFeed
  623. {
  624. NSMutableDictionary *feed = [NSMutableDictionary dictionaryWithObjectsAndKeys:
  625. [NSString stringWithFormat:@"%@?type=tv",kVIDEOAPI],@"endpoint",
  626. [NSNumber numberWithInteger:18],@"id",
  627. [NSNumber numberWithInteger:0],@"default",
  628. @"WhambushTV",@"name",
  629. @"tv_feed.png",@"icon",
  630. @"TV",@"type",
  631. nil];
  632. return feed;
  633. }
  634. //-(NSString*)deviceType
  635. //{
  636. // struct utsname systemInfo;
  637. // uname(&systemInfo);
  638. //
  639. // //NSString *version = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
  640. // //NSString *devicesystemv = [UIDevice currentDevice].systemVersion;
  641. //
  642. // return [NSString stringWithFormat:@"%@ %@",[NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding],[UIDevice currentDevice].systemVersion];
  643. //}
  644. -(void)createSupportMessage:(NSDictionary*)loginInfo
  645. {
  646. NSString *tmp = [NSString stringWithFormat:@"\n\n-----info to support don't remove-----\n %@\n %@\n %@\n %@\n %@\n %@\n-----------------",
  647. [loginInfo objectForKey:@"username"],
  648. [loginInfo objectForKey:@"manufacturer"],
  649. [loginInfo objectForKey:@"os"],
  650. [loginInfo objectForKey:@"os_version"],
  651. [loginInfo objectForKey:@"device"],
  652. [loginInfo objectForKey:@"whambush_version"]];
  653. supportMessage = tmp;
  654. }
  655. //username,@"username",
  656. //password,@"password",
  657. //@"Apple",@"manufacturer",
  658. //@"iOS",@"os",
  659. //[UIDevice currentDevice].systemVersion,@"os_version",
  660. //[NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding],@"device",
  661. //[[NSUserDefaults standardUserDefaults] objectForKey:@"version"],@"whambush_version",
  662. //guest_id,@"guest_id",
  663. @end