| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- //
- // InvitationListViewController.m
- // kneet
- //
- // Created by Jason Lee on 6/12/15.
- // Copyright (c) 2015 ntels. All rights reserved.
- //
- #import "RequestHandler.h"
- #import "LoginModel.h"
- #import "CustomTableView.h"
- #import "CustomButton.h"
- #import "CustomLabel.h"
- #import "ImageUtil.h"
- #import "UIImageView+WebCache.h"
- #import "CustomImageView.h"
- #import "CustomAlertView.h"
- #import "InvitationAnswerPopupView.h"
- #import "LoginViewController.h"
- #import "InvitationListViewController.h"
- #import "InvitationAnswerViewController.h"
- #import "UIButton+WebCache.h"
- @implementation InvitationTableViewCell
- - (void)awakeFromNib {
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.backgroundColor = [UIColor clearColor];
- }
- - (void)didMoveToSuperview {
- _lblJoin.text = NSLocalizedString(@"참여", @"참여");
- _lblReject.text = NSLocalizedString(@"거절", @"거절");
-
- [_lblJoin setUnderLine:_lblJoin.text];
- [_lblReject setUnderLine:_lblReject.text];
- }
- @end
- @interface InvitationListViewController () <UITableViewDataSource, UITableViewDelegate> {
- NSMutableArray<InvitationModel> *_invitationList;
- }
- @end
- #pragma mark - Class Definition
- @implementation InvitationListViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self initUI];
- [self prepareViewDidLoad];
- }
- - (void)initUI {
-
- [self initTableViewAsDefaultStyle:_tableView];
- }
- - (void)prepareViewDidLoad {
-
- // [[JDFacade facade] updateLoginInfo:^{
- // _invitationList = [JDFacade facade].loginUser.invitationList;
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- // [_tableView reloadData];
- // });
- // }];
- [self requestInvitationList];
- }
- - (void)updateTitle {
-
- _lblTitle.text = [NSString stringWithFormat:@"초대알림 %zd", _invitationList.count];
- [_lblTitle setColor:kUITextColor02 text:[NSString stringWithFormat:@"%zd", _invitationList.count]];
- }
- #pragma mark - Main Logic
- - (void)requestInvitationList {
- //parameters
- NSString *path = [NSString stringWithFormat:API_GET_HOMEGROUP_MEMBER_INVITATIONS];
-
- [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:nil modelClass:[InvitationListModel class] completion:^(id responseObject) {
- if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
- return;
- }
-
- InvitationListModel *fetchedInvitationList = (InvitationListModel *) responseObject;
-
- if (fetchedInvitationList && fetchedInvitationList.list) {//API 성공 ,
- _invitationList = [fetchedInvitationList.list mutableCopy];
- }
-
- if (_invitationList && !_invitationList.count) {
- [self btnCloseTouched:nil];
- return;
- }
- [_tableView reloadData];
- [self updateTitle];
-
- } failure:^(id errorObject) {
-
- JDErrorModel *error = (JDErrorModel *)errorObject;
- [[JDFacade facade] alert:error.errorMessage];
- }];
- }
- - (void)requestRejectInvitation:(InvitationModel *)invitation {
- //parameters
- NSDictionary *parameter = @{@"homegrp_id": invitation.homegrpId,
- @"status_code": ksNO};
- NSString *path = [NSString stringWithFormat:API_POST_HOMEGROUP_MEMBER_INVITATIONS];
- [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
-
- [_invitationList removeObject:invitation];
- if (_invitationList.count > 0) {//초대건수가 있으면, 다시 로드함.
- [_tableView reloadData];
-
- } else {//다음 플로우 진행
- [[JDFacade facade] alertTitle:@"홈 초대 거절" message:@"모든 초대를 거절했습니다" completionHander:^{
- [self btnCloseTouched:nil];
- }];
- }
-
- } failure:^(id errorObject) {
-
- JDErrorModel *error = (JDErrorModel *)errorObject;
- [[JDFacade facade] alert:error.errorMessage];
- }];
- }
- #pragma mark - UITableView DataSource & Delegate
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- NSInteger count = _invitationList.count;
- return count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- CGFloat height = 0;
- CGFloat width = IPHONE_WIDTH - 80 - 20;
- CustomLabel *lblTemp = [[CustomLabel alloc] initWithFrame:CGRectMake(0, 0, width, 17)];
- lblTemp.font = [UIFont systemFontOfSize:kUIFontSize01];
- lblTemp.numberOfLines = 0;
- InvitationModel *invitation = _invitationList[indexPath.row];
- NSString *fromNickname = invitation.nickname;
- CGFloat adjustHeight = [CommonUtil getSizeFromString:fromNickname font:lblTemp.font width:width].height;
- adjustHeight = adjustHeight < 20 ? 0 : adjustHeight - 20;
- height = 86 + adjustHeight;
-
- return height;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- InvitationModel *invitation = _invitationList[indexPath.row];
- InvitationTableViewCell *tcell = [tableView dequeueReusableCellWithIdentifier:@"InvitationCellIdentifier"];
- tcell.lblFromNickname.text = invitation.nickname;
- [tcell.btnProfile sd_setBackgroundImageWithURL:[NSURL URLWithString:invitation.imageFileName] forState:UIControlStateNormal placeholderImage:nil options:SDWebImageRefreshCached];
-
- tcell.lblJoin.value = invitation;
- tcell.lblReject.value = invitation;
-
- if (!tcell.lblJoin.touchHandler) {
- [tcell.lblJoin addTouchEventHandler:^(id label) {
- [self lblJoinTouched:label];
- }];
- }
-
- if (!tcell.lblReject.touchHandler) {
- [tcell.lblReject addTouchEventHandler:^(id label) {
- [self lblRejectTouched:label];
- }];
- }
-
- return tcell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [super tableView:tableView didSelectRowAtIndexPath:indexPath];
- }
- #pragma mark - UI Events
- - (void)lblJoinTouched:(id)sender {
- CustomLabel *lblJoin = (CustomLabel *)sender;
- InvitationModel *invitation = lblJoin.value;
-
- InvitationAnswerViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"InvitationAnswerViewController" storyboardName:@"Main"];
- vc.invitation = invitation;
-
-
- NSString *message1 = [NSString stringWithFormat:@"%@님의 홈에 참여할까요?\n\n", invitation.nickname];
- NSString *message2 = ksEmptyString;
-
- if (![JDFacade facade].loginUser.homegrpId || [[JDFacade facade].loginUser.homegrpId isEmptyString]) {//홈이 없을 경우,
- message2 = @"한 아이디로 한 개의 홈만 참여 가능하며,\n다른 홈엔 더이상 참여할 수 없습니다.";
-
- } else if (![JDFacade facade].loginUser.hasHomeHub) {//홈허브가 삭제된 경우,
-
- if ([JDFacade facade].loginUser.level > 10) {//마스터일 경우,
- message2 = @"한 아이디로 한 개의 홈만 참여 가능하며,\n현재 운영 중인 홈이 삭제됩니다.";
- } else {
- message2 = @"한 아이디로 한 개의 홈만 참여 가능하며,\n다른 홈엔 더이상 참여할 수 없습니다.";
- }
- }
-
- CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:@"홈 초대 수락"
- message:[NSString stringWithFormat:@"%@%@", message1, message2]
- delegate:nil OKButtonTitle:@"예" cancelButtonTitle:@"아니오"];
-
- if (message2 && ![message2 isEmptyString]) {
- [alert.lblMessage1 setColor:kUITextColor02 text:message2];
- }
- [alert showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
- if (buttonIndex == 0) {//OK
- [self presentViewController:vc animated:YES completion:nil];
- }
- }];
- }
- - (void)lblRejectTouched:(id)sender {
- CustomLabel *lblReject = (CustomLabel *)sender;
- InvitationModel *invitation = lblReject.value;
-
- [self requestRejectInvitation:invitation];
- }
- - (IBAction)btnCloseTouched:(id)sender {
-
- LoginViewController *lvc = [[JDFacade facade] viewControllerOnPresentingViewController:[JDFacade facade].currentViewController viewControllerClass:[LoginViewController class]];
- // (LoginViewController *)[JDFacade facade].currentViewController.presentingViewController;
- if ([lvc isKindOfClass:[LoginViewController class]]) {
- [lvc actionAfterInvitaion];
- }
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- #pragma mark - MemoryWarning
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|