mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 11:08:06 +00:00
start dev
This commit is contained in:
parent
e9252e2cf1
commit
0fc673f941
2 changed files with 31 additions and 32 deletions
|
|
@ -9,10 +9,12 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface ChatConversationCreateTableView : UITableViewController <UISearchBarDelegate>
|
||||
@property(weak, nonatomic) IBOutlet UISearchBar *searchBar;
|
||||
@property(nonatomic) Boolean allFilter;
|
||||
@property(nonatomic) Boolean notFirstTime;
|
||||
@property(nonatomic, strong) NSMutableArray *contactsGroup;
|
||||
@property(nonatomic) LinphoneMagicSearch *magicSearch;
|
||||
|
||||
@property(weak, nonatomic) IBOutlet UISearchBar *searchBar;
|
||||
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
|
||||
@property (weak, nonatomic) IBOutlet UIIconButton *controllerNextButton;
|
||||
@property (weak, nonatomic) IBOutlet UIView *waitView;
|
||||
|
|
|
|||
|
|
@ -23,15 +23,6 @@
|
|||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
[super viewWillAppear:animated];
|
||||
_allContacts = [[NSMutableDictionary alloc] initWithDictionary:LinphoneManager.instance.fastAddressBook.addressBookMap];
|
||||
_sortedAddresses = [[LinphoneManager.instance.fastAddressBook.addressBookMap allKeys] sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
|
||||
Contact* first = [_allContacts objectForKey:a];
|
||||
Contact* second = [_allContacts objectForKey:b];
|
||||
if([[first.firstName lowercaseString] compare:[second.firstName lowercaseString]] == NSOrderedSame)
|
||||
return [[first.lastName lowercaseString] compare:[second.lastName lowercaseString]];
|
||||
else
|
||||
return [[first.firstName lowercaseString] compare:[second.firstName lowercaseString]];
|
||||
}];
|
||||
|
||||
int y = _contactsGroup.count > 0
|
||||
? _collectionView.frame.origin.y + _collectionView.frame.size.height
|
||||
|
|
@ -47,7 +38,7 @@
|
|||
}
|
||||
completion:nil];
|
||||
|
||||
_addresses = [[NSMutableArray alloc] initWithCapacity:_sortedAddresses.count];
|
||||
_addresses = [[NSMutableArray alloc] initWithCapacity:LinphoneManager.instance.fastAddressBook.addressBookMap.allKeys.count];
|
||||
if(_notFirstTime) {
|
||||
for(NSString *addr in _contactsGroup) {
|
||||
[_collectionView registerClass:UIChatCreateCollectionViewCell.class forCellWithReuseIdentifier:addr];
|
||||
|
|
@ -59,10 +50,13 @@
|
|||
[_searchBar setText:@""];
|
||||
[self searchBar:_searchBar textDidChange:_searchBar.text];
|
||||
self.tableView.accessibilityIdentifier = @"Suggested addresses";
|
||||
_magicSearch = linphone_core_create_magic_search(LC);
|
||||
}
|
||||
|
||||
- (void) viewWillDisappear:(BOOL)animated {
|
||||
_notFirstTime = FALSE;
|
||||
linphone_magic_search_unref(_magicSearch);
|
||||
_magicSearch = NULL;
|
||||
}
|
||||
|
||||
- (void) loadData {
|
||||
|
|
@ -72,34 +66,33 @@
|
|||
- (void)reloadDataWithFilter:(NSString *)filter {
|
||||
[_addresses removeAllObjects];
|
||||
|
||||
for (NSString* key in _sortedAddresses) {
|
||||
Contact *contact = [LinphoneManager.instance.fastAddressBook.addressBookMap objectForKey:key];
|
||||
if (!_magicSearch)
|
||||
return;
|
||||
|
||||
bctbx_list_t *results = linphone_magic_search_get_contact_list_from_filter(_magicSearch, filter.UTF8String, "");
|
||||
|
||||
while (results) {
|
||||
LinphoneSearchResult *result = results->data;
|
||||
const LinphoneAddress* addr = linphone_search_result_get_address(result) ?: linphone_friend_get_address(linphone_search_result_get_friend(result));
|
||||
char *uri = linphone_address_as_string_uri_only(addr);
|
||||
NSString *address = [NSString stringWithUTF8String:uri];
|
||||
ms_free(uri);
|
||||
|
||||
Contact *contact = [LinphoneManager.instance.fastAddressBook.addressBookMap objectForKey:address];
|
||||
NSString *name = [FastAddressBook displayNameForContact:contact];
|
||||
Boolean linphoneContact = [FastAddressBook contactHasValidSipDomain:contact]
|
||||
|| (contact.friend && linphone_presence_model_get_basic_status(linphone_friend_get_presence_model(contact.friend)) == LinphonePresenceBasicStatusOpen);
|
||||
|| (contact.friend && linphone_presence_model_get_basic_status(linphone_friend_get_presence_model(contact.friend)) == LinphonePresenceBasicStatusOpen);
|
||||
BOOL add = _allFilter || linphoneContact;
|
||||
|
||||
if (((filter.length == 0)
|
||||
|| ([name.lowercaseString containsSubstring:filter.lowercaseString])
|
||||
|| ([key.lowercaseString containsSubstring:filter.lowercaseString]))
|
||||
|| ([name.lowercaseString containsSubstring:filter.lowercaseString])
|
||||
|| ([address.lowercaseString containsSubstring:filter.lowercaseString]))
|
||||
&& add)
|
||||
[_addresses addObject:key];
|
||||
[_addresses addObject:address];
|
||||
|
||||
results = results->next;
|
||||
}
|
||||
|
||||
// also add current entry, if not listed
|
||||
NSString *nsuri = filter.lowercaseString;
|
||||
LinphoneAddress *addr = [LinphoneUtils normalizeSipOrPhoneAddress:nsuri];
|
||||
if (addr) {
|
||||
char *uri = linphone_address_as_string(addr);
|
||||
nsuri = [NSString stringWithUTF8String:uri];
|
||||
ms_free(uri);
|
||||
linphone_address_destroy(addr);
|
||||
}
|
||||
|
||||
if (nsuri.length > 0 && ![_addresses containsObject:nsuri])
|
||||
[_addresses addObject:nsuri];
|
||||
|
||||
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
|
||||
|
|
@ -220,8 +213,12 @@
|
|||
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
|
||||
searchBar.showsCancelButton = (searchText.length > 0);
|
||||
[self reloadDataWithFilter:searchText];
|
||||
if ([searchText isEqualToString:@""])
|
||||
if ([searchText isEqualToString:@""]) {
|
||||
if (_magicSearch)
|
||||
linphone_magic_search_reset_search_cache(_magicSearch);
|
||||
|
||||
[_searchBar resignFirstResponder];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue