BallotDispatcher.m 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 "BallotDispatcher.h"
  21. #import "BallotVoteViewController.h"
  22. #import "BallotCreateViewController.h"
  23. #import "BallotResultViewController.h"
  24. #import "ModalNavigationController.h"
  25. @implementation BallotDispatcher
  26. + (UIViewController *)viewControllerForBallot:(Ballot *)ballot {
  27. if ([ballot isClosed]) {
  28. return [BallotResultViewController ballotResultViewControllerForBallot: ballot];
  29. } else {
  30. return [BallotVoteViewController ballotVoteViewControllerForBallot: ballot];
  31. }
  32. }
  33. + (void)showViewControllerForBallot:(Ballot *)ballot onNavigationController:(UINavigationController*)navigationController {
  34. /* present open ballots as modal dialogs as the user must take action or cancel, and simply push closed ballots */
  35. if ([ballot isClosed]) {
  36. BallotResultViewController *viewController = [BallotResultViewController ballotResultViewControllerForBallot: ballot];
  37. [self pushController:viewController onNavigationController:navigationController];
  38. } else {
  39. BallotVoteViewController *viewController = [BallotVoteViewController ballotVoteViewControllerForBallot: ballot];
  40. [self presentAsModal:viewController onNavigationController:navigationController];
  41. }
  42. }
  43. + (void)showBallotCreateViewControllerForConversation:(Conversation *)conversation onNavigationController:(UINavigationController*)navigationController {
  44. BallotCreateViewController *viewController = [BallotCreateViewController ballotCreateViewControllerForConversation: conversation];
  45. [self presentAsModal:viewController onNavigationController:navigationController];
  46. }
  47. + (void)presentAsModal:(UIViewController*)viewController onNavigationController:(UINavigationController*)navigationController {
  48. ModalNavigationController *modalNav = [[ModalNavigationController alloc] initWithRootViewController:viewController];
  49. modalNav.modalPresentationStyle = UIModalPresentationFullScreen;
  50. [navigationController presentViewController:modalNav animated:YES completion:nil];
  51. }
  52. + (void)pushController:(UIViewController*)viewController onNavigationController:(UINavigationController*)navigationController {
  53. if (SYSTEM_IS_IPAD) {
  54. ModalNavigationController *modalNav = [[ModalNavigationController alloc] initWithRootViewController:viewController];
  55. modalNav.showDoneButton = YES;
  56. modalNav.dismissOnTapOutside = YES;
  57. [navigationController presentViewController:modalNav animated:YES completion:nil];
  58. } else {
  59. [navigationController pushViewController:viewController animated:YES];
  60. }
  61. }
  62. @end