PDFSettingsViewController.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. //
  2. // PDFSettingsViewController.m
  3. // PDFReader
  4. //
  5. // Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // The PDF Reader Sample applications are licensed with a modified BSD license.
  8. // Please see License for details. This notice may not be removed from this file.
  9. //
  10. #import "PDFSettingsViewController.h"
  11. #import "PDFSettingsValueViewController.h"
  12. #import <ComPDFKit/ComPDFKit.h>
  13. @interface PDFSettingsViewController () <UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
  14. @property (nonatomic,retain) UITableView *tableView;
  15. @end
  16. @implementation PDFSettingsViewController
  17. #pragma mark - UIViewController Methods
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view.
  21. self.title = NSLocalizedString(@"Settings", nil);
  22. self.tableView = [[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped] autorelease];
  23. self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  24. self.tableView.delegate = self;
  25. self.tableView.dataSource = self;
  26. [self.view addSubview:self.tableView];
  27. }
  28. #pragma mark - UITableViewDataSource
  29. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  30. return 2;
  31. }
  32. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  33. return 4;
  34. }
  35. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  36. if (section == 0) {
  37. return NSLocalizedString(@"PDF Reader", nil);
  38. } else {
  39. return NSLocalizedString(@"PDF SDK", nil);
  40. }
  41. }
  42. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
  43. if (section == 0) {
  44. return nil;
  45. } else {
  46. return NSLocalizedString(@"Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.", nil);
  47. }
  48. }
  49. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  50. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
  51. if (!cell) {
  52. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell"] autorelease];
  53. }
  54. if (indexPath.section == 0) {
  55. switch (indexPath.row) {
  56. case 0:
  57. {
  58. cell.textLabel.text = NSLocalizedString(@"Highlight Links", nil);
  59. UISwitch *sw = [[[UISwitch alloc] init] autorelease];
  60. sw.on = CPDFKitShareConfig.enableLinkFieldHighlight;
  61. [sw addTarget:self action:@selector(highlightLinksAction:) forControlEvents:UIControlEventTouchUpInside];
  62. cell.accessoryView = sw;
  63. }
  64. break;
  65. case 1:
  66. {
  67. cell.textLabel.text = NSLocalizedString(@"Scroll Pages", nil);
  68. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  69. if (CPDFDisplayDirectionVertical == CPDFKitShareConfig.displayDirection) {
  70. cell.detailTextLabel.text = NSLocalizedString(@"Vertical", nil);
  71. } else {
  72. cell.detailTextLabel.text = NSLocalizedString(@"Horizontal", nil);
  73. }
  74. }
  75. break;
  76. case 2:
  77. {
  78. cell.textLabel.text = NSLocalizedString(@"Annotation Author:", nil);
  79. UITextField *textField = [[[UITextField alloc] initWithFrame:CGRectMake(0, 0, 160, 30)] autorelease];
  80. textField.textAlignment = NSTextAlignmentRight;
  81. textField.returnKeyType = UIReturnKeyDone;
  82. textField.delegate = self;
  83. textField.text = CPDFKitShareConfig.annotationAuthor;
  84. cell.accessoryView = textField;
  85. }
  86. break;
  87. case 3:
  88. {
  89. unsigned long long cacheSize = CPDFKitShareConfig.cacheSize;
  90. NSString *string = [NSByteCountFormatter stringFromByteCount:cacheSize
  91. countStyle:NSByteCountFormatterCountStyleFile];
  92. cell.textLabel.text = NSLocalizedString(@"Clear Cache", nil);
  93. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  94. cell.detailTextLabel.text = string;
  95. }
  96. break;
  97. }
  98. } else if (indexPath.section == 1) {
  99. cell.detailTextLabel.font = [UIFont systemFontOfSize:12];
  100. switch (indexPath.row) {
  101. case 0:
  102. {
  103. cell.textLabel.text = NSLocalizedString(@"Version", nil);
  104. cell.detailTextLabel.text = [NSString stringWithFormat:@"v%@", [[CPDFKit sharedInstance] versionNumber]];
  105. }
  106. break;
  107. case 1:
  108. {
  109. cell.textLabel.text = NSLocalizedString(@"Phone", nil);
  110. cell.detailTextLabel.text = @"+886-731-8422-5961";
  111. }
  112. break;
  113. case 2:
  114. {
  115. cell.textLabel.text = NSLocalizedString(@"Email", nil);
  116. cell.detailTextLabel.text = @"support@compdf.com";
  117. }
  118. break;
  119. case 3:
  120. {
  121. cell.textLabel.text = NSLocalizedString(@"Official website", nil);
  122. cell.detailTextLabel.text = @"https://www.compdf.com";
  123. }
  124. break;
  125. }
  126. }
  127. return cell;
  128. }
  129. #pragma mark - UITableViewDelegate
  130. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  131. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  132. if (indexPath.section == 0) {
  133. switch (indexPath.row) {
  134. case 1:
  135. {
  136. PDFSettingsValueViewController *vc = [[PDFSettingsValueViewController alloc] init];
  137. vc.title = NSLocalizedString(@"Scroll Pages", nil);
  138. vc.dataSource = @[NSLocalizedString(@"Vertical", nil),
  139. NSLocalizedString(@"Horizontal", nil)];
  140. if (CPDFDisplayDirectionVertical == CPDFKitShareConfig.displayDirection) {
  141. vc.selectedIndex = 0;
  142. } else {
  143. vc.selectedIndex = 1;
  144. }
  145. vc.callback = ^(NSUInteger selectedIndex) {
  146. if (selectedIndex == 0) {
  147. CPDFKitShareConfig.displayDirection = CPDFDisplayDirectionVertical;
  148. } else {
  149. CPDFKitShareConfig.displayDirection = CPDFDisplayDirectionHorizontal;
  150. }
  151. [self.tableView reloadData];
  152. };
  153. [self.navigationController pushViewController:vc animated:YES];
  154. [vc release];
  155. }
  156. break;
  157. case 3:
  158. {
  159. [CPDFKitShareConfig clearCache];
  160. [self.tableView reloadData];
  161. }
  162. break;
  163. }
  164. }
  165. }
  166. #pragma mark - UITextFieldDelegate
  167. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  168. [textField resignFirstResponder];
  169. if (textField.text) {
  170. CPDFKitShareConfig.annotationAuthor = textField.text;
  171. }
  172. return YES;
  173. }
  174. #pragma mark - Button Actions
  175. - (void)highlightLinksAction:(UISwitch *)sender {
  176. CPDFKitShareConfig.enableLinkFieldHighlight = sender.isOn;
  177. }
  178. @end