ImageSizeViewController.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2012-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import "ImageSizeViewController.h"
  21. #import "UserSettings.h"
  22. #import "BundleUtil.h"
  23. @interface ImageSizeViewController ()
  24. @end
  25. @implementation ImageSizeViewController {
  26. NSIndexPath *selectedIndexPath;
  27. }
  28. - (id)initWithStyle:(UITableViewStyle)style
  29. {
  30. self = [super initWithStyle:style];
  31. if (self) {
  32. // Custom initialization
  33. }
  34. return self;
  35. }
  36. - (void)viewWillAppear:(BOOL)animated {
  37. [super viewWillAppear:animated];
  38. [self.tableView footerViewForSection:0].textLabel.preferredMaxLayoutWidth = [self.tableView footerViewForSection:0].textLabel.frame.size.width;
  39. [self.tableView footerViewForSection:0].textLabel.numberOfLines = 0;
  40. [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
  41. }
  42. - (BOOL)shouldAutorotate {
  43. return YES;
  44. }
  45. -(UIInterfaceOrientationMask)supportedInterfaceOrientations {
  46. if (SYSTEM_IS_IPAD) {
  47. return UIInterfaceOrientationMaskAll;
  48. }
  49. return UIInterfaceOrientationMaskAllButUpsideDown;
  50. }
  51. #pragma mark - Table view data source
  52. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  53. [super tableView:tableView willDisplayCell:cell forRowAtIndexPath:indexPath];
  54. [cell.detailTextLabel setTextColor:[Colors fontLight]];
  55. }
  56. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  57. {
  58. return 1;
  59. }
  60. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  61. {
  62. return [ImageURLSenderItemCreator getImageSizeNo];
  63. }
  64. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  65. {
  66. static NSString *CellIdentifier = @"ImageSizeCell";
  67. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  68. NSString *size = (NSString *)[ImageURLSenderItemCreator imageSizes][indexPath.row];
  69. cell.textLabel.text = NSLocalizedString(size, nil);
  70. NSNumber *pixels = (NSNumber *)[ImageURLSenderItemCreator imagePixelSizes][indexPath.row];
  71. if (pixels.intValue == 0) {
  72. cell.detailTextLabel.text = [NSString stringWithFormat:NSLocalizedString(@"images are not scaled", nil)];
  73. } else {
  74. cell.detailTextLabel.text = [NSString stringWithFormat:NSLocalizedString(@"max_x_by_x_pixels", nil), pixels, pixels];
  75. }
  76. if ([[UserSettings sharedUserSettings].imageSize isEqualToString:size]) {
  77. cell.accessoryType = UITableViewCellAccessoryCheckmark;
  78. selectedIndexPath = indexPath;
  79. } else
  80. cell.accessoryType = UITableViewCellAccessoryNone;
  81. return cell;
  82. }
  83. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
  84. if (selectedIndexPath.row == 3 || selectedIndexPath.row == 4) {
  85. return [BundleUtil localizedStringForKey:@"image_resize_share_extension"];
  86. }
  87. return @"";
  88. }
  89. #pragma mark - Table view delegate
  90. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  91. {
  92. [UserSettings sharedUserSettings].imageSize = [ImageURLSenderItemCreator imageSizes][indexPath.row];
  93. if (selectedIndexPath != nil)
  94. [self.tableView cellForRowAtIndexPath:selectedIndexPath].accessoryType = UITableViewCellAccessoryNone;
  95. [self.tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
  96. [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  97. selectedIndexPath = indexPath;
  98. [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
  99. [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
  100. }
  101. @end