From e77ad93331d92b195e4f604554bd84449c00c5d0 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Fri, 6 Oct 2017 10:49:21 +0200 Subject: [PATCH] better text fiel management --- ...ionCreateConfirmCollectionViewController.h | 12 +++++++ ...ionCreateConfirmCollectionViewController.m | 30 ++++++++++++++++ Classes/ChatConversationCreateConfirmView.h | 4 +++ Classes/ChatConversationCreateConfirmView.m | 34 +++++++++++++++++-- Classes/ChatConversationCreateConfirmView.xib | 1 + Classes/ChatConversationCreateView.m | 9 ++--- linphone.xcodeproj/project.pbxproj | 6 ++++ 7 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 Classes/ChatConversationCreateConfirmCollectionViewController.h create mode 100644 Classes/ChatConversationCreateConfirmCollectionViewController.m diff --git a/Classes/ChatConversationCreateConfirmCollectionViewController.h b/Classes/ChatConversationCreateConfirmCollectionViewController.h new file mode 100644 index 000000000..35a61034b --- /dev/null +++ b/Classes/ChatConversationCreateConfirmCollectionViewController.h @@ -0,0 +1,12 @@ +// +// ChatConversationCreateConfirmCollectionViewController.h +// linphone +// +// Created by REIS Benjamin on 05/10/2017. +// + +#import + +@interface ChatConversationCreateConfirmCollectionViewController : UICollectionViewController + +@end diff --git a/Classes/ChatConversationCreateConfirmCollectionViewController.m b/Classes/ChatConversationCreateConfirmCollectionViewController.m new file mode 100644 index 000000000..0a1457ab9 --- /dev/null +++ b/Classes/ChatConversationCreateConfirmCollectionViewController.m @@ -0,0 +1,30 @@ +// +// ChatConversationCreateConfirmCollectionViewController.m +// linphone +// +// Created by REIS Benjamin on 05/10/2017. +// + +#import "ChatConversationCreateConfirmCollectionViewController.h" +#import "UIChatCreateConfirmCollectionViewCell.h" + +@interface ChatConversationCreateConfirmCollectionViewController () + +@end + +@implementation ChatConversationCreateConfirmCollectionViewController + +static NSString * const reuseIdentifier = @"Cell"; + +- (void)viewDidLoad { + [super viewDidLoad]; + + // Register cell classes + [self.collectionView registerClass:[UIChatCreateConfirmCollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier]; +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; +} + +@end diff --git a/Classes/ChatConversationCreateConfirmView.h b/Classes/ChatConversationCreateConfirmView.h index 672a72126..e3f2ebbda 100644 --- a/Classes/ChatConversationCreateConfirmView.h +++ b/Classes/ChatConversationCreateConfirmView.h @@ -7,11 +7,15 @@ #import #import "UICompositeView.h" +#import "ChatConversationCreateConfirmCollectionViewController.h" @interface ChatConversationCreateConfirmView : UIViewController @property (weak, nonatomic) IBOutlet UITextField *nameField; @property (weak, nonatomic) IBOutlet UIIconButton *validateButton; @property(nonatomic, strong) NSMutableDictionary *contacts; +@property(nonatomic, strong) NSMutableArray *contactsGroup; +@property (weak, nonatomic) IBOutlet UICollectionView *collectionView; +@property(strong, nonatomic) IBOutlet ChatConversationCreateConfirmCollectionViewController *collectionController; - (IBAction)onBackClick:(id)sender; - (IBAction)onValidateClick:(id)sender; diff --git a/Classes/ChatConversationCreateConfirmView.m b/Classes/ChatConversationCreateConfirmView.m index 49422cc43..0db723fb0 100644 --- a/Classes/ChatConversationCreateConfirmView.m +++ b/Classes/ChatConversationCreateConfirmView.m @@ -32,12 +32,34 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)viewDidLoad { [super viewDidLoad]; + _contactsGroup = [[NSMutableArray alloc] init]; _nameField.delegate = self; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboards)]; tap.delegate = self; [self.view addGestureRecognizer:tap]; + UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; + layout.scrollDirection = UICollectionViewScrollDirectionVertical; + layout.itemSize = CGSizeMake(100.0 , 50.0); + _collectionController.collectionView = _collectionView; + _collectionController = (ChatConversationCreateConfirmCollectionViewController *)[[UICollectionViewController alloc] initWithCollectionViewLayout:layout]; + _collectionView.dataSource = self; + [_collectionView setCollectionViewLayout:layout]; +} + +- (void) viewWillAppear:(BOOL)animated { + for(id uri in _contacts.allKeys) { + [_collectionController.collectionView registerClass:UIChatCreateConfirmCollectionViewCell.class forCellWithReuseIdentifier:uri]; + if(![_contactsGroup containsObject:_contacts[uri]]) + [_contactsGroup addObject:_contacts[uri]]; + } + [_collectionView reloadData]; +} + +- (void)viewWillDisappear:(BOOL)animated { + [_contactsGroup removeAllObjects]; + [_contacts removeAllObjects]; } - (void)dismissKeyboards { @@ -51,12 +73,14 @@ static UICompositeViewDescription *compositeDescription = nil; } - (IBAction)onValidateClick:(id)sender { + [_collectionView reloadData]; } #pragma mark - UITextFieldDelegate -- (void)textFieldDidEndEditing:(UITextField *)textField { - _validateButton.enabled = (textField.text.length > 0 && textField.text != nil && ![textField.text isEqual:@""]); +- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { + _validateButton.enabled = !((string.length == 0 || string == nil || [string isEqual:@""]) && (textField.text.length == 1)); + return TRUE; } #pragma mark - UICollectionViewDataSource @@ -70,7 +94,11 @@ static UICompositeViewDescription *compositeDescription = nil; } - (UIChatCreateConfirmCollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { - return NULL; + NSString *uri = _contactsGroup[indexPath.item]; + UIChatCreateConfirmCollectionViewCell *cell = (UIChatCreateConfirmCollectionViewCell *)[_collectionView dequeueReusableCellWithReuseIdentifier:uri forIndexPath:indexPath]; + cell.uri = uri; + cell = [cell initWithName:_contacts[uri]]; + return cell; } @end diff --git a/Classes/ChatConversationCreateConfirmView.xib b/Classes/ChatConversationCreateConfirmView.xib index b90acb577..1354e1f32 100644 --- a/Classes/ChatConversationCreateConfirmView.xib +++ b/Classes/ChatConversationCreateConfirmView.xib @@ -11,6 +11,7 @@ + diff --git a/Classes/ChatConversationCreateView.m b/Classes/ChatConversationCreateView.m index d670e7458..4e68af554 100644 --- a/Classes/ChatConversationCreateView.m +++ b/Classes/ChatConversationCreateView.m @@ -76,6 +76,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (IBAction)onNextClick:(id)sender { ChatConversationCreateConfirmView *view = VIEW(ChatConversationCreateConfirmView); + view.contacts = _tableController.contactsDict; [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; } @@ -132,11 +133,11 @@ typedef enum { ContactsAll, ContactsLinphone, ContactsMAX } ContactsCategory; } - (UIChatCreateCollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { - NSString *name = _tableController.contactsGroup[indexPath.item]; - UIChatCreateCollectionViewCell *cell = (UIChatCreateCollectionViewCell *)[_collectionView dequeueReusableCellWithReuseIdentifier:name forIndexPath:indexPath]; + NSString *uri = _tableController.contactsGroup[indexPath.item]; + UIChatCreateCollectionViewCell *cell = (UIChatCreateCollectionViewCell *)[_collectionView dequeueReusableCellWithReuseIdentifier:uri forIndexPath:indexPath]; cell.controller = self; - cell.uri = name; - cell = [cell initWithName:_tableController.contactsDict[name]]; + cell.uri = uri; + cell = [cell initWithName:_tableController.contactsDict[uri]]; return cell; } diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index ea09687e4..09a9b4917 100755 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -689,6 +689,7 @@ 8CB2B8FA1F86229E0015CEE2 /* next_disabled.png in Resources */ = {isa = PBXBuildFile; fileRef = 8CB2B8F71F86229C0015CEE2 /* next_disabled.png */; }; 8CB2B8FB1F86229E0015CEE2 /* next_disabled@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 8CB2B8F81F86229D0015CEE2 /* next_disabled@2x.png */; }; 8CD3F5AC1F86632100680C98 /* UIChatCreateConfirmCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 8CD3F5AB1F86632100680C98 /* UIChatCreateConfirmCollectionViewCell.m */; }; + 8CD3F5B71F867A1400680C98 /* ChatConversationCreateConfirmCollectionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8CD3F5B61F867A1400680C98 /* ChatConversationCreateConfirmCollectionViewController.m */; }; 8CDC61951F84D89B0087CF7F /* check_selected.png in Resources */ = {isa = PBXBuildFile; fileRef = 8CDC618C1F84D89B0087CF7F /* check_selected.png */; }; 8CDC61971F84D9270087CF7F /* check_selected@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 8CDC61961F84D9270087CF7F /* check_selected@2x.png */; }; 8CDC619A1F84EAC10087CF7F /* ChatConversationCreateConfirmView.m in Sources */ = {isa = PBXBuildFile; fileRef = 8CDC61991F84EAC10087CF7F /* ChatConversationCreateConfirmView.m */; }; @@ -1701,6 +1702,8 @@ 8CB2B8F81F86229D0015CEE2 /* next_disabled@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "next_disabled@2x.png"; sourceTree = ""; }; 8CD3F5AA1F86632100680C98 /* UIChatCreateConfirmCollectionViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIChatCreateConfirmCollectionViewCell.h; sourceTree = ""; }; 8CD3F5AB1F86632100680C98 /* UIChatCreateConfirmCollectionViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UIChatCreateConfirmCollectionViewCell.m; sourceTree = ""; }; + 8CD3F5B51F867A1400680C98 /* ChatConversationCreateConfirmCollectionViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ChatConversationCreateConfirmCollectionViewController.h; sourceTree = ""; }; + 8CD3F5B61F867A1400680C98 /* ChatConversationCreateConfirmCollectionViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ChatConversationCreateConfirmCollectionViewController.m; sourceTree = ""; }; 8CDC618C1F84D89B0087CF7F /* check_selected.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = check_selected.png; path = "../../../ressources 27.07.17/check_selected.png"; sourceTree = ""; }; 8CDC61961F84D9270087CF7F /* check_selected@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "check_selected@2x.png"; path = "../../../ressources 27.07.17/check_selected@2x.png"; sourceTree = ""; }; 8CDC61981F84EAC10087CF7F /* ChatConversationCreateConfirmView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ChatConversationCreateConfirmView.h; sourceTree = ""; }; @@ -2038,6 +2041,8 @@ 6336715E1BCBAAD200BFCBDE /* ChatConversationCreateView.h */, 6336715F1BCBAAD200BFCBDE /* ChatConversationCreateView.m */, 63B8D68E1BCBE65600C12B09 /* ChatConversationCreateView.xib */, + 8CD3F5B51F867A1400680C98 /* ChatConversationCreateConfirmCollectionViewController.h */, + 8CD3F5B61F867A1400680C98 /* ChatConversationCreateConfirmCollectionViewController.m */, 8CDC61981F84EAC10087CF7F /* ChatConversationCreateConfirmView.h */, 8CDC61991F84EAC10087CF7F /* ChatConversationCreateConfirmView.m */, 8CDC619B1F84EAFD0087CF7F /* ChatConversationCreateConfirmView.xib */, @@ -4045,6 +4050,7 @@ D3807FF815C2894A005BE9BC /* IASKPSSliderSpecifierViewCell.m in Sources */, D3807FFA15C2894A005BE9BC /* IASKPSTextFieldSpecifierViewCell.m in Sources */, D3807FFC15C2894A005BE9BC /* IASKPSTitleValueSpecifierViewCell.m in Sources */, + 8CD3F5B71F867A1400680C98 /* ChatConversationCreateConfirmCollectionViewController.m in Sources */, D3807FFE15C2894A005BE9BC /* IASKSlider.m in Sources */, D380800015C2894A005BE9BC /* IASKSwitch.m in Sources */, D380800215C2894A005BE9BC /* IASKTextField.m in Sources */,