VideoQualityViewController.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 "VideoQualityViewController.h"
  21. #import "MediaConverter.h"
  22. #import "UserSettings.h"
  23. @interface VideoQualityViewController ()
  24. @end
  25. @implementation VideoQualityViewController {
  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 reloadData];
  39. }
  40. - (BOOL)shouldAutorotate {
  41. return YES;
  42. }
  43. -(UIInterfaceOrientationMask)supportedInterfaceOrientations {
  44. if (SYSTEM_IS_IPAD) {
  45. return UIInterfaceOrientationMaskAll;
  46. }
  47. return UIInterfaceOrientationMaskAllButUpsideDown;
  48. }
  49. #pragma mark - Table view data source
  50. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  51. {
  52. return 1;
  53. }
  54. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  55. {
  56. return [MediaConverter videoQualities].count;
  57. }
  58. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  59. {
  60. static NSString *CellIdentifier = @"VideoQualityCell";
  61. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  62. NSString *quality = [MediaConverter videoQualities][indexPath.row];
  63. cell.textLabel.text = NSLocalizedString(quality, nil);
  64. NSNumber *maxDuration = [MediaConverter videoQualityMaxDurations][indexPath.row];
  65. if (maxDuration.intValue == 1)
  66. cell.detailTextLabel.text = NSLocalizedString(@"max_1_minute", nil);
  67. else
  68. cell.detailTextLabel.text = [NSString stringWithFormat:NSLocalizedString(@"max_x_minutes", nil), maxDuration.intValue];
  69. if ([[UserSettings sharedUserSettings].videoQuality isEqualToString:quality]) {
  70. cell.accessoryType = UITableViewCellAccessoryCheckmark;
  71. selectedIndexPath = indexPath;
  72. } else
  73. cell.accessoryType = UITableViewCellAccessoryNone;
  74. return cell;
  75. }
  76. #pragma mark - Table view delegate
  77. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  78. {
  79. [UserSettings sharedUserSettings].videoQuality = [MediaConverter videoQualities][indexPath.row];
  80. if (selectedIndexPath != nil)
  81. [self.tableView cellForRowAtIndexPath:selectedIndexPath].accessoryType = UITableViewCellAccessoryNone;
  82. [self.tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
  83. [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  84. selectedIndexPath = indexPath;
  85. }
  86. @end