host_setup_view_controller.mm 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #import "remoting/ios/app/host_setup_view_controller.h"
  5. #import <MaterialComponents/MaterialShadowElevations.h>
  6. #import <MaterialComponents/MaterialShadowLayer.h>
  7. #import "remoting/ios/app/host_setup_header_view.h"
  8. #import "remoting/ios/app/host_setup_view_cell.h"
  9. #include "base/strings/string_split.h"
  10. #include "base/strings/sys_string_conversions.h"
  11. #include "remoting/base/string_resources.h"
  12. #include "ui/base/l10n/l10n_util.h"
  13. #if !defined(__has_feature) || !__has_feature(objc_arc)
  14. #error "This file requires ARC support."
  15. #endif
  16. static NSString* const kInstallationLink = @"remotedesktop.google.com/access";
  17. static NSString* const kHostSetupViewCellIdentifierItem =
  18. @"HostSetupViewCellIdentifier";
  19. static NSString* const kHeaderViewIdentifierItem =
  20. @"HostSetupHeaderViewIdentifier";
  21. static const CGFloat kEstimatedRowHeight = 88.f;
  22. @interface HostSetupViewController () {
  23. NSArray<NSString*>* _setupSteps;
  24. }
  25. @end
  26. @implementation HostSetupViewController
  27. @synthesize scrollViewDelegate = _scrollViewDelegate;
  28. #pragma mark - UIViewController
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. self.tableView.allowsSelection = NO;
  32. self.tableView.backgroundColor = UIColor.clearColor;
  33. self.tableView.estimatedRowHeight = kEstimatedRowHeight;
  34. self.tableView.rowHeight = UITableViewAutomaticDimension;
  35. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  36. // Implement the header as a cell instead of a section header so that it
  37. // doesn't float on the top.
  38. [self.tableView registerClass:[HostSetupHeaderView class]
  39. forCellReuseIdentifier:kHeaderViewIdentifierItem];
  40. [self.tableView registerClass:[HostSetupViewCell class]
  41. forCellReuseIdentifier:kHostSetupViewCellIdentifierItem];
  42. _setupSteps = @[
  43. base::SysUTF8ToNSString(l10n_util::GetStringFUTF8(
  44. IDS_HOST_SETUP_STEP_1, base::SysNSStringToUTF16(kInstallationLink))),
  45. base::SysUTF8ToNSString(l10n_util::GetStringUTF8(IDS_HOST_SETUP_STEP_2)),
  46. base::SysUTF8ToNSString(l10n_util::GetStringUTF8(IDS_HOST_SETUP_STEP_3))
  47. ];
  48. }
  49. #pragma mark - UITableViewDataSource
  50. - (NSInteger)tableView:(UITableView*)tableView
  51. numberOfRowsInSection:(NSInteger)section {
  52. // Number of steps + header.
  53. return _setupSteps.count + 1;
  54. }
  55. - (UITableViewCell*)tableView:(UITableView*)tableView
  56. cellForRowAtIndexPath:(NSIndexPath*)indexPath {
  57. if (indexPath.item == 0) {
  58. // Header.
  59. return
  60. [tableView dequeueReusableCellWithIdentifier:kHeaderViewIdentifierItem
  61. forIndexPath:indexPath];
  62. }
  63. HostSetupViewCell* cell = [tableView
  64. dequeueReusableCellWithIdentifier:kHostSetupViewCellIdentifierItem
  65. forIndexPath:indexPath];
  66. NSInteger stepIndex = indexPath.item - 1;
  67. NSString* contentText = _setupSteps[stepIndex];
  68. [cell setContentText:contentText number:stepIndex + 1];
  69. return cell;
  70. }
  71. #pragma mark - UIScrollViewDelegate
  72. - (void)scrollViewDidScroll:(UIScrollView*)scrollView {
  73. [_scrollViewDelegate scrollViewDidScroll:scrollView];
  74. }
  75. @end