UserInfoViewController.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "UserInfoViewController.h"
  17. #import "FIRUser.h"
  18. #import "FIRUserInfo.h"
  19. #import "StaticContentTableViewManager.h"
  20. /** @fn stringWithBool
  21. @brief Converts a boolean value to a string for display.
  22. @param boolValue the boolean value.
  23. @return The string form of the boolean value.
  24. */
  25. static NSString *stringWithBool(BOOL boolValue) {
  26. return boolValue ? @"YES" : @"NO";
  27. }
  28. @implementation UserInfoViewController {
  29. FIRUser *_user;
  30. }
  31. - (instancetype)initWithUser:(FIRUser *)user {
  32. self = [super initWithNibName:NSStringFromClass([self class]) bundle:nil];
  33. if (self) {
  34. _user = user;
  35. }
  36. return self;
  37. }
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. [self loadTableView];
  41. }
  42. - (void)loadTableView {
  43. NSMutableArray<StaticContentTableViewSection *> *sections = [@[
  44. [StaticContentTableViewSection sectionWithTitle:@"User" cells:@[
  45. [StaticContentTableViewCell cellWithTitle:@"anonymous" value:stringWithBool(_user.anonymous)],
  46. [StaticContentTableViewCell cellWithTitle:@"emailVerified"
  47. value:stringWithBool(_user.emailVerified)],
  48. [StaticContentTableViewCell cellWithTitle:@"refreshToken" value:_user.refreshToken],
  49. ]]
  50. ] mutableCopy];
  51. [sections addObject:[self sectionWithUserInfo:_user]];
  52. for (id<FIRUserInfo> userInfo in _user.providerData) {
  53. [sections addObject:[self sectionWithUserInfo:userInfo]];
  54. }
  55. _tableViewManager.contents = [StaticContentTableViewContent contentWithSections:sections];
  56. }
  57. - (StaticContentTableViewSection *)sectionWithUserInfo:(id<FIRUserInfo>)userInfo {
  58. return [StaticContentTableViewSection sectionWithTitle:userInfo.providerID cells:@[
  59. [StaticContentTableViewCell cellWithTitle:@"uid" value:userInfo.uid],
  60. [StaticContentTableViewCell cellWithTitle:@"displayName" value:userInfo.displayName],
  61. [StaticContentTableViewCell cellWithTitle:@"photoURL" value:[userInfo.photoURL absoluteString]],
  62. [StaticContentTableViewCell cellWithTitle:@"email" value:userInfo.email],
  63. [StaticContentTableViewCell cellWithTitle:@"phoneNumber" value:userInfo.phoneNumber]
  64. ]];
  65. }
  66. - (IBAction)done:(id)sender {
  67. [self dismissViewControllerAnimated:YES completion:nil];
  68. }
  69. @end