Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ProfileViewController.m
- // Moselo
- //
- // Created by Ritchie Nathaniel on 2/17/17.
- // Copyright © 2017 Moselo. All rights reserved.
- //
- #import "ProfileViewController.h"
- #import "ProfileView.h"
- #import "ProfileTableViewCell.h"
- #import "ProfileHeaderTableViewCell.h"
- #import "ExpertSettingViewController.h"
- #import "PickerViewController.h"
- #import "SetProfilePictureViewController.h"
- #import "UserProfileSettingViewController.h"
- #import "AddServiceViewController.h"
- #import "WebViewViewController.h"
- #import "HelpViewController.h"
- //AS TEMP LinkedAccount
- #import "LinkedAccountViewController.h"
- @interface ProfileViewController () <UITableViewDelegate, UITableViewDataSource, ProfileHeaderTableViewCellDelegate>
- @property (strong, nonatomic) ProfileView *profileView;
- //AS TEMP
- @property (strong, nonatomic) NSString *name;
- @property (strong, nonatomic) NSString *username;
- @property (strong, nonatomic) NSString *avatarSmall;
- @property (strong, nonatomic) NSString *avatarMedium;
- @property (strong, nonatomic) NSString *avatarLarge;
- //END
- @property (nonatomic) CGFloat newCellHeight;
- @property (nonatomic) BOOL isCellHeightUpdated;
- - (void)applyNowButtonDidTapped;
- @end
- @implementation ProfileViewController
- #pragma mark - Lifecycle
- - (id)init {
- self = [super init];
- if(self) {
- self.title = NSLocalizedString(@"Account", @"");
- }
- return self;
- }
- - (void)loadView {
- [super loadView];
- _profileView = [[ProfileView alloc] initWithFrame:[BaseView frameWithNavigationBar]];
- [self.view addSubview:self.profileView];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.profileView.tableView.delegate = self;
- self.profileView.tableView.dataSource = self;
- [self.profileView.applyNowButton addTarget:self action:@selector(applyNowButtonDidTapped) forControlEvents:UIControlEventTouchDown];
- //AS TEMP
- //initiate empty string
- _name = @"";
- _username = @"";
- _avatarLarge = @"";
- _isCellHeightUpdated = NO;
- //END
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- NSDictionary *activeUser = [[NSUserDefaults standardUserDefaults] secretObjectForKey:PREFS_ACTIVE_USER];
- NSString *userRole = [activeUser valueForKeyPath:@"userRole.roleName"];
- if([userRole isEqualToString:@"user"]) {
- self.profileView.profileViewType = ProfileViewTypeUser;
- [self.profileView.tableView reloadData];
- }
- else if([userRole isEqualToString:@"expert"]) {
- self.profileView.profileViewType = ProfileViewTypeExpert;
- [self.profileView.tableView reloadData];
- }
- //AS TEMP
- //get data user profile
- [DataManager callAPIGetUserProfileWithSuccess:^(UserModel *userData) {
- self.name = userData.name;
- self.username = userData.username;
- AvatarURLModel *avatarURL = userData.avatarURL;
- self.avatarSmall = avatarURL.small;
- self.avatarMedium = avatarURL.medium;
- self.avatarLarge = avatarURL.large;
- NSLog(@"Name : %@", self.name);
- NSLog(@"Username : %@", self.username);
- NSLog(@"image : %@", self.self.avatarLarge);
- self.isCellHeightUpdated = NO;
- [self.profileView.tableView reloadData];
- } failure:^(NSError *error) {
- NSLog(@"failure block!!!");
- }];
- //END
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - Data Source
- #pragma mark UITableView
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.row == 0) {
- if(self.isCellHeightUpdated) {
- return self.newCellHeight;
- }
- else {
- return 193.0f;
- }
- }
- return 56.0f;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- //V1 Temporary Hidden
- // if(self.profileView.profileViewType == ProfileViewTypeExpert) {
- // return 5;
- // }
- // else if(self.profileView.profileViewType == ProfileViewTypeUser) {
- // return 4;
- // }
- if(self.profileView.profileViewType == ProfileViewTypeExpert) {
- return 4 + 1;
- }
- else if(self.profileView.profileViewType == ProfileViewTypeUser) {
- return 3 + 1;
- }
- //END V1 Temporary Hidden
- return 0;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return FLT_MIN;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (self.profileView.profileViewType == ProfileViewTypeExpert && indexPath.row == 0) {
- static NSString *cellHeaderID = @"ProfileHeaderTableViewCell";
- ProfileHeaderTableViewCell *cellHeader = [tableView dequeueReusableCellWithIdentifier:cellHeaderID];
- if (nil == cellHeader) {
- cellHeader = [[ProfileHeaderTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
- reuseIdentifier:cellHeaderID];
- [cellHeader setSelectionStyle:UITableViewCellSelectionStyleNone];
- }
- //5. sesudah buat delegate daftar dl di view controller yang pakainy
- cellHeader.delegate = self;
- cellHeader.userInteractionEnabled = YES;
- if(self.profileView.profileViewType == ProfileViewTypeExpert) {
- [cellHeader setPreviewButtonExpertVisible:YES];
- }
- else {
- [cellHeader setPreviewButtonExpertVisible:NO];
- }
- //NSString *fullname = @"Axel Soedarsono Axel Soedarsono";
- //[cellHeader setProfileHeaderTableViewCellWithImageURL:@"" name:fullname username:@"axelsoedarsono"];
- //AS TEMP set data from API
- [cellHeader setProfileHeaderTableViewCellWithImageURL:self.avatarLarge name:self.name username:self.username];
- //END
- return cellHeader;
- }
- else if (self.profileView.profileViewType == ProfileViewTypeUser && indexPath.row == 0) {
- static NSString *cellHeaderID = @"ProfileHeaderTableViewCell";
- ProfileHeaderTableViewCell *cellHeader = [tableView dequeueReusableCellWithIdentifier:cellHeaderID];
- if (nil == cellHeader) {
- cellHeader = [[ProfileHeaderTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
- reuseIdentifier:cellHeaderID];
- [cellHeader setSelectionStyle:UITableViewCellSelectionStyleNone];
- }
- //5. sesudah buat delegate daftar dl di view controller yang pakainy
- cellHeader.delegate = self;
- cellHeader.userInteractionEnabled = YES;
- if(self.profileView.profileViewType == ProfileViewTypeExpert) {
- [cellHeader setPreviewButtonExpertVisible:YES];
- }
- else {
- [cellHeader setPreviewButtonExpertVisible:NO];
- }
- NSString *fullname = @"Axel Soedarsono Axel Soedarsono";
- [cellHeader setProfileHeaderTableViewCellWithImageURL:@"" name:fullname username:@"axelsoe"];
- return cellHeader;
- }
- else {
- static NSString *cellID = @"ProfileTableViewCell";
- ProfileTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
- if(nil == cell) {
- cell = [[ProfileTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
- reuseIdentifier:cellID];
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
- }
- if(self.profileView.profileViewType == ProfileViewTypeExpert) {
- if(indexPath.row == 1) {
- //Expert Setting
- [cell setProfileTableViewCellType:ProfileTableViewCellTypeExpertSetting];
- }
- else if(indexPath.row == 2) {
- //Help
- [cell setProfileTableViewCellType:ProfileTableViewCellTypeHelp];
- }
- else if (indexPath.row == 3) {
- //About Us
- [cell setProfileTableViewCellType:ProfileTableViewCellTypeInformation];
- }
- else if (indexPath.row == 4) {
- //App Version
- [cell setProfileTableViewCellType:ProfileTableViewCellTypeAppVersion];
- }
- }
- else if (self.profileView.profileViewType == ProfileViewTypeUser) {
- if(indexPath.row == 1) {
- //Help
- [cell setProfileTableViewCellType:ProfileTableViewCellTypeHelp];
- }
- else if(indexPath.row == 2) {
- //About Us
- [cell setProfileTableViewCellType:ProfileTableViewCellTypeInformation];
- }
- else if (indexPath.row == 3) {
- //App Version
- [cell setProfileTableViewCellType:ProfileTableViewCellTypeAppVersion];
- }
- }
- return cell;
- }
- //END V1 Temporary Hidden
- }
- #pragma mark - Delegate
- #pragma mark UITableView
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
- if(self.profileView.profileViewType == ProfileViewTypeExpert) {
- if(indexPath.row == 1) {
- //Expert Setting
- ExpertSettingViewController *expertSettingViewController = [[ExpertSettingViewController alloc] init];
- expertSettingViewController.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:expertSettingViewController animated:YES];
- }
- else if(indexPath.row == 2) {
- //Help
- HelpViewController *helpViewController = [[HelpViewController alloc] init];
- helpViewController.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:helpViewController animated:YES];
- }
- else if(indexPath.row == 3) {
- //About Us
- WebViewViewController *viewController = [[WebViewViewController alloc] init];
- [viewController setWebViewViewControllerType:WebViewViewControllerTypeAboutUs];
- [viewController setWebViewViewControllerHeightType:WebViewViewControllerTypeWithNavigation];
- [self.navigationController pushViewController:viewController animated:YES];
- }
- else if(indexPath.row == 4) {
- //AS TEMP to show Linked Account UI
- LinkedAccountViewController *linkedAccountViewController = [[LinkedAccountViewController alloc] init];
- linkedAccountViewController.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:linkedAccountViewController animated:YES];
- //END TEMP
- }
- }
- else if (self.profileView.profileViewType == ProfileViewTypeUser) {
- if(indexPath.row == 1) {
- //Help
- HelpViewController *helpViewController = [[HelpViewController alloc] init];
- helpViewController.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:helpViewController animated:YES];
- }
- else if(indexPath.row == 2) {
- //About Us
- WebViewViewController *viewController = [[WebViewViewController alloc] init];
- [viewController setWebViewViewControllerType:WebViewViewControllerTypeAboutUs];
- [viewController setWebViewViewControllerHeightType:WebViewViewControllerTypeWithNavigation];
- [self.navigationController pushViewController:viewController animated:YES];
- }
- //AS TEMP to show Linked Account UI
- else if(indexPath.row == 3) {
- //LinkedAccount
- LinkedAccountViewController *linkedAccountController = [[LinkedAccountViewController alloc] init];
- linkedAccountController.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:linkedAccountController animated:YES];
- }
- //END TEMP
- }
- }
- //6.Implement Delegate
- #pragma mark ProfileHeaderTableViewCell
- - (void)profileHeaderTableViewCellResizeViewWithTotalHeight:(CGFloat)height {
- if(!self.isCellHeightUpdated) {
- self.isCellHeightUpdated = YES;
- self.newCellHeight = height;
- [self.profileView.tableView reloadData];
- }
- }
- - (void)profileHeaderTableViewDidTappedEditProfileButton {
- UserProfileSettingViewController *userProfileSettingViewController = [[UserProfileSettingViewController alloc] init];
- userProfileSettingViewController.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:userProfileSettingViewController animated:YES];
- }
- - (void)profileHeaderTableViewDidTappedPreviewProfileButton {
- //not yet implement
- NSLog(@"PreviewProfileButton pressed!");
- }
- #pragma mark - Custom Method
- - (void)applyNowButtonDidTapped {
- WebViewViewController *viewController = [[WebViewViewController alloc] init];
- [viewController setWebViewViewControllerType:WebViewViewControllerTypeApplyExpert];
- [viewController setWebViewViewControllerHeightType:WebViewViewControllerTypeWithoutNavigation];
- [self presentViewController:viewController animated:YES completion:nil];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement