123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- //
- // PDFSettingsViewController.m
- // PDFReader
- //
- // Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
- //
- // The PDF Reader Sample applications are licensed with a modified BSD license.
- // Please see License for details. This notice may not be removed from this file.
- //
- #import "PDFSettingsViewController.h"
- #import "PDFSettingsValueViewController.h"
- #import <ComPDFKit/ComPDFKit.h>
- @interface PDFSettingsViewController () <UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
- @property (nonatomic,retain) UITableView *tableView;
- @end
- @implementation PDFSettingsViewController
- #pragma mark - UIViewController Methods
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- // Do any additional setup after loading the view.
- self.title = NSLocalizedString(@"Settings", nil);
- self.tableView = [[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped] autorelease];
- self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- [self.view addSubview:self.tableView];
- }
- #pragma mark - UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 2;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 4;
- }
- - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
- if (section == 0) {
- return NSLocalizedString(@"PDF Reader", nil);
- } else {
- return NSLocalizedString(@"PDF SDK", nil);
- }
- }
- - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
- if (section == 0) {
- return nil;
- } else {
- return NSLocalizedString(@"Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.", nil);
- }
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
- if (!cell) {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell"] autorelease];
- }
- if (indexPath.section == 0) {
- switch (indexPath.row) {
- case 0:
- {
- cell.textLabel.text = NSLocalizedString(@"Highlight Links", nil);
- UISwitch *sw = [[[UISwitch alloc] init] autorelease];
- sw.on = CPDFKitShareConfig.enableLinkFieldHighlight;
- [sw addTarget:self action:@selector(highlightLinksAction:) forControlEvents:UIControlEventTouchUpInside];
- cell.accessoryView = sw;
- }
- break;
- case 1:
- {
- cell.textLabel.text = NSLocalizedString(@"Scroll Pages", nil);
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- if (CPDFDisplayDirectionVertical == CPDFKitShareConfig.displayDirection) {
- cell.detailTextLabel.text = NSLocalizedString(@"Vertical", nil);
- } else {
- cell.detailTextLabel.text = NSLocalizedString(@"Horizontal", nil);
- }
- }
- break;
- case 2:
- {
- cell.textLabel.text = NSLocalizedString(@"Annotation Author:", nil);
- UITextField *textField = [[[UITextField alloc] initWithFrame:CGRectMake(0, 0, 160, 30)] autorelease];
- textField.textAlignment = NSTextAlignmentRight;
- textField.returnKeyType = UIReturnKeyDone;
- textField.delegate = self;
- textField.text = CPDFKitShareConfig.annotationAuthor;
- cell.accessoryView = textField;
- }
- break;
- case 3:
- {
- unsigned long long cacheSize = CPDFKitShareConfig.cacheSize;
- NSString *string = [NSByteCountFormatter stringFromByteCount:cacheSize
- countStyle:NSByteCountFormatterCountStyleFile];
- cell.textLabel.text = NSLocalizedString(@"Clear Cache", nil);
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- cell.detailTextLabel.text = string;
- }
- break;
- }
- } else if (indexPath.section == 1) {
- cell.detailTextLabel.font = [UIFont systemFontOfSize:12];
- switch (indexPath.row) {
- case 0:
- {
- cell.textLabel.text = NSLocalizedString(@"Version", nil);
- cell.detailTextLabel.text = [NSString stringWithFormat:@"v%@", [[CPDFKit sharedInstance] versionNumber]];
- }
- break;
- case 1:
- {
- cell.textLabel.text = NSLocalizedString(@"Phone", nil);
- cell.detailTextLabel.text = @"+886-731-8422-5961";
- }
- break;
- case 2:
- {
- cell.textLabel.text = NSLocalizedString(@"Email", nil);
- cell.detailTextLabel.text = @"support@compdf.com";
- }
- break;
- case 3:
- {
- cell.textLabel.text = NSLocalizedString(@"Official website", nil);
- cell.detailTextLabel.text = @"https://www.compdf.com";
- }
- break;
- }
- }
- return cell;
- }
- #pragma mark - UITableViewDelegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- if (indexPath.section == 0) {
- switch (indexPath.row) {
- case 1:
- {
- PDFSettingsValueViewController *vc = [[PDFSettingsValueViewController alloc] init];
- vc.title = NSLocalizedString(@"Scroll Pages", nil);
- vc.dataSource = @[NSLocalizedString(@"Vertical", nil),
- NSLocalizedString(@"Horizontal", nil)];
- if (CPDFDisplayDirectionVertical == CPDFKitShareConfig.displayDirection) {
- vc.selectedIndex = 0;
- } else {
- vc.selectedIndex = 1;
- }
- vc.callback = ^(NSUInteger selectedIndex) {
- if (selectedIndex == 0) {
- CPDFKitShareConfig.displayDirection = CPDFDisplayDirectionVertical;
- } else {
- CPDFKitShareConfig.displayDirection = CPDFDisplayDirectionHorizontal;
- }
- [self.tableView reloadData];
- };
- [self.navigationController pushViewController:vc animated:YES];
- [vc release];
- }
- break;
- case 3:
- {
- [CPDFKitShareConfig clearCache];
- [self.tableView reloadData];
- }
- break;
- }
- }
- }
- #pragma mark - UITextFieldDelegate
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
- [textField resignFirstResponder];
- if (textField.text) {
- CPDFKitShareConfig.annotationAuthor = textField.text;
- }
- return YES;
- }
- #pragma mark - Button Actions
- - (void)highlightLinksAction:(UISwitch *)sender {
- CPDFKitShareConfig.enableLinkFieldHighlight = sender.isOn;
- }
- @end
|