BallotHeaderView.m 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2014-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 "BallotHeaderView.h"
  21. #import "EntityManager.h"
  22. #import "Contact.h"
  23. #import "BundleUtil.h"
  24. #import "AvatarMaker.h"
  25. #define HEADER_BOUNCE_OFFSET 70.0
  26. @implementation BallotHeaderView
  27. - (void)awakeFromNib {
  28. [self setup];
  29. [super awakeFromNib];
  30. }
  31. - (void)setup {
  32. self.ddMainView = self.mainView;
  33. self.ddDetailView = self.accessoryView;
  34. self.imageView.layer.masksToBounds = YES;
  35. self.imageView.contentMode = UIViewContentModeScaleAspectFill;
  36. self.imageView.layer.cornerRadius = self.imageView.frame.size.width/2;
  37. self.bounceOffset = HEADER_BOUNCE_OFFSET;
  38. [self setupColors];
  39. }
  40. - (void)setupColors {
  41. _mainView.backgroundColor = [Colors background];
  42. _titleLabel.textColor = [Colors fontNormal];
  43. _accessoryView.backgroundColor = [Colors backgroundInverted];
  44. _createdByNameLabel.textColor = [Colors fontInverted];
  45. _dateLabel.textColor = [Colors fontInverted];
  46. }
  47. -(void)setBallot:(Ballot *)ballot {
  48. _ballot = ballot;
  49. [_titleLabel setText: ballot.title];
  50. [self updateDate];
  51. [self updateContact];
  52. }
  53. -(void)updateDate {
  54. NSDate *date = _ballot.modifyDate;
  55. if (date == nil) {
  56. date = _ballot.createDate;
  57. }
  58. [_dateLabel setText: [DateFormatter shortStyleDateTime: date]];
  59. }
  60. -(void)updateContact {
  61. if (_ballot.creatorId == nil) {
  62. return;
  63. }
  64. EntityManager *entityManager = [[EntityManager alloc] init];
  65. [_createdByNameLabel setText: [entityManager.entityFetcher displayNameForContactId: _ballot.creatorId]];
  66. Contact *creatorContact = [entityManager.entityFetcher contactForId:_ballot.creatorId];
  67. [_imageView setImage: [[AvatarMaker sharedAvatarMaker] avatarForContact:creatorContact size:_imageView.frame.size.width masked:NO]];
  68. }
  69. @end