DemoData.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright 2016 Google LLC. All rights reserved.
  3. *
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
  6. * file except in compliance with the License. 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 distributed under
  11. * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
  12. * ANY KIND, either express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #import "GooglePlacesDemos/DemoData.h"
  16. #import "GooglePlacesDemos/Samples/Autocomplete/AutocompleteModalViewController.h"
  17. #import "GooglePlacesDemos/Samples/Autocomplete/AutocompletePushViewController.h"
  18. #import "GooglePlacesDemos/Samples/Autocomplete/AutocompleteWithCustomColors.h"
  19. #import "GooglePlacesDemos/Samples/Autocomplete/AutocompleteWithSearchViewController.h"
  20. #import "GooglePlacesDemos/Samples/Autocomplete/AutocompleteWithTextFieldController.h"
  21. #import "GooglePlacesDemos/Samples/FindPlaceLikelihoodListViewController.h"
  22. #import "GooglePlacesDemos/Support/BaseDemoViewController.h"
  23. @implementation Demo {
  24. Class _viewControllerClass;
  25. }
  26. - (instancetype)initWithViewControllerClass:(Class)viewControllerClass {
  27. if ((self = [self init])) {
  28. _title = [viewControllerClass demoTitle];
  29. _viewControllerClass = viewControllerClass;
  30. }
  31. return self;
  32. }
  33. - (UIViewController *)createViewControllerWithAutocompleteFilter:
  34. (GMSAutocompleteFilter *)autocompleteFilter
  35. placeFields:(GMSPlaceField)placeFields {
  36. // Construct the demo view controller.
  37. UIViewController *demoViewController = [[_viewControllerClass alloc] init];
  38. // Pass the place fields to the view controller for these classes.
  39. if ([demoViewController isKindOfClass:[AutocompleteBaseViewController class]]) {
  40. AutocompleteBaseViewController *controller =
  41. (AutocompleteBaseViewController *)demoViewController;
  42. controller.autocompleteFilter = autocompleteFilter;
  43. controller.placeFields = placeFields;
  44. }
  45. return demoViewController;
  46. }
  47. @end
  48. @implementation DemoSection
  49. - (instancetype)initWithTitle:(NSString *)title demos:(NSArray<Demo *> *)demos {
  50. if ((self = [self init])) {
  51. _title = [title copy];
  52. _demos = [demos copy];
  53. }
  54. return self;
  55. }
  56. @end
  57. @implementation DemoData
  58. - (instancetype)init {
  59. if ((self = [super init])) {
  60. NSArray<Demo *> *autocompleteDemos = @[
  61. [[Demo alloc] initWithViewControllerClass:[AutocompleteWithCustomColors class]],
  62. [[Demo alloc] initWithViewControllerClass:[AutocompleteModalViewController class]],
  63. [[Demo alloc] initWithViewControllerClass:[AutocompletePushViewController class]],
  64. [[Demo alloc] initWithViewControllerClass:[AutocompleteWithSearchViewController class]],
  65. [[Demo alloc] initWithViewControllerClass:[AutocompleteWithTextFieldController class]],
  66. ];
  67. NSArray<Demo *> *findPlaceLikelihoodDemos = @[ [[Demo alloc]
  68. initWithViewControllerClass:[FindPlaceLikelihoodListViewController class]] ];
  69. _sections = @[
  70. [[DemoSection alloc]
  71. initWithTitle:NSLocalizedString(@"Demo.Section.Title.Autocomplete",
  72. @"Title of the autocomplete demo section")
  73. demos:autocompleteDemos],
  74. [[DemoSection alloc]
  75. initWithTitle:NSLocalizedString(@"Demo.Section.Title.FindPlaceLikelihood",
  76. @"Title of the findPlaceLikelihood demo section")
  77. demos:findPlaceLikelihoodDemos]
  78. ];
  79. }
  80. return self;
  81. }
  82. - (Demo *)firstDemo {
  83. return _sections[0].demos[0];
  84. }
  85. @end