Today's Menu  Portugal
journal and plan nutrition
Instance Methods | Properties | List of all members
T1HealthKitViewController Class Reference

#import <T1HealthKitViewController.h>

Inheritance diagram for T1HealthKitViewController:
Inheritance graph
[legend]
Collaboration diagram for T1HealthKitViewController:
Collaboration graph
[legend]

Instance Methods

(void) - viewDidLoad [implementation]
 
(NSInteger) - numberOfSectionsInTableView: [implementation]
 
(NSInteger) - tableView:numberOfRowsInSection: [implementation]
 
(UITableViewCell *) - tableView:cellForRowAtIndexPath: [implementation]
 
(NSString *) - tableView:titleForHeaderInSection: [implementation]
 
(void) - tableView:didSelectRowAtIndexPath: [implementation]
 
(void) - healthQuantityTypeData:success: [implementation]
 
(void) - updateToAuthorizationOK [implementation]
 
(NSArray< NSDictionary *> *) - authorityConditionSections [implementation]
 
(void) - didReceiveMemoryWarning [implementation]
 

Properties

NSDateFormatter * mDateFormatter [implementation]
 

Detailed Description

Definition at line 12 of file T1HealthKitViewController.h.

Method Documentation

◆ authorityConditionSections()

- (NSArray< NSDictionary * > *) authorityConditionSections
implementation

this method returns an array of dictionaries. Each dictionary consists of a status caption, whether not-determined ("non questioned"), sharing-denied ("denied"), or sharing-approved ("shared"), and an array of nutrition component names of nutrition components of that status.

Definition at line 169 of file T1HealthKitViewController.m.

170 {
171  int notDetermined = 0;
172  int itemDenied = 0;
173  int itemAuthorized = 0;
174  NSMutableArray<NSMutableDictionary *> *notDeterminedTypes = [[NSMutableArray alloc] init];
175  NSMutableArray<NSMutableDictionary *> *deniedTypes = [[NSMutableArray alloc] init];
176  NSMutableArray<NSMutableDictionary *> *allowedTypes = [[NSMutableArray alloc] init];
177  // AT THIS POINT I NEED THE LAST CHANGE TO THE COMPONENT AUTHORITY
178  for (NSDictionary *compo in updatedAuthorityStatus) {
179  NSNumber *authorityData = [compo objectForKey:[Z5LocalDataController componentAuthorityKey]];
180  NSString *nameData = [compo objectForKey:[Z5LocalDataController componentNameKey]];
181  NSDate *dateData = [compo objectForKey:[Z5LocalDataController componentAuthorityDateKey]];
182 
183  // in lieu of a string 'name', compose a dictionary with 'name' and 'date'
184  NSMutableDictionary *componentData = [[NSMutableDictionary alloc] init];
185  [componentData setObject:nameData forKey:@"component-name"];
186  [componentData setObject:dateData forKey:@"component-authority-date"];
187  // END - in lieu of a string 'name', compose a dictionary with 'name' and 'date'
188  HKAuthorizationStatus status = [authorityData integerValue];
189  switch (status) {
190  case HKAuthorizationStatusNotDetermined:
191  // [notDeterminedTypes addObject:nameData];
192  [notDeterminedTypes addObject:componentData];
193  notDetermined++;
194  break;
195  case HKAuthorizationStatusSharingDenied:
196  // [deniedTypes addObject:nameData];
197  [deniedTypes addObject:componentData];
198  itemDenied++;
199  break;
200  case HKAuthorizationStatusSharingAuthorized:
201  // [allowedTypes addObject:nameData];
202  [allowedTypes addObject:componentData];
203  itemAuthorized++;
204  break;
205  } // end switch
206  }
207  NSMutableArray<NSDictionary *> *ret = [[NSMutableArray alloc] initWithCapacity:3];
208  NSNumber *statusNumb;
209  if (0 < notDetermined)
210  {
211  statusNumb = [NSNumber numberWithInt:HKAuthorizationStatusNotDetermined];
212  // statusCount = [NSNumber numberWithInt:notDetermined];
213  NSArray *statusTypes = [[NSArray alloc] initWithArray:notDeterminedTypes];
214  NSDictionary *notDeterminedElement = [[NSDictionary alloc] initWithObjectsAndKeys:@"not deteermined", @"HKAuthority-status-ident", statusTypes, @"HKAuthority-status-types", nil];
215  [ret addObject:notDeterminedElement];
216  }
217  if (0 < itemDenied)
218  {
219  statusNumb = [NSNumber numberWithInt:HKAuthorizationStatusSharingDenied];
220  // statusCount = [NSNumber numberWithInt:notDetermined];
221  NSArray *statusTypes = [[NSArray alloc] initWithArray:deniedTypes];
222  NSDictionary *sharingDeniedElement = [[NSDictionary alloc] initWithObjectsAndKeys:@"denied", @"HKAuthority-status-ident", statusTypes, @"HKAuthority-status-types", nil];
223  [ret addObject:sharingDeniedElement];
224  }
225  if (0 < itemAuthorized)
226  {
227  statusNumb = [NSNumber numberWithInt:HKAuthorizationStatusSharingAuthorized];
228  // statusCount = [NSNumber numberWithInt:notDetermined];
229  NSArray *statusTypes = [[NSArray alloc] initWithArray:allowedTypes];
230  NSDictionary *sharingApprovedElement = [[NSDictionary alloc] initWithObjectsAndKeys:@"authorized", @"HKAuthority-status-ident", statusTypes, @"HKAuthority-status-types", nil];
231  [ret addObject:sharingApprovedElement];
232  }
233  return ret;
234 }
NSMutableArray< NSDictionary * > * updatedAuthorityStatus

◆ didReceiveMemoryWarning()

- (void) didReceiveMemoryWarning
implementation

Definition at line 238 of file T1HealthKitViewController.m.

238  {
239  [super didReceiveMemoryWarning];
240  // Dispose of any resources that can be recreated.
241 }

◆ healthQuantityTypeData:success:()

- (void) healthQuantityTypeData: (HKQuantityType *)  quantityType
success: (Boolean)  flag 
implementation

Definition at line 154 of file T1HealthKitViewController.m.

154  : (HKQuantityType *)quantityType success: (Boolean) flag
155 {
156 
157 }

◆ numberOfSectionsInTableView:()

- (NSInteger) numberOfSectionsInTableView: (UITableView *)  tableView
implementation

Definition at line 81 of file T1HealthKitViewController.m.

81  :(UITableView *)tableView
82 {
83  Z5LocalDataController *localData = [[Z5DataController sharedInstance] localDataController];
84  updatedAuthorityStatus = [localData annotateAuthority:componentsAuthorityStatus];
85  /*
86  * the updated-authority-status is an array of dictionaries with good authority
87  * status inside. Count how many different authority conditions there are.
88  */
89  NSArray *authorityConditionArray = [self authorityConditionSections];
90  NSInteger nSections = [authorityConditionArray count];
91  NSLog(@"healthKitView.numberOfSectionsInTableView: nSections: %ld", (long)nSections);
92  return nSections;
93 }
instancetype sharedInstance()
NSMutableArray< NSDictionary * > * updatedAuthorityStatus
Singleton interface to both core and remote data sources.
NSMutableArray * annotateAuthority:(NSArray *componentArray)

◆ tableView:cellForRowAtIndexPath:()

- (UITableViewCell *) tableView: (UITableView *)  tableView
cellForRowAtIndexPath: (NSIndexPath *)  indexPath 
implementation

Definition at line 104 of file T1HealthKitViewController.m.

104  :(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
105 {
106 
107  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"health-kit-categories"];
108  if (cell == nil) {
109  cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"health-kit-categories"];
110  // cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
111  }
112 
113  NSString *caption;
114  NSString *detailCaption;
115  NSDictionary *sectionDictionary = [[self authorityConditionSections] objectAtIndex:[indexPath section]];
116  NSArray *sectionItems = [sectionDictionary objectForKey:@"HKAuthority-status-types"];
117  if ([indexPath row] < [sectionItems count]) {
118  // caption = [sectionItems objectAtIndex:[indexPath row]];
119  // detailCaption = @"detail";
120 
121  NSDictionary *rowInfo = [sectionItems objectAtIndex:[indexPath row]];
122  caption = [rowInfo objectForKey:@"component-name"];
123  NSDate *authorityDate = [rowInfo objectForKey:@"component-authority-date"];
124  detailCaption = [_mDateFormatter stringFromDate:authorityDate];
125 
126  }
127 
128  [Z5DataController labelizeCell:cell withText:caption inColor:[UIColor brownColor] andDetail:detailCaption];
129 
130  return cell;
131 }
Singleton interface to both core and remote data sources.
void labelizeCell:withText:inColor:andDetail:(UITableViewCell *targCell, [withText] NSString *txt, [inColor] UIColor *color, [andDetail] NSString *detailTxt)

◆ tableView:didSelectRowAtIndexPath:()

- (void) tableView: (UITableView *)  tableView
didSelectRowAtIndexPath: (NSIndexPath *)  indexPath 
implementation

Definition at line 142 of file T1HealthKitViewController.m.

142  :(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
143 {
144  // Z5LocalDataController *localData = [[Z5DataController sharedInstance] localDataController];
145 
146  NSLog(@"HealthKitVIew.didSelectRow: section: %ld row: %ld\nset: %@", (long)[indexPath section], (long)[indexPath row], needAuthorizationSet);
147 
148  // modify the following to get only the component identified with the row
149  // this pops up the healthkei screen if any component (?) is unquestioned
150  // [localData getAddedAuthorizationToShare:needAuthorizationSet forDelegate:self];
151 
152 }
NSMutableSet * needAuthorizationSet

◆ tableView:numberOfRowsInSection:()

- (NSInteger) tableView: (UITableView *)  tableView
numberOfRowsInSection: (NSInteger)  section 
implementation

Definition at line 94 of file T1HealthKitViewController.m.

94  :(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
95 {
96  NSLog(@"healthKitView.numberOfSectionsInTableView");
97  NSDictionary *sectionDictionary = [[self authorityConditionSections] objectAtIndex:section];
98 
99  NSArray *sectionComponentCount = [sectionDictionary objectForKey:@"HKAuthority-status-types"];
100  NSInteger sectionCount = [sectionComponentCount count];
101  NSLog(@"healthKitView.numberOfSectionsInTableView: sectionCount: %ld", (long)sectionCount);
102  return sectionCount;
103 }

◆ tableView:titleForHeaderInSection:()

- (NSString *) tableView: (UITableView *)  tableView
titleForHeaderInSection: (NSInteger)  section 
implementation

Definition at line 134 of file T1HealthKitViewController.m.

134  :(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
135 {
136  NSDictionary *sectionDictionary = [[self authorityConditionSections] objectAtIndex:section];
137  NSString *sectionName = [sectionDictionary objectForKey:@"HKAuthority-status-ident"];
138 
139  return sectionName;
140 }

◆ updateToAuthorizationOK()

- (void) updateToAuthorizationOK
implementation

Definition at line 158 of file T1HealthKitViewController.m.

159 {
160 
161 }

◆ viewDidLoad()

- (void) viewDidLoad
implementation

Definition at line 23 of file T1HealthKitViewController.m.

23  {
24  [super viewDidLoad];
25  // Do any additional setup after loading the view.
26  Z5LocalDataController *localData = [[Z5DataController sharedInstance] localDataController];
27 
28  _mDateFormatter = [[NSDateFormatter alloc] init];
29  [_mDateFormatter setDateStyle:NSDateFormatterMediumStyle];
30  [_mDateFormatter setTimeStyle:NSDateFormatterNoStyle];
31 
32  // fetch, scale, and add a subview background image
33  UIImage *backgrdImage = [UIImage imageNamed:@"HealthKit.png"];
34  CGSize photoSize = [backgrdImage size];
35  CGRect totalFrame = self.view.frame;
36  float resizeRatio = photoSize.width / totalFrame.size.width;
37  UIImage *resizedImage = [UIImage imageWithCGImage:[backgrdImage CGImage]
38  scale:backgrdImage.scale * resizeRatio
39  orientation:(backgrdImage.imageOrientation) ];
40  UIImageView *backgrd = [[UIImageView alloc] initWithImage:resizedImage];
41  [self.view addSubview:backgrd];
42  // end - fetch, scale, and add a subview background image
43 
44  // data source and delegate connect
45  self.tableView.delegate = self;
46  self.tableView.dataSource = self;
47 
48  componentsAuthorityStatus = [[NSMutableArray alloc] init];
49  needAuthorizationSet = [[NSMutableSet alloc] init];
50  Boolean needsAdditionalAuthority = NO;
51  for (NSString *param in [localData establishNutritionParameters]) {
52  HKQuantityType *rowQuantityType = [HKObjectType quantityTypeForIdentifier:param];
53  [needAuthorizationSet addObject:rowQuantityType];
54  needsAdditionalAuthority = YES;
55 
56  NSString *shortName = [param substringFromIndex:31];
57  NSDictionary *authorityEntry = [[NSDictionary alloc] initWithObjectsAndKeys:shortName, [Z5LocalDataController componentNameKey], nil];
58  [componentsAuthorityStatus addObject:authorityEntry];
59  }
60  /*
61  * these lines cool well and try to get approval, however it keeps all future
62  * requests leaving the user picking the way through 'Health' app
63  - if (needsAdditionalAuthority) {
64  - [localData getAddedAuthorizationToShare:needAuthorizationSet forDelegate:self];
65  - } */
66 
67  for (NSString *param in [localData establishNutritionParameters]) {
68 
69  HKQuantityType *rowQuantityType = [HKObjectType quantityTypeForIdentifier:param];
70 
71  // get new authority info
72  if (rowQuantityType) {
73  NSNumber *shareOK = [localData checkTypeAuthorization:rowQuantityType];
74  NSLog(@"healthKitView.viewDidLoad: param: %@ shareOk: %@", param, shareOK);
75  }
76  }
77  [self.tableView reloadData];
78 }
NSMutableSet * needAuthorizationSet
instancetype sharedInstance()
NSMutableArray< NSDictionary * > * componentsAuthorityStatus
NSNumber * checkTypeAuthorization:(HKQuantityType *quantityType)
Singleton interface to both core and remote data sources.

Property Documentation

◆ mDateFormatter

- (NSDateFormatter*) mDateFormatter
readwritenonatomicstrongimplementation

Definition at line 13 of file T1HealthKitViewController.m.


The documentation for this class was generated from the following files: