Skip to content

Commit

Permalink
SHR-60. IOS - Performance issues when search text is deleted in Share…
Browse files Browse the repository at this point in the history
…d items
  • Loading branch information
rgmez committed Mar 24, 2023
1 parent a5e3504 commit 68e4045
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
3 changes: 1 addition & 2 deletions iMEGA/Node/Shared Items/SharedItemsTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ final class SharedItemsTableViewCell: UITableViewCell {

func updateAppearance() {
infoLabel.textColor = UIColor.mnz_subtitles(for: traitCollection)
backgroundColor = UIColor.mnz_tertiaryBackground(traitCollection)
backgroundColor = traitCollection.userInterfaceStyle == .dark ? Colors.General.Black._000000.color : Colors.General.White.ffffff.color
}

}
38 changes: 28 additions & 10 deletions iMEGA/Node/Shared Items/SharedItemsViewController+Search.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,36 @@ extension SharedItemsViewController: UISearchBarDelegate {
tableView?.reloadData()
}

@objc func evaluateSearchResult(nodeArray: [MEGANode]?, error: Error?) {
DispatchQueue.main.async {
if let error {
SVProgressHUD.showError(withStatus: error.localizedDescription)
} else if let nodeArray {
if let mutableNodeArray = (nodeArray as NSArray).mutableCopy() as? NSMutableArray {
self.searchNodesArray = mutableNodeArray
func evaluateSearchResult(searchText: String, sortType: MEGASortOrderType, asyncSearchClosure: @escaping (String, MEGASortOrderType) async throws -> [MEGANode]?) async {
do {
SVProgressHUD.show()
if let nodes = try await asyncSearchClosure(searchText, sortType) {
if let mutableNodeArray = (nodes as NSArray).mutableCopy() as? NSMutableArray {
searchNodesArray = mutableNodeArray
}
} else {
self.searchNodesArray.removeAllObjects()
} else {
searchNodesArray.removeAllObjects()
}
await SVProgressHUD.dismiss()
} catch {
SVProgressHUD.showError(withStatus: error.localizedDescription)
}
self.tableView?.reloadData()
}

@objc func search(by searchText: String) {
guard let searchNodeUseCaseOCWrapper else { return }
Task { @MainActor in
if incomingButton?.isSelected ?? false {
searchUnverifiedNodes(key: searchText)
await evaluateSearchResult(searchText: searchText, sortType: sortOrderType, asyncSearchClosure: searchNodeUseCaseOCWrapper.searchOnInShares)
} else if outgoingButton?.isSelected ?? false {
searchUnverifiedNodes(key: searchText)
await evaluateSearchResult(searchText: searchText, sortType: sortOrderType, asyncSearchClosure: searchNodeUseCaseOCWrapper.searchOnOutShares)
} else if linksButton?.isSelected ?? false {
searchUnverifiedNodesArray.removeAllObjects()
await evaluateSearchResult(searchText: searchText, sortType: sortOrderType, asyncSearchClosure: searchNodeUseCaseOCWrapper.searchOnPublicLinks)
}
self.tableView?.reloadData()
}
}

Expand Down
25 changes: 5 additions & 20 deletions iMEGA/Node/Shared Items/SharedItemsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1106,32 +1106,17 @@ - (void)tableView:(UITableView *)tableView willPerformPreviewActionForMenuWithCo
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController {
NSString *searchString = searchController.searchBar.text;
if (searchController.isActive) {
if ([searchString isEqualToString:@""]) {
if (self.searchController.searchBar.text.length < kMinimumLettersToStartTheSearch) {
if (self.searchNodeUseCaseOCWrapper != nil) {
[self.searchNodeUseCaseOCWrapper cancelSearch];
}
[self loadDefaultSharedItems];
} else {
if (self.searchNodeUseCaseOCWrapper == nil) {
self.searchNodeUseCaseOCWrapper = SearchNodeUseCaseOCWrapper.alloc.init;
}

if (self.incomingButton.selected) {
[self searchUnverifiedNodesWithKey:searchString];
__weak __typeof__(self) weakSelf = self;
[self.searchNodeUseCaseOCWrapper searchOnInSharesWithText:searchString sortType:self.sortOrderType completionHandler:^(NSArray<MEGANode *> * _Nullable nodes, NSError * _Nullable error) {
[weakSelf evaluateSearchResultWithNodeArray:nodes error:error];
}];
} else if (self.outgoingButton.selected) {
[self searchUnverifiedNodesWithKey:searchString];
__weak __typeof__(self) weakSelf = self;
[self.searchNodeUseCaseOCWrapper searchOnOutSharesWithText:searchString sortType:self.sortOrderType completionHandler:^(NSArray<MEGANode *> * _Nullable nodes, NSError * _Nullable error) {
[weakSelf evaluateSearchResultWithNodeArray:nodes error:error];
}];
} else if (self.linksButton.selected) {
[self.searchUnverifiedNodesArray removeAllObjects];
__weak __typeof__(self) weakSelf = self;
[self.searchNodeUseCaseOCWrapper searchOnPublicLinksWithText:searchString sortType:self.sortOrderType completionHandler:^(NSArray<MEGANode *> * _Nullable nodes, NSError * _Nullable error) {
[weakSelf evaluateSearchResultWithNodeArray:nodes error:error];
}];
}
[self searchBy:searchString];
}
} else {
if (self.searchNodeUseCaseOCWrapper != nil) {
Expand Down
3 changes: 2 additions & 1 deletion iMEGA/Utils/SharedItems/SharedItemsUseCaseOCWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import MEGADomain
}

@objc func cancelSearch() {
searchUC.cancelSearch()
searchUC.cancelSearch()
SVProgressHUD.dismiss()
}

private func search(type: SearchNodeTypeEntity, text: String, sortType: MEGASortOrderType) async throws -> [MEGANode]? {
Expand Down

0 comments on commit 68e4045

Please sign in to comment.