InvitationAnswerViewController.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // InvitationAnswerViewController.m
  3. // kneet2
  4. //
  5. // Created by Jason Lee on 10/21/15.
  6. // Copyright © 2015 ntels. All rights reserved.
  7. //
  8. #import "InvitationAnswerViewController.h"
  9. #import "InvitationAnswerPopupView.h"
  10. #import "RequestHandler.h"
  11. #import "LoginModel.h"
  12. #import "InvitationListViewController.h"
  13. #import "UIImageView+WebCache.h"
  14. #import "CustomImageView.h"
  15. #import "ImageUtil.h"
  16. @interface InvitationAnswerViewController () {
  17. InvitationAnswerPopupView *_apopup;
  18. }
  19. @end
  20. #pragma mark - Class Definition
  21. @implementation InvitationAnswerViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. // Do any additional setup after loading the view.
  25. [self initUI];
  26. [self prepareViewDidLoad];
  27. }
  28. - (void)initUI {
  29. [_imgvFromProfile sd_setImageWithURL:[NSURL URLWithString:_invitation.imageFileName] placeholderImage:nil options:SDWebImageRefreshCached
  30. completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  31. UIImage *maskImage = [ImageUtil resizeImage:[UIImage imageNamed:@"common_mask_circle"] width:90 height:90];
  32. UIImage *thumbImage = [ImageUtil getMaskedImageWithSourchImage:image andMaskImage:maskImage];
  33. _imgvFromProfile.image = thumbImage;
  34. }];
  35. _lblQuiz.text = _invitation.authorizationQuestion;
  36. }
  37. - (void)prepareViewDidLoad {
  38. }
  39. #pragma mark - Main Logic
  40. - (void)requestJoinInvitation:(InvitationModel *)invitation {
  41. //parameters
  42. NSDictionary *parameter = @{@"homegrp_id": invitation.homegrpId,
  43. @"authorization_reply": invitation.sdate,
  44. @"status_code": ksYES};
  45. NSString *path = [NSString stringWithFormat:API_POST_HOMEGROUP_MEMBER_INVITATIONS];
  46. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[LoginModel class] completion:^(id responseObject) {
  47. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  48. return;
  49. }
  50. LoginModel *result = (LoginModel *) responseObject;
  51. if (result) {//API 성공 ,
  52. [JDFacade facade].loginUser.homegrpId = result.homegrpId; //초대에서 넘어오는 경우,
  53. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"WelcomeViewController" storyboardName:@"Main"];
  54. [self presentViewController:vc animated:YES completion:nil];
  55. }
  56. } failure:^(id errorObject) {//답변이 틀린 경우,
  57. JDErrorModel *error = (JDErrorModel *)errorObject;
  58. if ([error.errorCode isEqualToString:@"400-102"]) {//답변이
  59. if ([error.errorCount integerValue] < 3) {//답변이 1,2회 틀린 경우,
  60. [[JDFacade facade] alert:error.errorMessage completionHander:^{
  61. [self popInvitationAnswer:invitation];
  62. }];
  63. } else {//답변이 3회 틀린 경우,
  64. [[JDFacade facade] alert:error.errorMessage completionHander:^{
  65. [self dismissViewControllerAnimated:YES completion:^{
  66. InvitationListViewController *vc = (InvitationListViewController *)[JDFacade facade].currentViewController;
  67. if ([vc isKindOfClass:[InvitationListViewController class]]) {
  68. [vc requestInvitationList];
  69. }
  70. }];
  71. }];
  72. }
  73. } else {
  74. [[JDFacade facade] alert:error.errorMessage];
  75. }
  76. }];
  77. }
  78. - (void)popInvitationAnswer:(InvitationModel *)invitation {
  79. //pop
  80. if (!_apopup) {
  81. _apopup = [[InvitationAnswerPopupView alloc] initFromNib];
  82. }
  83. _apopup.invitation = invitation;
  84. [_apopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  85. if (buttonIndex == 0) {//OK
  86. invitation.sdate = _apopup.selectedDate;
  87. [self requestJoinInvitation:invitation];
  88. }
  89. }];
  90. }
  91. #pragma mark - UI Events
  92. - (IBAction)btnAnswerTouched:(id)sender {
  93. [self popInvitationAnswer:_invitation];
  94. }
  95. - (IBAction)btnCloseTouched:(id)sender {
  96. [self dismissViewControllerAnimated:YES completion:nil];
  97. }
  98. #pragma mark - MemoryWarning
  99. - (void)didReceiveMemoryWarning
  100. {
  101. [super didReceiveMemoryWarning];
  102. // Dispose of any resources that can be recreated.
  103. }
  104. @end