ThemedTableViewController.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2016-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 "ThemedTableViewController.h"
  21. #import "VoIPHelper.h"
  22. @interface ThemedTableViewController ()
  23. @end
  24. @implementation ThemedTableViewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. [self setupForColorTheme];
  28. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleDynamicTypeChange:) name:UIContentSizeCategoryDidChangeNotification object:nil];
  29. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callInBackgroundTimeChanged:) name:kNotificationCallInBackgroundTimeChanged object:nil];
  30. }
  31. - (void)viewWillAppear:(BOOL)animated {
  32. [super viewWillAppear:animated];
  33. self.tableView.estimatedRowHeight = UITableViewAutomaticDimension;
  34. self.tableView.rowHeight = UITableViewAutomaticDimension;
  35. self.navigationItem.prompt = [[VoIPHelper shared] currentPromtString:nil];
  36. }
  37. - (void)dealloc {
  38. [[NSNotificationCenter defaultCenter] removeObserver:self];
  39. }
  40. - (void)refresh {
  41. [self setupForColorTheme];
  42. [self.tableView reloadData];
  43. }
  44. - (void)setupForColorTheme {
  45. [self.view setBackgroundColor:[Colors background]];
  46. [Colors updateTableView:self.tableView];
  47. }
  48. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  49. if ([cell isKindOfClass:[UITableViewCell class]]) {
  50. [Colors updateTableViewCell:cell];
  51. }
  52. }
  53. - (void)tableView:(UITableView *)tableView willDisplayHeaderView:(nonnull UIView *)view forSection:(NSInteger)section {
  54. [self colorizeHeaderFooterView:view];
  55. }
  56. - (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section {
  57. [self colorizeHeaderFooterView:view];
  58. }
  59. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  60. return UITableViewAutomaticDimension;
  61. }
  62. - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
  63. return UITableViewAutomaticDimension;
  64. }
  65. - (void)colorizeHeaderFooterView:(UIView *)view {
  66. if ([view isKindOfClass:[UITableViewHeaderFooterView class]]) {
  67. UITableViewHeaderFooterView *headerView = (UITableViewHeaderFooterView*)view;
  68. [headerView.contentView setBackgroundColor:[Colors backgroundDark]];
  69. [headerView.textLabel setTextColor:[Colors fontLight]];
  70. }
  71. }
  72. - (void)handleDynamicTypeChange:(NSNotification *)theNotification {
  73. [self refresh];
  74. }
  75. - (void)callInBackgroundTimeChanged:(NSNotification*)notification {
  76. NSNumber *time = notification.object;
  77. self.navigationItem.prompt = [[VoIPHelper shared] currentPromtString:time];
  78. if (self.navigationItem.prompt == nil) {
  79. if ([self respondsToSelector:@selector(updateLayoutAfterCall)]) {
  80. double delayInSeconds = 0.3;
  81. dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
  82. dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
  83. [self performSelector:@selector(updateLayoutAfterCall)];
  84. });
  85. }
  86. }
  87. }
  88. - (void)updateLayoutAfterCall {
  89. // do nothing
  90. }
  91. @end